Skip to main content

Postgres is also an option than MySQL

Last month I got a chance to optimize some queries of a postgre sql database in my current organization. I was totally new to this database. SQL Server, mySQL, MongoDB, and now, postgres. I  never say a 'no' if some work related to database comes to me, and especially, if the database belongs to the RDBMS family, then, I can never say a 'no', as I am always keen to learn new and new trends.

My thought for postgres was wrong earlier. I used to think that it is less popular than mySQL, but, I was wrong. When I started working on it, I found it much better mySQL in some scenarios, like - query optimization(using execution plan and statistics).

Technically, Postgres is "better SQL" as it is more standardized. With better query planning, so that you can follow the relational model more closely if it suits you. Socially, MySQL has been very popular for a long time and many people are familiar with it. Postgres is neither owned by a major conglomerate with a questionable track record nor forked into half a dozen broadly similar projects.



Some differences between mySql and Postgres I consolidated from Quora , can be read from the following link :

By the way, Wiki says : PostgreSQL is developed by the PostgreSQL Global Development Group, a diverse group of many companies and individual contributors. It is free and open-source software, released under the terms of the PostgreSQL License, a permissive free-software license. Postgres, is an object-relational database (ORDBMS) – i.e. a RDBMS, with additional "object" features – with an emphasis on extensibility and standards compliance; on macOS, PostgreSQL is the default database – for web hosting and it is also available for Microsoft Windows and Linux. PostgreSQL is ACID-compliant and transactional. PostgreSQL has updatable views and materialized views, triggers, foreign keys. Supports functions and stored procedures, and other expandability.

Postgres execution plan is more detailed and deeper than mysql. See the below execution plan (Explain output) of a query.

Limit  (cost=68.72..68.84 rows=50 width=44)
  ->  Sort  (cost=68.72..69.28 rows=226 width=44)
        Sort Key: tq.TQ
        ->  Hash Left Join  (cost=35.26..61.21 rows=226 width=44)
              Hash Cond: (p.Id = tq.PlayerId)
              ->  Hash Left Join  (cost=26.66..48.37 rows=226 width=40)
                    Hash Cond: (p.Id = f2.PlayerId)
                    Join Filter: (f.FundingLineId = 2)
                    ->  Hash Left Join  (cost=17.85..35.89 rows=226 width=40)
                          Hash Cond: (p.Id = f.PlayerId)
                          ->  Hash Left Join  (cost=8.40..23.33 rows=226 width=32)
                                Hash Cond: (p.CountryId = c.Id)
                                Join Filter: (p.CountryId > 0)
                                ->  Seq Scan on players p  (cost=0.00..11.26 rows=226 width=33)
                                ->  Hash  (cost=5.40..5.40 rows=240 width=7)
                                      ->  Seq Scan on country c  (cost=0.00..5.40 rows=240 width=7)
                          ->  Hash  (cost=6.22..6.22 rows=258 width=12)
                                ->  Seq Scan on funds f  (cost=0.00..6.22 rows=258 width=12)
                                      Filter: (FundingLineId = 1)
                    ->  Hash  (cost=5.58..5.58 rows=258 width=8)
                          ->  Seq Scan on funds f2  (cost=0.00..5.58 rows=258 width=8)
              ->  Hash  (cost=5.49..5.49 rows=249 width=8)
                    ->  Seq Scan on playertq tq  (cost=0.00..5.49 rows=249 width=8)

Online tool to understand execution plan metadata in described … https://explain.depesz.com/

Even postgres admin also given GUI like sql server for understanding there plan.


Thanks for reading

Comments

  1. Thank you so much it is actually a very nice blog written to provide adequate information about Postgre and SQL and its related aspects.

    SSIS Postgresql Write

    ReplyDelete
  2. Thank you for putting up a descriptive post on a very useful aspect of SQL. This actually helped me a lot to understand this topic.

    SSIS PostgreSql Write

    ReplyDelete

Post a Comment

Plz dont forget to like Facebook Page..
https://www.facebook.com/pages/Sql-DBAcoin/523110684456757

Popular posts from this blog

History of MySQL from AB Corp to Cloud Database

MySQL was created by a Swedish company, MySQL AB, founded by David Axmark, Allan Larsson and Michael "Monty" Widenius. Original development of MySQL by Widenius and Axmark began in 1994. The first version of MySQL appeared on 23 May 1995. Its name is a combination of "My", the name of co-founder Michael Widenius's daughter,and "SQL", the abbreviation for Structured Query Language. ·          23 May 1995 - First internal release ·          Year 1996 - Version 3 o     Simple CRUD operations o     January 1997 Windows version was released on 8 January 1998 for Windows 95 and NT o     production release 1998, from www.mysql.com ·          Year 2002 - Version 4 o     MyISAM o     unions o     Tracking o     B-trees o     s...

Configure Impersonation Authentication in IIS8 for MVC Application

Impersonation is when ASP.NET executes code in the context of an authenticated and authorized client. By default, ASP.NET does not use impersonation and instead executes all code using the same user account as the ASP.NET process, which is typically the ASPNET account. There are 5 below steps by which we can establish Impersonation configuration in our secured application environment. 1.)    Creation of Application/Proxy user where Application is hosted. 2.)    Give appropriate access to the user. 3.)    Create Database Login user on database. 4.)    Authenticate User and provide credential on IIS. 5.)    Then Configure web.config on Application.

How to add an article in Transactional Replication

If we have a set-up of Transactional Replication for Data Distribution running and wanting to add new object to replication on other server we can follow below process. To add an article In Transaction replication with PUSH Subscription