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

Popular posts from this blog

mongoDB error : aborting after fassert() failure

What to do when facing errors on mongoDB “aborting after fassert() failure”

I like errors, in mongoDB this is the first error I faced and luckily many times. This error i faced during restoring name-space on local and restarting db system. I am still searching the exact root cause of this issue but i am able to resolve the current problem through below steps.

Remove all relevant namespace files from data-file route path..Now repair mongo instance using mongod process.mongod --repair ////////// execute command from bin folder path Then start server using mongd process, if started server successfully then ..mongod  ////////// execute command from bin folder path Restore last backups as normal process.Now check database by connecting mongo shell. Thanks for reading, 
Please comment your experience if you faced and also share knowledge if you have better steps to resolve...


https://www.facebook.com/pages/Sql-DBAcoin/523110684456757

SQL71562: external references are not supported when creating a package from this platform

Last week I got this error from one of developer who was trying to deploy his project from Testing server to SQL Azure QA server. He was using “Deploy Database to SQL Azure” option from SSMS Tool-Task option.

After connecting to SQL Azure portal when operation started to deployment below errors occurs.

Validation of the schema model for data package failed. Error SQL71562: Error validating element xx.xxx.xx:function .dbo.xxx has an unresolved refrence to object xx.dbo.xxxx external refrences are not supported when creating a package from this platform.



Reason: The reason of the this error was; some functions of project was dependent on master database and only single database was being deploy to SQL Azure. DACFx must block Export when object definitions (views, procedures, etc.) contain external references, as Azure SQL Database does not allow cross-database external references So, this error was coming.

Solution : I suggested him to create those function to locally on local database what…

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