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 1rRhXQ-008l0Y-7B for pgsql-hackers@arkaria.postgresql.org; Sun, 21 Jan 2024 23:47:40 +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 1rRhXO-00GuKc-Jn for pgsql-hackers@arkaria.postgresql.org; Sun, 21 Jan 2024 23:47:38 +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 1rRhXO-00GuKT-9k for pgsql-hackers@lists.postgresql.org; Sun, 21 Jan 2024 23:47:38 +0000 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rRhXG-0031sb-Ai for pgsql-hackers@lists.postgresql.org; Sun, 21 Jan 2024 23:47:36 +0000 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-40eaf24d1e7so592595e9.2 for ; Sun, 21 Jan 2024 15:47:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; t=1705880848; x=1706485648; darn=lists.postgresql.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=Etr4lRs9GGgmisMNRYf+ZGtVlEQbIWK4n9nIsrDn8L8=; b=QBNy+iIzFcF1J1KqOTuEQyTbb3+c/i5YN8MTYbvJBAG4x1xy/Mt7tD0K8pBX5yTbvz AvEgA2Rk/YB26H9X9MmMHf4cPe6Hf3ikxQX49YB0bAjC/M8MKpgbHFEHz+AhO5OHXa3G PFyAR4boKE0VP6ci8pG+7+5Swkks8v95/wxAh9xPvlSuS3cYDA1o9l5s05b2kGO+tSNw 3eOHVtJXTIvsEI0nYEHHFzF8k/zZVYWKsZ6trdTBfdwa8fLY5ZIzL48/ak7IyU2NsjBY XkpsuO3enx0T/WdloE0Z0UO2m/bPVszf6SZ7A7gQfPrvbYKTe7RkGq7IBRDudiaiTHk4 w9JQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705880848; x=1706485648; h=content-transfer-encoding:in-reply-to:from:references:cc: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=Etr4lRs9GGgmisMNRYf+ZGtVlEQbIWK4n9nIsrDn8L8=; b=mufxxtI85op8grnt0b05h1EuJE5Kqnnw0NKoqCzB5oy1HyvRWucNaeZmfOQurQvfdU +2zDCr+Hi+PLXDysE8lcUDeOc5vLbV94Y4Z0CdYlMN0iPNGv814qqnlP/9N8Ts+T7197 72vWK/oEqXI5wZDe+U/44jiXKJ5pdoBmhrZom447iOkHp5BHpuGMSN2AC8OAOCSJGM30 pgO22BByxyPovc/CaijUPKVppIbvKIJyqFdp7x3lpNZgEk3jZ2+klijqh7P/7cuvjKN2 EW+GEZdmhWpAHv8R/vt9QDr3ZD756A2qT4i/6qC6/7j+bqcDxWycblCXGS8+PpPa2jii Bs7g== X-Gm-Message-State: AOJu0YxlvLnbgD0Xejpk6LQEROWmlSOUNAPnl0r6CkwANohu/qBmURlV Eqm9oHF+hQdi0bHASOCWbYsX/VgO2F+ioK3bELOMemD0hTaa1dy/IcKi3fozW0xJ3Gx/1RuDUdQ = X-Google-Smtp-Source: AGHT+IGZZuvU+BmgPDsZxK2nGYiFIoh4PxRcOrfKOggZgVL+Za2Fl1J05RCV8F8FcEwneWzV+0jTBw== X-Received: by 2002:a7b:cb93:0:b0:40e:431c:76d9 with SMTP id m19-20020a7bcb93000000b0040e431c76d9mr1692616wmi.148.1705880848255; Sun, 21 Jan 2024 15:47:28 -0800 (PST) Received: from [10.137.0.18] (ip-86-49-229-30.bb.vodafone.cz. [86.49.229.30]) by smtp.gmail.com with ESMTPSA id a11-20020adfe5cb000000b00337d92e8b9csm8191958wrn.109.2024.01.21.15.47.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 21 Jan 2024 15:47:27 -0800 (PST) Message-ID: <2fda99cb-52b1-432f-b570-d9acbecb42bb@enterprisedb.com> Date: Mon, 22 Jan 2024 00:47:27 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: index prefetching Content-Language: en-US To: Konstantin Knizhnik Cc: PostgreSQL Hackers References: <8ec36f51-b863-60e3-20e2-b9c981c5ce5e@enterprisedb.com> <280dc83c-a16f-4424-1319-95e7e3f798bd@enterprisedb.com> <98ba4b25-fae8-c1f4-1597-8093375a1986@enterprisedb.com> <20231221134314.wf2rs62d37u62j7t@alap3.anarazel.de> <20231221154352.ijtg6wloa3nowivh@alap3.anarazel.de> <482ec3ff-52ad-415d-96fd-f3832a894023@enterprisedb.com> <8969e2cf-6b23-4682-ab56-b3c0aca877ab@garret.ru> <214d5bbe-21d7-4a63-b62b-91fe84f281f5@enterprisedb.com> <731c8bb7-0662-47a5-a782-5cb631916f1d@enterprisedb.com> <22dbfb04-24e4-49b1-b3fa-5367c8d171d2@garret.ru> <41b959cb-f483-413a-ba5e-f1ac4db0ef0b@garret.ru> From: Tomas Vondra In-Reply-To: <41b959cb-f483-413a-ba5e-f1ac4db0ef0b@garret.ru> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 1/21/24 20:56, Konstantin Knizhnik wrote: > > On 19/01/2024 2:35 pm, Tomas Vondra wrote: >> >> On 1/19/24 09:34, Konstantin Knizhnik wrote: >>> On 18/01/2024 6:00 pm, Tomas Vondra wrote: >>>> On 1/17/24 09:45, Konstantin Knizhnik wrote: >>>>> I have integrated your prefetch patch in Neon and it actually works! >>>>> Moreover, I combined it with prefetch of leaf pages for IOS and it >>>>> also >>>>> seems to work. >>>>> >>>> Cool! And do you think this is the right design/way to do this? >>> I like the idea of prefetching TIDs in executor. >>> >>> But looking though your patch I have some questions: >>> >>> >>> 1. Why it is necessary to allocate and store all_visible flag in data >>> buffer. Why caller of  IndexPrefetchNext can not look at prefetch field? >>> >>> +        /* store the all_visible flag in the private part of the >>> entry */ >>> +        entry->data = palloc(sizeof(bool)); >>> +        *(bool *) entry->data = all_visible; >>> >> What you mean by "prefetch field"? > > > I mean "prefetch" field of IndexPrefetchEntry: > > + > +typedef struct IndexPrefetchEntry > +{ > +    ItemPointerData tid; > + > +    /* should we prefetch heap page for this TID? */ > +    bool        prefetch; > + > > You store the same flag twice: > > +        /* prefetch only if not all visible */ > +        entry->prefetch = !all_visible; > + > +        /* store the all_visible flag in the private part of the entry */ > +        entry->data = palloc(sizeof(bool)); > +        *(bool *) entry->data = all_visible; > > My question was: why do we need to allocate something in entry->data and > store all_visible in it, while we already stored !all-visible in > entry->prefetch. > Ah, right. Well, you're right in this case we perhaps could set just one of those flags, but the "purpose" of the two places is quite different. The "prefetch" flag is fully controlled by the prefetcher, and it's up to it to change it (e.g. I can easily imagine some new logic touching setting it to "false" for some reason). The "data" flag is fully controlled by the custom callbacks, so whatever the callback stores, will be there. I don't think it's worth simplifying this. In particular, I don't think the callback can assume it can rely on the "prefetch" flag. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company