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 1tkLTg-0031ij-7D for pgsql-hackers@arkaria.postgresql.org; Tue, 18 Feb 2025 11:09: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 1tkLTe-009E2R-EQ for pgsql-hackers@arkaria.postgresql.org; Tue, 18 Feb 2025 11:09: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 1tkLTe-009E2J-3q for pgsql-hackers@lists.postgresql.org; Tue, 18 Feb 2025 11:09:22 +0000 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tkLTb-001Xpl-2k for pgsql-hackers@lists.postgresql.org; Tue, 18 Feb 2025 11:09:21 +0000 Received: by mail-pl1-x643.google.com with SMTP id d9443c01a7336-220ecbdb4c2so104543925ad.3 for ; Tue, 18 Feb 2025 03:09:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739876957; x=1740481757; darn=lists.postgresql.org; h=mime-version:subject:references:in-reply-to:message-id:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to; bh=//y72BXfb3OTBdafOoJUR5rgW3qBr3HHvSrNOrLs5Xs=; b=RY1UwxbX4yiDKHM/jXZ3BC8nFyzmOG80zvHwmc1rq8B07ymoyuk8Iu/HyFIZCuZ9px XBe9HloEUvFcGXIAaS1eMmYZ4JCuHe3aHG2l2Ga4+hfZJ0nCfyUUNbjDICoJ4Tgz25W6 Au56e2p2nAk2/wPppkve0tAIjmxdYIF27ceATPgCmdkvkfVwzEq6Elsxp+SFrwMo3eAe az0T10mOHEgW1pDU1hGfXyAE8lk4+AfkVhZk76YIuaaEYMNotI4wTbSLyHBWI7owl4uq R76MJiv++CfuVQe4b8TdbZtAq8B78Hbm4IRTsBl8wfOUH3Qb9Vf0PCrsaR0gC8mzar9P QNsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739876957; x=1740481757; h=mime-version:subject:references:in-reply-to:message-id:cc:to:from :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=//y72BXfb3OTBdafOoJUR5rgW3qBr3HHvSrNOrLs5Xs=; b=YcNriZ5KKwj3y6lV4gZwTfplZPX+olzUrK+gPFet3466QoZ/rgWQvH+aPPo2CAzdO6 IMQXmmzsI0KX2ghM3tWBkB7LI/ch0qUf/VoJAJq5ax4YR/B88bXUpjo2xumEbE6OVhZM qxmkIP5uHNDLZf8a6h4hGo/iNbvlHIW6S0TGp+0uJ7P8x4bmWxbeRjO3RJaFZO5JPeYr mQ5mAMm3P01IPvjC6gvz9k0SYDmkuhBj8YbrCKDv7LXT0eAlNPwgGshAl5nJecI2gkMv qD1CJts/vrfh1Gu2TNajCFDLAMOphFuWOdWjOeRLf2akt2uxpN5SsZXV9+Aoc6T7UHpg UKxQ== X-Gm-Message-State: AOJu0Yy5bcJMijK86iywggx8atlJXBJdWTSF1Bz4PKWToh0q3wQNG3sN uvqShIkccJQwAd9JCk59KAFJfbc6MRe9cFXt2PbCCHptg1v4hcN0 X-Gm-Gg: ASbGnctODCM3b6icCP2xyq8Gxp39DT80oFG9nAcZ2ifD7pWHgk5kPn97kYBjJuGGWCu E77TH1TWIbwBfsmep22CQbewCjsfZubxYA4QhFOcNas1VM2mbtajXvSBWvVBxoiUTh4vgwBIM/A v/P9J8ljLmJseLloeNcndnfkxbJt3p4LvmsHKvenPfRhSqTaGWQDzCGXd8ZFJkpDyyShhVGcIvO EC4IqTSowIzJopwP3P4eWcJfR5+GNrGei0PzMzjbMN/cRIGjAXasFzmMf5OFm3kvyzJzrdUqiip vUP2WUjtDaeI4eJK4Fj+ X-Google-Smtp-Source: AGHT+IGQDVxNK2vlrxZjdiDKh6ZnnX1Y3wVp4wxG++8ILydUnhDTvTLszHji93NPSkHDJc6CdbJX/Q== X-Received: by 2002:a05:6a20:43a0:b0:1ee:7ac8:8256 with SMTP id adf61e73a8af0-1ee8cb83182mr25034958637.25.1739876957397; Tue, 18 Feb 2025 03:09:17 -0800 (PST) Received: from [127.0.0.1] ([2407:cdc0:d003:2c06:badb:71b:f533:1074]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7327eb20b98sm3635823b3a.147.2025.02.18.03.09.15 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Feb 2025 03:09:17 -0800 (PST) Date: Tue, 18 Feb 2025 19:09:08 +0800 From: Zhang Mingli To: songjinzhou , Japin Li Cc: pgsql-hackers , David Rowley Message-ID: In-Reply-To: References: Subject: Re: Modify an incorrect regression test case in the group by key value elimination function X-Readdle-Message-ID: c9b3ac67-bb2e-4dd8-ab63-8b343af5ec38@Spark MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="67b46a59_7cfb422_7ffc" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --67b46a59_7cfb422_7ffc Content-Type: multipart/alternative; boundary="67b46a59_349be1a0_7ffc" --67b46a59_349be1a0_7ffc Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On =46eb 18, 2025 at 16:17 +0800, Japin Li , wrote= : > On Tue, 18 =46eb 2025 at 15:40, =22songjinzhou=22 wrote: > > Dear hackers: > > > > Two months ago, we enhanced the group by key value elimination functi= on. This is a very useful function. When I was > > learning, I found a regression test case that was not suitable, as fo= llows: > > > > -- When there are multiple supporting unique indexes and the GROUP BY= contains > > -- columns to cover all of those, ensure we pick the index with the l= east > > -- number of columns so that we can remove more columns from the GROU= P BY. > > explain (costs off) select a,b,c from t3 group by a,b,c; > > QUERY PLAN > > ---------------------- > > HashAggregate > > Group Key: c > > -> Seq Scan on t3 > > (3 rows) > > > > -- As above but try ordering the columns differently to ensure we get= the > > -- same result. > > explain (costs off) select a,b,c from t3 group by c,a,b; > > QUERY PLAN > > ---------------------- > > HashAggregate > > Group Key: c > > -> Seq Scan on t3 > > (3 rows) > > > > Because the table structure of t3 is defined as follows(Its PK is def= errable): > > > > postgres=3D=23 =5Cd+ t3 > > Table =22pg=5Ftemp=5F1.t3=22 > > Column =7C Type =7C Collation =7C Nullable =7C Default =7C Storage =7C= Compression =7C Stats target =7C Description > > --------+---------+-----------+----------+---------+---------+-------= ------+--------------+------------- > > a =7C integer =7C =7C not null =7C =7C plain =7C =7C =7C > > b =7C integer =7C =7C not null =7C =7C plain =7C =7C =7C > > c =7C integer =7C =7C not null =7C =7C plain =7C =7C =7C > > Indexes: > > =22t3=5Fpkey=22 PRIMARY KEY, btree (a, b) DE=46ERRABLE > > =22t3=5Fc=5Fuidx=22 UNIQUE, btree (c) > > Not-null constraints: > > =22t3=5Fa=5Fnot=5Fnull=22 NOT NULL =22a=22 > > =22t3=5Fb=5Fnot=5Fnull=22 NOT NULL =22b=22 > > =22t3=5Fc=5Fnot=5Fnull=22 NOT NULL =22c=22 > > Access method: heap > > > > postgres=3D=23 > > > > I think this test case does not fully reflect the original meaning. S= o I made a small change to this and look forward to > > your feedback. Thanks=21 > > Hi, Good catch. > > Yeah, the primary key of t3 is deferred, so only the t3=5Fc=5Fuidx can = be used. > The test case is inconsistent with comments. > > It seems that the t2 does not have a unique index on z, do you forget t= o > create it in the patch=3F While there isn't an unique index, an unique constraint with a NOT NULL o= n that column should serve the same purpose. =C2=A0=C2=A0+alter table t2 alter column z set not null, add constraint t= 2=5Fz=5Fuidx unique (z); In patch v2, I made a slight adjustment: creating a unique index on t3 wi= ll handle multiple choice scenarios. Thanks for the patch. -- Zhang Mingli HashData --67b46a59_349be1a0_7ffc Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline
On =46eb 18, 2025 at 16:17 +0800, Japin Li <japi= nli=40hotmail.com>, wrote:
On Tue, 18 =46eb 2025 at 15:40, =22songjinzhou=22 <tsinghualucky912=40= foxmail.com> wrote:
Dear hackers:

