Re: support for MERGE
Alvaro Herrera <alvherre@alvh.no-ip.org>
From: Alvaro Herrera <alvherre@alvh.no-ip.org>
To: Pg Hackers <pgsql-hackers@lists.postgresql.org>
Cc: Simon Riggs <simon.riggs@enterprisedb.com>, Tomas Vondra <tomas.vondra@enterprisedb.com>, Zhihong Yu <zyu@yugabyte.com>, Daniel Westermann <dwe@dbi-services.com>, Amit Langote <amitlangote09@gmail.com>, Justin Pryzby <pryzby@telsasoft.com>, Japin Li <japinli@hotmail.com>, Erik Rijkers <er@xs4all.nl>, Jaime Casanova <jcasanov@systemguards.com.ec>
Date: 2022-01-27T15:15:27Z
Lists: pgsql-hackers
Attachments
- v9-0001-MERGE-SQL-Command-following-SQL-2016.patch (text/x-diff)
Here's MERGE v9. The main difference in this version is that I have changed the way MERGE is processed at parse analysis. In previous versions, a fake JOIN was constructed at that point; this was critiziced a long time ago ([1] is an example, but IIRC there were others) and had not been addressed. The new code is ~30 lines shorter. I think those can be attributed to comments explaining why the previous thing was so strange; with the new code we don't need to explain as much. In this rewrite, the two relations (target and source) are preserved and passed down separately, and the JOIN is constructed in early optimizer. This is what was suggested in those earlier sub-threads. The new code looks a bit simpler, though some things are not completely clear to me, such as why it works even though we have an empty 'joinaliasvars' for that join. Another odd thing is the way we pass the join condition from parse analysis to optimizer. In this code we're using the regular 'jointree' to store the source relation, and the 'quals' there refer to both the source relation and the target relation -- which is not in the jointree. Later at optimizer time we swap that jointree out with the manufactured one; and the quals are moved one layer down. So for a brief time, the quals can refer to Vars that are not part of the rangetable they are attached to. I still have some things to clean up, but it seems worth sharing at this point as the remaining items that I'm aware of are pretty minor. [1] https://www.postgresql.org/message-id/CA%2BTgmoZj8fyJGAFxs%3D8Or9LeNyKe_xtoSN_zTeCSgoLrUye%3D9Q%40mail.gmail.com -- Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/ "Las cosas son buenas o malas segun las hace nuestra opinión" (Lisias)
Commits
-
Doc fixes for MERGE statement
- 5dcebd10baa8 16.0 landed
- 5bb88967ed5c 15.0 landed
-
MERGE docs adjustments
- d6d1fbf353d1 15.0 landed
- 3d895bc846f2 16.0 landed
-
Link to MVCC docs in MERGE docs
- ffffeebf2447 15.0 landed
-
Fix EXPLAIN MERGE output when no tuples are processed
- 12e423e21d8e 15.0 landed
-
Make EXPLAIN MERGE output format more compact
- 598ac10be1c2 15.0 landed
-
Add support for MERGE SQL command
- 7103ebb7aae8 15.0 landed
-
Split ExecUpdate and ExecDelete into reusable pieces
- 25e777cf8e54 15.0 landed
-
Add API of sorts for transition table handling in trigger.c
- 3a46a45f6f00 15.0 landed
-
Represent Lists as expansible arrays, not chains of cons-cells.
- 1cff1b95ab6d 13.0 cited