Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YcztY-0004wY-FZ for pgsql-bugs@arkaria.postgresql.org; Tue, 31 Mar 2015 17:24:08 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YcztX-0004FR-T3 for pgsql-bugs@arkaria.postgresql.org; Tue, 31 Mar 2015 17:24:07 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YcztX-0004FL-6X for pgsql-bugs@postgresql.org; Tue, 31 Mar 2015 17:24:07 +0000 Received: from wrigleys.postgresql.org ([204.145.124.246]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YcztT-0001eG-82 for pgsql-bugs@postgresql.org; Tue, 31 Mar 2015 17:24:06 +0000 MIME-Version: 1.0 Subject: BUG #12933: Custom prepared plan vs partitioning. To: pgsql-bugs@postgresql.org From: maxim.boguk@gmail.com Date: Tue, 31 Mar 2015 17:23:29 +0000 Message-ID: <20150331172329.2563.85270@wrigleys.postgresql.org> X-Pg-Spam-Score: -0.3 (/) Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org 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