Re: Add new for_each macros for iterating over a List that do not require ListCell pointer

From: Jelte Fennema-Nio <postgres(at)jeltef(dot)nl>
To: vignesh C <vignesh21(at)gmail(dot)com>
Cc: Nathan Bossart <nathandbossart(at)gmail(dot)com>, David Rowley <dgrowleyml(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Add new for_each macros for iterating over a List that do not require ListCell pointer
Date: 2023-12-19 14:44:43
Message-ID: CAGECzQSXq4_2xNE0eJ2D5Zs4-anf1o74OLGdrwai7ct73875+Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, 19 Dec 2023 at 11:59, vignesh C <vignesh21(at)gmail(dot)com> wrote:
> I noticed that this change can be done in several other places too.

My guess would be that ~90% of all existing foreach loops in the
codebase can be easily rewritten (and simplified) using these new
macros. So converting all of those would likely be quite a bit of
work. In patch 0003 I only converted a few of them to get some
coverage of the new macros and show how much simpler the usage of them
is.

> Should we start doing these changes too now?

I think we should at least wait until this patchset is merged before
we start changing other places. If there's some feedback on the macros
and decide we change how they get called, then it would be a waste of
time to have to change all the call sites.

And even once these patches are merged to master, I think we should
only do any bulk changes if/when we backport these macros to all
supported PG versions. Backporting to PG12 is probably the hardest,
since List its internal layout got heavily changed in PG13. Probably
not too hard though, in Citus we've had similar macros work since
PG11. I'm also not sure what the policy is for backporting patches
that introduce new functions/macros in public headers.

We probably even want to consider some automatic rewriting script (for
the obvious cases) and/or timing the merge, to avoid having to do many
rebases of the patch.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2023-12-19 14:50:37 Re: Update the comment in nodes.h to cover Cardinality
Previous Message Japin Li 2023-12-19 14:10:53 Re: [DOC] Introducing Quick Start Guide to PL/pgSQL and PL/Python Documentation