I have been trying queries and indexes for two days to find the fastest solution and only today I discover thanks to this answer that using the "analyze $table_name;
" command the EXPLAIN
and then the query changes completely after adding or removing indexes.
My work consists of this:
- use Potgresql 13
- use a database that is as similar as possible to the production ones, both in terms of data type and quantity
- write a query that will be generated and used by the backend language
- try various indices (I am also learning Postgresql in the meantime)
- add one index and try the EXPLAIN
- I still see the
Sequential Scan
despite the new index - so since the index is not used I proceed to understand better and find another solution
- EXCEPT ONLY TODAY I realized that it was enough to use "
analyze $table_name;
" to update the Postgresql query planning
QUESTIONS
Is this something I always have to do?
Can I set it automatically so that after each modification on the indexes or on the structure under development it is automatically analyzed?
Is this analysis performed automatically in production?