Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cGiB1-0000lC-Rw for pgsql-hackers@arkaria.postgresql.org; Tue, 13 Dec 2016 08:11:07 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cGiB1-0005Ep-Fj for pgsql-hackers@arkaria.postgresql.org; Tue, 13 Dec 2016 08:11:07 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cGi9b-0003aw-Na for pgsql-hackers@postgresql.org; Tue, 13 Dec 2016 08:09:39 +0000 Received: from mimolette.dalibo.net ([212.85.157.144] helo=mail.dalibo.com) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cGi9Y-0004Bc-2q for pgsql-hackers@postgresql.org; Tue, 13 Dec 2016 08:09:39 +0000 Received: from [192.168.1.41] (rea75-3-88-190-133-18.fbxo.proxad.net [88.190.133.18]) by mail.dalibo.com (Postfix) with ESMTPSA id 82F132C0018 for ; Tue, 13 Dec 2016 09:09:33 +0100 (CET) Subject: Re: New design for FK-based join selectivity estimation To: pgsql-hackers@postgresql.org References: <31041.1465069446@sss.pgh.pa.us> <25469.1465138626@sss.pgh.pa.us> <15245.1466031608@sss.pgh.pa.us> <20877.1466175216@sss.pgh.pa.us> <15396.1466268742@sss.pgh.pa.us> <13294.1466278050@sss.pgh.pa.us> From: Adrien Nayrat Message-ID: <9e35d4cb-a12d-7987-e23a-8a6020e01e88@dalibo.com> Date: Tue, 13 Dec 2016 09:10:47 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 In-Reply-To: <13294.1466278050@sss.pgh.pa.us> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="EReXH1Gk87CvVw3wGjMcsmGPm9P6b0VQc" X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --EReXH1Gk87CvVw3wGjMcsmGPm9P6b0VQc From: Adrien Nayrat To: pgsql-hackers@postgresql.org Message-ID: <9e35d4cb-a12d-7987-e23a-8a6020e01e88@dalibo.com> Subject: Re: [HACKERS] New design for FK-based join selectivity estimation References: <31041.1465069446@sss.pgh.pa.us> <25469.1465138626@sss.pgh.pa.us> <15245.1466031608@sss.pgh.pa.us> <20877.1466175216@sss.pgh.pa.us> <15396.1466268742@sss.pgh.pa.us> <13294.1466278050@sss.pgh.pa.us> In-Reply-To: <13294.1466278050@sss.pgh.pa.us> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable 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=3D2.36..18053.61 rows=3D90000 width=3D4) (actual time=3D0.217..282.325 rows=3D90000 loops=3D1) Hash Cond: (t3.j =3D t4.j) -> Seq Scan on t3 (cost=3D0.00..14425.00 rows=3D1000000 width=3D4) (actual time=3D0.112..116.063 rows=3D1000000 loops=3D1) -> Hash (cost=3D2.25..2.25 rows=3D9 width=3D4) (actual time=3D0.083..0= .083 rows=3D9 loops=3D1) Buckets: 1024 Batches: 1 Memory Usage: 9kB -> Seq Scan on t4 (cost=3D0.00..2.25 rows=3D9 width=3D4) (actual time=3D0.019..0.074 rows=3D9 loops=3D1) 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=3D2.36..18053.61 rows=3D1000000 width=3D4) (actual time=3D0.089..232.327 rows=3D90000 loops=3D1) Hash Cond: (t3.j =3D t4.j) -> Seq Scan on t3 (cost=3D0.00..14425.00 rows=3D1000000 width=3D4) (actual time=3D0.047..97.926 rows=3D1000000 loops=3D1) -> Hash (cost=3D2.25..2.25 rows=3D9 width=3D4) (actual time=3D0.032..0= .032 rows=3D9 loops=3D1) Buckets: 1024 Batches: 1 Memory Usage: 9kB -> Seq Scan on t4 (cost=3D0.00..2.25 rows=3D9 width=3D4) (actual time=3D0.008..0.030 rows=3D9 loops=3D1) 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, --=20 Adrien NAYRAT http://dalibo.com - http://dalibo.org --EReXH1Gk87CvVw3wGjMcsmGPm9P6b0VQc Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQEcBAEBCAAGBQJYT60IAAoJELLqSLcyeLN/xT0H/j8Wj4Jwqv56XLZ6H2amqghQ tt7JSfDMWSVgCFZom+c2y3dhrJvkszp2nEOjsCk7rQG2PhOY3HYw0Sw+0HC+ib19 NJcmhANBJ0xnQVVTcSRn3RPBYGM3RFmmyoBgE5jP44/z7txE92EgSKxS4r+3ihEQ 8tx7cnJ9rFj26EKf/msdKcPzwbqTWlsU8hvm3F/3lLFJfDugxMmBm2q5ova3z4pO uf+xPOlsPP9ZWwNY1AYZjrmBFLq6oTVJTRtsT0YqJyoGJEzb2HILWyTVFKi8wbwX IJQKFx+0KG/JpiTa7oFYgiWy7jtuK6ard5KoWM4mElchMTl9TRoRfU8Lwx1BVr0= =Hmjq -----END PGP SIGNATURE----- --EReXH1Gk87CvVw3wGjMcsmGPm9P6b0VQc--