This is an automated email from the ASF dual-hosted git repository. reshke pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit 04e6ac6e513a74cc5e940c5dd2fc4e2dee1c8463 Author: Sasasu <[email protected]> AuthorDate: Fri May 20 09:53:30 2022 +0800 Don't dispatch temp namespace oid to writer gang (#13523) follow up #13213 and #13221. dispatch temp namespace oid in every query. on writer gang skips set temp namespace oid, the writer gang will do InitTempTableNamespace(). on reader gang always use the oid from query message, allow temp NS oid change dynamically. temp namespace oid will stale after creating temp NS rollback. it should be fine, new oid will be dispatched in the next sql. --- src/backend/catalog/namespace.c | 14 ++++++++------ src/backend/cdb/dispatcher/cdbdisp_query.c | 2 +- src/backend/tcop/postgres.c | 2 +- src/test/regress/expected/bfv_temp.out | 28 ++++++++++++++++++++++++++++ src/test/regress/sql/bfv_temp.sql | 14 ++++++++++++++ 5 files changed, 52 insertions(+), 8 deletions(-) diff --git a/src/backend/catalog/namespace.c b/src/backend/catalog/namespace.c index 6f3c4e1574..f367b00a67 100644 --- a/src/backend/catalog/namespace.c +++ b/src/backend/catalog/namespace.c @@ -3487,17 +3487,19 @@ SetTempNamespaceState(Oid tempNamespaceId, Oid tempToastNamespaceId) /* * like SetTempNamespaceState, but the process running normally * - * GPDB: used to set session level temporary namespace after gang launched. + * GPDB: used to set session level temporary namespace after reader gang launched. */ void SetTempNamespaceStateAfterBoot(Oid tempNamespaceId, Oid tempToastNamespaceId) { - /* same as PG, can not switch to other temp namespace dynamically */ - Assert(myTempNamespace == InvalidOid || myTempNamespace == tempNamespaceId); - Assert(myTempToastNamespace == InvalidOid || myTempToastNamespace == tempToastNamespaceId); + Assert(Gp_role == GP_ROLE_EXECUTE); - /* if the namespace OID already setted, baseSearchPath is still valid */ - if (myTempNamespace == tempToastNamespaceId && myTempToastNamespace == tempToastNamespaceId) + /* writer gang will do InitTempTableNamespace(), ignore the dispatch on writer gang */ + if (Gp_is_writer) + return; + + /* skip rebuild search path if search path is correct and valid */ + if (tempNamespaceId == myTempNamespace && myTempToastNamespace == tempToastNamespaceId) return; myTempNamespace = tempNamespaceId; diff --git a/src/backend/cdb/dispatcher/cdbdisp_query.c b/src/backend/cdb/dispatcher/cdbdisp_query.c index e9efb4a8d0..0a136074d5 100644 --- a/src/backend/cdb/dispatcher/cdbdisp_query.c +++ b/src/backend/cdb/dispatcher/cdbdisp_query.c @@ -1021,7 +1021,7 @@ buildGpQueryString(DispatchCommandQueryParms *pQueryParms, pos += resgroupInfo.len; } - /* in-process variable for temporary namespace */ + /* pass process local variables to QEs */ GetTempNamespaceState(&tempNamespaceId, &tempToastNamespaceId); tempNamespaceId = htonl(tempNamespaceId); tempToastNamespaceId = htonl(tempToastNamespaceId); diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c index 031d84b757..d996a14ec5 100644 --- a/src/backend/tcop/postgres.c +++ b/src/backend/tcop/postgres.c @@ -5722,7 +5722,7 @@ PostgresMain(int argc, char *argv[], if (resgroupInfoLen > 0) resgroupInfoBuf = pq_getmsgbytes(&input_message, resgroupInfoLen); - /* in-process variable for temporary namespace */ + /* process local variables for temporary namespace */ { Oid tempNamespaceId, tempToastNamespaceId; diff --git a/src/test/regress/expected/bfv_temp.out b/src/test/regress/expected/bfv_temp.out index 989279dc05..320e9a2633 100644 --- a/src/test/regress/expected/bfv_temp.out +++ b/src/test/regress/expected/bfv_temp.out @@ -99,3 +99,31 @@ drop table tn_b_b; drop table tn_b_temp; drop table tn_b_new; drop function fun(sql text, a oid); +-- Chek if error out inside UDF, myTempNamespace will roll back +\c +create or replace function errored_udf() returns int[] as 'BEGIN RAISE EXCEPTION ''AAA''; END' language plpgsql; +create table n as select from generate_series(1, 10); +NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column(s) named '' 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. +select count(*) from n n1, n n2; -- boot reader gang + count +------- + 100 +(1 row) + +create temp table nn as select errored_udf() from n; +NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column(s) named 'errored_udf' 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. +ERROR: AAA (seg0 slice1 127.0.0.1:7002 pid=123850) +CONTEXT: PL/pgSQL function errored_udf() line 1 at RAISE +create temp table nnn as select * from generate_series(1, 10); -- check if reader do the rollback. should OK +NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column(s) named 'generate_series' 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. +select count(*) from nnn n1, nnn n2; -- check if reader can read temp table. should OK + count +------- + 100 +(1 row) + +drop table n; +drop function errored_udf(); diff --git a/src/test/regress/sql/bfv_temp.sql b/src/test/regress/sql/bfv_temp.sql index 4df911099d..8cdd104635 100644 --- a/src/test/regress/sql/bfv_temp.sql +++ b/src/test/regress/sql/bfv_temp.sql @@ -84,3 +84,17 @@ drop table tn_b_b; drop table tn_b_temp; drop table tn_b_new; drop function fun(sql text, a oid); + +-- Chek if error out inside UDF, myTempNamespace will roll back +\c +create or replace function errored_udf() returns int[] as 'BEGIN RAISE EXCEPTION ''AAA''; END' language plpgsql; + +create table n as select from generate_series(1, 10); +select count(*) from n n1, n n2; -- boot reader gang + +create temp table nn as select errored_udf() from n; +create temp table nnn as select * from generate_series(1, 10); -- check if reader do the rollback. should OK +select count(*) from nnn n1, nnn n2; -- check if reader can read temp table. should OK + +drop table n; +drop function errored_udf(); --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
