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

From Alvaro Herrera
Subject Re: [HACKERS] UPDATE of partition key
Date
Msg-id 20171114165205.52ligem7qley3col@alvherre.pgsql
Whole thread Raw
In response to Re: [HACKERS] UPDATE of partition key  (David Rowley <david.rowley@2ndquadrant.com>)
List pgsql-hackers
David Rowley wrote:

> 5. Triggers. Do we need a new "TG_" tag to allow trigger functions to
> do something special when the DELETE/INSERT is a partition move? I
> have audit tables in mind here it may appear as though a user
> performed a DELETE when they actually performed an UPDATE giving
> visibility of this to the trigger function will allow the application
> to work around this.

+1  I think we do need a flag that can be inspected from the user
trigger function.

> 9. Also, this should likely be reworded:
> 
>  * 'num_update_rri' : number of UPDATE per-subplan result rels. For INSERT,
>  *      this is 0.
> 
>  'num_update_rri' number of elements in 'update_rri' array or zero for INSERT.

Also:

/pgsql/source/master/src/backend/executor/execMain.c: In function 'ExecSetupPartitionTupleRouting':
/pgsql/source/master/src/backend/executor/execMain.c:3401:18: warning: 'leaf_part_arr' may be used uninitialized in
thisfunction [-Wmaybe-uninitialized]   leaf_part_rri = leaf_part_arr + i;   ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
 

I think using num_update_rri==0 as a flag to indicate INSERT is strange.
I suggest passing an additional boolean -- or maybe just split the whole
function in two, one for updates and another for inserts, say
ExecSetupPartitionTupleRoutingForInsert() and
ExecSetupPartitionTupleRoutingForUpdate().  They seem to
share almost no code, and the current flow is hard to read; maybe just
add a common subroutine for the lower bottom of the loop.

-- 
Álvaro Herrera                https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


pgsql-hackers by date:

Previous
From: Pavel Stehule
Date:
Subject: Re: plpgsql test layout
Next
From: Andrew Dunstan
Date:
Subject: Re: [HACKERS] MAIN, Uncompressed?