Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wcJHg-003Ffh-2Y for pgsql-hackers@arkaria.postgresql.org; Wed, 24 Jun 2026 08:48:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wcJHf-00GOqC-2G for pgsql-hackers@arkaria.postgresql.org; Wed, 24 Jun 2026 08:48:35 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wcJHf-00GOpj-0w for pgsql-hackers@lists.postgresql.org; Wed, 24 Jun 2026 08:48:35 +0000 Received: from mail-qv1-xf31.google.com ([2607:f8b0:4864:20::f31]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wcJHd-00000001tNR-2cIj for pgsql-hackers@lists.postgresql.org; Wed, 24 Jun 2026 08:48:34 +0000 Received: by mail-qv1-xf31.google.com with SMTP id 6a1803df08f44-8dd74f90e3eso9485746d6.2 for ; Wed, 24 Jun 2026 01:48:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1782290911; cv=none; d=google.com; s=arc-20240605; b=bLthGeOTuCEV5w/t1FLG4h9W9g6qwP68oTirH/derCEsZ0iZ5fy4b+NIOnOAvvXG2w +c/cTui+F3lixGPeLYTfpGzP038LNBXq7alSkTPoMyDtBpGYIU1+zPOWdO9ny9WHdSMb SAZi7Z1cNGUuxZqpM4pVwpv1L0/K6ZZdOyyqtiQdfq01p9XxAqO8GZrnnYqD+rY4bDOo NNkHz0daiYkIrRYNQDs5THjpyjEyk/uQl48dGqSyfzsqpN6FtRZlDTLBt8qDPgh8/4az QLFXO/s/Nyy55mFhYX/9ZVeNIWB2DJ413dqUxvRXsWfpCFN8v3C5gF74K2o+vyuxvajf VWjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=47bfFbYpJEUlPRp+AjBppVlqauGgwktO1pGPQz7cOIM=; fh=nxjOp4Rl9UHhB4Ld3mevWcWLX9Yx9sEe0ARFoZuLdBw=; b=asa3VymXbAiSEbivFosQopqa8O76UAl3n3L+wv3uYAXQyp1GsuePn1OmR01axWbB7X 5ghPv/aM/zuMjWa+9Zrly8GOmHopjCWJb+fKA2iWVpiO8MArfirBuzjjrKkKKf9tDYkT 778baNws1yYj4vxUXD+EMj4zeOJIRCQeQ5j0m0e87E48ARtKmIT3SqsBovEYS0hisahl 4+O+hJ4pef/VHHazt00Rc92mg2mMfo8Zp66M2uUOkiHhAoGuj0zqtZO3cFBCYfQwGFIH ljzNxkK2CN6LciD1+ANURC8NImtXJi+i1fBkt1wdc+fRbX+Ev+Ry+zVUSukHjVtK0YwT 84Dg==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; t=1782290911; x=1782895711; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=47bfFbYpJEUlPRp+AjBppVlqauGgwktO1pGPQz7cOIM=; b=cP2s7zwGvwa/HYDdySEj9GfMvIX+GdjC+iOgky1XfbANNioe281Vq8mfsWCNXCkj+C ZVgW+34c17UFEMoMmUexq4pzL4zA9B/YWVmK76kgKSZLUD54aMAoeBWCjpDEQJD0MlGI vnnE9+Apw2lEi54hNBdTv6zpxb7NMCA5k4fszbzqv7tP5p+tjyoDokaN3d7u2Cend87l P9UUsQSuixQD5UTimVUkf1MkS0irIsmGhWR5hEjp/j77MxQaBH6hcL+lMnnC2iLhATiq ERaKgZ+TVISqVor8b+W4UGTEJiFb4DLSTAB4CUX2/V5NQPzaRImiYU5EFO783KQVt2jj N6mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782290911; x=1782895711; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=47bfFbYpJEUlPRp+AjBppVlqauGgwktO1pGPQz7cOIM=; b=pTPTiExwpHHnNLeEjxRsRN0uh9mmxTiWJaoMDM21IvjYUSi5aSCKCnDDLvFo3KGkZA 1+404RaxsmTvYfqX+EnhbImhfBYYbI3X4wW2EFv/YwcPyurbJUyVX12zybYzr9QaoG82 Xwz2uUHUJyTInNcIdOddI4JGORKT2UffPUzzXldYvUH/O8UEeHdkApCaAvGCS7JtYRKx TX5Kzzjp6gMEqQqYEMy4fM418VcPd0sHz6VceRaqe5oEIYZ1IomgYZquOQgnLkdRPvRA d9JuLUWwPhHwHNxXdJH8g13pZN8PurI+HuugyZ6Mzd2NKeg/hFmpTicCGPFGIuhpTyhf s2GA== X-Forwarded-Encrypted: i=1; AHgh+RqgcH0SRk70LYccrruszooo57JBT30MH9bkdVjJBQprged2NHr22chOCKxYw8wrB5++Xr/LmDmc8MlFv3Ex@lists.postgresql.org X-Gm-Message-State: AOJu0Yzx0/Wap63/d4QXpq+Z4u/s+UpJ5YhkByXSvDi7BJxU0ecp4vnT WvAod1HbKYiRu9aHXH6g2rWP42WlDi7RxceroP5MNQGPXQW/dTkjpZPNGmGUIS4nJsq41by4m9N zDjiRoBeTKo8xP3dQ/OEHjkZ1W+il8JanGrcBmsRr X-Gm-Gg: AfdE7clGcl/wqYgECfOczb6g+BKTvZNH3nwKjH7gwrcITqNINXluvL3uKzcOrIMEOCN YsY1xLTVLBu6ROiFh7rR2FY1JikaZFQol55jAuAcybFk854aeZ/SWFEj262WphMBh9kHpuMkwJb zWaLp7zAO/BGdW809BfF+tGmTJAvb3UCch5Vk18vaSMzaQcWQ+PsOwWF0ITcg08bQwZUXT9QfbE e1xJIoDJCRWRiraH8qqWkwpxtzxCQP6Gt0ApYk3TQcCAPToJrq7QFifho6bScWAireZ/toGmdql GEqOB6W9fjAQy/jF6EEQmCJ7puKRnF+bv2jsBAZHo1iekEvDVF3n7YbPQg== X-Received: by 2002:ad4:5968:0:b0:89c:4ea7:a70f with SMTP id 6a1803df08f44-8df8f90fb89mr315910656d6.14.1782290911014; Wed, 24 Jun 2026 01:48:31 -0700 (PDT) MIME-Version: 1.0 References: <4s3vd2rjll4vgnhdnajrqwsnhnmnmtmjtwjngfsrzmjx3nrxvp@la2vohpjojnk> In-Reply-To: From: Jakub Wartak Date: Wed, 24 Jun 2026 10:48:19 +0200 X-Gm-Features: AVVi8CffeNA28nNdnM1MPm-G5GM5cB6SkYYlUALUvrRfSsc4VP2lijfxmDCck0E Message-ID: Subject: Re: Problems with get_actual_variable_range's VISITED_PAGES_LIMIT To: Peter Geoghegan Cc: Andres Freund , PostgreSQL Hackers , MARK CALLAGHAN , Tomas Vondra Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, Jun 23, 2026 at 10:06=E2=80=AFPM Peter Geoghegan wrote= : > > On Thu, Mar 12, 2026 at 9:13=E2=80=AFPM Peter Geoghegan wrot= e: > > I'm trying to be practical here. I want to design a solution > > compatible with the changes that we're making to the table AM > > interface. That fixes Mark's complaint. Ideally, this should avoid > > adding much new code to hot code paths. Any design that meets those > > goals is acceptable to me. > > The latest version of the index prefetching patch set has a new patch for= this: > > https://postgr.es/m/CAH2-WzkZTkDuyVFszLwPJesF9pS5E8m0UA+344bx-B-zfA5kaw@m= ail.gmail.com > > My original proposal involved wholly replacing VISITED_PAGES_LIMIT; my > new approach complements it by specifically targeting its one major > weakness. A new INDEX_PAGES_LIMIT mechanism will only tally index leaf > page reads that return zero matching items to the table AM, and will > only give up when that count reaches 3. VISITED_PAGES_LIMIT itself > works as before. > > Importantly, this allows VISITED_PAGES_LIMIT to work exactly the same > way on standbys as it does today. During hot standby, LP_DEAD bits > cannot be set or used to avoid heap fetches. As long as each leaf page > returns at least one match (which could still be a TID pointing to a > dead heap tuple), nothing changes -- INDEX_PAGES_LIMIT does nothing > new, we rely on VISITED_PAGES_LIMIT in the traditional way. Hi Peter, thanks for working on this. I have noob question, in v28-0003: --- a/src/backend/utils/adt/selfuncs.c +++ b/src/backend/utils/adt/selfuncs.c @@ -7185,8 +7185,17 @@ get_actual_variable_endpoint(Relation heapRel, * We set xs_visited_pages_limit to tell the table AM to count distinc= t * heap pages visited for non-visible tuples and give up after the lim= it * is exceeded. + * + * We also set xs_index_pages_limit to independently tell the index AM= to + * give up when this many leaf pages that lack even one matching index + * tuple have been read. This acts as a backstop against pages entire= ly + * full of index entries that were already marked killed (typically by + * prior calls here). That way we avoid hopelessly searching through = an + * unbounded number of index leaf pages that don't contain even a sing= le + * still-live entry (which can't trigger xs_visited_pages_limit). */ #define VISITED_PAGES_LIMIT 100 +#define INDEX_PAGES_LIMIT 3 So, is this based that proportion that we assume that everywhere on average 33 heap pages are going to be covered by 1 btree page? (just asking if we I get the assumption right, I don't have anything against it). -J.