pgsql: Account better for planning cost when choosing whether to use cu

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Account better for planning cost when choosing whether to use cu
Date: 2013-08-24 19:14:44
Message-ID: E1VDJIK-0007zm-U1@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/2aac3399aef47e40d688f3eee3f92b6deea2f974

Modified Files
--------------
src/backend/utils/cache/plancache.c | 52 +++++++++++++++++++++++++++++------
1 file changed, 43 insertions(+), 9 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2013-08-24 19:14:45 pgsql: Account better for planning cost when choosing whether to use cu
Previous Message Magnus Hagander 2013-08-24 15:16:28 pgsql: Don't crash when pg_xlog is empty and pg_basebackup -x is used