Re: move PartitionBoundInfo creation code

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>
Cc: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: move PartitionBoundInfo creation code
Date: 2018-11-13 02:34:55
Message-ID: 20181113023455.GC1336@paquier.xyz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Nov 13, 2018 at 10:34:50AM +0900, Amit Langote wrote:
> Hmm, Assert or elog is your call, but I'd learned that we prefer elog when
> checking a value read from the disk?

Let's keep elog() then, which is consistent with the previous code. If
there is any meaning in switching to an assert(), it could always be
changed later, if that proves necessary.

> Thank you, the new logic seems sane to me.
>
> I noticed a few things while going over the new patch.

Thanks for going through it.

> I'd accidentally ended up changing the mapping elements to mean that they
> map canonical indexes of partitions to their original indexes, but your
> rewrite has restored the original meaning, so the following comment that I
> wrote is obsolete:
>
> + * Upon return from this function, *mapping is set to an array of
> + * list_length(boundspecs) elements, each of which maps the canonical
> + * index of a given partition to its 0-based position in the original list.
>
> It should be: "each of which maps the original index of a partition to its
> canonical index."

Indeed. Good point. I have missed that bit.

> Maybe we can slightly rearrange this comment (along with fixing typos and
> obsolete facts) as:
>
> /*
> * For each partitioning method, we first convert the partition bounds f
> * from their parser node representation to the internal representation,
> * along with any additional preprocessing (such as de-duplicating range
> * bounds). Resulting bound datums are then added to the 'datums' array
> * in PartitionBoundInfo. For each datum added, an integer indicating the
> * canonical partition index is added to the 'indexes' array.
> *
> * For each bound, we remember its partition's position (0-based) in the
> * original list to later map it to the canonical index.
> */

OK, that looks cleaner.

> I'd proposed:
>
> /*
> * Set the canonical value for null_index, if any.
> *
> * It's possible that the null-accepting partition has not been
> * assigned an index yet, which could happen if such partition
> * accepts only null and hence not handled in the above loop
> * which only looked at non-null values.
> */

No issues with that. So canonical index is used as a more common term,
which seems fine.

> I'd proposed:
>
> /* Set the canonical value for default_index, if any. */

And this one either, using a conditional at the end is more adapted
anyway. And there are two occurences of that.

Attached is an updated patch. Perhaps you are spotting something else?
--
Michael

Attachment Content-Type Size
partition-bound-refactor-v2.patch text/x-diff 40.4 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Thomas Munro 2018-11-13 02:42:21 Re: Possible buffer overrun in src/backend/libpq/hba.c gethba_options()
Previous Message Tom Lane 2018-11-13 02:05:59 Re: Pull up sublink of type 'NOT NOT (expr)'