Two months ago, we enhanced the group by key value elimination function. = This is a very useful function. When I was
learning, I found a regression test case that was not suitable, as follow= s:

-- When there are multiple supporting unique indexes and the GROUP BY con= tains
-- columns to cover all of those, ensure we pick the index with the least=
-- number of columns so that we can remove more columns from the GROUP BY= .
explain (costs off) select a,b,c from t3 group by a,b,c;
QUERY PLAN
----------------------
HashAggregate
Group Key: c
-> Seq Scan on t3
(3 rows)

-- As above but try ordering the columns differently to ensure we get the=
-- same result.
explain (costs off) select a,b,c from t3 group by c,a,b;
QUERY PLAN
----------------------
HashAggregate
Group Key: c
-> Seq Scan on t3
(3 rows)

Because the table structure of t3 is defined as follows(Its PK is deferra= ble):

postgres=3D=23 =5Cd+ t3
Table =22pg=5Ftemp=5F1.t3=22
Column =7C Type =7C Collation =7C Nullable =7C Default =7C Storage =7C Co= mpression =7C Stats target =7C Description
--------+---------+-----------+----------+---------+---------+-----------= --+--------------+-------------
a =7C integer =7C =7C not null =7C =7C plain =7C =7C =7C
b =7C integer =7C =7C not null =7C =7C plain =7C =7C =7C
c =7C integer =7C =7C not null =7C =7C plain =7C =7C =7C
Indexes:
=22t3=5Fpkey=22 PRIMARY KEY, btree (a, b) DE=46ERRABLE
=22t3=5Fc=5Fuidx=22 UNIQUE, btree (c)
Not-null constraints:
=22t3=5Fa=5Fnot=5Fnull=22 NOT NULL =22a=22
=22t3=5Fb=5Fnot=5Fnull=22 NOT NULL =22b=22
=22t3=5Fc=5Fnot=5Fnull=22 NOT NULL =22c=22
Access method: heap

