From 0e327269d4105f88f85368bbf3903725e63c06d1 Mon Sep 17 00:00:00 2001 From: Tim Chang Date: Tue, 24 Sep 2024 12:51:01 -0400 Subject: [PATCH] Disable Shared Catcache Invalidation Messages for Temp Tables (#2770) * Empty * empty * empty * Resolve merge diff with relcache changes Signed-off-by: Tim Chang * Clean up unnecessary code, added comments Signed-off-by: Tim Chang * Add some tests for local cache inval Signed-off-by: Tim Chang * Added alter table and drop function Signed-off-by: Tim Chang * Move SIMessageIsForTempTable to hook Signed-off-by: Tim Chang * Revert "Move SIMessageIsForTempTable to hook" This reverts commit c79ac5a12024a26bad55242763ad21d077a802de. --------- Signed-off-by: Tim Chang --- contrib/babelfishpg_tsql/src/hooks.c | 2 +- .../temp_catalog_inval-vu-cleanup.out | 0 .../temp_catalog_inval-vu-prepare.out | 0 .../expected/temp_catalog_inval-vu-verify.out | 79 +++++++++++++++++++ .../temp_catalog_inval-vu-cleanup.sql | 0 .../temp_catalog_inval-vu-prepare.sql | 0 .../temp_catalog_inval-vu-verify.sql | 51 ++++++++++++ 7 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 test/JDBC/expected/temp_catalog_inval-vu-cleanup.out create mode 100644 test/JDBC/expected/temp_catalog_inval-vu-prepare.out create mode 100644 test/JDBC/expected/temp_catalog_inval-vu-verify.out create mode 100644 test/JDBC/input/temp_tables/temp_catalog_inval-vu-cleanup.sql create mode 100644 test/JDBC/input/temp_tables/temp_catalog_inval-vu-prepare.sql create mode 100644 test/JDBC/input/temp_tables/temp_catalog_inval-vu-verify.sql diff --git a/contrib/babelfishpg_tsql/src/hooks.c b/contrib/babelfishpg_tsql/src/hooks.c index 2d8561e5a99..54ad1ec59f6 100644 --- a/contrib/babelfishpg_tsql/src/hooks.c +++ b/contrib/babelfishpg_tsql/src/hooks.c @@ -4791,7 +4791,7 @@ static bool set_and_persist_temp_oid_buffer_start(Oid new_oid) static bool pltsql_is_local_only_inval_msg(const SharedInvalidationMessage *msg) { - return temp_oid_buffer_size > 0 && (msg->id == SHAREDINVALRELCACHE_ID && msg->rc.local_only); + return SIMessageIsForTempTable(msg); } static EphemeralNamedRelation diff --git a/test/JDBC/expected/temp_catalog_inval-vu-cleanup.out b/test/JDBC/expected/temp_catalog_inval-vu-cleanup.out new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test/JDBC/expected/temp_catalog_inval-vu-prepare.out b/test/JDBC/expected/temp_catalog_inval-vu-prepare.out new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test/JDBC/expected/temp_catalog_inval-vu-verify.out b/test/JDBC/expected/temp_catalog_inval-vu-verify.out new file mode 100644 index 00000000000..a432662af26 --- /dev/null +++ b/test/JDBC/expected/temp_catalog_inval-vu-verify.out @@ -0,0 +1,79 @@ + +-- Catalog entries for temp tables are not visible from places like `pg_class` or `information_schema.tables` +-- So the best way to check whether the cache entries have been updated locally properly is to just ensure that +-- it's visible in typical use. +-- pg_class, pg_type, pg_attribute +CREATE TABLE #t1(a int) +go + +insert into #t1 values (1) +go +~~ROW COUNT: 1~~ + + +select * from #t1 +go +~~START~~ +int +1 +~~END~~ + + +drop table #t1 +go + +select * from #t1 +go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: relation "#t1" does not exist)~~ + + + +-- constraint, depend, index, sequence, attrdefault +create table #t2(a int identity primary key, b int default 0) +go + +alter table #t2 add c int +go + +ALTER TABLE #t2 ALTER COLUMN a bigint +go + +alter table #t2 alter column b bigint +go + +insert into #t2(c) values (2) +go +~~ROW COUNT: 1~~ + + +insert into #t2(c) values (4) +go +~~ROW COUNT: 1~~ + + +insert into #t2(b, c) values (3, 2) +go +~~ROW COUNT: 1~~ + + +select * from #t2 +go +~~START~~ +bigint#!#bigint#!#int +1#!#0#!#2 +2#!#0#!#4 +3#!#3#!#2 +~~END~~ + + +drop table #t2 +go + +select * from #t2 +go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: relation "#t2" does not exist)~~ + diff --git a/test/JDBC/input/temp_tables/temp_catalog_inval-vu-cleanup.sql b/test/JDBC/input/temp_tables/temp_catalog_inval-vu-cleanup.sql new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test/JDBC/input/temp_tables/temp_catalog_inval-vu-prepare.sql b/test/JDBC/input/temp_tables/temp_catalog_inval-vu-prepare.sql new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test/JDBC/input/temp_tables/temp_catalog_inval-vu-verify.sql b/test/JDBC/input/temp_tables/temp_catalog_inval-vu-verify.sql new file mode 100644 index 00000000000..aa4d60c2689 --- /dev/null +++ b/test/JDBC/input/temp_tables/temp_catalog_inval-vu-verify.sql @@ -0,0 +1,51 @@ +-- Catalog entries for temp tables are not visible from places like `pg_class` or `information_schema.tables` +-- So the best way to check whether the cache entries have been updated locally properly is to just ensure that +-- it's visible in typical use. + +-- pg_class, pg_type, pg_attribute +CREATE TABLE #t1(a int) +go + +insert into #t1 values (1) +go + +select * from #t1 +go + +drop table #t1 +go + +select * from #t1 +go + +-- constraint, depend, index, sequence, attrdefault + +create table #t2(a int identity primary key, b int default 0) +go + +alter table #t2 add c int +go + +ALTER TABLE #t2 ALTER COLUMN a bigint +go + +alter table #t2 alter column b bigint +go + +insert into #t2(c) values (2) +go + +insert into #t2(c) values (4) +go + +insert into #t2(b, c) values (3, 2) +go + +select * from #t2 +go + +drop table #t2 +go + +select * from #t2 +go