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 1pSLAR-0008PC-TK for pgsql-hackers@arkaria.postgresql.org; Wed, 15 Feb 2023 17:02:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pSLAQ-0006EW-51 for pgsql-hackers@arkaria.postgresql.org; Wed, 15 Feb 2023 17:02:02 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pSLAP-0006EN-RF for pgsql-hackers@lists.postgresql.org; Wed, 15 Feb 2023 17:02:01 +0000 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pSLAI-0004Qx-Ua for pgsql-hackers@postgresql.org; Wed, 15 Feb 2023 17:02:00 +0000 Received: by mail-wr1-x42d.google.com with SMTP id by3so18541261wrb.10 for ; Wed, 15 Feb 2023 09:01:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=dXFSWLl3L6d3S61GliRckwkBwpt1K6fjtbSy5y5x+P4=; b=k2X1YuSXKi9rt6oXHtgX3tXfq2iVbps7vZN4Kujc4Kx44pqPrwCHGFq2HztBWa60af c1/Z8KNu44rpVeaD5/OSlce2tQ8eK2W+4VofABBFVuYzUm70NSmgJsit7Ks5n1xEufwN c7TuyzmrG8Mf/0v3TpjTY2vqlOzsKifxDYQJS5vq7dR5MlMyhw2mhjs4lbgAwqbsLZC4 3QykbwZ3nizQIr5rn/OnpuLP/q+4jJFT3/8BjXl7SNz+uxnwt3mEQniz5fq7Hqa2c1ON U/Kkp7hju3/nRzubx6WKeYWrPEPJfrZ64wZ5WIVMrAwi9suSldBf+uLx//2XHTX5LoH7 SlFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=dXFSWLl3L6d3S61GliRckwkBwpt1K6fjtbSy5y5x+P4=; b=GgSbJSnh0sgUZIs40gZhHcmUOMCGN/G5h7MZ2mHOi/S7JEH3aHT/zA2Unvs61SY2Yh 4illG8lH01w/DgEVNB4NIf2vBdfwmlNwzbz2pV/DAd2qTPk39EdbIXV1ErT2d+7IgFKI by2oTfb4UOrwo3+Kz5uXB6JEhqa/NOjVHu+XYkVQmRnxrqXufA2nosxFuWkvKQl/CX/o 9AMOGafF4dQcqf48nJbV5fvTXEhxOihvzSI/3E4cRCnV/Vr+d7WePYTPxVDk5JB3JoHv 5wNx6gVKkQrxI3V+pq0j6aK2E3K39iVARCja+37t1H9higqy13fh6ir8RZ64cPnufO2n tBpg== X-Gm-Message-State: AO0yUKWVDx+Mjh9yJQLHZ2aqn+Y+B8s5abonp06BoybQL2GikEpjhrPr k5db9SArh9/w9E6SDRu0cPaS+NcCTQc0cx9mboMvSJls380kWVIaZ+4CDC0+QgQRKAPFQiAUoL/ nfWQhkkObT4i0+TE5epHBVVHEzQtrg1VLweWBeFy3Uxqe7CREFQowWLYZlA+e/n5VIgNgwGknTH B0FXHVPcSGOPX/AsUiZX/apoXFenEuM1ljtF8GoVD37eSUgOQ= X-Google-Smtp-Source: AK7set/GrzDvfBkYhfZLDRuY7tlaKJwTYJGvbvfsHCDAI+shVh5IsRz92n/g5rXFNajurySIUQzomg== X-Received: by 2002:a5d:4d11:0:b0:2c3:d83a:113a with SMTP id z17-20020a5d4d11000000b002c3d83a113amr2659763wrt.4.1676480512250; Wed, 15 Feb 2023 09:01:52 -0800 (PST) Received: from [10.137.0.17] (ip-86-49-228-162.bb.vodafone.cz. [86.49.228.162]) by smtp.gmail.com with ESMTPSA id n2-20020a5d67c2000000b002c53f6c7599sm15355126wrw.29.2023.02.15.09.01.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 15 Feb 2023 09:01:51 -0800 (PST) Message-ID: <6683b9d4-3bac-a4ad-50ca-06412c6d7d77@enterprisedb.com> Date: Wed, 15 Feb 2023 18:01:50 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 Subject: Re: Use of additional index columns in rows filtering Content-Language: en-US To: Tom Lane Cc: Maxim Ivanov , "pgsql-hackers@postgresql.org" References: <2084884.1676474292@sss.pgh.pa.us> From: Tomas Vondra In-Reply-To: <2084884.1676474292@sss.pgh.pa.us> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-CLOUD-SEC-AV-Info: enterprisedb,google_mail,monitor X-CLOUD-SEC-AV-Sent: true X-Gm-Spam: 0 X-Gm-Phishy: 0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2/15/23 16:18, Tom Lane wrote: > Tomas Vondra writes: >> On 2/15/23 09:57, Maxim Ivanov wrote: >>> TLDR; additional index column B specified in CREATE INDEX .. (A) >>> INCLUDE(B) is not used to filter rows in queries like WHERE B = $1 >>> ORDER BY A during IndexScan. https://dbfiddle.uk/iehtq44L > >> Seems doable, unless I'm missing some fatal issue. > > Partly this is lack of round tuits, but there's another significant > issue: there very likely are index entries corresponding to dead heap > rows. Applying random user-defined quals to values found in such rows > could produce semantic anomalies; for example, divide-by-zero failures > even though you deleted all the rows having a zero in that column. > > This isn't a problem for operators found in operator families, because > we trust those to not have undesirable side effects like raising > data-dependent errors. But it'd be an issue if we started to apply > quals that aren't index quals directly to index rows before doing > the heap liveness check. (And, of course, once you've fetched the > heap row there's no point in having a special path for columns > available from the index.) Sure, but we can do the same VM check as index-only scan, right? That would save some of the I/O to fetch the heap tuple, as long as the page is all-visible and the filter eliminates the tuples. It makes the costing a bit trickier, because it needs to consider both how many pages are all-visible and selectivity of the condition. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company