postgres=3D=23

I think this test case does not fully reflect the original meaning. So I = made a small change to this and look forward to
your feedback. Thanks=21

Hi,

Good catch.

Yeah, the primary key of t3 is deferred, so only the t3=5Fc=5Fuidx can be= used.
The test case is inconsistent with comments.

It seems that the t2 does not have a unique index on z, do you forget to<= br /> create it in the patch=3F
While there isn't an unique index, an unique constr= aint with a NOT NULL on that column should serve the same purpose.
&=23160;
&=23160;&=23160;+alter table t2 alter column z set not null, add constrai= nt t2=5Fz=5Fuidx unique (z);

In patch v2, I made a slight adjustment: creating a unique index on t3 wi= ll handle multiple choice scenarios.

Thanks for the patch.

--
Zhang Mingli
HashData
--67b46a59_349be1a0_7ffc-- --67b46a59_7cfb422_7ffc Content-Type: application/octet-stream Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="v2-0001-Modify-an-incorrect-regression-test-case-in-the-grou.patch" RnJvbSBjOTJlYmE4OTRiZTNmNGQ2YjIzODkxN2U2MTc0MzczZjE0MDRhMGZjIE1vbiBTZXAgMTcg MDA6MDA6MDAgMjAwMQpGcm9tOiBzb25namluemhvdSA8dHNpbmdodWFsdWNreTkxMkBmb3htYWls LmNvbT4KRGF0ZTogVHVlLCAxOCBGZWIgMjAyNSAxOTowMjozNiArMDgwMApTdWJqZWN0OiBbUEFU Q0hdIE1vZGlmeSBhbiBpbmNvcnJlY3QgcmVncmVzc2lvbiB0ZXN0IGNhc2UgaW4gdGhlIGdyb3Vw IGJ5IGtleQogdmFsdWUgZWxpbWluYXRpb24gZnVuY3Rpb24KCi0tLQogc3JjL3Rlc3QvcmVncmVz cy9leHBlY3RlZC9hZ2dyZWdhdGVzLm91dCB8IDIgKysKIHNyYy90ZXN0L3JlZ3Jlc3Mvc3FsL2Fn Z3JlZ2F0ZXMuc3FsICAgICAgfCAyICsrCiAyIGZpbGVzIGNoYW5nZWQsIDQgaW5zZXJ0aW9ucygr KQoKZGlmZiAtLWdpdCBhL3NyYy90ZXN0L3JlZ3Jlc3MvZXhwZWN0ZWQvYWdncmVnYXRlcy5vdXQg Yi9zcmMvdGVzdC9yZWdyZXNzL2V4cGVj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