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 1tAQw0-00Fi8Q-I0 for pgsql-performance@arkaria.postgresql.org; Mon, 11 Nov 2024 09:42:11 +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 1tAQuz-00CuKn-Ta for pgsql-performance@arkaria.postgresql.org; Mon, 11 Nov 2024 09:41:10 +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 1tAQuz-00CuKf-Ik for pgsql-performance@lists.postgresql.org; Mon, 11 Nov 2024 09:41:10 +0000 Received: from mail-lj1-x22c.google.com ([2a00:1450:4864:20::22c]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1tAQuu-001L15-C6 for pgsql-performance@lists.postgresql.org; Mon, 11 Nov 2024 09:41:09 +0000 Received: by mail-lj1-x22c.google.com with SMTP id 38308e7fff4ca-2fb59652cb9so33749861fa.3 for ; Mon, 11 Nov 2024 01:41:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731318063; x=1731922863; 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=2rMX2Sl7RoN2HDbmdr0y43Rto5iG9JWdo+K1T0UHHm8=; b=gmE4xXnX0WMPQu83L9foi0uxmmWsQodpZwNMIQwaAqa3vmfbcQPR7Lcao61p5HsksO dH6gKafDDEaUlC3ln3LtEKa+Zt3GYGy6cwQYCI9GjtybJYRzmFnG/ygq6dR59vOELKGc PgFh+mrpMfMdBo6MyDXlvvEG3wRcYA8y+8louxF6X6YTeCMGmWsOX7Df3Xj1pBv1N/d8 8Kyd+vfm4UPLNMTUqACtzXHnUiZNqwwdldZ2skssnwNteVKdnqhHNZHxumcollVbDmBz dygWSAMJbrGmMLb48O0JujWy0MAl1cBNW+PZuTkT/rIul6z6kAkI9SUFqQ3Yqg9EvBMG v2vQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731318063; x=1731922863; 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=2rMX2Sl7RoN2HDbmdr0y43Rto5iG9JWdo+K1T0UHHm8=; b=EzW/eIgti6/d8Hr38fi0oBv//4lcLKXsVcSWAfOWRS6cTZnoC74D9Iq0EJmsAfFpXL fUIB2lxtHcE3Lp5KeZjvfLZaEMfjBk4HgQPfsNNgyUkbZ1DQ6qLCvm49DNesQE0qIY3X LZfqYKJSwAO0eLXANz7dBXOEzfiDhfHZe9bwAaV23r/1B/EcrRrHdvH6IokgEM4jbYXJ WN2uUY4Js6Xm/W9QOv9NTlgsqmzCs8RHCa4qdtMW9ADAY3+XC7coWs9HbSQZrA3iCec8 mTnRfUkEs3AiLamJaHp+xsiM7dxYH4Qdmx13drUdh/uhG4oJBX3T6HMT96XsBFqsusl0 N5rA== X-Forwarded-Encrypted: i=1; AJvYcCURlhRbIkDh/QoaMDvyDbutvYg+84F0ulIc7+xzLs2ZrMebdC1Rt2NdTB4uC9QEghIVSb8Rt1x7/CGAyhP+7Y3ZRw==@lists.postgresql.org X-Gm-Message-State: AOJu0Yykwx5Ohv3SJW80W4iFyWy2OB5W8RQlQAbAfmNnF6CJus9Yt3V0 7B2Tv0qShAyRs+dJONSNaW/43dr+sf9JvXxkZRgnaJyBvTPci9Dl X-Google-Smtp-Source: AGHT+IGW9o/UG6mi9vpBDoGnThyVAGPVU5Cxb7gz9F6ArUOt7LMBJBqYvPcH0tyivZWtVGOb7K8e/g== X-Received: by 2002:a2e:a552:0:b0:2f7:58bc:f497 with SMTP id 38308e7fff4ca-2ff202e1810mr53102701fa.28.1731318063203; Mon, 11 Nov 2024 01:41:03 -0800 (PST) Received: from [10.4.15.162] ([93.174.131.141]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-2ff179d834dsm16394251fa.114.2024.11.11.01.41.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 11 Nov 2024 01:41:02 -0800 (PST) Message-ID: Date: Mon, 11 Nov 2024 16:41:01 +0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Performance of Query 4 on TPC-DS Benchmark To: Ba Jinsheng , "pgsql-performance@lists.postgresql.org" References: 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 11/11/24 02:35, Ba Jinsheng wrote: > Hi all, > > Please see this case: > > > Query 4 on TPC-DS benchmark: Thank you for interesting example! Looking into explains I see two sortings: -> Sort (cost=794037.94..794037.95 rows=1 width=132) (actual time=3024403.310..3024403.313 rows=8 loops=1) -> Sort (cost=794033.93..794033.94 rows=1 width=132) (actual time=8068.869..8068.872 rows=8 loops=1) Almost the same cost and different execution time. So, I think, the core of the problem in accuracy of selectivity estimation. In this specific example I see lots of composite scan filters: - ((sale_type = 'w'::text) AND (dyear = 2002)) - ((year_total > '0'::numeric) AND (sale_type = 'w'::text) AND (dyear = 2001)) - ((year_total > '0'::numeric) AND (sale_type = 's'::text) AND (dyear = 2001)) It is all the time a challenge for PostgreSQL to estimate such a filter because of absent information on joint column distribution. Can you research this way by building extended statistics on these clauses? It could move the plan to the more optimal direction. -- regards, Andrei Lepikhov