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.94.2) (envelope-from ) id 1ucynt-001iTW-3J for pgsql-hackers@arkaria.postgresql.org; Sat, 19 Jul 2025 04:04:05 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1ucynp-002eFe-82 for pgsql-hackers@arkaria.postgresql.org; Sat, 19 Jul 2025 04:04:01 +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.94.2) (envelope-from ) id 1ucyno-002eFW-Ua for pgsql-hackers@lists.postgresql.org; Sat, 19 Jul 2025 04:04:01 +0000 Received: from mail-oa1-x30.google.com ([2001:4860:4864:20::30]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1ucynn-008YtE-0c for pgsql-hackers@lists.postgresql.org; Sat, 19 Jul 2025 04:04:01 +0000 Received: by mail-oa1-x30.google.com with SMTP id 586e51a60fabf-2ff9477320dso466755fac.1 for ; Fri, 18 Jul 2025 21:03:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1752897837; x=1753502637; 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=Q8wvMpvB0GymxYFyKgJjHhArkZ5zzV9JWMyuEafh3us=; b=FQXQtN7HjTQq1B4BLzDnyzc5rfN26bRoyF24i2jI3qWHkpUUo4PmKagXTJ0WPBUQEC ocl1JJk1AYxEsnvmx7a/k5c+lJTvjGUqFzyPEeuvkNQM4z6X7zuDs43au0HyUuuA1LTj kB1O3tZ1CtcnCi9VwL7F3iTO9lLvEQbL+lRvBBNub2PjkDMontH8UZ5Rlz8Yr6YN06VP tvZ0fF/mdAFy/RzGtvg7q4CovnKalgz2NHv1AruKkG1O82Yss57KvSOTWhVxN+ZcFr6Y EkgkBuLKJnHlqQKxZayO+53FdXuPsb/K5xU9rHylhyqLS92/h43hWwG5a3nRzv3q5btO dMLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752897837; x=1753502637; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Q8wvMpvB0GymxYFyKgJjHhArkZ5zzV9JWMyuEafh3us=; b=EtFzTgJUV7p/0pDG066T/Ekly//RlMWVudJOW39nbjo3Z8Wx3GkzYqDIXkZGm2qE7L 5vQlDv9P2xS9IYVbHd6pUC+ZaTXRePpt2Riqw4mdHhscJhGnvljG+GIwC5xTN5qXg5IE 3CTCVFw8V1+rADhdsYB2McV49MVNhUNR2rLUgPwGWRkUP4oSQiXKqhvthCl7ZP/7jnMP PH478uTcSRgFE9rQ6zNn0AQ/ccz/KMOVJluZuG31Ad3IZGxlm2jU3PdG4WT4i8k9sE6n UHL3GCVUqaOjRoZ6dkPIWXb7k3yoOWHlHk3kAx2s4IG2vEyLWoIwblmbN24Cvc/v2/9V kYsQ== X-Forwarded-Encrypted: i=1; AJvYcCXv7UMd/Tgfms6EQ86suMHijLJLf3nJOo3vbTdlj+NrcSUXgEebI5sAd+all2Gl5iLRObk0jj4bQlnMHmpM@lists.postgresql.org X-Gm-Message-State: AOJu0YzTifG5meQ750XlREENVDBgwMs1WSPsndeaEFjwyp5AXApCKS/a Eww6VqgEsoOgSzp4N/7QQ80ET421xwvc7VLkdYc+oSN9wo3g67EbaSJC0y3gUgfjAvV3SIPh4xB 1VyBsV7l4CR5G8l8AOQpWtccVv5qeoOE= X-Gm-Gg: ASbGncuBaeinbw9AbuNS3Wb6IyXFHKw1NSfz+yq2l3Cz8g/3DrIBcceWaHRbFL92t5f W1c5pduqdiS6xbsUBrvhsbon7nx8X+P1owDiH5SMY2WGql2/rO3N58dMEpaxke0qpQG9yFEf6AJ xCyOnCUeZwbZBdYeSdJWGaugbSWI3MUOgvlJ0wUUyBP4AEfTHoGvZHakQWZ14HM6qcC4Zhqz4Xk Y6VTNaRthcJfS2brNg= X-Google-Smtp-Source: AGHT+IFsd5H4urN3CA84F7SJkdXfesdCQWXg6XKUFdsRWollCxI8+0m6PoaYsp97dTlCNt33jA3zr4O/gAVDo6zJPbw= X-Received: by 2002:a05:6870:1f1a:b0:2d6:1e7:f583 with SMTP id 586e51a60fabf-2ffaf21413cmr3806612fac.3.1752897836842; Fri, 18 Jul 2025 21:03:56 -0700 (PDT) MIME-Version: 1.0 References: <57d0e292-73d5-4ab9-9855-110ee9cbd90a@vondra.me> <32c15a30-6e25-4f6d-9191-76a19482c556@vondra.me> <64c8b824-6203-46a3-b045-5e95b796feee@vondra.me> <03dcc1a9-c5d0-4965-889c-684dc0a7580c@vondra.me> In-Reply-To: From: Thomas Munro Date: Sat, 19 Jul 2025 16:03:19 +1200 X-Gm-Features: Ac12FXxPyfST6oTP9OwKQWj4Kt38xkGOzrdMOmM5onQde7iUrIyTGzdE3y9Om6k Message-ID: Subject: Re: index prefetching To: Tomas Vondra Cc: Peter Geoghegan , Andres Freund , Robert Haas , Melanie Plageman , PostgreSQL Hackers , Georgios , Konstantin Knizhnik , Dilip Kumar 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 Sat, Jul 19, 2025 at 6:31=E2=80=AFAM Tomas Vondra wrot= e: > Perhaps the ReadStream should do something like this? Of course, the > simple patch resets the stream very often, likely mcuh more often than > anything else in the code. But wouldn't it be beneficial for streams > reset because of a rescan? Possibly needs to be optional. Right, that's also discussed, with a similar patch, here: https://www.postgresql.org/message-id/CA%2BhUKG%2Bx2BcqWzBC77cN0ewhzMF0kYhC= 6c4G_T2gJLPbqYQ6Ow%40mail.gmail.com Resetting the distance was a short-sighted mistake: I was thinking about rescans, the original use case for the reset operation, and guessing that the data would remain cached. But all the new users of _reset() have a completely different motivation, namely temporary exhaustion in their source data, so that guess was simply wrong. There was also some discussion at the time about whether "reset so I can rescan", and "reset so I can continue after a temporary stop" should be different operations requiring different APIs. It now seems like one operation is sufficient, but it should preserve the distance as you showed and then let the algorithm learn about already-cached data in the rescan case (if it is even true then, which is also debatable since it depends on the size of the scan). So, I think we should just go ahead and commit a patch like that.