Re: Wired if-statement in gen_partprune_steps_internal

From: David Rowley <dgrowleyml(at)gmail(dot)com>
To: Amit Langote <amitlangote09(at)gmail(dot)com>
Cc: Andy Fan <zhihui(dot)fan1213(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Wired if-statement in gen_partprune_steps_internal
Date: 2021-04-07 07:43:19
Message-ID: CAApHDvoW0YCON4E0grvp4eSz_zghNaNrhjnBQGr1j6mfOUefbg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, 4 Mar 2021 at 19:03, Amit Langote <amitlangote09(at)gmail(dot)com> wrote:
>
> On Tue, Oct 20, 2020 at 9:46 PM Amit Langote <amitlangote09(at)gmail(dot)com> wrote:
> > I had updated the patch last week to address Horiguchi-san's comments
> > but didn't manage to post a polished-enough version. I will try again
> > this week.
>
> Sorry, this seems to have totally slipped my mind.
>
> Attached is the patch I had promised.

I've been looking at this patch today and spent quite a bit of time
staring at the following fragment:

case PARTCLAUSE_MATCH_STEPS:
- Assert(clause_steps != NIL);
- result = list_concat(result, clause_steps);
+ Assert(clause_step != NULL);
+ steps = lappend(steps, clause_step);
break;

So here, we used to use list_concat to add the steps that
match_clause_to_partition_key() output, but now we lappend() the
single step that match_clause_to_partition_key set in its output arg.

This appears to be ok as we only return PARTCLAUSE_MATCH_STEPS from
match_clause_to_partition_key() when we process a ScalarArrayOpExpr.
There we just transform the IN(<list of consts>) into a Boolean OR
clause with a set of OpExprs which are equivalent to the
ScalarArrayOpExpr. e.g. "a IN (1,2)" becomes "a = 1 OR a = 2". The
code path which processes the list of OR clauses in
gen_partprune_steps_internal() will always just output a single
PARTPRUNE_COMBINE_UNION combine step. So it does not appear that there
are any behavioural changes there. The list_concat would always have
been just adding a single item to the list before anyway.

However, it does change the meaning of what PARTCLAUSE_MATCH_STEPS
does. If we ever needed to expand what PARTCLAUSE_MATCH_STEPS does,
then we'll have less flexibility with the newly updated code. For
example if we needed to return multiple steps and only combine them at
the top level then we now can't. I feel there's a good possibility
that we'll never need to do that, but I'm not certain of that.

I'm keen to hear your opinion on this.

David

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Masahiko Sawada 2021-04-07 07:50:17 Re: New IndexAM API controlling index vacuum strategies
Previous Message shiy.fnst@fujitsu.com 2021-04-07 07:40:57 RE: psql - add SHOW_ALL_RESULTS option