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 1rGITJ-00Ea3L-7p for pgsql-hackers@arkaria.postgresql.org; Thu, 21 Dec 2023 12:48:17 +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 1rGITH-008bOr-JS for pgsql-hackers@arkaria.postgresql.org; Thu, 21 Dec 2023 12:48:15 +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 1rGITH-008bJc-7v for pgsql-hackers@lists.postgresql.org; Thu, 21 Dec 2023 12:48:15 +0000 Received: from mail-ej1-x632.google.com ([2a00:1450:4864:20::632]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rGITD-00BV5I-OX for pgsql-hackers@lists.postgresql.org; Thu, 21 Dec 2023 12:48:13 +0000 Received: by mail-ej1-x632.google.com with SMTP id a640c23a62f3a-a2339262835so79685666b.3 for ; Thu, 21 Dec 2023 04:48:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; t=1703162890; x=1703767690; 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=wg3e+cm8zIQ/AjGPw+GdeisQX5swnmHkEgpK5FUppwI=; b=XtW8dYTrMMWChe8Q9+c1rmibfSVBuYNPPKniSDqc6exZIbHNNL0FgETdUS+CtzpfP+ BG0vasDjaT8G06+Att0Lzzhxyr0HrXR4avvzoRcSjslohVjTV0zzW7b5RCn7dGqdYdpO 9sgcANiMz2m/byQE2vYqMbhnesNILbL1ew41LoqsBTHn9uX8ebTs+nPoK4nANvYLBG4f BXcG3bPDh4wiJGzlWEF+Gqfvc745X32ehMpLmc2cOsrJRnZWaliPgf+IvKrM8JDdD1bc 60sQ22onTJUMbB07ofrKGKQ2hidfLlINKsRXUjT78rsBwmIzaT5+6wr2+RvQiCRe5RHO 6zLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703162890; x=1703767690; 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=wg3e+cm8zIQ/AjGPw+GdeisQX5swnmHkEgpK5FUppwI=; b=M7IlPC+80ySlqqTkQ7A8DFWhNLE1QuKoaW2uQCwEce31pEawmlsF8KanFdjTslGvkt DSlINw39QkWJrbWPCeZzGKTHHMyireVHBLbCaZ4ezLNxuyQCltrKZ+4Fz5FRVRk04hy4 g+WQeRRzN1YYIjzK26vgdv5z7Yvw3BaPCYlz+d4eqm9MPocNLL37FoPj1ZKBWg0jXaqI CnhMcmmiRlXC4PhcsWp3Ab0jPGMcux7ej4dJ4o8tx18qUk5f4QSERECmAq1S7JZlX0G0 d2/YQRue5PSCKNKBD5lIvGnhcz6TRZSt89QUj0tEXCoyje+ECQKSVV588+7E5nweQRQC 4j1g== X-Gm-Message-State: AOJu0YwM0DrGBx20pZa0ls7bnltvLl0rHjHQMXdsZtjNqyzgseO/ufT6 QQOP3DOfol2/+lQXVxtSzm7NRw== X-Google-Smtp-Source: AGHT+IG4pSzcjGTA/OvqzmIsGupT5+2+5KIdhvI+TjWz3N0rb4qLWKytGObuv0hpGNushkaqzJJpSA== X-Received: by 2002:a17:906:5198:b0:a26:9656:28b2 with SMTP id y24-20020a170906519800b00a26965628b2mr1189379ejk.113.1703162890194; Thu, 21 Dec 2023 04:48:10 -0800 (PST) Received: from [10.137.0.17] (srv1.mobissw.com. [89.235.0.226]) by smtp.gmail.com with ESMTPSA id hg24-20020a1709072cd800b00a2368de9471sm916861ejc.202.2023.12.21.04.48.09 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 21 Dec 2023 04:48:09 -0800 (PST) Message-ID: Date: Thu, 21 Dec 2023 13:48:09 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: index prefetching Content-Language: en-US To: Dilip Kumar Cc: Robert Haas , Andres Freund , PostgreSQL Hackers , Georgios 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> From: Tomas Vondra In-Reply-To: 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 12/21/23 07:49, Dilip Kumar wrote: > On Wed, Dec 20, 2023 at 7:11 AM Tomas Vondra > wrote: >> > I was going through to understand the idea, couple of observations > > -- > + for (int i = 0; i < PREFETCH_LRU_SIZE; i++) > + { > + entry = &prefetch->prefetchCache[lru * PREFETCH_LRU_SIZE + i]; > + > + /* Is this the oldest prefetch request in this LRU? */ > + if (entry->request < oldestRequest) > + { > + oldestRequest = entry->request; > + oldestIndex = 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 == 0) > + continue; > > If the 'entry->request == 0' then we should break instead of continue, right? > Yes, I think that's true. The small LRU caches are accessed/filled linearly, so once we find an empty entry, all following entries are going to be empty too. I thought this shouldn't make any difference, because the LRUs are very small (only 8 entries, and I don't think we should make them larger). And it's going to go away once the cache gets full. But now that I think about it, maybe this could matter for small queries that only ever hit a couple rows. Hmmm, I'll have to check. Thanks for noticing this! > --- > /* > * 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 > > --- Right, I think there's no reason to keep these two separate constants. I believe this is a remnant from an earlier patch version which tried to do something smarter, but I ended up abandoning that. > > + * > + * 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 = 1; i < PREFETCH_SEQ_PATTERN_BLOCKS; i++) > > Correct, I think if we fetch this forward it will have an advantage > with memory prefetching. > OK, although we only really have a couple uint32 values, so it should be the same cacheline I guess. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company