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 1rgYD1-006jPo-Ji for pgsql-hackers@arkaria.postgresql.org; Sat, 02 Mar 2024 22:52:00 +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 1rgYCy-00HL46-ET for pgsql-hackers@arkaria.postgresql.org; Sat, 02 Mar 2024 22:51:56 +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 1rgYCy-00HL3y-4O for pgsql-hackers@lists.postgresql.org; Sat, 02 Mar 2024 22:51:56 +0000 Received: from mail-ej1-x62b.google.com ([2a00:1450:4864:20::62b]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rgYCt-002YD1-Kh for pgsql-hackers@postgresql.org; Sat, 02 Mar 2024 22:51:54 +0000 Received: by mail-ej1-x62b.google.com with SMTP id a640c23a62f3a-a44e3176120so70095666b.1 for ; Sat, 02 Mar 2024 14:51:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; t=1709419911; x=1710024711; 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=0FAlOw29bDJLEGzSY6koiNOae5WSa4x8OvxBdPEQ4L4=; b=g0fbCISdk3iDksy9lYUZ4IZ/+nUh3QGENdEXE80AZYbHPWsEDits+3E8EF7RVdKdO/ Sg1ZjJ56pDU5OrYp5qiUsOunlSwXf60/Gk0RUzpnS/dLUvZoGoEjaVe87miySH0ViCTh Ikfb89Bmrswn5iqTjC97CuauMAVXKl4Z5TMRnCJaIfESzYr2Xf3rZWLXnKohTJBNA3HQ Tg9fNVUuB6Mh680sHxOwlPt52HSPiw9gH5usW4ngkLigJOnk7PfBsl1gGvH5TsXBbCTh s36tAb/Bxzf0P2WF/67AzQdRU6sR8vjEf+lOEFDhKqr6Uaf56eLL3Qq6uq+rqqrvx60L vh9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709419911; x=1710024711; 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=0FAlOw29bDJLEGzSY6koiNOae5WSa4x8OvxBdPEQ4L4=; b=C3SdF6s/PYiR4sgtPPC3GBe9FtEe1hVlfMDChKTbu68iXW6rDdaUbZviEhuPH/c0Bf EcsNphrWKmJsZVGnVxX1Z6UNpoJfgYtl60ZuNhYsBFO9jgHq6YnT/CSC/xlh3+cbmmvh OLrijA6+RDKHm5X2TxcPsmp6vd8G8vtNxCUu8jeq1ZzfuoJxWgkeVZXrr/4JqcPPjIXF fQwWlJzSF61TaLyju+USce2222VpyRfj82OpaggEyXllky/cn6ZkEg3Dxqe/ntkrqelA xKZHQT0MjNIupT57efc235/wRXo+U/QFHDkRmKXAQA6XemyttQcf9gdfE09zVk/Pjna5 u1+w== X-Forwarded-Encrypted: i=1; AJvYcCUzVmADQJDn9J1AvoOZFFEoZhj2vtRrVRzI0JUxfuxhnwhTDSLs/v8w2kdLA6ltiJWPL2PGroVTU15Vx2vaIer6EtYubUOECPhm2Gpa X-Gm-Message-State: AOJu0YyNrP0H7ooeeEJWRj565sDKJ2uKoxq70nP0v9BsAD9Q5P2HKLvK Z1znkimIDsRNJxPxaDVsGgAayzLtK7EmtyoCyJa09WTGojzC9PClspnYA19MEirOdU7Od7voDDE = X-Google-Smtp-Source: AGHT+IEZrfKKmtaIL+D1vBK3GdBtTYJ3LmJt74DHvZxY4yME8M10kRh4zGS8rKfjg5eav10nAZk0YA== X-Received: by 2002:a17:906:b2d8:b0:a44:e8ec:f075 with SMTP id cf24-20020a170906b2d800b00a44e8ecf075mr1293397ejb.57.1709419911252; Sat, 02 Mar 2024 14:51:51 -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 gt25-20020a170906f21900b00a3ec216ec6csm3086794ejb.45.2024.03.02.14.51.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 02 Mar 2024 14:51:50 -0800 (PST) Message-ID: <45e3e300-f06a-42a0-8f14-acc6092edacc@enterprisedb.com> Date: Sat, 2 Mar 2024 23:51:49 +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: <20240227015028.knohvy3spaqwk7lf@liskov> <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> 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/2/24 23:11, Melanie Plageman wrote: > On Fri, Mar 1, 2024 at 2:31 PM Melanie Plageman > wrote: >> >> ... >> >> Hold the phone on this one. I realized why I moved >> BitmapAdjustPrefetchIterator after table_scan_bitmap_next_block() in >> the first place -- master calls BitmapAdjustPrefetchIterator after the >> tbm_iterate() for the current block -- otherwise with eic = 1, it >> considers the prefetch iterator behind the current block iterator. I'm >> going to go through and figure out what order this must be done in and >> fix it. > > So, I investigated this further, and, as far as I can tell, for > parallel bitmapheapscan the timing around when workers decrement > prefetch_pages causes the performance differences with patch 0010 > applied. It makes very little sense to me, but some of the queries I > borrowed from your regression examples are up to 30% slower when this > code from BitmapAdjustPrefetchIterator() is after > table_scan_bitmap_next_block() instead of before it. > > SpinLockAcquire(&pstate->mutex); > if (pstate->prefetch_pages > 0) > pstate->prefetch_pages--; > SpinLockRelease(&pstate->mutex); > > I did some stracing and did see much more time spent in futex/wait > with this code after the call to table_scan_bitmap_next_block() vs > before it. (table_scan_bitmap_next_block()) calls ReadBuffer()). > > In my branch, I've now moved only the parallel prefetch_pages-- code > to before table_scan_bitmap_next_block(). > https://github.com/melanieplageman/postgres/tree/bhs_pgsr > I'd be interested to know if you see the regressions go away with 0010 > applied (commit message "Make table_scan_bitmap_next_block() async > friendly" and sha bfdcbfee7be8e2c461). > I'll give this a try once the runs with MAX_BUFFERS_PER_TRANSFER=1 complete. But it seems really bizarre that simply moving this code a little bit would cause such a regression ... regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company