| ▲ | SigmundA 12 hours ago | |||||||
>Currently, constraint exclusion is enabled by default only for cases that are often used to implement table partitioning via inheritance trees. Turning it on for all tables imposes extra planning overhead that is quite noticeable on simple queries, and most often will yield no benefit for simple queries. PG's lack of plan caching strikes again, this sort of thing is not a concern in other DB's that reuse query plans. | ||||||||
| ▲ | singron 11 hours ago | parent [-] | |||||||
PG does reuse plans, but only if you prepare a query and run it more than 5 times on that connection. See plan_cache_mode[0] and the PREPARE docs it links to. This works great on simple queries that run all the time. It sometimes really stinks on some queries since the generic plan can't "see" the parameter values anymore. E.g. if you have an index on (customer_id, item_id) and run a query where `customer_id = $1 AND item_id = ANY($2)` ($2 is an array parameter), the generic query plan doesn't know how many elements are in the array and can decide to do an elaborate plan like a bitmap index scan instead of a nested loop join. I've seen the generic plan flip-flop in a situation like this and have a >100x load difference. The plan cache is also per-connection, so you still have to plan a query multiple times. This is another reason why consolidating connections in PG is important. 0: https://www.postgresql.org/docs/current/runtime-config-query... | ||||||||
| ||||||||