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.98.2) (envelope-from ) id 1xTaO1-00000000Q3z-20tP for pgsql-hackers@arkaria.postgresql.org; Wed, 18 Nov 2026 07:47:21 +0000 Received: from localhost ([127.0.0.1]:46894 helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xTaO0-0000000A1QW-3sOX for pgsql-hackers@arkaria.postgresql.org; Wed, 18 Nov 2026 07:47:20 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]:57976) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xTaO0-0000000A1QD-2jVI for pgsql-hackers@lists.postgresql.org; Wed, 18 Nov 2026 07:47:20 +0000 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1xTaNx-00000000HOo-2jYo for pgsql-hackers@lists.postgresql.org; Wed, 18 Nov 2026 07:47:19 +0000 Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-490f38e9688so330486f8f.0 for ; Tue, 17 Nov 2026 23:47:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1794988037; x=1795592837; darn=lists.postgresql.org; h=in-reply-to:content-transfer-encoding:content-disposition :content-type:mime-version:references:message-id:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to:content-type; bh=du2E3jFK8Faba2IyRCNY4zvC62/gg3sR/Z7+34DoM2U=; b=dWlEM28T3ncycTa5zXnEliA5wOr3eM1QB8dVlRRsgXmbrSnBlUHzdodigIJYrRR8LX PGoRhdkIRD58WgwZ+p+4hWreoMqFoGKT6hN75R7zlpdB4oPjfqgA+8xOpuPeJfA3EvpS 2jW9PZHzPHmthyO/Uv5th4DyJgLLqk/kzVuanR2iEL6BIKDseSCVYLFM/wry6zOZs0/g FX9X1y62RbwAZYdPWiOanyGU+kW4SWTO4A1dPX+N0wMbnYsbTOuc1TgE7yCSpf3RK5Hm RE/jnL1E/uRu6GFZgU0eRlFOvZ+tNLqINXSdow7YHd/gyUcZH9iOHrEoVk57sNJcRCrj mpTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794988037; x=1795592837; h=in-reply-to:content-transfer-encoding:content-disposition :content-type:mime-version:references:message-id:subject:cc:to:from :date:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to:content-type; bh=du2E3jFK8Faba2IyRCNY4zvC62/gg3sR/Z7+34DoM2U=; b=wNmlDcafHI7bjj2sUCfme3pok7WTKon4rITEEZXPgehvu5h1z9fZJrvH9flZl4iAHL Ttf7AziEFodCEOgojsy1iAI7sexrXeFlPGIwRkkj8n7ov/jB2uadppgKKe/zfMcrvsG7 hKm8Klw47rb5B8NVyR/dd2YHQB4zntepuSmYlBJh/qFtLl8BZEuICnXNVAm1ySPz45Dk 3XycDnZGS45Eb3RMbn9EKQVaxHQ6h2zwq0ez+otZJlRKCA6EEs4hC353jvqgL2dRp8/q aXsBxrHXVlUBBpAyc4ypUbHTEanKsZ0ftFp+CvPiG4jHcet/PZapcY/QEJNvAHUjmF21 y88w== X-Gm-Message-State: APuU4Z+H8AuPk6/odlYB47WL52SwRf5fUysABaLAMVos+0EBIygIUPac J3HtkzWEHZYqllqanx8oAqJ77oCFSdD9jF+TP9glvJ0+ZXzOOTqHZCzs X-Gm-Gg: AZFdTZcBirMBjVd7YvFIxVlECSrFg3OyQI3kn9GfS5ETPkUcljE8/buFxY5sPRYoDXi QsCT6+gnmyn6/u+fKljH48AXIpZgQOWNO58ebWfUHYTBRyYHMojn7mgoxpt21e+orC08J50bQ9J AM58PJy+NMU6GvYcCw5G2OplUTu5luR71w2FYDns0jk0RXsJhq4ZTIu75hrgeDvA43/1RqnY2Cx htaUS4ScXwtINJjfHI91wBac2qWvatHVL8VZ/7tEPpRjhC7l1CwPBX2/YR0D/njq5DmxVGWvdEJ TDzCfwgJUHBOR6l+kg0HoB7oLdYrV9lpiLxuNSYquZDUD8qmOIo7DFU+GjzIvL/cgUgmWxcY9Xc klwzujlEctSwytm7CCvxomTBbUCcrTzlxKQmwEweHagcIr1cEs/xqyesq2W7KbxS9PV64e4wJdO /BBD5O4Ha/pyxeqGoQ489Vg/Tv3Jbwbr0dvhyyfzHQuFR0V/mImeopaa3+r3E5yRanfWO33fRBb aR1IDfyKvKsZrDNfhfpGQnhn+EForWFYs6kqD8yqXPQONDegMJAEk5bD4aUKBJ5dLGnCujwtYiG 6tuy/ct0pshuAfriq23FBGpxww9Z7Wi5fSUpyoM1qmwDq9hoDFD6uylxdgBSVKiT2Sn7/bEkU/N 8c/DYjkRPVslQ X-Received: by 2002:a05:6000:40dd:b0:4a7:dcc2:a36f with SMTP id ffacd0b85a97d-4a7dcc2a387mr144468f8f.26.1794988036500; Tue, 17 Nov 2026 23:47:16 -0800 (PST) Received: from bdtpg (ec2-15-237-197-144.eu-west-3.compute.amazonaws.com. [15.237.197.144]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4a65560b2a1sm3056010f8f.32.2026.11.17.23.47.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Nov 2026 23:47:16 -0800 (PST) Date: Wed, 18 Nov 2026 07:47:15 +0000 From: Bertrand Drouvot To: Melanie Plageman Cc: pgsql-hackers@lists.postgresql.org, Thomas Munro Subject: Re: Fix ReadStream handling when heap rescan strategy changes Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On Tue, Nov 17, 2026 at 04:54:08PM -0500, Melanie Plageman wrote: > On Tue, Nov 3, 2026 at 1:40 AM Bertrand Drouvot > wrote: > > > > 0001 takes a different approach (than [2]) and recreates the ReadStream when > > initscan() changes whether a strategy is active. Ordinary rescans continue to > > reset and reuse the existing stream. It uses the existing ReadStream APIs, which > > could also make the backpatches easier. > > Now that initscan() has to concern itself with the read stream because > it has to reset or end the stream before changing the strategy, then > change the strategy, and then make the new read stream, I think the > separation between initscan() and making the read stream is no longer > useful. In fact, the ping-ponging has become confusing. I think your > version might actually have read_stream_reset() getting called twice > in some cases since read_stream_end() also calls it. Attached v2 just > moves all the read stream setup into initscan() and adds some flags to > make it more clear when we want to rebuild the stream/strategy. Thanks for looking at it! Yeah, that makes sense to me. Having initscan() own the reset/end, strategy update, and stream creation makes the ordering clearer (and also avoids the possible double reset). I've one Nit, if we want this comment to describe the complete stream lifecycle, in heapam.h: " stream is allocated at the beginning of the scan and reset on rescan or when the scan direction changes. " worth to change it to something like? " The read stream is allocated at the beginning of the scan. It is reset when the scan direction changes. On rescan, it is reset if strategy use remains unchanged, and recreated otherwise. " Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com