Thread: pgsql-server: When using extended-query protocol, postpone planning of

pgsql-server: When using extended-query protocol, postpone planning of

From
tgl@svr1.postgresql.org (Tom Lane)
Date:
Log Message:
-----------
When using extended-query protocol, postpone planning of unnamed statements
until Bind is received, so that actual parameter values are visible to the
planner.  Make use of the parameter values for estimation purposes (but
don't fold them into the actual plan).  This buys back most of the
potential loss of plan quality that ensues from using out-of-line
parameters instead of putting literal values right into the query text.

This patch creates a notion of constant-folding expressions 'for
estimation purposes only', in which case we can be more aggressive than
the normal eval_const_expressions() logic can be.  Right now the only
difference in behavior is inserting bound values for Params, but it will
be interesting to look at other possibilities.  One that we've seen
come up repeatedly is reducing now() and related functions to current
values, so that queries like ... WHERE timestampcol > now() - '1 day'
have some chance of being planned effectively.

Oliver Jowett, with some kibitzing from Tom Lane.

Modified Files:
--------------
    pgsql-server/doc/src/sgml:
        protocol.sgml (r1.51 -> r1.52)
        (http://developer.postgresql.org/cvsweb.cgi/pgsql-server/doc/src/sgml/protocol.sgml.diff?r1=1.51&r2=1.52)
    pgsql-server/src/backend/commands:
        explain.c (r1.121 -> r1.122)
        (http://developer.postgresql.org/cvsweb.cgi/pgsql-server/src/backend/commands/explain.c.diff?r1=1.121&r2=1.122)
        portalcmds.c (r1.27 -> r1.28)

(http://developer.postgresql.org/cvsweb.cgi/pgsql-server/src/backend/commands/portalcmds.c.diff?r1=1.27&r2=1.28)
        prepare.c (r1.27 -> r1.28)
        (http://developer.postgresql.org/cvsweb.cgi/pgsql-server/src/backend/commands/prepare.c.diff?r1=1.27&r2=1.28)
    pgsql-server/src/backend/executor:
        functions.c (r1.81 -> r1.82)
        (http://developer.postgresql.org/cvsweb.cgi/pgsql-server/src/backend/executor/functions.c.diff?r1=1.81&r2=1.82)
        spi.c (r1.117 -> r1.118)
        (http://developer.postgresql.org/cvsweb.cgi/pgsql-server/src/backend/executor/spi.c.diff?r1=1.117&r2=1.118)
    pgsql-server/src/backend/optimizer/path:
        clausesel.c (r1.67 -> r1.68)

(http://developer.postgresql.org/cvsweb.cgi/pgsql-server/src/backend/optimizer/path/clausesel.c.diff?r1=1.67&r2=1.68)
    pgsql-server/src/backend/optimizer/plan:
        planner.c (r1.171 -> r1.172)

(http://developer.postgresql.org/cvsweb.cgi/pgsql-server/src/backend/optimizer/plan/planner.c.diff?r1=1.171&r2=1.172)
    pgsql-server/src/backend/optimizer/util:
        clauses.c (r1.175 -> r1.176)

(http://developer.postgresql.org/cvsweb.cgi/pgsql-server/src/backend/optimizer/util/clauses.c.diff?r1=1.175&r2=1.176)
    pgsql-server/src/backend/tcop:
        postgres.c (r1.419 -> r1.420)
        (http://developer.postgresql.org/cvsweb.cgi/pgsql-server/src/backend/tcop/postgres.c.diff?r1=1.419&r2=1.420)
    pgsql-server/src/backend/utils/adt:
        selfuncs.c (r1.160 -> r1.161)

(http://developer.postgresql.org/cvsweb.cgi/pgsql-server/src/backend/utils/adt/selfuncs.c.diff?r1=1.160&r2=1.161)
    pgsql-server/src/include/optimizer:
        clauses.h (r1.73 -> r1.74)
        (http://developer.postgresql.org/cvsweb.cgi/pgsql-server/src/include/optimizer/clauses.h.diff?r1=1.73&r2=1.74)
        planner.h (r1.28 -> r1.29)
        (http://developer.postgresql.org/cvsweb.cgi/pgsql-server/src/include/optimizer/planner.h.diff?r1=1.28&r2=1.29)
    pgsql-server/src/include/tcop:
        tcopprot.h (r1.66 -> r1.67)
        (http://developer.postgresql.org/cvsweb.cgi/pgsql-server/src/include/tcop/tcopprot.h.diff?r1=1.66&r2=1.67)