Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cGs0V-00008p-5q for pgsql-hackers@arkaria.postgresql.org; Tue, 13 Dec 2016 18:40:55 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cGs0U-00026N-P0 for pgsql-hackers@arkaria.postgresql.org; Tue, 13 Dec 2016 18:40:54 +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 1cGrz6-0000S7-1x for pgsql-hackers@postgresql.org; Tue, 13 Dec 2016 18:39:28 +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 1cGrz3-0007OW-AZ for pgsql-hackers@postgresql.org; Tue, 13 Dec 2016 18:39:27 +0000 Received: from ronan_laptop.localnet (rea75-3-88-190-133-18.fbxo.proxad.net [88.190.133.18]) by mail.dalibo.com (Postfix) with ESMTPSA id B41D32C01C6; Tue, 13 Dec 2016 19:39:23 +0100 (CET) From: ronan.dunklau@dalibo.com To: pgsql-hackers@postgresql.org Cc: Adrien Nayrat Subject: Re: New design for FK-based join selectivity estimation Date: Tue, 13 Dec 2016 19:39:23 +0100 Message-ID: <3012483.BymkNIPMEm@ronan_laptop> User-Agent: KMail/5.3.2 (Linux/4.8.4-1-ARCH; KDE/5.27.0; x86_64; ; ) In-Reply-To: <9e35d4cb-a12d-7987-e23a-8a6020e01e88@dalibo.com> References: <31041.1465069446@sss.pgh.pa.us> <13294.1466278050@sss.pgh.pa.us> <9e35d4cb-a12d-7987-e23a-8a6020e01e88@dalibo.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="iso-8859-1" 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 On mardi 13 d=E9cembre 2016 09:10:47 CET Adrien Nayrat wrote: > Hi hackers, >=20 > The commit 100340e2dcd05d6505082a8fe343fb2ef2fa5b2a introduce an > estimation error : [....] >=20 > Estimated row is 10x larger since 100340e2d >=20 > Regards, Hello, I think I understand what the problem is. In get_foreign_key_join_selectivi= y,=20 we remove the restrict info clauses which match a foreign key. This is done= so=20 that the selectivy is not applied twice (once in the function itself, once= =20 when processing the restrictinfos). The problem is, for semi and anti joins, we assume that we have nohing to d= o=20 (costsize.c:4253): else if (jointype =3D=3D JOIN_SEMI || jointype =3D=3D JOIN_ANTI) { /* * For JOIN_SEMI and JOIN_ANTI, the selectivity is defined as the * fraction of LHS rows that have matches. If the referenced * table is on the inner side, that means the selectivity is 1.0 * (modulo nulls, which we're ignoring for now). We already * covered the other case, so no work here. */ } This results in assuming that the whole outerrel will match, no matter the= =20 selectivity of the innerrel. If I understand it correctly and the above is right, I think we should igno= re=20 SEMI or ANTI joins altogether when considering FKs, and keep the correspond= ing=20 restrictinfos for later processing since they are already special-cased lat= er=20 on.=20 Regards, -- Ronan Dunklau =20=20 --=20 Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers