Re: Oddity in tuple routing for foreign partitions
Etsuro Fujita <fujita.etsuro@lab.ntt.co.jp>
From: Etsuro Fujita <fujita.etsuro@lab.ntt.co.jp>
To: Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>
Cc: Kyotaro HORIGUCHI <horiguchi.kyotaro@lab.ntt.co.jp>,
robertmhaas@gmail.com,
alvherre@alvh.no-ip.org, pgsql-hackers@postgresql.org
Date: 2018-04-26T06:27:02Z
Lists: pgsql-hackers
Attachments
- fix-tuple-routing-for-foreign-partitions-7.patch (text/x-diff) patch
(2018/04/26 12:43), Etsuro Fujita wrote: > (2018/04/25 17:29), Amit Langote wrote: >> On 2018/04/25 16:42, Kyotaro HORIGUCHI wrote: >>> At Wed, 25 Apr 2018 11:19:23 +0900, Amit Langote wrote: >>>> After the refactoring, it appears to me that we only need this much: >>>> >>>> + rte = makeNode(RangeTblEntry); >>>> + rte->rtekind = RTE_RELATION; >>>> + rte->relid = RelationGetRelid(rel); >>>> + rte->relkind = RELKIND_FOREIGN_TABLE; >>> >>> Mmm.. That is, only relid is required to deparse (I don't mean >>> that it should be refactored so.). On the other hand >>> create_foreign_modify requires rte->checkAsUser as well. > > That's right. I took care of this in my version, but unfortuneately, > that was ignored in the updated versions. Maybe the comments I added to > the patch were not enough, though. > >> Hmm, I missed that we do need information from a proper RTE as well. So, >> I suppose we should be doing this instead of creating the RTE for foreign >> partition from scratch. >> >> + rte = list_nth(estate->es_range_table, resultRelation - 1); >> + rte = copyObject(rte); >> + rte->relid = RelationGetRelid(rel); >> + rte->relkind = RELKIND_FOREIGN_TABLE; > > As I said upthread, we can use the RTE in the range table as-is if the > foreign table is one of the UPDATE subplan partitions or the target > specified in a COPY command. So, I created the patch that way because > that would save cycles. Why not just use that RTE in those cases? > >> If we apply the other patch I proposed, resultRelation always points to >> the correct RTE. >> >>>> I tried to do that. So, attached are two patches. >>>> >>>> 1. Fix for ExecInitPartitionInfo to use the right RT index to pass to >>>> InitResultRelInfo >>>> >>>> 2. v5 of the patch to fix the bug of foreign partitions >>>> >>>> Thoughts? > > Actually, I also thought the former when creating the patch, but I left > that as-is because I'm not sure that would be really safe; > ExecConstraints looks at the RT index via > GetInsertedColumns/GetUpdatedColumns, so what I thought was: that might > cause unexpected behavior. Anyway, I think that the former is more like > an improvement rather than a fix, so it would be better to leave that > for another patch for PG12? Here is a new version I'd like to propose for fixing this issue without the former patch. Thanks for working on this! Best regards, Etsuro Fujita
Commits
-
Remove now-unnecessary cast.
- a365f52d5831 11.0 landed
-
Fix interaction of foreign tuple routing with remote triggers.
- 37a3058bc7c8 11.0 landed