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 1rPlyM-00E2Cf-JH for pgsql-hackers@arkaria.postgresql.org; Tue, 16 Jan 2024 16:07:31 +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 1rPlyL-004qJa-EY for pgsql-hackers@arkaria.postgresql.org; Tue, 16 Jan 2024 16:07:29 +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.94.2) (envelope-from ) id 1rPlyL-004qJR-1T for pgsql-hackers@lists.postgresql.org; Tue, 16 Jan 2024 16:07:29 +0000 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rPlyE-001pzP-0p for pgsql-hackers@postgresql.org; Tue, 16 Jan 2024 16:07:27 +0000 Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-337b583453bso666642f8f.2 for ; Tue, 16 Jan 2024 08:07:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=garret-ru.20230601.gappssmtp.com; s=20230601; t=1705421239; x=1706026039; darn=postgresql.org; h=in-reply-to:from:references:to:content-language:subject:user-agent :mime-version:date:message-id:from:to:cc:subject:date:message-id :reply-to; bh=c1MSoz3yzYTG8CrvYpBu/5mHvbitVZFbhPThMwi9KV4=; b=JzJgQHJXzFVq4UTl/SuGISmcC12wXwKt0OrB8+bAEpnxq6OSk5vC9iQdTxw/vLvD0e wOUSq/PtLe5NlvoiS8mfXXjn1XAwP38wIICnPNDR2oEvUic9HTYkdoN7kEwqAfoNrud2 sLKY76GdfGix8Mbd4t/2Memow4J89glCjJru7U8KTDMu4ShAjnepq3s6zyZEzR8duSiV hvblQ451iN1rRM68KnShZtPLiLrACjeaZR2tViznjPspuqawx96hdHeMDaz3XBCD8Pzw +h4AF2SSanuA58kLD91QUZd0+zlNXXq+VKDvdGU7+QtXtyXKE46zEVFcoas2Db2n0DWV 6c4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705421239; x=1706026039; h=in-reply-to:from:references:to:content-language:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=c1MSoz3yzYTG8CrvYpBu/5mHvbitVZFbhPThMwi9KV4=; b=qAc8TtI4qSpiaZr2S70FIEObQkJ1DyU8JumvPavnSYusuEZGAFV8MNRPoFNO9mic3F 98iXhZs3SwpsGH/aNVsolrOBHfhHJ/d5GWXmuHG8SX9Xm6YTNL8mfQypuvXXoYi3d+IY /RVqCvMTQv02mrJLY0V4pNLQuEQ5eji3zsDD8X+4Gci22nrMlu9ePg5rVdnuDmTd8Was sn3xBjHHR2vu40G7FAPsUBBSClUjbF/cyWx3OziRK9Qg4j0mVMJevqauau9NeIHJ3f2v SEguhuYOIf9wcVJnfPiwWehgUI60OTu5jak7PD2PfZGVoU0Te9m9SQzSsD/pWH5unINN xqnw== X-Gm-Message-State: AOJu0YzKvJ+c9nwfCqT0o2ZLWN70zldQ38xphAypqBy0oo3p0KwJyb5A HSGfYSZoD5+p1ZBhcZ9DoAinBfEQQKR1QdA1cw/I+BIVjA== X-Google-Smtp-Source: AGHT+IG3liGbDVs/ABKwcvo6vxVuRsLrVM40iBs0JRKnDyR+MMF+yeLdXoMeHZfoCgUrbnagbEk7gg== X-Received: by 2002:a5d:6046:0:b0:337:491e:bc46 with SMTP id j6-20020a5d6046000000b00337491ebc46mr2679254wrt.56.1705421238920; Tue, 16 Jan 2024 08:07:18 -0800 (PST) Received: from [192.168.2.11] ([217.175.216.56]) by smtp.gmail.com with ESMTPSA id v1-20020a5d6101000000b003374555d88esm14906781wrt.56.2024.01.16.08.07.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 16 Jan 2024 08:07:18 -0800 (PST) Content-Type: multipart/alternative; boundary="------------fICM1Sy856110lwTF4LXw8px" Message-ID: <5e5df8c7-790f-492f-b8f6-f9ee09321d47@garret.ru> Date: Tue, 16 Jan 2024 18:07:16 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Custom explain options Content-Language: en-US To: Tomas Vondra , PostgreSQL Hackers References: <6cd5caa7-06e1-4460-bf35-00a59da3f677@garret.ru> <629afb5e-9327-422c-a29f-4484279939b4@enterprisedb.com> <04aeec17-ad57-4d90-b2f1-7881369b7920@garret.ru> <50bf548d-44a1-49d8-aac9-6e4988badaae@enterprisedb.com> <57bc73d0-5f70-40bb-8d9e-ba4bc1f59d47@garret.ru> From: Konstantin Knizhnik In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------fICM1Sy856110lwTF4LXw8px Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 16/01/2024 5:38 pm, Tomas Vondra wrote: > By "broken" you mean that you prefetch items only from a single leaf > page, so immediately after reading the next one nothing is prefetched. > Correct? Yes, exactly. It means that reading first heap page from next leaf page will be done without prefetch which in case of Neon means roundtrip with page server (~0.2msec within one data center). > Yeah, I had this problem initially too, when I did the > prefetching in the index AM code. One of the reasons why it got moved to > the executor. Yeh, it works nice for vanilla Postgres. You call index_getnext_tid() and when it reaches end of leaf page it reads next read page. Because of OS read-ahead this read is expected to be fast even without prefetch. But not in Neon case - we have to download this page from page server (see above). So ideal solution for Neon will be to prefetch both leave pages and referenced heap pages. And prefetch of last one should be initiated as soon as leaf page is loaded. Unfortunately it is non-trivial to implement and current index scan prefetch implementation for Neon is not doing it. --------------fICM1Sy856110lwTF4LXw8px Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit


On 16/01/2024 5:38 pm, Tomas Vondra wrote:
By "broken" you mean that you prefetch items only from a single leaf
page, so immediately after reading the next one nothing is prefetched.
Correct?


Yes, exactly. It means that reading first heap page from next leaf page will be done without prefetch which in case of Neon means roundtrip with page server (~0.2msec within one data center).


 Yeah, I had this problem initially too, when I did the
prefetching in the index AM code. One of the reasons why it got moved to
the executor.

Yeh, it works nice for vanilla Postgres. You call index_getnext_tid() and when it reaches end of leaf page it reads next read page. Because of OS read-ahead this read is expected to be fast even without prefetch. But not in Neon case - we have to download this page from page server (see above). So ideal solution for Neon will be to prefetch both leave pages and referenced heap pages. And prefetch of last one should be initiated as soon as leaf page is loaded. Unfortunately it is non-trivial to implement and current index scan prefetch implementation for Neon is not doing it.


--------------fICM1Sy856110lwTF4LXw8px--