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 1vpbnC-00Bxky-01 for pgsql-hackers@arkaria.postgresql.org; Tue, 10 Feb 2026 00:39:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vpbnB-00DHYm-03 for pgsql-hackers@arkaria.postgresql.org; Tue, 10 Feb 2026 00:39:48 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vpbnA-00DHYc-2J for pgsql-hackers@lists.postgresql.org; Tue, 10 Feb 2026 00:39:48 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1vpbn5-00000001u6K-0Ajl for pgsql-hackers@lists.postgresql.org; Tue, 10 Feb 2026 00:39:48 +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 61A0dXNZ3613044; Mon, 9 Feb 2026 19:39:34 -0500 From: Tom Lane To: Peter Geoghegan cc: PostgreSQL Hackers , MARK CALLAGHAN , Tomas Vondra Subject: Re: Problems with get_actual_variable_range's VISITED_PAGES_LIMIT In-reply-to: References: Comments: In-reply-to Peter Geoghegan message dated "Mon, 09 Feb 2026 18:14:27 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3613042.1770683973.1@sss.pgh.pa.us> Date: Mon, 09 Feb 2026 19:39:33 -0500 Message-ID: <3613043.1770683973@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Peter Geoghegan writes: > VISITED_PAGES_LIMIT counts heap page visits. But when there are many > index tuples marked LP_DEAD, btgettuple will traverse > indefinitely-many *index* pages before returning even a single tuple > to the selfuncs.c caller. Yup, that's a problem. > Proposed solution > ================= > Rather than counting heap page visits, I propose limiting the scan to > the extremal leaf page only. If the extremal index leaf page yields no > visible tuples, we give up immediately. The latest version of the > index prefetching patch [2] adds a WIP patch that does just that. I think that's throwing the baby out with the bathwater. In exchange for a tight limit on planner time expended, you have an enormously increased chance of getting no useful data at all. For one thing, it is likely that the extremal page is only partly filled, so that there may be only a very small number of index entries that this strategy would consider at all. Maybe it would work to express the limit as number of dead index entries we will skip past before failing? I'd want a threshold of maybe a thousand, but that would still work to bound the index AM's work as well as the heap AM's. > Testing of the patch posted to that other thead today shows that this > is much more effective. What definition of "effective" are you using? It sounds like you are putting zero weight on successfully obtaining an estimate, and I find that approach quite unacceptable. regards, tom lane