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 1tFBLp-00BofV-Gl for pgsql-performance@arkaria.postgresql.org; Sun, 24 Nov 2024 12:04:29 +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 1tFBLo-007de6-1G for pgsql-performance@arkaria.postgresql.org; Sun, 24 Nov 2024 12:04:28 +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 1tFBLn-007ddy-Jv for pgsql-performance@lists.postgresql.org; Sun, 24 Nov 2024 12:04:27 +0000 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1tFBLm-003ayg-1N for pgsql-performance@lists.postgresql.org; Sun, 24 Nov 2024 12:04:27 +0000 Received: by mail-pj1-x102d.google.com with SMTP id 98e67ed59e1d1-2ea5a22d80cso2781306a91.0 for ; Sun, 24 Nov 2024 04:04:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732449864; x=1733054664; darn=lists.postgresql.org; h=content-transfer-encoding:in-reply-to:content-language:references :to:subject:from:user-agent:mime-version:date:message-id:from:to:cc :subject:date:message-id:reply-to; bh=9AU7CzMhJRVxbFRDeNcRtnOt5EKWqqVBH9YD9X9gvcA=; b=YjhWJH3j79wxlEOqK9OfznlMF56PfDyesMLzGFaVo0HypNaxnsokjuvaaC/J1vy3sJ AuvAtBfRNV8Ey14v2G4F+jZQFtekDFRDAG8N77lR3SYzhpsx0HhgX48SSsHXOR2+NolG a+GO9ljmvXaJpLu2ODwMEJeZdNU9tYGQyWEKypQhczfFmkNEDsnbh+kXGzoUQCF/F3jH 9TpKfQlpTLCvb0/fJV1swkIu7U/OlT6R6Gqp1P3pSeFYezE0UErcwsTPkg4Ih0bKlzyQ NjDR+xp47TTZOJ+G6NF/b+4/J/kcyNfZl0qrlWJn8yG9DvtOn3VJUyP53ZPlwiOTU2K3 QI0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732449864; x=1733054664; h=content-transfer-encoding:in-reply-to:content-language:references :to:subject:from:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=9AU7CzMhJRVxbFRDeNcRtnOt5EKWqqVBH9YD9X9gvcA=; b=o8jsjTqZa4umXqt7QYwlEFYMaCJMKM+JOZYIuyXFu3rwFiQ6VfBfEy4J7RPpFe7R5a 0wupagrzFyRpYIcz69OgOmEdlkaU2QeWqlWJS9+Y2oMeqzlV0KbV5lblqr6rbmSrhSgW Ayl8VtKp6dQORr3nE5CL2Hl0IiiRt3jPinz5SlCRtkyVz/3685Z8fH7jdTWup3CJ9e84 ixO7A1bEqw4ahPcfHLcujBRQREuLB7bajZSA2UTb3UC6Us6B9JXU90pC8CoWbooKq5wX L3j29jpXIGMDwmr0S+wNON5WrWgHlZ5cZ7vYR/isBq5a2h32lkIYlYzgYb7u8qEcas7l rmmQ== X-Forwarded-Encrypted: i=1; AJvYcCXx3DUEnFc5FXahTumcQjsOC5Ey07aCfxytxqsUDqKvWO4OLSpsCB1zgHCvii9Rj0lU/WI9TGVByncncUl7xEOZSQ==@lists.postgresql.org X-Gm-Message-State: AOJu0YzslZgWfShKAQTRi5eIXr64mCh2WqEQmmkpb4K3H8/qb7g8elDP dunU1u7718JwRLM8slkfm5C1w8Uh+kUcVHcDB6oHUW0c5Gdy4vS9 X-Gm-Gg: ASbGncs1tB5hcvgAJRT14Sm64Vlp7QHmxS8Iu0SQgzUEnrYElJNnXhyVdXbd5xbqvsh 6TEgHKDqXIAfCKQDcZn27VHUrcBIdS1/rxbsPkZ54hInMh2bBpWl/y9YG1d80mTwWQ1tOtv9tYW sExMgx/5ycMR5RSl+/BJYMScMVcSM+X1y4BmXEl3G7Hxe6sY3Pvj55EoJ1znf1h9TmC67YxIUW+ R+QpBEVZ/K71VADtiq1JWIF+Jq17CAmqcCXeW/5kjeYGqXK7ThE/z2t+Iv8JBA9Nro5W+ffLmcn yKbY8de2F2Nv9xrkEJq+EtH/lVVqoQ== X-Google-Smtp-Source: AGHT+IGl5bXWle7twqaDX3PBeDvAomQ/UbY2n9+Vg8Alr6qINXeEsm3K8sH3vCX9Ubfor/jSJaKlpw== X-Received: by 2002:a17:90b:4d8b:b0:2ea:3ab5:cb9d with SMTP id 98e67ed59e1d1-2eb0e125798mr12524280a91.8.1732449863790; Sun, 24 Nov 2024 04:04:23 -0800 (PST) Received: from [192.168.1.37] (cm-27-145-170-174.revip12.asianet.co.th. [27.145.170.174]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2ead03356fbsm8189163a91.31.2024.11.24.04.04.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 24 Nov 2024 04:04:23 -0800 (PST) Message-ID: <8efe2768-bc32-47dc-9a7c-ef20861eb150@gmail.com> Date: Sun, 24 Nov 2024 19:04:17 +0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: Andrei Lepikhov Subject: Re: Performance of Query 60 on TPC-DS Benchmark To: Ba Jinsheng , "pgsql-performance@lists.postgresql.org" , n.malakhov@postgrespro.ru References: Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 22/11/2024 18:12, Ba Jinsheng wrote: > I think the key difference is that the patch disables the usage of Hash > Join, which incurs a worse performance. Discovering your case a little more I found out the origins of the problem: Memoize+NestLoop was not chosen because top-query LIMIT node wasn't counted in estimation on lower levels of the query. At first, I found that join prediction is overestimated, that is unusual. Look at this: -> Merge Semi Join (cost=3611.16..3694.10 rows=2107 width=21) (actual time=28.195..30.243 rows=498 loops=2) Merge Cond: (item_2.i_item_id = item_3.i_item_id) -> Sort (cost=2051.70..2078.17 rows=10588 width=21) (actual time=14.113..14.625 rows=2416 loops=2) Sort Key: item_2.i_item_id Sort Method: quicksort Memory: 938kB Worker 0: Sort Method: quicksort Memory: 247kB -> Parallel Seq Scan on item item_2 (cost=0.00..1343.88 rows=10588 width=21) (actual time=0.029..5.954 rows=9000 loops=2) -> Sort (cost=1559.47..1563.93 rows=1786 width=17) (actual time=14.072..14.247 rows=950 loops=2) Sort Key: item_3.i_item_id Sort Method: quicksort Memory: 49kB Worker 0: Sort Method: quicksort Memory: 49kB -> Seq Scan on item item_3 (cost=0.00..1463.00 rows=1786 width=17) (actual time=0.018..12.638 rows=1786 loops=2) Filter: (i_category = 'Children'::bpchar) Rows Removed by Filter: 16214 Because of that the Memoize node wasn't chosen. Executing this specific part of the query: SET max_parallel_workers_per_gather = 1; SET parallel_setup_cost = 0.001; SET parallel_tuple_cost = 0.00005; SET min_parallel_table_scan_size = 0; EXPLAIN (ANALYZE) SELECT * FROM item i1 WHERE i_item_id IN (SELECT i_item_id FROM item i2 WHERE i2.i_category IN ('Children')); I found that prediction was correct: Merge Semi Join (cost=3611.16..3694.10 rows=2107 width=21) (actual time=19.878..26.321 rows=1931 loops=2) So, top-level nodes just didn't pull more tuples than possible because of LIMIT. If you remove LIMIT 100 from the query, you can see that your plan (NestLoop+Memoize) works 24s, much worse than the 3s Postgres (with HashJoin) created without your changes. In toto, this example demonstrates the problem of planning queries that need only fractional results. I may be wrong, but is this a problem of an Append node? -- regards, Andrei Lepikhov