pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: clinton.adams@gmail.com
To: pgsql-bugs@postgresql.org
Subject: BUG #14404: High row estimates when query uses master inherited tables
Date: Fri, 28 Oct 2016 20:04:12 +0000
Message-ID: <20161028200412.15987.96482@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:      14404
Logged by:          Clinton Adams
Email address:      clinton.adams@gmail.com
PostgreSQL version: 9.6.1
Operating system:   centos 7, 4.3.0-1.el7.elrepo.x86_64 #1 SMP Tue Nov
Description:        

Row estimates are way off (406484054678631 vs 38) when using master
partition tables. If I change the query to go directly against one child
table, estimates and query time are in line with what I expect.

Issue occurs on 9.6.1, all tables analyzed. Row counts per child table
(sensorcore8, coredetail8, etc) are 126340588 each.

Issue does not occur on 9.4.6 (do not have 9.5 handy to test atm).

--
-- Plan with high estimate
--
EXPLAIN
SELECT core.sensorcoreid
   FROM sensor.sensorcore core                                              
                                                                        
     JOIN sensor.coredetail cored ON cored.typeid = core.typeid AND
cored.sensorcoreid = core.sensorcoreid
     JOIN sensor.corefilldetail corefd ON corefd.typeid = core.typeid AND
corefd.sensorcoreid = core.sensorcoreid
  WHERE
core.typeid = 8 AND core.sensorid = 1814821;
                                                            QUERY PLAN      
                                                     
-----------------------------------------------------------------------------------------------------------------------------------
 Merge Join  (cost=5.62..57175008.37 rows=406484054678631 width=4)
   Merge Cond: (corefd.sensorcoreid = cored.sensorcoreid)
   ->  Merge Append  (cost=2.81..28268953.91 rows=126340593 width=8)
         Sort Key: corefd.sensorcoreid
         ->  Index Scan using ix_corefilldetail on corefilldetail corefd 
(cost=0.50..3.59 rows=1 width=8)
               Filter: (typeid = 8)
         ->  Index Scan using ix_corefilldetail8 on corefilldetail8 corefd_1
 (cost=2.27..21951920.63 rows=126340592 width=8)
               Filter: (typeid = 8)
   ->  Materialize  (cost=2.81..16349690.36 rows=125477313 width=12)
         ->  Nested Loop  (cost=2.81..15094917.23 rows=125477313 width=12)
               ->  Merge Append  (cost=2.81..15094701.36 rows=39 width=8)
                     Sort Key: core.sensorcoreid
                     ->  Index Scan using pk_sensorcore on sensorcore core 
(cost=0.50..3.60 rows=1 width=8)
                           Filter: ((typeid = 8) AND (sensorid = 1814821))
                     ->  Index Scan using sensor_sensorcore8_pkey on
sensorcore8 core_1  (cost=2.27..15094695.77 rows=38 width=8)
                           Filter: ((typeid = 8) AND (sensorid = 1814821))
               ->  Append  (cost=0.00..5.38 rows=2 width=8)
                     ->  Seq Scan on coredetail cored  (cost=0.00..0.00
rows=1 width=8)
                           Filter: ((typeid = 8) AND (core.sensorcoreid =
sensorcoreid))
                     ->  Index Scan using ix_coredetail8 on coredetail8
cored_1  (cost=2.27..5.38 rows=1 width=8)
                           Index Cond: (sensorcoreid = core.sensorcoreid)
                           Filter: (typeid = 8)


--
-- Plan using child partition
--
EXPLAIN
SELECT core.sensorcoreid
   FROM sensor.sensorcore8 core
     JOIN sensor.coredetail cored ON cored.typeid = core.typeid AND
cored.sensorcoreid = core.sensorcoreid
     JOIN sensor.corefilldetail corefd ON corefd.typeid = core.typeid AND
corefd.sensorcoreid = core.sensorcoreid
  WHERE
core.typeid = 8 AND core.sensorid = 1814821;
                                                                  QUERY PLAN
                                                                
----------------------------------------------------------------------------------------------------------------------------------------------
 Nested Loop  (cost=2.27..415.58 rows=38 width=4)
   Join Filter: (core.sensorcoreid = cored.sensorcoreid)
   ->  Nested Loop  (cost=2.27..227.03 rows=38 width=12)
         ->  Index Scan using ix_sensorcore8 on sensorcore8 core 
(cost=2.27..54.20 rows=38 width=8)
               Index Cond: (sensorid = 1814821)
               Filter: (typeid = 8)
         ->  Append  (cost=0.00..4.39 rows=2 width=8)
               ->  Seq Scan on corefilldetail corefd  (cost=0.00..0.00
rows=1 width=8)
                     Filter: ((typeid = 8) AND (core.sensorcoreid =
sensorcoreid))
               ->  Index Only Scan using
corefilldetail8_typeid_sensorcoreid_idx on corefilldetail8 corefd_1 
(cost=2.27..4.39 rows=1 width=8)
                     Index Cond: ((typeid = 8) AND (sensorcoreid =
core.sensorcoreid))
   ->  Append  (cost=0.00..4.78 rows=2 width=8)
         ->  Seq Scan on coredetail cored  (cost=0.00..0.00 rows=1
width=8)
               Filter: ((typeid = 8) AND (corefd.sensorcoreid =
sensorcoreid))
         ->  Index Scan using ix_coredetail8 on coredetail8 cored_1 
(cost=2.27..4.78 rows=1 width=8)
               Index Cond: (sensorcoreid = corefd.sensorcoreid)
               Filter: (typeid = 8)



-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs


view thread (5+ messages)  latest in thread

Message-ID: <20161028200412.15987.96482@wrigleys.postgresql.org>
Permalink:  ../20161028200412.15987.96482@wrigleys.postgresql.org/
Also on:    postgresql.org/message-id/20161028200412.15987.96482@wrigleys.postgresql.org

 · 

reply

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: clinton.adams@gmail.com
  Subject: Re: BUG #14404: High row estimates when query uses master inherited tables
  In-Reply-To: <20161028200412.15987.96482@wrigleys.postgresql.org>
  References: <20161028200412.15987.96482@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