@@ -1253,3 +1253,109 @@ insert t133329
12531253 └── filters
12541254 ├── a = t133329.a
12551255 └── k != t133329.k
1256+
1257+ # Regression test for #154672. Do not set target columns when re-projecting
1258+ # computed columns after a BEFORE trigger.
1259+ exec-ddl
1260+ CREATE TABLE t154672 (
1261+ k INT PRIMARY KEY,
1262+ a INT,
1263+ b INT AS (a + 1) STORED
1264+ )
1265+ ----
1266+
1267+ exec-ddl
1268+ CREATE FUNCTION f154672() RETURNS TRIGGER LANGUAGE PLpgSQL AS $$
1269+ BEGIN
1270+ RETURN COALESCE(NEW, OLD);
1271+ END
1272+ $$
1273+ ----
1274+
1275+ exec-ddl
1276+ CREATE TRIGGER tr154672 BEFORE INSERT OR UPDATE OR DELETE ON t154672 FOR EACH ROW EXECUTE FUNCTION f154672()
1277+ ----
1278+
1279+ norm
1280+ INSERT INTO t154672 (k, a) VALUES (1, 2) ON CONFLICT (k) DO UPDATE SET a = 3
1281+ ----
1282+ upsert t154672
1283+ ├── arbiter indexes: t154672_pkey
1284+ ├── columns: <none>
1285+ ├── canary column: k:9
1286+ ├── fetch columns: k:9 a:10 b:11
1287+ ├── insert-mapping:
1288+ │ ├── k_new:29 => k:1
1289+ │ ├── a_new:30 => a:2
1290+ │ └── b_comp:31 => b:3
1291+ ├── update-mapping:
1292+ │ ├── upsert_k:40 => k:1
1293+ │ ├── upsert_a:41 => a:2
1294+ │ └── upsert_b:42 => b:3
1295+ ├── before-triggers
1296+ │ └── tr154672
1297+ └── project
1298+ ├── columns: upsert_k:40 upsert_a:41 upsert_b:42 k:9 a:10 b:11 k_new:29 a_new:30 b_comp:31
1299+ ├── project
1300+ │ ├── columns: k_new:37 a_new:38 k:9 a:10 b:11 k_new:29 a_new:30 b_comp:31
1301+ │ ├── barrier
1302+ │ │ ├── columns: column1:6!null column2:7!null b_comp:8!null k:9 a:10 b:11 crdb_internal_mvcc_timestamp:12 tableoid:13 new:14 f154672:28!null k_new:29 a_new:30 b_comp:31 a_new:32!null b_comp:33!null old:34 new:35 f154672:36!null
1303+ │ │ └── select
1304+ │ │ ├── columns: column1:6!null column2:7!null b_comp:8!null k:9 a:10 b:11 crdb_internal_mvcc_timestamp:12 tableoid:13 new:14 f154672:28!null k_new:29 a_new:30 b_comp:31 a_new:32!null b_comp:33!null old:34 new:35 f154672:36!null
1305+ │ │ ├── project
1306+ │ │ │ ├── columns: f154672:36 column1:6!null column2:7!null b_comp:8!null k:9 a:10 b:11 crdb_internal_mvcc_timestamp:12 tableoid:13 new:14 f154672:28!null k_new:29 a_new:30 b_comp:31 a_new:32!null b_comp:33!null old:34 new:35
1307+ │ │ │ ├── barrier
1308+ │ │ │ │ ├── columns: column1:6!null column2:7!null b_comp:8!null k:9 a:10 b:11 crdb_internal_mvcc_timestamp:12 tableoid:13 new:14 f154672:28!null k_new:29 a_new:30 b_comp:31 a_new:32!null b_comp:33!null old:34 new:35
1309+ │ │ │ │ └── project
1310+ │ │ │ │ ├── columns: new:35 old:34 b_comp:33!null a_new:32!null b_comp:31 k_new:29 a_new:30 column1:6!null column2:7!null b_comp:8!null k:9 a:10 b:11 crdb_internal_mvcc_timestamp:12 tableoid:13 new:14 f154672:28!null
1311+ │ │ │ │ ├── barrier
1312+ │ │ │ │ │ ├── columns: column1:6!null column2:7!null b_comp:8!null k:9 a:10 b:11 crdb_internal_mvcc_timestamp:12 tableoid:13 new:14 f154672:28!null
1313+ │ │ │ │ │ └── select
1314+ │ │ │ │ │ ├── columns: column1:6!null column2:7!null b_comp:8!null k:9 a:10 b:11 crdb_internal_mvcc_timestamp:12 tableoid:13 new:14 f154672:28!null
1315+ │ │ │ │ │ ├── project
1316+ │ │ │ │ │ │ ├── columns: f154672:28 column1:6!null column2:7!null b_comp:8!null k:9 a:10 b:11 crdb_internal_mvcc_timestamp:12 tableoid:13 new:14
1317+ │ │ │ │ │ │ ├── barrier
1318+ │ │ │ │ │ │ │ ├── columns: column1:6!null column2:7!null b_comp:8!null k:9 a:10 b:11 crdb_internal_mvcc_timestamp:12 tableoid:13 new:14
1319+ │ │ │ │ │ │ │ └── project
1320+ │ │ │ │ │ │ │ ├── columns: new:14 column1:6!null column2:7!null b_comp:8!null k:9 a:10 b:11 crdb_internal_mvcc_timestamp:12 tableoid:13
1321+ │ │ │ │ │ │ │ ├── left-join (cross)
1322+ │ │ │ │ │ │ │ │ ├── columns: column1:6!null column2:7!null b_comp:8!null k:9 a:10 b:11 crdb_internal_mvcc_timestamp:12 tableoid:13
1323+ │ │ │ │ │ │ │ │ ├── values
1324+ │ │ │ │ │ │ │ │ │ ├── columns: column1:6!null column2:7!null b_comp:8!null
1325+ │ │ │ │ │ │ │ │ │ └── (1, 2, 3)
1326+ │ │ │ │ │ │ │ │ ├── select
1327+ │ │ │ │ │ │ │ │ │ ├── columns: k:9!null a:10 b:11 crdb_internal_mvcc_timestamp:12 tableoid:13
1328+ │ │ │ │ │ │ │ │ │ ├── scan t154672
1329+ │ │ │ │ │ │ │ │ │ │ ├── columns: k:9!null a:10 b:11 crdb_internal_mvcc_timestamp:12 tableoid:13
1330+ │ │ │ │ │ │ │ │ │ │ ├── computed column expressions
1331+ │ │ │ │ │ │ │ │ │ │ │ └── b:11
1332+ │ │ │ │ │ │ │ │ │ │ │ └── a:10 + 1
1333+ │ │ │ │ │ │ │ │ │ │ └── flags: avoid-full-scan disabled not visible index feature
1334+ │ │ │ │ │ │ │ │ │ └── filters
1335+ │ │ │ │ │ │ │ │ │ └── k:9 = 1
1336+ │ │ │ │ │ │ │ │ └── filters (true)
1337+ │ │ │ │ │ │ │ └── projections
1338+ │ │ │ │ │ │ │ └── ((column1:6, column2:7, CAST(NULL AS INT8)) AS k, a, b) [as=new:14]
1339+ │ │ │ │ │ │ └── projections
1340+ │ │ │ │ │ │ └── f154672(new:14, NULL, 'tr154672', 'BEFORE', 'ROW', 'INSERT', 61, 't154672', 't154672', 'public', 0, ARRAY[]) [as=f154672:28]
1341+ │ │ │ │ │ └── filters
1342+ │ │ │ │ │ └── f154672:28 IS DISTINCT FROM NULL
1343+ │ │ │ │ └── projections
1344+ │ │ │ │ ├── ((k:9, 3, CAST(NULL AS INT8)) AS k, a, b) [as=new:35]
1345+ │ │ │ │ ├── ((k:9, a:10, CAST(NULL AS INT8)) AS k, a, b) [as=old:34]
1346+ │ │ │ │ ├── 4 [as=b_comp:33]
1347+ │ │ │ │ ├── 3 [as=a_new:32]
1348+ │ │ │ │ ├── a:10 + 1 [as=b_comp:31]
1349+ │ │ │ │ ├── (f154672:28).k [as=k_new:29]
1350+ │ │ │ │ └── (f154672:28).a [as=a_new:30]
1351+ │ │ │ └── projections
1352+ │ │ │ └── CASE WHEN k:9 IS NOT NULL THEN f154672(new:35, old:34, 'tr154672', 'BEFORE', 'ROW', 'UPDATE', 61, 't154672', 't154672', 'public', 0, ARRAY[]) ELSE new:35 END [as=f154672:36]
1353+ │ │ └── filters
1354+ │ │ └── f154672:36 IS DISTINCT FROM NULL
1355+ │ └── projections
1356+ │ ├── (f154672:36).k [as=k_new:37]
1357+ │ └── (f154672:36).a [as=a_new:38]
1358+ └── projections
1359+ ├── CASE WHEN k:9 IS NULL THEN k_new:29 ELSE k_new:37 END [as=upsert_k:40]
1360+ ├── CASE WHEN k:9 IS NULL THEN a_new:30 ELSE a_new:38 END [as=upsert_a:41]
1361+ └── CASE WHEN k:9 IS NULL THEN b_comp:31 ELSE a_new:38 + 1 END [as=upsert_b:42]
0 commit comments