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 1t1Gbk-00FRa7-8f for pgsql-bugs@arkaria.postgresql.org; Thu, 17 Oct 2024 02:51:24 +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 1t1Gbi-00EjSJ-82 for pgsql-bugs@arkaria.postgresql.org; Thu, 17 Oct 2024 02:51:22 +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 1t1Gbh-00EjRM-VE for pgsql-bugs@lists.postgresql.org; Thu, 17 Oct 2024 02:51:22 +0000 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1t1Gbf-001SbY-VD for pgsql-bugs@lists.postgresql.org; Thu, 17 Oct 2024 02:51:21 +0000 Received: by mail-pj1-x102b.google.com with SMTP id 98e67ed59e1d1-2e28b75dbd6so342105a91.0 for ; Wed, 16 Oct 2024 19:51:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729133478; x=1729738278; darn=lists.postgresql.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id:from :to:cc:subject:date:message-id:reply-to; bh=9+jRWV4Wh8NcSWDyXV7llWAn9QdmbWtRc6pkviQK97s=; b=Lmvu/gprNPKihUrb3tY6t3/7ZsD/6GZrzUXoVjQgqvxtef51gQGmcvQdhBAxR8WoO8 sj2pp4i2AwsnPH2j5mYgKNcT2aKgzk4suXcspeLgik6+1DHAmS/DJnkMBllcRCk7UFdp scbssIH1GniJSYHxxUHqjAgCr7+33JSpNcEpqasXmRO6JTW9Y+cjxTmhReLM/YacMQN4 F9lkos60ygYg0cYQnLK2JHcAgwU6y4zKXaSeYqV6jajhaWipkIN5Ut/gqA/g5tR0EOeT uO/nQBwxQUjBC2ml33AbHCIB3w53Nqqs8pAATvbL5+pV9hL2FEZKDMPkyHukqtNyrBzm R2bA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729133478; x=1729738278; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=9+jRWV4Wh8NcSWDyXV7llWAn9QdmbWtRc6pkviQK97s=; b=A+KKqw1Wbjg4S5knbXvvCG7SXYvW1h5Z0tLn8aH4xfHUt94vBmHwryDM/SKaWox9UP d63aRqbmYrUKjKUzvSHd92kCkA3mA8YqvXsOTdrPRW4HDVL/cfXO0i2IPfQ+xxr5eKCt exEcGUa0UdakrH79NYKtdf8nXtB59FYNNPnSyue5Y/FekK71rfADpiKoHG/UkbMMYNQv 4Wtp/I3Pwuky8A8O63G6r2MgM3rGAf1BpGk71SlwvqPI0d3qQ2Nmb1zBDIfpDI1Z1xOI ARNDjfdCjYlcqLOoFBqT+Z5eG1kxJ2XJbCLfsWDRRLCPgp1N2Shok+KSLE57SJQNL0sO eTwQ== X-Forwarded-Encrypted: i=1; AJvYcCWUr2UgMmqpvfmgwqLzqFzZ10bd4DgRyWfAzQx28YlOWML8wAsWHtGNJZixoltxCkGjCjIXmqptwKse@lists.postgresql.org X-Gm-Message-State: AOJu0Yz+SJc+EKikImokh5mAjBMnUi9v6uV0+eTdKZX19AFMWK6WEeK5 iCN5jo1RmgjBzFW9ZJmPXVj8lGj7v4aisiFiZKE0KOgW2M6Zu9UnBpJMQbIY3+A= X-Google-Smtp-Source: AGHT+IFq6mKyaSlGpKA2oS4tUf6G60rB3bcdgh4KsvEeZio0/4f9A9Q6PWfSUCRHHuCyt8lN1uhNaA== X-Received: by 2002:a17:90b:14c:b0:2e2:c423:8e17 with SMTP id 98e67ed59e1d1-2e3152b1a6cmr21949794a91.7.1729133477564; Wed, 16 Oct 2024 19:51:17 -0700 (PDT) Received: from [10.10.20.104] (node-u1e.pool-101-109.dynamic.totinternet.net. [101.109.152.18]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e3e08c36c6sm619936a91.22.2024.10.16.19.51.15 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 16 Oct 2024 19:51:16 -0700 (PDT) Message-ID: <98398f84-6079-47f9-958c-c7e323228cc7@gmail.com> Date: Thu, 17 Oct 2024 09:51:12 +0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Performance Issue on Query 18 of TPC-H Benchmark To: Ba Jinsheng , Alena Rybakina , "pgsql-bugs@lists.postgresql.org" References: <44b42d35-2283-4a7f-aa2d-a9abe2dcf1b6@gmail.com> <45323a23-47d9-46f5-8e1b-8f0c961a4fad@postgrespro.ru> <955eefa0-2158-4604-b79b-68a087646e91@postgrespro.ru> Content-Language: en-AU From: Andrei Lepikhov 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 10/17/24 01:26, Ba Jinsheng wrote: > >I believe you are not allowing the optimizer to generate a different > aggregation path (Group Aggregate) because it requires a sort operation. > So I think this is not correct. > > Yes, this is what I did. I though it is what you were asking? I have not > found another way to enforce HashAggregate, so I directly modified the > code. Can you eliberate why it is incorrect? As I see, the main problem lies in the first aggregate (with HAVING clause) where hash aggregation seems preferable. To disable that, you can use some trick: SET enable_hashagg = 'on'; SET enable_sort = 'off'; SET work_mem = '1GB'; In my case the optimiser have built aggregation: -> HashAggregate (cost=202639.35..208346.45 rows=126825 width=4) (actual time=3540.761..4224.547 rows=9 loops=3) Group Key: lineitem_1.l_orderkey Filter: (sum(lineitem_1.l_quantity) > '314'::numeric) Batches: 1 Memory Usage: 638993kB Rows Removed by Filter: 1499991 Worker 0: Batches: 1 Memory Usage: 638993kB Worker 1: Batches: 1 Memory Usage: 638993kB -> Seq Scan on lineitem lineitem_1 (cost=0.00..172626.23 rows=6002623 width=9) (actual time=0.014..675.552 rows=6001215 loops=3) Not sure it is the best plan possible in this case. I know only about re-optimisation feature which can provide correct number of groups estimation to aggregates as well as cardinality and work_mem and give the optimiser all correct estimations. But it is still an enterprise feature :(. > Can I understand disabling parallelism is a good setup for finding > performance issues? I usually use such such a switch to identify problems. Parallel workers use HashJoin more frequently and it sometimes cause non-linear behaviour of execution time, compared to sequental plan. At the same time, they donn't support parameterised paths and it may end up in interesting performance jumps ... BTW, I also wonder why do you report to pgsql-bugs in presence of better fitted pgsql-performance thread? -- regards, Andrei Lepikhov