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 1rg6Mr-004Brk-VP for pgsql-hackers@arkaria.postgresql.org; Fri, 01 Mar 2024 17:08:18 +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 1rg6Mq-00EBEf-8B for pgsql-hackers@arkaria.postgresql.org; Fri, 01 Mar 2024 17:08:16 +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 1rg6Mp-00EBEX-Sa for pgsql-hackers@lists.postgresql.org; Fri, 01 Mar 2024 17:08:16 +0000 Received: from mail-ed1-x531.google.com ([2a00:1450:4864:20::531]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rg6Mi-002HhA-5m for pgsql-hackers@postgresql.org; Fri, 01 Mar 2024 17:08:15 +0000 Received: by mail-ed1-x531.google.com with SMTP id 4fb4d7f45d1cf-565b434f90aso3680622a12.3 for ; Fri, 01 Mar 2024 09:08:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; t=1709312885; x=1709917685; darn=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=YGOhDnvjPB1g8bSwGiI2uAYWba7piulr7dgR8+9NwZU=; b=KGZG+Bovp4ipoU0AVOYRZj8gkvwI9kJpKSgV5ju4ywKdRK4j9M2kRafaZ+aXKFdffl w5hhukC4MM8A8KaHgnS3V0Rwh4on9Bhui9CzfmWmLBS1USw9NeED6nyOGNr+MbCktxRU myXVdeEwxLzr7FHaOTPW45LRD4xSQFTPYuhdWGwG7gDkFgyEjvL0bQdMSJHzxbb19YIM ZG2Ihgn4g6M3Ng7EDuJ216+qIx6UJcyJ+ameoctxT+/Tmr9v6f3NUPeT9VyD8AjRqb6j bm2VXNxDrKZ6uLLH1fk8rmnhTaCqoJP8POqOqQAFWsSBhVHmsqaIy5Cz6LiTbBxkuraW 0iIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709312885; x=1709917685; 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=YGOhDnvjPB1g8bSwGiI2uAYWba7piulr7dgR8+9NwZU=; b=wYeLQc4C6ok3rSkIle8bnXK0XMFVl0ksELNEcMeg5NvA7PZUD3709WhxQiUM4vg1wk GugXDkZxrp4o+AnnT4Sibid5/Our6sR8dHx5L69ZdHslStIpyFvoN4qyKzTgYbpluqf6 CvZiMAZSBekRgJpTZ+NNv26H3pqaX2Ze8PIMwZFqybM0F6RaKBZIpGC9rOi02zvvclOw Jy/8x9EZcS4f8LMsusfQbgssrszj+6HUzZDe6dv6wxKmhM0es444OVfLifBjQeLPXSuV 2NELGK2FCtfj1ruK/7f7sZ6dn87WqVlEuvj9/5h6MbhJLXiUnee5BopNgecpMIePIfmB vpsw== X-Forwarded-Encrypted: i=1; AJvYcCU06zQ8JdJRyL86GoCrmcAHpikoX3fj0lg570QUv7liMS0btYIE2j6Ip9HLPKFgCu3JmhYf2adlCPTdSCgYgqskhBsJgG6Tl5Sn7OHi X-Gm-Message-State: AOJu0YxvGm479POpP9NPwChkZj70/sGMIm0X505Kz5c0M9r7mo2xHF0g hIgGq0OTssGCzLLs3E9LynEIcL6ab2szDj9I2PWI3h3S71uNgrs5Q1F8WEmJiQ== X-Google-Smtp-Source: AGHT+IGCAl9BoqkOUFoNilniDgwMZlOfCccsa0VqdR3qHmht17X/SOZhzjlRGDkF5D7gdtM3At1EAQ== X-Received: by 2002:a17:906:54c7:b0:a41:3e39:b918 with SMTP id c7-20020a17090654c700b00a413e39b918mr1851872ejp.24.1709312885627; Fri, 01 Mar 2024 09:08:05 -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 nb33-20020a1709071ca100b00a4403563ae3sm1838059ejc.153.2024.03.01.09.08.04 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 01 Mar 2024 09:08:05 -0800 (PST) Message-ID: <410c42e0-f17b-447f-aa48-fba052d5c080@enterprisedb.com> Date: Fri, 1 Mar 2024 18:08:03 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: BitmapHeapScan streaming read user and prelim refactoring Content-Language: en-US To: Melanie Plageman Cc: Andres Freund , Pg Hackers , Thomas Munro , Heikki Linnakangas , Nazir Bilal Yavuz References: <20240227142230.nu3ytvcjwouvczlt@liskov> <40c213cc-6a15-4e2c-9e56-dae344d52a73@enterprisedb.com> <4b751bc5-446f-4357-a1e1-827585bf22b0@enterprisedb.com> <45bed4f3-a5bf-4a34-b544-7e751bd437e1@enterprisedb.com> <91090d58-7d3f-4447-9425-f24ba66e292a@enterprisedb.com> <8de6f6d7-9b9d-47a4-98cc-84bf31a314db@enterprisedb.com> <35bdb7db-7412-4d18-9b06-fea5fcea37bc@enterprisedb.com> <0c7c0673-d012-41d1-8e76-31cc4a1b1eec@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 3/1/24 17:51, Melanie Plageman wrote: > On Fri, Mar 1, 2024 at 9:05 AM Tomas Vondra > wrote: >> >> On 3/1/24 02:18, Melanie Plageman wrote: >>> On Thu, Feb 29, 2024 at 6:44 PM Tomas Vondra >>> wrote: >>>> >>>> On 2/29/24 23:44, Tomas Vondra wrote: >>>> 1) On master there's clear difference between eic=0 and eic=1 cases, but >>>> on the patched build there's literally no difference - for example the >>>> "uniform" distribution is clearly not great for prefetching, but eic=0 >>>> regresses to eic=1 poor behavior). >>> >>> Yes, so eic=0 and eic=1 are identical with the streaming read API. >>> That is, eic 0 does not disable prefetching. Thomas is going to update >>> the streaming read API to avoid issuing an fadvise for the last block >>> in a range before issuing a read -- which would mean no prefetching >>> with eic 0 and eic 1. Not doing prefetching with eic 1 actually seems >>> like the right behavior -- which would be different than what master >>> is doing, right? >> >> I don't think we should stop doing prefetching for eic=1, or at least >> not based just on these charts. I suspect these "uniform" charts are not >> a great example for the prefetching, because it's about distribution of >> individual rows, and even a small fraction of rows may match most of the >> pages. It's great for finding strange behaviors / corner cases, but >> probably not a sufficient reason to change the default. > > Yes, I would like to see results from a data set where selectivity is > more correlated to pages/heap fetches. But, I'm not sure I see how > that is related to prefetching when eic = 1. > OK, I'll make that happen. >> I think it makes sense to issue a prefetch one page ahead, before >> reading/processing the preceding one, and it's fairly conservative >> setting, and I assume the default was chosen for a reason / after >> discussion. > > Yes, I suppose the overhead of an fadvise does not compare to the IO > latency of synchronously reading that block. Actually, I bet the > regression I saw by accidentally moving BitmapAdjustPrefetchIterator() > after table_scan_bitmap_next_block() would be similar to the > regression introduced by making eic = 1 not prefetch. > > When you think about IO concurrency = 1, it doesn't imply prefetching > to me. But, I think we want to do the right thing and have parity with > master. > Just to be sure we're on the same page regarding what eic=1 means, consider a simple sequence of pages: A, B, C, D, E, ... With the current "master" code, eic=1 means we'll issue a prefetch for B and then read+process A. And then issue prefetch for C and read+process B, and so on. It's always one page ahead. Yes, if the page is already in memory, the fadvise is just overhead. It may happen for various reasons (say, read-ahead). But it's just this one case, I'd bet in other cases eic=1 would be a win. >> My suggestion would be to keep the master behavior unless not practical, >> and then maybe discuss changing the details later. The patch is already >> complicated enough, better to leave that discussion for later. > > Agreed. Speaking of which, we need to add back use of tablespace IO > concurrency for the streaming read API (which is used by > BitmapHeapScan in master). > +1 >>> With very low selectivity, you are less likely to get readahead >>> (right?) and similarly less likely to be able to build up > 8kB IOs -- >>> which is one of the main value propositions of the streaming read >>> code. I imagine that this larger read benefit is part of why the >>> performance is better at higher selectivities with the patch. This >>> might be a silly experiment, but we could try decreasing >>> MAX_BUFFERS_PER_TRANSFER on the patched version and see if the >>> performance gains go away. >> >> Sure, I can do that. Do you have any particular suggestion what value to >> use for MAX_BUFFERS_PER_TRANSFER? > > I think setting it to 1 would be the same as always master -- doing > only 8kB reads. The only thing about that is that I imagine the other > streaming read code has some overhead which might end up being a > regression on balance even with the prefetching if we aren't actually > using the ranges/vectored capabilities of the streaming read > interface. Maybe if you just run it for one of the very obvious > performance improvement cases? I can also try this locally. > OK, I'll try with 1, and then we can adjust. >> I'll also try to add a better version of uniform, where the selectivity >> matches more closely to pages, not rows. > > This would be great. > regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company