I was looking for an option similar to OPTION (FORCE ORDER)
SQL Server, for postgresql and I didn't find anything. Exists? I have used it in SQL Server in large Queries and they go from taking 5min to 0.5sec.
I leave a review for those who do not know what it is for OPTION (FORCE ORDER)
in Sql Server:
When this statement is added to the query, SQL Server is told that when the statement is executed, the order of the JOINs in the query should not change. It will join the tables in the exact order that is specified in the query. Typically, the SQL Server optimizer rearranges the order that it thinks will be optimal for your search.
To use the FORCE ORDER query hint, you will need to add this to the end of the query.
Yes, you can do the same thing in PostgreSQL with the
join_collapse_limit = 1
.You can read about explicit joins (English) , or specifically about join_collapse_limit .
For example: