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 1xOX4B-00000000C9G-0iXh for pgsql-hackers@arkaria.postgresql.org; Wed, 04 Nov 2026 09:14:00 +0000 Received: from localhost ([127.0.0.1]:42448 helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xOX4B-0000000588V-2Pkl for pgsql-hackers@arkaria.postgresql.org; Wed, 04 Nov 2026 09:13:59 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]:59432) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xOX07-00000005378-34eI for pgsql-hackers@lists.postgresql.org; Wed, 04 Nov 2026 09:09:47 +0000 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1xOX04-000000009sn-3dlc for pgsql-hackers@lists.postgresql.org; Wed, 04 Nov 2026 09:09:46 +0000 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-4a1b07c3c5fso3718395e9.1 for ; Wed, 04 Nov 2026 01:09:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793783385; x=1794388185; darn=lists.postgresql.org; h=in-reply-to: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=gHaTlKWbdI2KkanwCleh7WqJrkADBVCt+hSeSOT7Gdo=; b=lbsp5HnyLzm2DT0gyEkHw2QU7T8fIT1qdKf7FzM9eRIhpEqMnRKsTaAqKZlNRdtY+E psjeUBcgSieHHh790+k8tgX0gocUok5+DCFlARbp9huUNxth68k36NK4EubYAvEjThLf DsHOaMB3WQYVnROEstE9bPKbOurPPv0JMU4020i6ZU2mSIxTGDfwk9YdnFcRKvSmTtRO HUoVgiVsbr11o5Uk1ZfuQ4yJ8DbEB3HM2/rIAAdyty0AvqH/um9Ak8Zf1RKS473gyQ7J ZKs4HoG0MkYSFacUeoMUTxurDxUVerew7uMC6iDeBft0Yz3AM7/FI3T1ZmbbiYbpmba9 hDoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793783385; x=1794388185; h=in-reply-to: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=gHaTlKWbdI2KkanwCleh7WqJrkADBVCt+hSeSOT7Gdo=; b=Bwbma+q13tVuHX4EpjUC+iX9zNg5oTByZfyMPFAm4wZhwSy1vnFSdXQ86OTfOKv2Uo jjFdxTNPdORdZSCHzsf49G+SJ8MRL4UzZ92s0aorYSD5oDpIbULEraLRoWqd1syr8yzU 3eLSA95Shlkd6a1OZLiP4x2nEvTw0Wluy72a0IwALYavSE0eswCUEM0BvlgUJReAuqBP bl7bhC5VudtZWp5VPJ/sOaEOFcq3VpmVub/Z5sp8UzkIBPksvvtrkPBf3OzVaUZd8a00 iqvcuA7hnTb+IAjMOIznQqNrIpsoJtKZV6NI1XKlAKm/ffwt2FtomdjhJkrPB8qPGcE9 mktg== X-Gm-Message-State: APuU4Z/1D/8p1invdf4GlgyuA2lGHoYMJ+XPweQP9KcZfPj8ed8ZvCvb /9ebkxjQ9FazBzivf+qgiLLtnJNSnqRgvfa/1KQ+KdmMnZxj1+UkQRux X-Gm-Gg: AYBFou3SDom9+ohVGc6tZSXw+yHmu2K0tGmanuFxWYyUcCIGyPXiUhpZi0utaCU/yFY 16c7R+aO8n//v6Fj8Eelpl0HSBufUi/zLIk+iSRwfD40GXWJd2+hueZQlgBG7Zz+GpDYivB3UDS 7kKrPYPUaKFYdDsEdGvRrFAh6KIqKNvH5O4LXdhVmSdr5Lp8ULc5ZrxYftGlvM2J8fv6baCPANa Hl6Yarb2CRR3kSPaleuq2dKO6SG0zwj/nVaX6pPb3SC2qhi7SE63+7Hyn0Kiq5U00iIHRMF0IWq dCXhAAQOM45cqSKQIjFdAalj3rtFvT8dg70LzftTXPEkLKR6tvHJfPsOrONJe95mq2z4zXwOdhT r0Y9liSMFts8h+RWFLDZL2Vd8VGySB9DoO/gdI212NfOy7GSRTbanvDLitOwzBA2cecL8egH1mK +oTEpwXb01e/z2wj/mF9SavzvXzEZc5XwcBNcsslJCm206GJDsDEbmABM+sPwxPhfhMukwqynr6 26Qgyj433bsRR5WwLd4HMl+ScFyI9LG8vQcDt1G9kasDUy40OGJn5RXhLzDoUIY8lMauvSES3IY doQBRRx8qpG0z8ukGYfCK5jmGbadqsWuVtl7ZPDLJ9mgtycHhhP64kfr245fGACNjwXfLmnvrTw IqLRzCIipC20= X-Received: by 2002:a05:600c:3b09:b0:4b1:4017:c4f4 with SMTP id 5b1f17b1804b1-4b14017c507mr172009235e9.20.1793783384545; Wed, 04 Nov 2026 01:09:44 -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 5b1f17b1804b1-4b2aa953d35sm127313355e9.9.2026.11.04.01.09.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Nov 2026 01:09:44 -0800 (PST) Date: Wed, 4 Nov 2026 09:09:42 +0000 From: Bertrand Drouvot To: Nazir Bilal Yavuz Cc: pgsql-hackers@lists.postgresql.org, Melanie Plageman , Thomas Munro Subject: Re: Fix ReadStream handling when heap rescan strategy changes Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On Tue, Nov 03, 2026 at 01:23:26PM +0300, Nazir Bilal Yavuz wrote: > Hi, > > On Tue, 3 Nov 2026 at 09:41, Bertrand Drouvot > wrote: > > > > The issue was introduced by b7b0f3f27241. Nazir pointed it out and Yuhang > > proposed fixing it with a new read_stream_set_strategy() API in [2]. Since the > > issue is independent of the streaming SampleScan changes, I wonder if it wouldn't > > make sense to fix it separately, as in the attached? > > Fixing it separately makes sense to me. Thanks for looking at it! > The main difference between Yuhang's ([2]) and your approach is that > [2] updates the existing stream through read_stream_set_strategy() > when the strategy is enabled but your approach ends and re-creates the > stream. Both approaches end and re-create the stream if the strategy > is disabled. It seems [2]'s performance is better because of this > reason but I am not sure whether it makes a measurable difference. OTOH, [2] calls read_stream_set_strategy() on every rescan when the bulk strategy remains enabled. FWIW, I ran a few benchmarks, and regardless of which approach was faster, the absolute difference remained below 0.15 microseconds per rescan. Each measurement timed 3 million rescans, and the results were repeatable across 15 samples. So I don't think performance strongly favors either approach. > Although I didn't find a correctness problem with [2] during my > earlier review, I can see the simplicity benefit here. Recreating the > stream keeps strategy-dependent initialization in one place. That > seems a reasonable approach for backpatching. +1 > > 0002 contains a test. I'm not sure it is worth adding to the tree given the amount > > of setup, but it demonstrates the issue. > > I haven't reviewed 0002 yet, but I think regression coverage for this > bug would be worthwhile. Yeah, I think the test is worthwhile. It initializes and starts a new cluster, which is not that cheap (and our test code has been growing quite a bit lately) but that seems justified here. > Minor readability suggestion: > > + if (scan->rs_read_stream && allow_strat != (scan->rs_strategy != NULL)) > > We can replace both '!=' with '=='. I find it slightly easier to read, > just a suggestion. Yeah, that's probably just a matter of taste. I find the existing links more directly to "the requested state differs from the current state" but I'm happy to change it if you feel strongly about it (I don't). Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com