I am trying to understand why the query planner is being so unoptimal on my DO managed Postgres 16.4. I have installed Postgres 16.4 on my Windows dev machine.
I restored the same database to both, VACUUM ANALYZEd both. Then, I run the same query on both. On DO managed, I get an execution time of 32.182s, but on my Windows machine, 7.282s. Accordingly, the output of EXPLAIN (ANALYZE, BUFFERS) on both machines is very different.
The query is using views and functions, so I'm not sure how relevant it is, unless I was to paste the 500 lines or so unfolding all the views. So, my specific questions:
1- How/why are the two query planners taking such different routes? Since I vaccumed analyzed the fresh pg_restore, I would think both clusters have the same statistics about the tables? Or does VACUUM ANALYZE not force all statistics to refresh? Is it down to the compilation on Linux vs Windows, or is there some configuration parameter I should look at?
2- DO query plan is at https://explain.dalibo.com/plan/e6gd8cde718dafbc. Windows query plan is at https://explain.dalibo.com/plan/gbgb978e5gc2e067. Any advice on getting DO query planner not be stupid and do the thing Windows query planner is doing and get an execution time of 5 seconds rather than 30?
3- While trying to figure out what's wrong, I also see this node, where it says doing an index scan on a table of about 800 rows takes 33s 465ms. Now clearly, that is not literally what is happening. What is happening? What part, what do I look at in the query plan to figure it out?