Re: Prepared statements considered harmful

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: "Jeroen T(dot) Vermeulen" <jtv(at)xs4all(dot)nl>
Cc: Phil Frost <indigo(at)bitglue(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Prepared statements considered harmful
Date: 2006-09-01 09:53:11
Message-ID: 20060901095311.GK12644@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Sep 01, 2006 at 03:56:19PM +0700, Jeroen T. Vermeulen wrote:
> That's a very common thing in processor design as well, and there's a
> standard trick for it: the saturating two-bit counter. It tends to work
> pretty well for branch prediction, value prediction etc. Usually it's the
> first thing you reach for, so of course somebody may already have tried it
> here and found it didn't work.

Interesting thought. It might be worth trying. But my big question: is
all this testing and counting actually going to be faster than just
replanning? Postgresql's planner is not that slow.

> Of course there's a problem when parameters do not match predicted values.
> That's where having one or two backup plans could come in handy. You
> could keep your original, fully-generalized plan around. If plans are
> cheap enough to store, you could try to keep a cache of old plans for the
> same query. The great thing about keeping some backup plans around is
> that a pseudo-constant parameter can have a different value once in a
> while, then flick back to its old habits without invalidating all your
> efforts. Your usually-unused search fields are a good example. You may
> also have two stable parameter patterns with different sets of
> pseudo-constants competing for your attention.

The thing is that number of possible plans is going to be proportional
to factorial(number of tables). Once you have 3 tables you're going to
have at least a dozen possible plans, probably more. What the best plan
is depends strongly on what the parameters are.

Anyway, your plan assumes that you have information to work with. The
current system plans prepared queries with no information at all about
parameters and people are advocating to keep it that way. I think a
good first step would be the plan on first execution, like Oracle does.

Have a nice day,
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message nhrcommu 2006-09-01 10:03:09 Training (from Thought provoking...)
Previous Message Martijn van Oosterhout 2006-09-01 09:03:42 Re: [pgsql-advocacy] Thought provoking piece on