pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: sienkomarcin@gmail.com
To: pgsql-bugs@postgresql.org
Subject: BUG #13816: Query planner strange choose while select/count small part of big table
Date: Mon, 14 Dec 2015 11:29:32 +0000
Message-ID: <20151214112932.2082.71114@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:      13816
Logged by:          Marcin Sieńko
Email address:      sienkomarcin@gmail.com
PostgreSQL version: 9.4.5
Operating system:   Windows 7 x64
Description:        

Hi,

I've check todo list but i can't find exact problem i'm reporting. It seems
like query planner fires not needed sequence scan by all rows in table when
only a few rows were picked. I will explain on example. I have 2 tables with
relation 1 - n. Index on foreign key exist. On n side there are a lot o rows
(about 4 000 000 in my db). When i select/count rows form n table
joined/subselected from 1-side than planner traverse every of 4 000 000 rows
although it has only 3 in "valid from where conditions". Execution takes
2191 ms on my pc. When i turn off sequence scan it takes 12 ms. 

Below i include query and explain analyze output with sequence scan on and
off. Similar situation is without subquery (with joins).

Query:

select
	*
        --count(this_.id) as y0_ 
    from
--
        shipment_order_sub_item this_ 
    left outer join
        shipment_order_item orderitem1_ 
            on this_.shipment_order_item_id=orderitem1_.id 
    where
        orderitem1_.id in (
            select
                oi_.id as y0_ 
            from
                shipment_order_item oi_ 
            inner join
                shipment_order order1_ 
                    on oi_.order_id=order1_.id 
            inner join
                court_department courtdepar3_ 
                    on
order1_.court_department_id=courtdepar3_.department_id 
            inner join
                application_user user2_ 
                    on order1_.user_id=user2_.users_id 
            where
                order1_.id = 610 
                and order1_.court_department_id in (1,292,32768 ) 
        )
        ;






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



Message-ID: <20151214112932.2082.71114@wrigleys.postgresql.org>
Permalink:  ../20151214112932.2082.71114@wrigleys.postgresql.org/
Also on:    postgresql.org/message-id/20151214112932.2082.71114@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: sienkomarcin@gmail.com
  Subject: Re: BUG #13816: Query planner strange choose while select/count small part of big table
  In-Reply-To: <20151214112932.2082.71114@wrigleys.postgresql.org>
  References: <20151214112932.2082.71114@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