Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pZIky-0001SU-9t for pgsql-hackers@arkaria.postgresql.org; Mon, 06 Mar 2023 21:52:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pZIkw-0007tx-TC for pgsql-hackers@arkaria.postgresql.org; Mon, 06 Mar 2023 21:52:30 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pZIkw-0007to-Hf for pgsql-hackers@lists.postgresql.org; Mon, 06 Mar 2023 21:52:30 +0000 Received: from mail-oa1-x2e.google.com ([2001:4860:4864:20::2e]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pZIkr-00057u-RK for pgsql-hackers@lists.postgresql.org; Mon, 06 Mar 2023 21:52:28 +0000 Received: by mail-oa1-x2e.google.com with SMTP id 586e51a60fabf-1767a208b30so11132215fac.2 for ; Mon, 06 Mar 2023 13:52:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678139543; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=OHlBKcyxSkM/53cLGtCkZTOOi6G6GjXqUzTBLwunh9g=; b=iAMPKN4RYDrPJHlsFvsW0Rd2apNlbgF6ccntJGB9s5ZbvdO62U16cDjyJGUV0Ob6IW V2KIWkPkx0CLq8y+RYl8CYlRWs9rpZiYFZg91ZlqJizBmOwe8tMsfpQH2/fGDrZY5DR2 k/bgGImTr2EPrSrMX4b6eCJHjhbFsoZ5tyvJeOdsCDZxDtoBDOxulGewnJzosD/a6HVT dW3FVGj9B3h6C5y7g4IddhUCetoL3/9/gX99XkhPMKvyeKBZyPO2yW23uqdP6iz9n8WK u9TNIWQXHYHPwL//B1X11gyU8f6ZaYAwi+Ygusu5OG7FpdMjvYbYIx0HWOZiH1GhQ9c3 dSCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678139543; h=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=OHlBKcyxSkM/53cLGtCkZTOOi6G6GjXqUzTBLwunh9g=; b=zI3+i2JfA0o/pVB2IQwCTq2rAheGzKgiF6NMLSFbs8NNUdHWaDtJBObcSj9k48WW5a tCSvXcgnyI6FXwrrmefXgu7IK6bSCgJ0Ynu6+PQUmqG8+p2VK/TGb3psiXUTkxvZhC2S RwT+VHGZV5unBcQB9WUcIMD20oCLGGPESumdE9QJY4kLlwsTRQAU30QA6GlOzRRgoZ99 P5/ml/tyr5CWiZ2W5WClbioOS4eoJC+UcJtU06KXCz2Pv93agCLu3IsMkWtuXqamyP8d k7gwlB1ut+1PJ8f3NyDzV2Zn5sxV2yDSOVLMLceJlVRguaTUKx/EQneEjpodZH/4kbXx s3qQ== X-Gm-Message-State: AO0yUKUxXUza0bEzoS1RGIuFoqxQaCPhnCGOzfMhqm7ypMEZibyFei46 WTrOpAiaX7kL12kTF8Rd9lpiA8KH9XnEnm1BFCeR46FDolA= X-Google-Smtp-Source: AK7set+6hQCxHH3zjMG43vzdJwZR34fQ8UWMQaDpk9BrFICfGt7ybpnpV3J9iLmvwbuULTU2TwwESPUiOT/MoklUf64= X-Received: by 2002:a05:6871:6a9a:b0:172:8986:e931 with SMTP id zf26-20020a0568716a9a00b001728986e931mr3438143oab.0.1678139543730; Mon, 06 Mar 2023 13:52:23 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: David Rowley Date: Tue, 7 Mar 2023 10:52:08 +1300 Message-ID: Subject: Re: using memoize in in paralel query decreases performance To: Pavel Stehule Cc: PostgreSQL Hackers Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, 6 Mar 2023 at 21:55, Pavel Stehule wrote: > default https://explain.depesz.com/s/fnBe It looks like the slowness is coming from the Bitmap Index scan and Bitmap heap scan rather than Memoize. -> Bitmap Heap Scan on public.item i (cost=285.69..41952.12 rows=29021 width=16) (actual time=20.395..591.606 rows=20471 loops=784) Output: i.id, i.item_category_id Recheck Cond: (i.item_category_id = ictc.sub_category_id) Heap Blocks: exact=1590348 Worker 0: actual time=20.128..591.426 rows=20471 loops=112 Worker 1: actual time=20.243..591.627 rows=20471 loops=112 Worker 2: actual time=20.318..591.660 rows=20471 loops=112 Worker 3: actual time=21.180..591.644 rows=20471 loops=112 Worker 4: actual time=20.226..591.357 rows=20471 loops=112 Worker 5: actual time=20.597..591.418 rows=20471 loops=112 -> Bitmap Index Scan on ixfk_ite_itemcategoryid (cost=0.00..278.43 rows=29021 width=0) (actual time=14.851..14.851 rows=25362 loops=784) Index Cond: (i.item_category_id = ictc.sub_category_id) Worker 0: actual time=14.863..14.863 rows=25362 loops=112 Worker 1: actual time=14.854..14.854 rows=25362 loops=112 Worker 2: actual time=14.611..14.611 rows=25362 loops=112 Worker 3: actual time=15.245..15.245 rows=25362 loops=112 Worker 4: actual time=14.909..14.909 rows=25362 loops=112 Worker 5: actual time=14.841..14.841 rows=25362 loops=112 > disabled memoize https://explain.depesz.com/s/P2rP -> Bitmap Heap Scan on public.item i (cost=285.69..41952.12 rows=29021 width=16) (actual time=9.256..57.503 rows=20471 loops=784) Output: i.id, i.item_category_id Recheck Cond: (i.item_category_id = ictc.sub_category_id) Heap Blocks: exact=1590349 Worker 0: actual time=9.422..58.420 rows=20471 loops=112 Worker 1: actual time=9.449..57.539 rows=20471 loops=112 Worker 2: actual time=9.751..58.129 rows=20471 loops=112 Worker 3: actual time=9.620..57.484 rows=20471 loops=112 Worker 4: actual time=8.940..57.911 rows=20471 loops=112 Worker 5: actual time=9.454..57.488 rows=20471 loops=112 -> Bitmap Index Scan on ixfk_ite_itemcategoryid (cost=0.00..278.43 rows=29021 width=0) (actual time=4.581..4.581 rows=25363 loops=784) Index Cond: (i.item_category_id = ictc.sub_category_id) Worker 0: actual time=4.846..4.846 rows=25363 loops=112 Worker 1: actual time=4.734..4.734 rows=25363 loops=112 Worker 2: actual time=4.803..4.803 rows=25363 loops=112 Worker 3: actual time=4.959..4.959 rows=25363 loops=112 Worker 4: actual time=4.402..4.402 rows=25363 loops=112 Worker 5: actual time=4.778..4.778 rows=25363 loops=112 I wonder if the additional work_mem required for Memoize is just doing something like causing kernel page cache evictions and leading to fewer buffers for ixfk_ite_itemcategoryid and the item table being cached in the kernel page cache. Maybe you could get an idea of that if you SET track_io_timing = on; and EXPLAIN (ANALYZE, BUFFERS) both queries. David