diff --git a/src/backend/catalog/namespace.c b/src/backend/catalog/namespace.c index aa4156abf564b09756143d98a312915693d8eb31..0caf62320ad5815949b4845241ad155698ec9381 100644 --- a/src/backend/catalog/namespace.c +++ b/src/backend/catalog/namespace.c @@ -3167,7 +3167,7 @@ InitTempTableNamespace(void) /* * GPDB: Delete old temp schema. * - * Remove any vestigages of old temporary schema, if any. This can + * Remove any vestiges of old temporary schema, if any. This can * happen when an old session crashes and doesn't run normal session * shutdown. * @@ -3503,6 +3503,7 @@ RemoveTempRelationsCallback(int code, Datum arg) /* MPP-3390: drop pg_temp_N schema entry from pg_namespace */ RemoveSchemaById(myTempNamespace); + RemoveSchemaById(myTempToastNamespace); elog(DEBUG1, "Remove schema entry %u from pg_namespace", myTempNamespace); } diff --git a/src/test/regress/expected/bfv_temp.out b/src/test/regress/expected/bfv_temp.out index 6b964d00de8ef9feca215c9b3813608092590203..77c4272e4ee25f5f501c5f9effd7680e0e889683 100644 --- a/src/test/regress/expected/bfv_temp.out +++ b/src/test/regress/expected/bfv_temp.out @@ -19,9 +19,17 @@ NOTICE: Table created (1 row) --- There should be one temp table, the one we created (we assume that there are no --- other backends using temp tables running at the same time). -select count(*) from pg_tables where schemaname like 'pg_temp%'; +-- Remember the name of the temp namespace and temp toast namespace +CREATE TABLE temp_nspnames as +select nsp.nspname as nspname, toastnsp.nspname as toastnspname from pg_class c +inner join pg_namespace nsp on c.relnamespace = nsp.oid +inner join pg_class toastc on toastc.oid = c.reltoastrelid +inner join pg_namespace toastnsp on toastc.relnamespace = toastnsp.oid +where c.oid = 'wmt_toast_issue_temp'::regclass; +NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column(s) named 'nspname' as the Greenplum Database data distribution key for this table. +HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew. +-- there should be exactly one temp table with that name. +select count(*) from temp_nspnames; count ------- 1 @@ -37,13 +45,22 @@ select pg_sleep(2); (1 row) --- Check that the temporary table was dropped at disconnect. -select * from pg_tables where schemaname like 'pg_temp%'; +-- Check that the temp namespaces were dropped altogether. +select nsp.nspname, temp_nspnames.* FROM pg_namespace nsp, temp_nspnames +where nsp.nspname = temp_nspnames.nspname OR nsp.nspname = temp_nspnames.toastnspname; + nspname | nspname | toastnspname +---------+---------+-------------- +(0 rows) + +-- Check that the temporary table was dropped at disconnect. (It really should be +-- gone if the whole namespace is gone, but doesn't hurt to check.) +select * from pg_tables where tablename = 'wmt_toast_issue_temp'; schemaname | tablename | tableowner | tablespace | hasindexes | hasrules | hastriggers ------------+-----------+------------+------------+------------+----------+------------- (0 rows) -- Clean up reset role; +drop table temp_nspnames; drop function public.sec_definer_create_test(); drop role sec_definer_role; diff --git a/src/test/regress/sql/bfv_temp.sql b/src/test/regress/sql/bfv_temp.sql index 68580888e233c75e5ccbd13925accf477d629a1d..c1aa90653c9a751b8724192b7eb7e8e3e1ea05a7 100644 --- a/src/test/regress/sql/bfv_temp.sql +++ b/src/test/regress/sql/bfv_temp.sql @@ -17,9 +17,17 @@ set role sec_definer_role; select sec_definer_create_test() ; --- There should be one temp table, the one we created (we assume that there are no --- other backends using temp tables running at the same time). -select count(*) from pg_tables where schemaname like 'pg_temp%'; +-- Remember the name of the temp namespace and temp toast namespace +CREATE TABLE temp_nspnames as +select nsp.nspname as nspname, toastnsp.nspname as toastnspname from pg_class c +inner join pg_namespace nsp on c.relnamespace = nsp.oid +inner join pg_class toastc on toastc.oid = c.reltoastrelid +inner join pg_namespace toastnsp on toastc.relnamespace = toastnsp.oid +where c.oid = 'wmt_toast_issue_temp'::regclass; + +-- there should be exactly one temp table with that name. +select count(*) from temp_nspnames; + -- Disconnect and reconnect. \c regression @@ -28,11 +36,17 @@ select count(*) from pg_tables where schemaname like 'pg_temp%'; -- temp tables. select pg_sleep(2); --- Check that the temporary table was dropped at disconnect. -select * from pg_tables where schemaname like 'pg_temp%'; +-- Check that the temp namespaces were dropped altogether. +select nsp.nspname, temp_nspnames.* FROM pg_namespace nsp, temp_nspnames +where nsp.nspname = temp_nspnames.nspname OR nsp.nspname = temp_nspnames.toastnspname; + +-- Check that the temporary table was dropped at disconnect. (It really should be +-- gone if the whole namespace is gone, but doesn't hurt to check.) +select * from pg_tables where tablename = 'wmt_toast_issue_temp'; + -- Clean up reset role; +drop table temp_nspnames; drop function public.sec_definer_create_test(); drop role sec_definer_role; -