Re: Prepared statements and suboptimal plans

From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Royce Ausburn <royce(dot)ml(at)inomial(dot)com>
Cc: Craig Ringer <ringerc(at)ringerc(dot)id(dot)au>, pgsql-performance <pgsql-performance(at)postgresql(dot)org>
Subject: Re: Prepared statements and suboptimal plans
Date: 2011-09-21 02:36:15
Message-ID: 20110921023615.GV12765@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

* Royce Ausburn (royce(dot)ml(at)inomial(dot)com) wrote:
> > Tom just mentioned that 9.1 will be able to re-plan parameterized prepared statements, so this issue will go away. In the mean time you can only really use the standard workaround of setting the prepare theshold to 0 to disable server-side prepare, so you can continue to use JDBC prepared statements and have the driver do the parameter substitution for you.
>
> Thanks Craig -- that trick helps a lot.

You might also be able to bump up work_mem by a fair bit to get PG to
use a hashagg instead of groupagg/sort, even though its estimate is way
off. That's what I've done in the past for similar situations and it's
worked well. I'd recommend increasing it for just this query and then
resetting it (assuming you don't just drop the connection, in which case
you don't need to reset it since a new connection will get the default).

Thanks,

Stephen

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Stephen Frost 2011-09-21 02:38:30 Re: Prepared statements and suboptimal plans
Previous Message Tom Lane 2011-09-21 01:00:32 Re: Prepared statements and suboptimal plans