Re: Propose a new function - list_is_empty - Mailing list pgsql-hackers

From Junwang Zhao
Subject Re: Propose a new function - list_is_empty
Date
Msg-id CAEG8a3JkTKJNsxSEotc3856dqk6jjHu1d8OKeSSsR7FGFS4kQQ@mail.gmail.com
Whole thread Raw
In response to Re: Propose a new function - list_is_empty  (Daniel Gustafsson <daniel@yesql.se>)
Responses Re: Propose a new function - list_is_empty
Re: Propose a new function - list_is_empty
List pgsql-hackers
There are some places that add extra parenthesis like here

--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -3097,7 +3097,7 @@ reorder_grouping_sets(List *groupingsets, List
*sortclause)
  GroupingSetData *gs = makeNode(GroupingSetData);

  while (list_length(sortclause) > list_length(previous) &&
-    list_length(new_elems) > 0)
+    (new_elems != NIL))
  {

and here,

--- a/src/backend/utils/adt/selfuncs.c
+++ b/src/backend/utils/adt/selfuncs.c
@@ -3408,7 +3408,7 @@ estimate_num_groups_incremental(PlannerInfo
*root, List *groupExprs,
  * for normal cases with GROUP BY or DISTINCT, but it is possible for
  * corner cases with set operations.)
  */
- if (groupExprs == NIL || (pgset && list_length(*pgset) < 1))
+ if (groupExprs == NIL || (pgset && (*pgset == NIL)))
  return 1.0;

Is it necessary to add that extra parenthesis?

On Wed, Aug 17, 2022 at 3:33 PM Daniel Gustafsson <daniel@yesql.se> wrote:
>
> > On 17 Aug 2022, at 03:09, Peter Smith <smithpb2250@gmail.com> wrote:
> >
> > On Wed, Aug 17, 2022 at 6:34 AM Daniel Gustafsson <daniel@yesql.se> wrote:
> >>
> >>> On 16 Aug 2022, at 16:03, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> >>
> >>> I agree though that while simplifying list_length() calls, I'd lean to using
> >>> explicit comparisons to NIL.
> >>
> >>
> >> Agreed, I prefer that too.
> >>
> >
> > Thanks for the feedback.
> >
> > PSA patch v3 which now uses explicit comparisons to NIL everywhere,
> > and also addresses the other review comments.
>
> From reading, this version of the patch looks good to me.
>
> --
> Daniel Gustafsson               https://vmware.com/
>
>
>


-- 
Regards
Junwang Zhao



pgsql-hackers by date:

Previous
From: Bharath Rupireddy
Date:
Subject: Re: Generalize ereport_startup_progress infrastructure
Next
From: Daniel Gustafsson
Date:
Subject: Re: Propose a new function - list_is_empty