Explain Analyze
EXPLAIN and ANALYZE is a PostgreSQL keyword used to see what would actually happen if the query were to be run, this can also be considered as a dry run.
ANALYZE see what strategy would be used to fetch the data and the EXPLAIN command tell us the time it took to run the query
In the output of the above keywords we can see some data which is very helpful for us
- we can check whether the scan was Sequential meaning it went through all the records and Index scan, which is self explanatory meaning the index was used for the search.
- we can also see when the scan was run how may rows were omitted or thrown away
In any Database Constraints > Indexes we can improve the performance by using LIMIT to fetch only the data required and stop a complete Sequential Scan