Re: [HACKERS] UPDATE of partition key - Mailing list pgsql-hackers

From Amit Khandekar
Subject Re: [HACKERS] UPDATE of partition key
Date
Msg-id CAJ3gD9fskh74UXtxG038_qGE0S1rfZkhTL4Hg+uJMkx3R1m1vw@mail.gmail.com
Whole thread Raw
In response to Re: [HACKERS] UPDATE of partition key  (Robert Haas <robertmhaas@gmail.com>)
Responses Re: [HACKERS] UPDATE of partition key  (Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>)
List pgsql-hackers
On 7 November 2017 at 00:33, Robert Haas <robertmhaas@gmail.com> wrote:
> +       /* The caller must have already locked all the partitioned tables. */
> +       root_rel = heap_open(root_relid, NoLock);
> +       *all_part_cols = NULL;
> +       foreach(lc, partitioned_rels)
> +       {
> +               Index           rti = lfirst_int(lc);
> +               Oid                     relid = getrelid(rti, rtables);
> +               Relation        part_rel = heap_open(relid, NoLock);
> +
> +               pull_child_partition_columns(part_rel, root_rel, all_part_cols);
> +               heap_close(part_rel, NoLock);
>
> I don't like the fact that we're opening and closing the relation here
> just to get information on the partitioning columns.  I think it would
> be better to do this someplace that already has the relation open and
> store the details in the RelOptInfo.  set_relation_partition_info()
> looks like the right spot.

It seems, for UPDATE, baserel RelOptInfos are created only for the
subplan relations, not for the partitioned tables. I verified that
build_simple_rel() does not get called for paritioned tables for
UPDATE.

In earlier versions of the patch, we used to collect the partition
keys while expanding the partition tree so that we could get them
while the relations are open. After some reviews, I was inclined to
think that the collection logic better be moved out into the
inheritance_planner(), because it involved pulling the attributes from
partition key expressions, and the bitmap operation, which would be
unnecessarily done for SELECTs as well.

On the other hand, if we collect the partition keys separately in
inheritance_planner(), then as you say, we need to open the relations.
Opening the relation which is already in relcache and which is already
locked, involves only a hash lookup. Do you think this is expensive ?
I am open for either of these approaches.

If we collect the partition keys in expand_partitioned_rtentry(), we
need to pass the root relation also, so that we can convert the
partition key attributes to root rel descriptor. And the other thing
is, may be, we can check beforehand (in expand_inherited_rtentry)
whether the rootrte's updatedCols is empty, which I think implies that
it's not an UPDATE operation. If yes, we can just skip collecting the
partition keys.

-- 
Thanks,
-Amit Khandekar
EnterpriseDB Corporation
The Postgres Database Company


pgsql-hackers by date:

Previous
From: Nikhil Sontakke
Date:
Subject: Re: [HACKERS] logical decoding of two-phase transactions
Next
From: Jeevan Chalke
Date:
Subject: Re: [HACKERS] Partition-wise aggregation/grouping