Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f8nUX-00009L-At for pgsql-general@arkaria.postgresql.org; Wed, 18 Apr 2018 13:51:21 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1f8nUV-0004GH-J3 for pgsql-general@arkaria.postgresql.org; Wed, 18 Apr 2018 13:51:19 +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.89) (envelope-from ) id 1f8nUV-0004G7-Al for pgsql-general@lists.postgresql.org; Wed, 18 Apr 2018 13:51:19 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f8nUS-000822-0f for pgsql-general@postgresql.org; Wed, 18 Apr 2018 13:51:18 +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 w3IDpBRM028216; Wed, 18 Apr 2018 09:51:11 -0400 From: Tom Lane To: Vitaliy Garnashevich cc: Postgres General Subject: Re: Tricking the optimizer In-reply-to: <612dae0f-16b3-e5f8-7458-1ec38aea163c@gmail.com> References: <612dae0f-16b3-e5f8-7458-1ec38aea163c@gmail.com> Comments: In-reply-to Vitaliy Garnashevich message dated "Wed, 18 Apr 2018 15:15:50 +0300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <28214.1524059471.1@sss.pgh.pa.us> Date: Wed, 18 Apr 2018 09:51:11 -0400 Message-ID: <28215.1524059471@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Vitaliy Garnashevich writes: > Is there any trick to craft the query in such a way, so that to make the > optimizer believe that the filters would not remove any rows, and all > rows will likely be returned by the query? If you don't mind writing some C code, you could create a dummy operator that just returns its boolean argument, and attach a selectivity estimator to it that returns 1.0. Then you'd write the query as, perhaps, WHERE ~~~(securityFilter1) AND ... where ~~~ could be read as "likely()". I wouldn't recommend using such a wrapper for any WHERE clause that the optimizer had any intelligence about at all, because it would defeat all of that. But in this case you're not getting any wins anyhow, so burying an opaque subselect in another layer of opacity won't hurt. regards, tom lane