Re: Cached Query Plans (was: global prepared statements)

From: Heikki Linnakangas <heikki(at)enterprisedb(dot)com>
To: Csaba Nagy <nagy(at)ecircle-ag(dot)com>
Cc: PFC <lists(at)peufeu(dot)com>, Dawid Kuroczko <qnex42(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Cached Query Plans (was: global prepared statements)
Date: 2008-04-14 13:54:10
Message-ID: 48036202.7060603@enterprisedb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Csaba Nagy wrote:
> If cached plans would be implemented, the dependence on parameter values
> could be solved too: use special "fork" nodes in the plan which execute
> different sub-plans depending on special parameter values/ranges,
> possibly looking up the stats at runtime, so that the plan is in a
> compiled state with the "decision points" wired in.

That's an idea I've been thinking about for a long time, but never got
around implementing. I see that as a completely orthogonal feature to
the server-side shared plan cache, though. There's plenty of scenarios,
like with client-side prepared statement cache, where it would be useful.

Figuring out the optimal "decision points" is hard, and potentially very
expensive. There is one pretty simple scenario though: enabling the use
of partial indexes, preparing one plan where a partial index can be
used, and another one where it can't. Another such case is "col LIKE ?"
queries, where ? is actually a prefix query, "foo%".

As an optimization, we could decide the decision points on the prepare
message, and delay actually planning the queries until they're needed.
That way we wouldn't waste time planning queries for combinations of
parameters that are never used.

--
Heikki Linnakangas
EnterpriseDB http://www.enterprisedb.com

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Heikki Linnakangas 2008-04-14 14:08:31 Re: Index AM change proposals, redux
Previous Message Bruce Momjian 2008-04-14 13:36:58 Re: Cached Query Plans (was: global prepared statements)