From:
Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To:
Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc:
Robert Haas <robertmhaas(at)gmail(dot)com>, Bart Samwel <bart(at)samwel(dot)tk>, Jeroen Vermeulen <jtv(at)xs4all(dot)nl>, pgsql-hackers(at)postgresql(dot)org
Subject:
Re: Avoiding bad prepared-statement plans.
Date:
2010-02-11 16:39:11
Message-ID:
162867791002110839n326bdb0cl3ebc3cb5cdf9d11a@mail.gmail.com (view raw or flat )
Thread:
2010-02-09 12:08:54 from Jeroen Vermeulen <jtv(at)xs4all(dot)nl>
2010-02-09 12:59:15 from Yeb Havinga <yebhavinga(at)gmail(dot)com>
2010-02-09 13:46:55 from Jeroen Vermeulen <jtv(at)xs4all(dot)nl>
2010-02-09 14:53:17 from Mark Mielke <mark(at)mark(dot)mielke(dot)cc>
2010-02-10 00:47:18 from Kris Jurka <books(at)ejurka(dot)com>
2010-02-11 03:12:41 from Bruce Momjian <bruce(at)momjian(dot)us>
2010-02-11 04:07:57 from Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
2010-02-09 22:21:43 from Dimitri Fontaine <dfontaine(at)hi-media(dot)com>
2010-02-09 13:50:32 from Richard Huxton <dev(at)archonet(dot)com>
2010-02-09 14:25:19 from Jeroen Vermeulen <jtv(at)xs4all(dot)nl>
2010-02-09 14:45:57 from Richard Huxton <dev(at)archonet(dot)com>
2010-02-09 14:10:22 from Andres Freund <andres(at)anarazel(dot)de>
2010-02-09 14:28:01 from Jeroen Vermeulen <jtv(at)xs4all(dot)nl>
2010-02-09 16:43:52 from Robert Haas <robertmhaas(at)gmail(dot)com>
2010-02-09 16:59:41 from Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
2010-02-11 03:15:01 from Bruce Momjian <bruce(at)momjian(dot)us>
2010-02-11 06:26:15 from Дмитрий Фефелов <fozzy(at)ac-sw(dot)com>
2010-02-11 12:09:33 from Bart Samwel <bart(at)samwel(dot)tk>
2010-02-11 12:25:28 from Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
2010-02-11 12:39:49 from Bart Samwel <bart(at)samwel(dot)tk>
2010-02-11 12:41:12 from Robert Haas <robertmhaas(at)gmail(dot)com>
2010-02-11 12:48:14 from Bart Samwel <bart(at)samwel(dot)tk>
2010-02-11 13:04:46 from Robert Haas <robertmhaas(at)gmail(dot)com>
2010-02-11 16:17:40 from Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
2010-02-11 16:39:11 from Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
2010-02-15 19:11:34 from Bruce Momjian <bruce(at)momjian(dot)us>
2010-02-15 20:03:21 from Robert Haas <robertmhaas(at)gmail(dot)com>
2010-02-15 20:05:29 from Bruce Momjian <bruce(at)momjian(dot)us>
2010-02-16 14:28:57 from Greg Stark <gsstark(at)mit(dot)edu>
2010-02-16 14:31:44 from Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
2010-02-16 20:17:32 from Bruce Momjian <bruce(at)momjian(dot)us>
2010-02-17 03:12:50 from Greg Stark <gsstark(at)mit(dot)edu>
2010-02-15 19:51:26 from Jeroen Vermeulen <jtv(at)xs4all(dot)nl>
2010-02-16 14:22:00 from Greg Stark <gsstark(at)mit(dot)edu>
2010-02-17 22:52:14 from Jeroen Vermeulen <jtv(at)xs4all(dot)nl>
2010-02-21 12:37:50 from Robert Haas <robertmhaas(at)gmail(dot)com>
2010-02-26 02:48:05 from Jeroen Vermeulen <jtv(at)xs4all(dot)nl>
2010-02-26 03:19:21 from Robert Haas <robertmhaas(at)gmail(dot)com>
2010-02-26 03:40:35 from Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
2010-02-26 04:01:14 from Robert Haas <robertmhaas(at)gmail(dot)com>
2010-02-26 04:25:46 from Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
2010-02-28 14:12:32 from Greg Stark <gsstark(at)mit(dot)edu>
2010-02-26 04:28:14 from Alex Hunsaker <badalex(at)gmail(dot)com>
2010-02-26 04:46:20 from Alex Hunsaker <badalex(at)gmail(dot)com>
2010-02-26 05:11:56 from Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
2010-02-26 06:29:41 from Alex Hunsaker <badalex(at)gmail(dot)com>
2010-02-26 15:07:00 from Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
2010-02-26 15:27:30 from Alex Hunsaker <badalex(at)gmail(dot)com>
2010-02-26 16:51:53 from Robert Haas <robertmhaas(at)gmail(dot)com>
2010-02-26 18:11:44 from Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
2010-02-26 16:50:37 from Robert Haas <robertmhaas(at)gmail(dot)com>
2010-02-26 20:02:40 from Alex Hunsaker <badalex(at)gmail(dot)com>
2010-02-26 08:13:31 from Mark Mielke <mark(at)mark(dot)mielke(dot)cc>
2010-02-26 10:20:17 from Jeroen Vermeulen <jtv(at)xs4all(dot)nl>
2010-02-26 14:49:35 from Mark Mielke <mark(at)mark(dot)mielke(dot)cc>
2010-02-26 16:27:11 from Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
2010-02-26 16:54:10 from Robert Haas <robertmhaas(at)gmail(dot)com>
2010-02-26 17:01:59 from Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
2010-02-26 20:11:16 from Yeb Havinga <yebhavinga(at)gmail(dot)com>
2010-02-26 20:29:11 from Mark Mielke <mark(at)mark(dot)mielke(dot)cc>
2010-02-26 20:46:27 from Yeb Havinga <yebhavinga(at)gmail(dot)com>
2010-02-26 22:40:06 from Robert Haas <robertmhaas(at)gmail(dot)com>
2010-02-27 00:03:06 from Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
2010-02-27 00:50:11 from Mark Mielke <mark(at)mark(dot)mielke(dot)cc>
2010-02-28 01:01:43 from Robert Haas <robertmhaas(at)gmail(dot)com>
2010-02-28 04:22:00 from Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
2010-03-01 02:47:38 from Robert Haas <robertmhaas(at)gmail(dot)com>
2010-02-26 18:53:38 from Mark Mielke <mark(at)mark(dot)mielke(dot)cc>
2010-02-26 18:59:22 from Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
2010-02-26 19:22:37 from Mark Mielke <mark(at)mark(dot)mielke(dot)cc>
2010-02-26 19:57:56 from Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
2010-02-26 20:26:05 from Mark Mielke <mark(at)mark(dot)mielke(dot)cc>
2010-02-26 20:47:55 from Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
2010-02-26 19:23:22 from Mark Mielke <mark(at)mark(dot)mielke(dot)cc>
2010-03-01 11:18:01 from Yeb Havinga <yebhavinga(at)gmail(dot)com>
2010-02-28 04:20:38 from Craig Ringer <craig(at)postnewspapers(dot)com(dot)au>
2010-02-28 07:52:55 from Mark Mielke <mark(at)mark(dot)mielke(dot)cc>
2010-03-01 02:51:14 from Robert Haas <robertmhaas(at)gmail(dot)com>
2010-03-02 23:54:28 from Bruce Momjian <bruce(at)momjian(dot)us>
2010-03-03 05:13:46 from Robert Haas <robertmhaas(at)gmail(dot)com>
2010-02-28 08:18:26 from Dimitri Fontaine <dfontaine(at)hi-media(dot)com>
2010-03-02 23:53:56 from Bruce Momjian <bruce(at)momjian(dot)us>
2010-02-18 14:58:25 from "Pierre C" <lists(at)peufeu(dot)com>
2010-02-18 15:09:42 from Dimitri Fontaine <dfontaine(at)hi-media(dot)com>
2010-02-18 16:47:01 from "Pierre C" <lists(at)peufeu(dot)com>
2010-02-18 16:54:31 from Dimitri Fontaine <dfontaine(at)hi-media(dot)com>
2010-02-18 20:19:21 from "Pierre C" <lists(at)peufeu(dot)com>
2010-02-19 02:31:05 from David Christensen <david(at)endpoint(dot)com>
2010-02-19 13:57:51 from Kenneth Marshall <ktm(at)rice(dot)edu>
2010-02-19 17:56:12 from Dimitri Fontaine <dfontaine(at)hi-media(dot)com>
2010-02-11 13:41:02 from Yeb Havinga <yebhavinga(at)gmail(dot)com>
Lists:
pgsql-hackers
2010/2/11 Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>:
> Robert Haas <robertmhaas(at)gmail(dot)com> writes:
>> On Thu, Feb 11, 2010 at 7:48 AM, Bart Samwel <bart(at)samwel(dot)tk> wrote:
>>> Because that's the
>>> underlying assumption of the "ratio" criterion -- that re-planning with
>>> filled-in parameters takes about as much time as the initial planning run
>>> took.
>
>> We only want to replan when replanning is relatively cheap compared to
>> execution,
>
> Well, no, consider the situation where planning takes 50 ms, the generic
> plan costs 100ms to execute, but a parameter-specific plan would take 1ms
> to execute. Planning is very expensive compared to execution but it's
> still a win to do it.
>
> The problem that we face is that we don't have any very good way to tell
> whether a fresh planning attempt is likely to yield a plan significantly
> better than the generic plan. I can think of some heuristics --- for
> example if the query contains LIKE with a parameterized pattern or a
> partitioned table --- but that doesn't seem like a particularly nice
> road to travel.
>
> A possible scheme is to try it and keep track of whether we ever
> actually do get a better plan. If, after N attempts, none of the custom
> plans were ever more than X% cheaper than the generic one, then give up
> and stop attempting to produce custom plans. Tuning the variables might
> be challenging though.
I afraid so every heuristic is bad. Problem is identification of bad
generic plan. And nobody ensure, so non generic plan will be better
than generic. Still I thing we need some way for lazy prepared
statements - plan is generated everytime with known parameters.
Other idea: some special debug/test mod, where pg store generic plan
for every prepared statement, and still generate specific plan. When
the prices are different, then pg produces a warning. This can be
slower, but can identify problematic queries. It could be implemented
as contrib module - some like autoexplain.
regards
Pavel
>
> regards, tom lane
>
In response to
Responses
pgsql-hackers by date
Next :From: Alexey KlyukinDate: 2010-02-11 16:41:14
Subject : Re: a common place for pl/perlu modules
Previous :From : Dimitri FontaineDate : 2010-02-11 16:38:19
Subject : Re: TCP keepalive support for libpq