aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>2018-07-10 16:16:14 +0300
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>2018-07-10 16:16:14 +0300
commit17b715c634d451da3edb221c55c614a7d993c289 (patch)
tree511803a32459a165edd84b00b97ca052df515501
parent1486f7f981c0052988891677d4e734b14317816c (diff)
downloadpostgresql-17b715c634d451da3edb221c55c614a7d993c289.tar.gz
postgresql-17b715c634d451da3edb221c55c614a7d993c289.zip
Add test case for EEOP_INNER_SYSVAR/EEOP_OUTER_SYSVAR executor opcodes.
The EEOP_INNER_SYSVAR and EEOP_OUTER_SYSVAR executor opcodes are not exercised by normal queries, because setrefs.c will resolve the references to system columns in the scan nodes already. Join nodes refer to them by their position in the child node's target list, like user columns. The only place where those opcodes are used, is in evaluating a trigger's WHEN condition that references system columns. Trigger evaluation abuses the INNER/OUTER Vars to refer to the OLD and NEW tuples. The code to handle the opcodes is pretty straightforward, but it seems like a good idea to have some test coverage for them, anyway, so that they don't get removed or broken by accident. Author: Ashutosh Bapat, with some changes by me. Discussion: https://www.postgresql.org/message-id/CAFjFpRerUFX=T0nSnCoroXAJMoo-xah9J+pi7+xDUx86PtQmew@mail.gmail.com
-rw-r--r--src/test/regress/expected/triggers.out10
-rw-r--r--src/test/regress/sql/triggers.sql10
2 files changed, 20 insertions, 0 deletions
diff --git a/src/test/regress/expected/triggers.out b/src/test/regress/expected/triggers.out
index bf271d536ef..e57c6e1c42d 100644
--- a/src/test/regress/expected/triggers.out
+++ b/src/test/regress/expected/triggers.out
@@ -440,6 +440,16 @@ DROP TRIGGER insert_a ON main_table;
DROP TRIGGER delete_a ON main_table;
DROP TRIGGER insert_when ON main_table;
DROP TRIGGER delete_when ON main_table;
+-- Test WHEN condition accessing system columns.
+create table table_with_oids(a int) with oids;
+insert into table_with_oids values (1);
+create trigger oid_unchanged_trig after update on table_with_oids
+ for each row
+ when (new.oid = old.oid AND new.oid <> 0)
+ execute procedure trigger_func('after_upd_oid_unchanged');
+update table_with_oids set a = a + 1;
+NOTICE: trigger_func(after_upd_oid_unchanged) called: action = UPDATE, when = AFTER, level = ROW
+drop table table_with_oids;
-- Test column-level triggers
DROP TRIGGER after_upd_row_trig ON main_table;
CREATE TRIGGER before_upd_a_row_trig BEFORE UPDATE OF a ON main_table
diff --git a/src/test/regress/sql/triggers.sql b/src/test/regress/sql/triggers.sql
index 7cfa5fdf92a..1250cd63e02 100644
--- a/src/test/regress/sql/triggers.sql
+++ b/src/test/regress/sql/triggers.sql
@@ -291,6 +291,16 @@ DROP TRIGGER delete_a ON main_table;
DROP TRIGGER insert_when ON main_table;
DROP TRIGGER delete_when ON main_table;
+-- Test WHEN condition accessing system columns.
+create table table_with_oids(a int) with oids;
+insert into table_with_oids values (1);
+create trigger oid_unchanged_trig after update on table_with_oids
+ for each row
+ when (new.oid = old.oid AND new.oid <> 0)
+ execute procedure trigger_func('after_upd_oid_unchanged');
+update table_with_oids set a = a + 1;
+drop table table_with_oids;
+
-- Test column-level triggers
DROP TRIGGER after_upd_row_trig ON main_table;