]> granicus.if.org Git - postgresql/commit
Account better for planning cost when choosing whether to use custom plans.
authorTom Lane <tgl@sss.pgh.pa.us>
Sat, 24 Aug 2013 19:14:24 +0000 (15:14 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Sat, 24 Aug 2013 19:14:24 +0000 (15:14 -0400)
commit005f583ba4e6d4d19b62959ef8e70a3da4d188a5
tree987110387553bb68a24bca8fc338ca0883981c7f
parent3979ff1fc6e9dd7847ff9bb24beb4d03ebe02cef
Account better for planning cost when choosing whether to use custom plans.

The previous coding in plancache.c essentially used 10% of the estimated
runtime as its cost estimate for planning.  This can be pretty bogus,
especially when the estimated runtime is very small, such as in a simple
expression plan created by plpgsql, or a simple INSERT ... VALUES.

While we don't have a really good handle on how planning time compares
to runtime, it seems reasonable to use an estimate based on the number of
relations referenced in the query, with a rather large multiplier.  This
patch uses 1000 * cpu_operator_cost * (nrelations + 1), so that even a
trivial query will be charged 1000 * cpu_operator_cost for planning.
This should address the problem reported by Marc Cousin and others that
9.2 and up prefer custom plans in cases where the planning time greatly
exceeds what can be saved.
src/backend/utils/cache/plancache.c