Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1obsfC-0004D0-2A for pgsql-bugs@arkaria.postgresql.org; Sat, 24 Sep 2022 00:04:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1obsfA-0004pw-LW for pgsql-bugs@arkaria.postgresql.org; Sat, 24 Sep 2022 00:04:56 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1obsfA-0004o7-CY for pgsql-bugs@lists.postgresql.org; Sat, 24 Sep 2022 00:04:56 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1obsf8-0001wJ-5X for pgsql-bugs@lists.postgresql.org; Sat, 24 Sep 2022 00:04:56 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 28O04pfq2174560; Fri, 23 Sep 2022 20:04:51 -0400 From: Tom Lane To: Richard Guo cc: Jeff Janes , sindysenorita@gmail.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #17618: unnecessary filter column <> text even after adding index In-reply-to: References: <17618-7a2240bfaa7e84ae@postgresql.org> <349136.1663601052@sss.pgh.pa.us> <739953.1663701274@sss.pgh.pa.us> <946195.1663718159@sss.pgh.pa.us> <2100290.1663942209@sss.pgh.pa.us> Comments: In-reply-to Richard Guo message dated "Sat, 24 Sep 2022 07:54:02 +0800" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2174558.1663977891.1@sss.pgh.pa.us> Date: Fri, 23 Sep 2022 20:04:51 -0400 Message-ID: <2174559.1663977891@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Richard Guo writes: > On Fri, Sep 23, 2022 at 10:10 PM Tom Lane wrote: >> Richard Guo writes: >>> So I think we need to run eval_const_expressions on indexquals before we >>> check for duplicate clauses, something like attached. >> [ squint... ] Surely that was done long before we ever get here? > We should have already done that long before. It seems afterwards we may > do additional transformation on indexquals. In this case with a boolean > index, I can see we convert the indexqual to form 'indexkey = TRUE' in > match_boolean_index_clause. Of course, but what about that transformation would introduce something that eval_const_expressions could simplify? (Actually, now that I think about it, I think eval_const_expressions would break it completely because it'd re-canonicalize the expression as just 'indexkey', exactly what we don't want here.) In any case, if there's something between the eval_const_expressions pass and createplan.c that introduces simplifiable expressions, I think it's on that something's head to re-simplify; we don't want to do something so expensive in a main code path if it's usually going to be a complete waste. regards, tom lane