Re: [HACKERS] MERGE SQL Statement for PG11
Amit Langote <langote_amit_f8@lab.ntt.co.jp>
From: Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>
To: Andres Freund <andres@anarazel.de>,
Pavan Deolasee <pavan.deolasee@gmail.com>
Cc: Simon Riggs <simon@2ndquadrant.com>, Tom Lane <tgl@sss.pgh.pa.us>,
Peter Geoghegan <pg@bowt.ie>, Robert Haas <robertmhaas@gmail.com>,
Tomas Vondra <tomas.vondra@2ndquadrant.com>,
Alvaro Herrera <alvherre@alvh.no-ip.org>,
Andrew Dunstan <andrew.dunstan@2ndquadrant.com>,
Pavan Deolasee <pavan.deolasee@2ndquadrant.com>,
Stephen Frost <sfrost@snowman.net>,
PostgreSQL-development <pgsql-hackers@postgresql.org>
Date: 2018-04-06T07:38:43Z
Lists: pgsql-hackers
Attachments
- ExecMergeMatched-thinko.patch (text/plain) patch
On 2018/04/06 5:00, Andres Freund wrote: > On 2018-04-05 11:31:48 +0530, Pavan Deolasee wrote: >>> + /* >>> + * If there are not WHEN MATCHED actions, we are done. >>> + */ >>> + if (mergeMatchedActionStates == NIL) >>> + return true; >>> >>> Maybe I'm confused, but why is mergeMatchedActionStates attached to >>> per-partition info? How can this differ in number between partitions, >>> requiring us to re-check it below fetching the partition info above? >>> >>> >> Because each partition may have a columns in different order, dropped >> attributes etc. So we need to give treatment to the quals/targetlists. See >> ON CONFLICT DO UPDATE for similar code. > > But the count wouldn't change, no? So we return before building the > partition info if there's no MATCHED action? Yeah, I think we should return at the top if there are no matched actions. With the current code, even if there aren't any matched actions we're doing ExecFindPartitionByOid() and ExecInitPartitionInfo() to only then see in the partition's resultRelInfo that the action states list is empty. I think there should be an Assert where there currently is the check for empty action states list and the check itself should be at the top of the function, as done in the attached. Thanks, Amit
Commits
-
Add support for MERGE SQL command
- 7103ebb7aae8 15.0 landed
-
Avoid repeated name lookups during table and index DDL.
- 5f173040e324 9.4.0 cited
-
Use an MVCC snapshot, rather than SnapshotNow, for catalog scans.
- 568d4138c646 9.4.0 cited