pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Etsuro Fujita <fujita.etsuro@lab.ntt.co.jp>
To: Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>
To: pgsql-hackers@postgresql.org
Subject: Re: Oddity in error handling of constraint violation in ExecConstraints for partitioned tables
Date: Mon, 10 Jul 2017 14:15:41 +0900
Message-ID: <56e0baa8-e458-2bbb-7936-367f7d832e43@lab.ntt.co.jp> (raw)
In-Reply-To: <8189d29e-27be-5c5c-a708-5e1f64ae6566@lab.ntt.co.jp>
References: <ee12f648-8907-77b5-afc0-2980bcb0aa37@lab.ntt.co.jp>
	<8189d29e-27be-5c5c-a708-5e1f64ae6566@lab.ntt.co.jp>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>

On 2017/07/07 18:47, Amit Langote wrote:
> On 2017/07/06 16:06, Etsuro Fujita wrote:
>> I think this should be fixed.  Attached is a patch for that.
> 
> Looking up the ResultRelInfo using the proposed method in
> ExecFindResultRelInfo() can be unreliable sometimes, that is, the method
> of using the root table OID to pin down the RangeTableEntry to get the the
> modified columns set.

You are right.  Thank you for pointing that out.

> How about setting ri_RangeTableIndex of the partition ResultRelInfo
> correctly in the first place?  If you look at the way InitResultRelInfo()
> is called in ExecSetupPartitionTupleRouting(), a dummy RT index of 1 is
> passed.  We could instead pass the correct one.  I think
> ModifyTable.nominalRelation is that (at least in the INSERT case.
> 
> The attached patch implements that.  It modifies
> ExecSetupPartitionTupleRouting to accept one more argument resultRTindex
> and passes along the same to InitResultRelInfo().  Later when
> ExecConstraints() wants to build the modifiedCols set, it looks up the
> correct RTE using the partition ResultRelInfo, which has the appropriate
> ri_RangeTableIndex set and uses the same.

Looks good to me.

> The patch keeps tests that you added in your patch.  Added this to the
> open items list.

Another thing I noticed is the error handling in ExecWithCheckOptions; 
it doesn't take any care for partition tables, so the column description 
in the error message for WCO_VIEW_CHECK is built using the partition 
table's rowtype, not the root table's.  But I think it'd be better to 
build that using the root table's rowtype, like ExecConstraints, because 
that would make the column description easier to understand since the 
parent view(s) (from which WithCheckOptions evaluated there are created) 
would have been defined on the root table.  This seems independent from 
the above issue, so I created a separate patch, which I'm attaching. 
What do you think about that?

Best regards,
Etsuro Fujita

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Attachments:

ExecWithCheckOptions.patch (text/plain, 1.8K) download *** a/src/backend/executor/execMain.c --- b/src/backend/executor/execMain.c *************** *** 2097,2102 **** ExecWithCheckOptions(WCOKind kind, ResultRelInfo *resultRelInfo, --- 2097,2121 ---- * USING policy. */ case WCO_VIEW_CHECK: + /* See the comment in ExecConstraints(). */ + if (resultRelInfo->ri_PartitionRoot) + { + HeapTuple tuple = ExecFetchSlotTuple(slot); + TupleDesc old_tupdesc = RelationGetDescr(rel); + TupleConversionMap *map; + + rel = resultRelInfo->ri_PartitionRoot; + tupdesc = RelationGetDescr(rel); + /* a reverse map */ + map = convert_tuples_by_name(old_tupdesc, tupdesc, + gettext_noop("could not convert row type")); + if (map != NULL) + { + tuple = do_convert_tuple(tuple, map); + ExecStoreTuple(tuple, slot, InvalidBuffer, false); + } + } + insertedCols = GetInsertedColumns(resultRelInfo, estate); updatedCols = GetUpdatedColumns(resultRelInfo, estate); modifiedCols = bms_union(insertedCols, updatedCols); *** a/src/test/regress/expected/updatable_views.out --- b/src/test/regress/expected/updatable_views.out *************** *** 2424,2429 **** select tableoid::regclass, * from pt; create view ptv_wco as select * from pt where a = 0 with check option; insert into ptv_wco values (1, 2); ERROR: new row violates check option for view "ptv_wco" ! DETAIL: Failing row contains (2, 1). drop view ptv, ptv_wco; drop table pt, pt1, pt11; --- 2424,2429 ---- create view ptv_wco as select * from pt where a = 0 with check option; insert into ptv_wco values (1, 2); ERROR: new row violates check option for view "ptv_wco" ! DETAIL: Failing row contains (1, 2). drop view ptv, ptv_wco; drop table pt, pt1, pt11;

view thread (15+ messages)  latest in thread

Message-ID: <56e0baa8-e458-2bbb-7936-367f7d832e43@lab.ntt.co.jp>
Permalink:  ../56e0baa8-e458-2bbb-7936-367f7d832e43@lab.ntt.co.jp/
Also on:    postgresql.org/message-id/56e0baa8-e458-2bbb-7936-367f7d832e43@lab.ntt.co.jp

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-hackers@postgresql.org
  Cc: fujita.etsuro@lab.ntt.co.jp, Langote_Amit_f8@lab.ntt.co.jp
  Subject: Re: Oddity in error handling of constraint violation in ExecConstraints for partitioned tables
  In-Reply-To: <56e0baa8-e458-2bbb-7936-367f7d832e43@lab.ntt.co.jp>
  References: <ee12f648-8907-77b5-afc0-2980bcb0aa37@lab.ntt.co.jp> <8189d29e-27be-5c5c-a708-5e1f64ae6566@lab.ntt.co.jp> <56e0baa8-e458-2bbb-7936-367f7d832e43@lab.ntt.co.jp>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox