From: Thomas Kellerer <spam_eater@gmx.net>
To: pgsql-jdbc@postgresql.org
Subject: Re: Very strange performance decrease when reusing a PreparedStatement
Date: Mon, 04 May 2009 11:03:17 +0200
Message-ID: <gtmb0l$s7p$1@ger.gmane.org> (raw)
In-Reply-To: <49FE24D5.4060904@astrofoto.org>
References: <5C2E1645-73B6-4509-96CD-FA77869516AB@noopsis.fr>
<49F71EDD.2070200@opencloud.com>
<02437794-A78D-449C-843F-B823195F9623@noopsis.fr>
<fdeb32eb0905030122t665113e5nd34e7268d9ab1863@mail.gmail.com>
<491f66a50905030310j5b4cdcd8jbf4f6e757c2ba580@mail.gmail.com>
<fdeb32eb0905030928j4e72f1e3vbecb78d0cb74be58@mail.gmail.com>
<49FDEB97.6050800@astrofoto.org>
<fdeb32eb0905031347o3f92f228ib0b6d62b2c0e0cd5@mail.gmail.com>
<49FE0731.2030403@kickstone.com>
<49FE24D5.4060904@astrofoto.org>
Roland Roberts, 04.05.2009 01:12:
> No, my point was that PostgreSQL is doing the same thing that Oracle is
> doing and in both cases it can bite you. Both are looking at the bind
> variables to come up with a plan but the plan is retained for reuse
> under the assumption that the bind variables will be, statistically at
> least, similar the next time. When that assumption is violated, you get
> stuck with a bad plan. The purpose of my Oracle example was to give a
> concrete example of such a violation.
Oracle 11 has introduced a feature called "Adaptive Cursor Sharing" which tries to solve this problem (Oracle 10 has some tweaks to address that problem manually, but they have their cornerstones as well)
Each time a prepared statement is re-used the optimizer compares the actuals with the stored assumptions (mainly estimated rows vs. actual rows, IIRC). If those figures deviate too much, a new plan is created and used from that point onwards _for that parameter combination_.
So each SQL actually has a map of prepared statements depending on the input parameters. Obviously there is still one statement execution (the first one) that is hit by the bad plan, but all subsequent executions will benefit from the new one.
Might be worth considering for PostgreSQL as well :)
Thomas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: spam_eater@gmx.net
Subject: Re: Very strange performance decrease when reusing a PreparedStatement
In-Reply-To: <gtmb0l$s7p$1@ger.gmane.org>
References: <5C2E1645-73B6-4509-96CD-FA77869516AB@noopsis.fr> <49F71EDD.2070200@opencloud.com> <02437794-A78D-449C-843F-B823195F9623@noopsis.fr> <fdeb32eb0905030122t665113e5nd34e7268d9ab1863@mail.gmail.com> <491f66a50905030310j5b4cdcd8jbf4f6e757c2ba580@mail.gmail.com> <fdeb32eb0905030928j4e72f1e3vbecb78d0cb74be58@mail.gmail.com> <49FDEB97.6050800@astrofoto.org> <fdeb32eb0905031347o3f92f228ib0b6d62b2c0e0cd5@mail.gmail.com> <49FE0731.2030403@kickstone.com> <49FE24D5.4060904@astrofoto.org> <gtmb0l$s7p$1@ger.gmane.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox