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 1rGCsK-00EDrl-Mp for pgsql-hackers@arkaria.postgresql.org; Thu, 21 Dec 2023 06:49:44 +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 1rGCsH-004TKv-C6 for pgsql-hackers@arkaria.postgresql.org; Thu, 21 Dec 2023 06:49:41 +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 1rGCsH-004TKn-2N for pgsql-hackers@lists.postgresql.org; Thu, 21 Dec 2023 06:49:41 +0000 Received: from mail-lj1-x22f.google.com ([2a00:1450:4864:20::22f]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rGCsE-00D85Q-8O for pgsql-hackers@lists.postgresql.org; Thu, 21 Dec 2023 06:49:40 +0000 Received: by mail-lj1-x22f.google.com with SMTP id 38308e7fff4ca-2cc99fc1858so3649811fa.2 for ; Wed, 20 Dec 2023 22:49:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703141377; x=1703746177; 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=fLyQok8VPqvQqdUMEpTEOT7kEYNzpSSmYtxycS3jvZE=; b=Bebc7aFUCGRMsBsN0c6HkpeaC47BfnsYShlIfV2BcCisf50s+IUg11KZS5JdMiccxz 6h0pt+jqSa4NXe2kslt/4J9K9mSdeS53506ECBGK41rbR2cRE4sF/9wMvMnE14wl9DzP sh+Q8D1M1NpTDvxrnKyYLZq5upMTOxm6JII4+1qrPhnNtUZesUzFVcgC3/tHMIskAbGN WUwjhr6tEyMZwOypDyDDjwRaVvH2mTQF8amFIC+vVL6fdsQH9xY/7lBzG7KZtIE1nTj2 W7FuhjOahQI2t13AMbtWpwtxDz0vV5tPbAUMjrXgkLPqNt/uSun1tbiG76mz4W1knuf6 YTIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703141377; x=1703746177; 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=fLyQok8VPqvQqdUMEpTEOT7kEYNzpSSmYtxycS3jvZE=; b=I4tit7D8TRKXy+yBjinbR1B2nt2uM36Q7ZwuB1OiM17khhzYvU7qSyda4Yzvuc1tb5 6EVgycswGOn2Dfsag+CsGbkyj1TOnpMUp88Nf/OQv5MHmn4blTSHi+XURypFJNRSVAZa +cdtm/b3iiSOJDaSqRz8XEWDwOglPczRDup17RhLbjHSMDlRYMz4VgBDuGGXDKrM8G+u ZJ9bPlR1ZdLsIsFplggYW+bwYJDjLHMg1aUw73pK0pIqgaD7sYjeNteckemqNx18aYTc eMvXgLwzdqDAS9LIP50eIcL8lQstAsUAEZpngNDZ5qxvbZuoDGrul0cyVtjqR8JbrCKi TOZQ== X-Gm-Message-State: AOJu0YxUWAsS1F/tFr4/ElUUFX9GeBAA+9G76X2nO2VrlJRwOauB9eqg ryvhUAYXd3i+WheKygowv9BJoryt9DxJiyz9UYA= X-Google-Smtp-Source: AGHT+IEopjo0AUu7d2nqd6Ju4gYxJGjgQ0QPvXqK1pHD6Fzt1SaQrqcwqXmqVm/ELjcqLdk8UXn2wTd1OJoRFQmSs0k= X-Received: by 2002:a2e:3608:0:b0:2cc:7147:c8d8 with SMTP id d8-20020a2e3608000000b002cc7147c8d8mr2073784lja.65.1703141376851; Wed, 20 Dec 2023 22:49:36 -0800 (PST) MIME-Version: 1.0 References: <20230609000600.syqy447e6metnvyj@awork3.anarazel.de> <20230610203456.5gancfekm4pj4pbs@awork3.anarazel.de> <6030d836-e8b7-e7b9-2cbb-144309679d03@enterprisedb.com> <8c86c3a6-074e-6c88-3e7e-9452b6a37b9b@enterprisedb.com> <3cd40425-965a-5ce1-1af3-d51971c44b93@enterprisedb.com> <8ec36f51-b863-60e3-20e2-b9c981c5ce5e@enterprisedb.com> <06bb7d02-2c44-3062-731e-a735ba13da7e@enterprisedb.com> <367160ea-b1ed-4481-e804-bca509128878@enterprisedb.com> <280dc83c-a16f-4424-1319-95e7e3f798bd@enterprisedb.com> In-Reply-To: <280dc83c-a16f-4424-1319-95e7e3f798bd@enterprisedb.com> From: Dilip Kumar Date: Thu, 21 Dec 2023 12:19:20 +0530 Message-ID: Subject: Re: index prefetching To: Tomas Vondra Cc: Robert Haas , Andres Freund , PostgreSQL Hackers , Georgios 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 Wed, Dec 20, 2023 at 7:11=E2=80=AFAM Tomas Vondra wrote: > I was going through to understand the idea, couple of observations -- + for (int i =3D 0; i < PREFETCH_LRU_SIZE; i++) + { + entry =3D &prefetch->prefetchCache[lru * PREFETCH_LRU_SIZE + i]; + + /* Is this the oldest prefetch request in this LRU? */ + if (entry->request < oldestRequest) + { + oldestRequest =3D entry->request; + oldestIndex =3D i; + } + + /* + * If the entry is unused (identified by request being set to 0), + * we're done. Notice the field is uint64, so empty entry is + * guaranteed to be the oldest one. + */ + if (entry->request =3D=3D 0) + continue; If the 'entry->request =3D=3D 0' then we should break instead of continue, = right? --- /* * Used to detect sequential patterns (and disable prefetching). */ #define PREFETCH_QUEUE_HISTORY 8 #define PREFETCH_SEQ_PATTERN_BLOCKS 4 If for sequential patterns we search only 4 blocks then why we are maintaining history for 8 blocks --- + * + * XXX Perhaps this should be tied to effective_io_concurrency somehow? + * + * XXX Could it be harmful that we read the queue backwards? Maybe memory + * prefetching works better for the forward direction? + */ + for (int i =3D 1; i < PREFETCH_SEQ_PATTERN_BLOCKS; i++) Correct, I think if we fetch this forward it will have an advantage with memory prefetching. --=20 Regards, Dilip Kumar EnterpriseDB: http://www.enterprisedb.com