Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hM3uE-0000Lq-Pl for pgsql-general@arkaria.postgresql.org; Thu, 02 May 2019 05:05:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hM3uD-0004YU-8o for pgsql-general@arkaria.postgresql.org; Thu, 02 May 2019 05:05:13 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1hM3uC-0004YN-VQ for pgsql-general@lists.postgresql.org; Thu, 02 May 2019 05:05:13 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hM3uA-0002ce-0O for pgsql-general@lists.postgresql.org; Thu, 02 May 2019 05:05:12 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x42555xi002649; Thu, 2 May 2019 01:05:05 -0400 From: Tom Lane To: Sergey Koposov cc: "pgsql-general@lists.postgresql.org" Subject: Re: strange nested loop row count estimates In-reply-to: <1556772565.7942.240.camel@cmu.edu> References: <1474.1556771819@sss.pgh.pa.us> <1556772565.7942.240.camel@cmu.edu> Comments: In-reply-to Sergey Koposov message dated "Thu, 02 May 2019 04:49:25 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2647.1556773505.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Thu, 02 May 2019 01:05:05 -0400 Message-ID: <2648.1556773505@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Sergey Koposov writes: > On Thu, 2019-05-02 at 00:36 -0400, Tom Lane wrote: >> What sort of selectivity estimator have you got attached to that custom >> operator? > This is the code, but basically it is just a constant based on the searc= h radius (which is the leftmost float argument of the operator) > https://github.com/segasai/q3c/blob/361140d4f1f36bf16c9c53721d1c4f03cb4d= e930/q3c.c#L89 Hm, that query should be paying attention to join selectivity, and you don't have a join selectivity function. I think that it applies the restriction selectivity while estimating the size of the bitmap scan's output. But that's not what's going to determine the estimated size of the join output. Too tired to look at this really closely, but I think basically the inconsistency boils down to the lack of consistency between your restriction estimator (1e-12) and your join estimator (which, since you haven't got one, is going to default to something way larger, possibly 0.5). regards, tom lane