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 1oJb3l-0002cd-73 for pgsql-general@arkaria.postgresql.org; Thu, 04 Aug 2022 13:38:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oJb3j-0005QK-To for pgsql-general@arkaria.postgresql.org; Thu, 04 Aug 2022 13:38:43 +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 1oJb3j-0005NB-IA for pgsql-general@lists.postgresql.org; Thu, 04 Aug 2022 13:38:43 +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 1oJb3e-0000gN-Vi for pgsql-general@lists.postgresql.org; Thu, 04 Aug 2022 13:38:43 +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 274Dcaja3435276; Thu, 4 Aug 2022 09:38:36 -0400 From: Tom Lane To: Danny Shemesh cc: "David G. Johnston" , "pgsql-general@lists.postgresql.org" Subject: Re: Index only scans for expressional indices when querying for the expression In-reply-to: References: Comments: In-reply-to Danny Shemesh message dated "Thu, 04 Aug 2022 15:31:32 +0300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3435274.1659620316.1@sss.pgh.pa.us> Date: Thu, 04 Aug 2022 09:38:36 -0400 Message-ID: <3435275.1659620316@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Danny Shemesh writes: > That is of course correct, but what I mean is that, I think that if one > would explicitly query f(x), and never for x directly, it would've been > theoretically possible to say that the index is covering for every f(x), > wouldn't it ? Theoretically, yeah, but we don't support that: an index-only scan will only be considered if x itself is available from the index. There are a couple of reasons for that, but the main one is that detecting whether an index matches the query would be far more expensive if it had to consider expression subtrees not just the base Vars. regards, tom lane