pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrien Nayrat <adrien.nayrat@dalibo.com>
To: pgsql-hackers@postgresql.org
Subject: Re: New design for FK-based join selectivity estimation
Date: Tue, 13 Dec 2016 09:10:47 +0100
Message-ID: <9e35d4cb-a12d-7987-e23a-8a6020e01e88@dalibo.com> (raw)
In-Reply-To: <13294.1466278050@sss.pgh.pa.us>
References: <31041.1465069446@sss.pgh.pa.us>
	<25469.1465138626@sss.pgh.pa.us>
	<b790983b-4503-66ff-30c0-e7f46e3ad2f7@2ndquadrant.com>
	<15245.1466031608@sss.pgh.pa.us>
	<b1648fc3-3fd9-312e-f02c-f7fc6278d7d3@2ndquadrant.com>
	<20877.1466175216@sss.pgh.pa.us>
	<ee1a76b0-43ed-a6a4-2acb-7c410d0be3ac@2ndquadrant.com>
	<15396.1466268742@sss.pgh.pa.us>
	<13294.1466278050@sss.pgh.pa.us>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>

Hi hackers,

The commit 100340e2dcd05d6505082a8fe343fb2ef2fa5b2a introduce an
estimation error :

create table t3 as select j from generate_series(1,10000)
i,generate_series(1,100) j ;
create table t4 as select j from generate_series(1,100) j ;
create unique index ON t4(j);
alter table t3 add constraint fk foreign key (j) references t4(j);
analyze;

9.5.5
explain analyze select * from t3 where j in (select * from t4 where j<10);
                                                     QUERY PLAN

--------------------------------------------------------------------------------------------------------------------
 Hash Semi Join  (cost=2.36..18053.61 rows=90000 width=4) (actual
time=0.217..282.325 rows=90000 loops=1)
   Hash Cond: (t3.j = t4.j)
   ->  Seq Scan on t3  (cost=0.00..14425.00 rows=1000000 width=4)
(actual time=0.112..116.063 rows=1000000 loops=1)
   ->  Hash  (cost=2.25..2.25 rows=9 width=4) (actual time=0.083..0.083
rows=9 loops=1)
         Buckets: 1024  Batches: 1  Memory Usage: 9kB
         ->  Seq Scan on t4  (cost=0.00..2.25 rows=9 width=4) (actual
time=0.019..0.074 rows=9 loops=1)
               Filter: (j < 10)
               Rows Removed by Filter: 91
 Planning time: 0.674 ms
 Execution time: 286.043 ms

On 9.6 HEAD

explain analyze select * from t3 where j in (select * from t4 where j<10);
                                                    QUERY PLAN

-------------------------------------------------------------------------------------------------------------------
 Hash Semi Join  (cost=2.36..18053.61 rows=1000000 width=4) (actual
time=0.089..232.327 rows=90000 loops=1)
   Hash Cond: (t3.j = t4.j)
   ->  Seq Scan on t3  (cost=0.00..14425.00 rows=1000000 width=4)
(actual time=0.047..97.926 rows=1000000 loops=1)
   ->  Hash  (cost=2.25..2.25 rows=9 width=4) (actual time=0.032..0.032
rows=9 loops=1)
         Buckets: 1024  Batches: 1  Memory Usage: 9kB
         ->  Seq Scan on t4  (cost=0.00..2.25 rows=9 width=4) (actual
time=0.008..0.030 rows=9 loops=1)
               Filter: (j < 10)
               Rows Removed by Filter: 91
 Planning time: 0.247 ms
 Execution time: 235.295 ms
(10 rows)


Estimated row is 10x larger since 100340e2d

Regards,

-- 
Adrien NAYRAT

http://dalibo.com - http://dalibo.org

Attachments:

  signature.asc (application/pgp-signature, 472B) download

view thread (25+ messages)  latest in thread

Message-ID: <9e35d4cb-a12d-7987-e23a-8a6020e01e88@dalibo.com>
Permalink:  ../9e35d4cb-a12d-7987-e23a-8a6020e01e88@dalibo.com/
Also on:    postgresql.org/message-id/9e35d4cb-a12d-7987-e23a-8a6020e01e88@dalibo.com

 · 

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-hackers@postgresql.org
  Cc: adrien.nayrat@dalibo.com
  Subject: Re: New design for FK-based join selectivity estimation
  In-Reply-To: <9e35d4cb-a12d-7987-e23a-8a6020e01e88@dalibo.com>
  References: <31041.1465069446@sss.pgh.pa.us> <25469.1465138626@sss.pgh.pa.us> <b790983b-4503-66ff-30c0-e7f46e3ad2f7@2ndquadrant.com> <15245.1466031608@sss.pgh.pa.us> <b1648fc3-3fd9-312e-f02c-f7fc6278d7d3@2ndquadrant.com> <20877.1466175216@sss.pgh.pa.us> <ee1a76b0-43ed-a6a4-2acb-7c410d0be3ac@2ndquadrant.com> <15396.1466268742@sss.pgh.pa.us> <13294.1466278050@sss.pgh.pa.us> <9e35d4cb-a12d-7987-e23a-8a6020e01e88@dalibo.com>

* 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