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 1soDSz-009Gmt-OV for pgsql-hackers@arkaria.postgresql.org; Wed, 11 Sep 2024 02:52:26 +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 1soDSx-0076uX-6v for pgsql-hackers@arkaria.postgresql.org; Wed, 11 Sep 2024 02:52:23 +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 1soDSw-0076uO-PI for pgsql-hackers@lists.postgresql.org; Wed, 11 Sep 2024 02:52:22 +0000 Received: from mail-ej1-x632.google.com ([2a00:1450:4864:20::632]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1soDSs-000ZDC-SQ for pgsql-hackers@postgresql.org; Wed, 11 Sep 2024 02:52:22 +0000 Received: by mail-ej1-x632.google.com with SMTP id a640c23a62f3a-a8d404c7634so421482466b.3 for ; Tue, 10 Sep 2024 19:52:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726023138; x=1726627938; darn=postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=1uPd3euVsJ5FWzDe0zy/QzfMKJhjew/GSp4dXend5vM=; b=iyjwAkuP7+3aEVSQd/N7s5n1zAKeykE9QkAjD+JIGF0NbjPL0u73lBMmkkbOdtekW5 spV+bgSwR4oskrV4Os6wiSCY9PRUaw/01Mr5baiEDAXoXWxEnqngNZbaZ7OEQhpt+Gdx B2FFw/v6KxvXUOQItsT0iBxp+dj6fk6LR6BmGmS9TANKTqC36MxObzMxFTPS5SL4fG/d 48O/SI1Et7GOdUTbroDkOKExvqQIKhrYLF4qd5Y3bhpRnUV1skfryyS9As7DfQ8SXJSD YnPdib/yrQe0VB/mUToqfxhd1L+WzouoXactUZnnWccZBhs/sILt7DvxN9sBPWxVS346 VRfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726023138; x=1726627938; 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=1uPd3euVsJ5FWzDe0zy/QzfMKJhjew/GSp4dXend5vM=; b=MPsjw4aSz93L/5jMVxtGltvXhI8HMxJ/oKHDAs1SAcUwwWa56cqC5owpa8HuErfT7z GHrnCNT5GqMsa60Y67AO+Hc7R+NhlU6iiZoaQeEfnBijLWgjfS7zJ3Fdrj4vIUd6PzIF B+21LPHiP3HKuoxhz6gMTBNGGXjoTh27de0nLoKLwKhvZg88ULZFwRD8oZvtNu41RdTz u+ZQba+Apqq3MDY4QHw8/KWU4Ryw0X8ygjUxofEf+ImUqiBuhwbm7wyI0MiS25H4gSha XFHOcC3dXIZsjArw1A6cWUS/E54XhnAhFnVbuzkx9jzexI3JrepprvQ7ZWhefAzZ5P+2 1+vQ== X-Forwarded-Encrypted: i=1; AJvYcCV+CPaifp4W9rccmhSOvl2RLlnGu/nD5JGEHHTQRvJOvHAb5BKx/lc/neNoVaNL6WLt56RJ0iPkcC8jj/Er@postgresql.org X-Gm-Message-State: AOJu0Yxfpcj8j8OoRdAmUwv12ApWzRfsJgNshqWftOcQuaSrWpDFqDta JRbvUgnXH7wCuMHIj4cL21m+JlvFHEW0lNOkh0A6beVJw1cH8C3AHaYfDguBqdg8UcfX+F+drFb B9BNiHAQ1emXqPxfysZkC5q9YQ1Y= X-Google-Smtp-Source: AGHT+IH3xgc0ARyX6/KzHnn2bztJre7J1fNw8JINF8OSa8wDsuHO8/BI1wDeYKfJg5zu3cYhg45FN4FqNyR4E7MdlIc= X-Received: by 2002:a17:906:7949:b0:a8d:7b7d:8c39 with SMTP id a640c23a62f3a-a8ffade55femr267607266b.43.1726023136696; Tue, 10 Sep 2024 19:52:16 -0700 (PDT) MIME-Version: 1.0 References: <87il22cj51.fsf@163.com> In-Reply-To: From: Tender Wang Date: Wed, 11 Sep 2024 10:52:05 +0800 Message-ID: Subject: Re: Eager aggregation, take 3 To: Richard Guo Cc: Paul George , Andy Fan , PostgreSQL-development , pgsql-hackers@lists.postgresql.org, Robert Haas Content-Type: multipart/alternative; boundary="000000000000efe2880621cf1377" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000efe2880621cf1377 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Richard Guo =E4=BA=8E2024=E5=B9=B48=E6=9C=8821=E6= =97=A5=E5=91=A8=E4=B8=89 15:11=E5=86=99=E9=81=93=EF=BC=9A > On Fri, Aug 16, 2024 at 4:14=E2=80=AFPM Richard Guo > wrote: > > I had a self-review of this patchset and made some refactoring, > > especially to the function that creates the RelAggInfo structure for a > > given relation. While there were no major changes, the code should > > now be simpler. > > I found a bug in v10 patchset: when we generate the GROUP BY clauses > for the partial aggregation that is pushed down to a non-aggregated > relation, we may produce a clause with a tleSortGroupRef that > duplicates one already present in the query's groupClause, which would > cause problems. > > Attached is the updated version of the patchset that fixes this bug > and includes further code refactoring. > > I continue to review the v11 version patches. Here are some my thoughts. 1. In make_one_rel(), we have the below codes: /* * Build grouped base relations for each base rel if possible. */ setup_base_grouped_rels(root); As far as I know, each base rel only has one grouped base relation, if possible. The comments may be changed to "Build a grouped base relation for each base rel if possible." 2. According to the comments of generate_grouped_paths(), we may generate paths for a grouped relation on top of paths of join relation. So the =E2=80=9Drel_plain" argum= ent in generate_grouped_paths() may be confused. "plain" usually means "base rel" . How about Re-naming rel_plain to input_rel? 3. In create_partial_grouping_paths(), The partially_grouped_rel could have been already created due to eager aggregation. If partially_grouped_rel exists, its reltarget has been created. So do we need below logic? /* * Build target list for partial aggregate paths. These paths cannot just * emit the same tlist as regular aggregate paths, because (1) we must * include Vars and Aggrefs needed in HAVING, which might not appear in * the result tlist, and (2) the Aggrefs must be set in partial mode. */ partially_grouped_rel->reltarget =3D make_partial_grouping_target(root, grouped_rel->reltarget, extra->havingQual); -- Thanks, Tender Wang --000000000000efe2880621cf1377 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
Richard Guo <guofenglinux@gmail.com> =E4=BA=8E2024=E5=B9=B48= =E6=9C=8821=E6=97=A5=E5=91=A8=E4=B8=89 15:11=E5=86=99=E9=81=93=EF=BC=9A
=
On Fri, Aug 16, 202= 4 at 4:14=E2=80=AFPM Richard Guo <guofenglinux@gmail.com> wrote:
> I had a self-review of this patchset and made some refactoring,
> especially to the function that creates the RelAggInfo structure for a=
> given relation.=C2=A0 While there were no major changes, the code shou= ld
> now be simpler.

I found a bug in v10 patchset: when we generate the GROUP BY clauses
for the partial aggregation that is pushed down to a non-aggregated
relation, we may produce a clause with a tleSortGroupRef that
duplicates one already present in the query's groupClause, which would<= br> cause problems.

Attached is the updated version of the patchset that fixes this bug
and includes further code refactoring.


I continue to review the v11 version patc= hes. Here are some my thoughts.

1. In make_one_rel(), we= have the below codes:
/*
* Build grouped base relations for= each base rel if possible.
*/
setup_base_grouped_rels(root);
<= /div>

As far as I know, each base rel only has one group= ed base relation, if possible.
The comments may be changed to &qu= ot;Build a grouped base relation for each base rel if possible."
=

2.=C2=A0 According to the comments of=C2=A0generate_grouped_paths(), we may generate paths for a g= rouped
relation on top of = paths of join relation. So the =E2=80=9Drel_plain" argument in generat= e_grouped_paths() may be
co= nfused. "plain" usually means "base rel" . How about R= e-naming rel_plain to input_rel?

3. In cr= eate_partial_grouping_paths(), The partially_grouped_rel could have been al= ready created due to eager
aggregation. If partially_grouped_rel = exists,=C2=A0 its reltarget has been created. So do we need below logic?

/*
* Build target list for partial aggregate pa= ths.=C2=A0 These paths cannot just
* emit the same tlist as regular ag= gregate paths, because (1) we must
* include Vars and Aggrefs needed i= n HAVING, which might not appear in
* the result tlist, and (2) the Ag= grefs must be set in partial mode.
*/
partially_grouped_rel->re= ltarget =3D
=C2=A0 =C2=A0 =C2=A0 =C2=A0make_partial_grouping_target(root= , grouped_rel->reltarget,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 extra->havingQual);


-= -
Thanks,
Tender Wang
--000000000000efe2880621cf1377--