Re: [HACKERS] UPDATE of partition key

From: Amit Khandekar <amitdkhan(dot)pg(at)gmail(dot)com>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>, Thomas Munro <thomas(dot)munro(at)enterprisedb(dot)com>
Subject: Re: [HACKERS] UPDATE of partition key
Date: 2017-11-23 12:57:16
Message-ID: CAJ3gD9fskh74UXtxG038_qGE0S1rfZkhTL4Hg+uJMkx3R1m1vw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 7 November 2017 at 00:33, Robert Haas <robertmhaas(at)gmail(dot)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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jeevan Chalke 2017-11-23 13:08:16 Re: [HACKERS] Partition-wise aggregation/grouping
Previous Message Nikhil Sontakke 2017-11-23 12:27:48 Re: [HACKERS] logical decoding of two-phase transactions