From: maxim.boguk@gmail.com
To: pgsql-bugs@postgresql.org
Subject: BUG #12933: Custom prepared plan vs partitioning.
Date: Tue, 31 Mar 2015 17:23:29 +0000
Message-ID: <20150331172329.2563.85270@wrigleys.postgresql.org> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
The following bug has been logged on the website:
Bug reference: 12933
Logged by: Maksym Boguk
Email address: maxim.boguk@gmail.com
PostgreSQL version: 9.2.10
Operating system: Linux
Description:
Hi,
I found case when custom plans with partitioning shows strange behavior.
First 5 repetitions of execute with the same parameters I getting fast
custom plan, on 6th run plan switch to slow generic (all-partitions)
version.
Very simplified test case:
create table parent (id serial);
create table child1 (like parent including all, check (id between 1 and 10))
INHERITS (parent);
create table child2 (like parent including all, check (id between 11 and
20)) INHERITS (parent);
create table child3 (like parent including all, check (id between 21 and
30)) INHERITS (parent);
prepare test(integer) as select * from parent where id=$1 limit 1;
explain execute test(5);
repeat explain 6 times.
first 5 time correct custom plan:
QUERY PLAN
----------------------------------------------------------------------------------
Limit (cost=0.00..10.46 rows=1 width=4)
-> Result (cost=0.00..136.00 rows=13 width=4)
-> Append (cost=0.00..136.00 rows=13 width=4)
-> Seq Scan on parent (cost=0.00..0.00 rows=1 width=4)
Filter: (id = 5)
-> Seq Scan on child1 parent (cost=0.00..136.00 rows=12
width=4)
Filter: (id = 5)
6th and all after - slower generic plan
QUERY PLAN
----------------------------------------------------------------------------------
Limit (cost=0.00..11.03 rows=1 width=4)
-> Result (cost=0.00..408.00 rows=37 width=4)
-> Append (cost=0.00..408.00 rows=37 width=4)
-> Seq Scan on parent (cost=0.00..0.00 rows=1 width=4)
Filter: (id = $1)
-> Seq Scan on child1 parent (cost=0.00..136.00 rows=12
width=4)
Filter: (id = $1)
-> Seq Scan on child2 parent (cost=0.00..136.00 rows=12
width=4)
Filter: (id = $1)
-> Seq Scan on child3 parent (cost=0.00..136.00 rows=12
width=4)
Filter: (id = $1)
Without LIMIT there no such issues happen but with LIMIT it very repeatable
over large range of partitioning structures/query conditions tested.
9.4.1 produce the same behavior.
--
Maxim Boguk
Senior Postgresql DBA
http://www.postgresql-consulting.ru/
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
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-bugs@postgresql.org
Cc: maxim.boguk@gmail.com
Subject: Re: BUG #12933: Custom prepared plan vs partitioning.
In-Reply-To: <20150331172329.2563.85270@wrigleys.postgresql.org>
References: <20150331172329.2563.85270@wrigleys.postgresql.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