From 205b15960696ecdf15021dfa1858079841a7e503 Mon Sep 17 00:00:00 2001 From: zhjwpku Date: Tue, 5 Sep 2023 23:40:22 +0800 Subject: [PATCH] get rid of {Push/Pop}OverrideSearchPath (#7145) --- .../distributed/commands/alter_table.c | 8 ++--- src/backend/distributed/commands/extension.c | 8 ++--- .../distributed/commands/foreign_constraint.c | 4 +-- src/backend/distributed/commands/function.c | 5 ++- src/backend/distributed/commands/statistics.c | 4 +-- src/backend/distributed/commands/trigger.c | 4 +-- src/backend/distributed/commands/view.c | 7 ++-- .../distributed/deparser/citus_ruleutils.c | 4 +-- .../deparser/deparse_domain_stmts.c | 12 +++---- .../deparser/deparse_publication_stmts.c | 4 +-- .../deparser/deparse_table_stmts.c | 4 +-- .../distributed/deparser/ruleutils_14.c | 22 ++++--------- .../distributed/deparser/ruleutils_15.c | 22 ++++--------- .../distributed/deparser/ruleutils_16.c | 22 ++++--------- .../distributed/operations/node_protocol.c | 8 ++--- .../replicate_none_dist_table_shard.c | 4 +-- .../distributed/utils/namespace_utils.c | 33 ++++++++++++------- src/include/distributed/namespace_utils.h | 3 +- 18 files changed, 80 insertions(+), 98 deletions(-) diff --git a/src/backend/distributed/commands/alter_table.c b/src/backend/distributed/commands/alter_table.c index 788a3b8b0..fbe7cfe07 100644 --- a/src/backend/distributed/commands/alter_table.c +++ b/src/backend/distributed/commands/alter_table.c @@ -53,6 +53,7 @@ #include "distributed/multi_executor.h" #include "distributed/multi_logical_planner.h" #include "distributed/multi_partitioning_utils.h" +#include "distributed/namespace_utils.h" #include "distributed/reference_table_utils.h" #include "distributed/relation_access_tracking.h" #include "distributed/replication_origin_session_utils.h" @@ -1764,10 +1765,7 @@ CreateMaterializedViewDDLCommand(Oid matViewOid) * Set search_path to NIL so that all objects outside of pg_catalog will be * schema-prefixed. */ - OverrideSearchPath *overridePath = GetOverrideSearchPath(CurrentMemoryContext); - overridePath->schemas = NIL; - overridePath->addCatalog = true; - PushOverrideSearchPath(overridePath); + int saveNestLevel = PushEmptySearchPath(); /* * Push the transaction snapshot to be able to get vief definition with pg_get_viewdef @@ -1779,7 +1777,7 @@ CreateMaterializedViewDDLCommand(Oid matViewOid) char *viewDefinition = TextDatumGetCString(viewDefinitionDatum); PopActiveSnapshot(); - PopOverrideSearchPath(); + PopEmptySearchPath(saveNestLevel); appendStringInfo(query, "AS %s", viewDefinition); diff --git a/src/backend/distributed/commands/extension.c b/src/backend/distributed/commands/extension.c index ac4bf135e..5bddf1ede 100644 --- a/src/backend/distributed/commands/extension.c +++ b/src/backend/distributed/commands/extension.c @@ -50,7 +50,7 @@ static List * GetAllViews(void); static bool ShouldPropagateExtensionCommand(Node *parseTree); static bool IsAlterExtensionSetSchemaCitus(Node *parseTree); static Node * RecreateExtensionStmt(Oid extensionOid); -static List * GenerateGrantCommandsOnExtesionDependentFDWs(Oid extensionId); +static List * GenerateGrantCommandsOnExtensionDependentFDWs(Oid extensionId); /* @@ -985,7 +985,7 @@ CreateExtensionDDLCommand(const ObjectAddress *extensionAddress) /* any privilege granted on FDWs that belong to the extension should be included */ List *FDWGrants = - GenerateGrantCommandsOnExtesionDependentFDWs(extensionAddress->objectId); + GenerateGrantCommandsOnExtensionDependentFDWs(extensionAddress->objectId); ddlCommands = list_concat(ddlCommands, FDWGrants); @@ -1048,11 +1048,11 @@ RecreateExtensionStmt(Oid extensionOid) /* - * GenerateGrantCommandsOnExtesionDependentFDWs returns a list of commands that GRANTs + * GenerateGrantCommandsOnExtensionDependentFDWs returns a list of commands that GRANTs * the privileges on FDWs that are depending on the given extension. */ static List * -GenerateGrantCommandsOnExtesionDependentFDWs(Oid extensionId) +GenerateGrantCommandsOnExtensionDependentFDWs(Oid extensionId) { List *commands = NIL; List *FDWOids = GetDependentFDWsToExtension(extensionId); diff --git a/src/backend/distributed/commands/foreign_constraint.c b/src/backend/distributed/commands/foreign_constraint.c index 0d5156353..7c2d50f44 100644 --- a/src/backend/distributed/commands/foreign_constraint.c +++ b/src/backend/distributed/commands/foreign_constraint.c @@ -895,7 +895,7 @@ GetForeignConstraintCommandsInternal(Oid relationId, int flags) List *foreignKeyCommands = NIL; - PushOverrideEmptySearchPath(CurrentMemoryContext); + int saveNestLevel = PushEmptySearchPath(); Oid foreignKeyOid = InvalidOid; foreach_oid(foreignKeyOid, foreignKeyOids) @@ -906,7 +906,7 @@ GetForeignConstraintCommandsInternal(Oid relationId, int flags) } /* revert back to original search_path */ - PopOverrideSearchPath(); + PopEmptySearchPath(saveNestLevel); return foreignKeyCommands; } diff --git a/src/backend/distributed/commands/function.c b/src/backend/distributed/commands/function.c index 76112ad9a..01911677d 100644 --- a/src/backend/distributed/commands/function.c +++ b/src/backend/distributed/commands/function.c @@ -909,15 +909,14 @@ GetFunctionDDLCommand(const RegProcedure funcOid, bool useCreateOrReplace) else { Datum sqlTextDatum = (Datum) 0; - - PushOverrideEmptySearchPath(CurrentMemoryContext); + int saveNestLevel = PushEmptySearchPath(); sqlTextDatum = DirectFunctionCall1(pg_get_functiondef, ObjectIdGetDatum(funcOid)); createFunctionSQL = TextDatumGetCString(sqlTextDatum); /* revert back to original search_path */ - PopOverrideSearchPath(); + PopEmptySearchPath(saveNestLevel); } return createFunctionSQL; diff --git a/src/backend/distributed/commands/statistics.c b/src/backend/distributed/commands/statistics.c index e5d5ac8ce..dae72ada9 100644 --- a/src/backend/distributed/commands/statistics.c +++ b/src/backend/distributed/commands/statistics.c @@ -530,7 +530,7 @@ GetExplicitStatisticsCommandList(Oid relationId) RelationClose(relation); /* generate fully-qualified names */ - PushOverrideEmptySearchPath(CurrentMemoryContext); + int saveNestLevel = PushEmptySearchPath(); Oid statisticsId = InvalidOid; foreach_oid(statisticsId, statisticsIdList) @@ -579,7 +579,7 @@ GetExplicitStatisticsCommandList(Oid relationId) } /* revert back to original search_path */ - PopOverrideSearchPath(); + PopEmptySearchPath(saveNestLevel); return explicitStatisticsCommandList; } diff --git a/src/backend/distributed/commands/trigger.c b/src/backend/distributed/commands/trigger.c index c7776bdb6..7577dfd31 100644 --- a/src/backend/distributed/commands/trigger.c +++ b/src/backend/distributed/commands/trigger.c @@ -74,7 +74,7 @@ GetExplicitTriggerCommandList(Oid relationId) { List *createTriggerCommandList = NIL; - PushOverrideEmptySearchPath(CurrentMemoryContext); + int saveNestLevel = PushEmptySearchPath(); List *triggerIdList = GetExplicitTriggerIdList(relationId); @@ -116,7 +116,7 @@ GetExplicitTriggerCommandList(Oid relationId) } /* revert back to original search_path */ - PopOverrideSearchPath(); + PopEmptySearchPath(saveNestLevel); return createTriggerCommandList; } diff --git a/src/backend/distributed/commands/view.c b/src/backend/distributed/commands/view.c index 02d6815d9..7c4816144 100644 --- a/src/backend/distributed/commands/view.c +++ b/src/backend/distributed/commands/view.c @@ -479,10 +479,7 @@ AppendViewDefinitionToCreateViewCommand(StringInfo buf, Oid viewOid) * Set search_path to NIL so that all objects outside of pg_catalog will be * schema-prefixed. */ - OverrideSearchPath *overridePath = GetOverrideSearchPath(CurrentMemoryContext); - overridePath->schemas = NIL; - overridePath->addCatalog = true; - PushOverrideSearchPath(overridePath); + int saveNestLevel = PushEmptySearchPath(); /* * Push the transaction snapshot to be able to get vief definition with pg_get_viewdef @@ -494,7 +491,7 @@ AppendViewDefinitionToCreateViewCommand(StringInfo buf, Oid viewOid) char *viewDefinition = TextDatumGetCString(viewDefinitionDatum); PopActiveSnapshot(); - PopOverrideSearchPath(); + PopEmptySearchPath(saveNestLevel); appendStringInfo(buf, "AS %s ", viewDefinition); } diff --git a/src/backend/distributed/deparser/citus_ruleutils.c b/src/backend/distributed/deparser/citus_ruleutils.c index 6b865e061..220ea3ec7 100644 --- a/src/backend/distributed/deparser/citus_ruleutils.c +++ b/src/backend/distributed/deparser/citus_ruleutils.c @@ -818,7 +818,7 @@ deparse_shard_index_statement(IndexStmt *origStmt, Oid distrelid, int64 shardid, * Switch to empty search_path to deparse_index_columns to produce fully- * qualified names in expressions. */ - PushOverrideEmptySearchPath(CurrentMemoryContext); + int saveNestLevel = PushEmptySearchPath(); /* index column or expression list begins here */ appendStringInfoChar(buffer, '('); @@ -855,7 +855,7 @@ deparse_shard_index_statement(IndexStmt *origStmt, Oid distrelid, int64 shardid, } /* revert back to original search_path */ - PopOverrideSearchPath(); + PopEmptySearchPath(saveNestLevel); } diff --git a/src/backend/distributed/deparser/deparse_domain_stmts.c b/src/backend/distributed/deparser/deparse_domain_stmts.c index 9891e0532..e517074ec 100644 --- a/src/backend/distributed/deparser/deparse_domain_stmts.c +++ b/src/backend/distributed/deparser/deparse_domain_stmts.c @@ -345,9 +345,9 @@ AppendAlterDomainStmtSetDefault(StringInfo buf, AlterDomainStmt *stmt) expr = TransformDefaultExpr(expr, stmt->typeName, baseTypeName); /* deparse while the searchpath is cleared to force qualification of identifiers */ - PushOverrideEmptySearchPath(CurrentMemoryContext); + int saveNestLevel = PushEmptySearchPath(); char *exprSql = deparse_expression(expr, NIL, true, true); - PopOverrideSearchPath(); + PopEmptySearchPath(saveNestLevel); appendStringInfo(buf, "SET DEFAULT %s", exprSql); } @@ -443,9 +443,9 @@ AppendConstraint(StringInfo buf, Constraint *constraint, List *domainName, elog(ERROR, "missing expression for domain constraint"); } - PushOverrideEmptySearchPath(CurrentMemoryContext); + int saveNestLevel = PushEmptySearchPath(); char *exprSql = deparse_expression(expr, NIL, true, true); - PopOverrideSearchPath(); + PopEmptySearchPath(saveNestLevel); appendStringInfo(buf, " CHECK (%s)", exprSql); return; @@ -469,9 +469,9 @@ AppendConstraint(StringInfo buf, Constraint *constraint, List *domainName, elog(ERROR, "missing expression for domain default"); } - PushOverrideEmptySearchPath(CurrentMemoryContext); + int saveNestLevel = PushEmptySearchPath(); char *exprSql = deparse_expression(expr, NIL, true, true); - PopOverrideSearchPath(); + PopEmptySearchPath(saveNestLevel); appendStringInfo(buf, " DEFAULT %s", exprSql); return; diff --git a/src/backend/distributed/deparser/deparse_publication_stmts.c b/src/backend/distributed/deparser/deparse_publication_stmts.c index deb8e7285..e22333146 100644 --- a/src/backend/distributed/deparser/deparse_publication_stmts.c +++ b/src/backend/distributed/deparser/deparse_publication_stmts.c @@ -307,11 +307,11 @@ AppendWhereClauseExpression(StringInfo buf, RangeVar *tableName, List *relationContext = deparse_context_for(tableName->relname, relation->rd_id); - PushOverrideEmptySearchPath(CurrentMemoryContext); + int saveNestLevel = PushEmptySearchPath(); char *whereClauseString = deparse_expression(whereClause, relationContext, true, true); - PopOverrideSearchPath(); + PopEmptySearchPath(saveNestLevel); appendStringInfoString(buf, whereClauseString); diff --git a/src/backend/distributed/deparser/deparse_table_stmts.c b/src/backend/distributed/deparser/deparse_table_stmts.c index a90d38655..ff96d7fc3 100644 --- a/src/backend/distributed/deparser/deparse_table_stmts.c +++ b/src/backend/distributed/deparser/deparse_table_stmts.c @@ -562,9 +562,9 @@ DeparseRawExprForColumnDefault(Oid relationId, Oid columnTypeId, int32 columnTyp List *deparseContext = deparse_context_for(get_rel_name(relationId), relationId); - PushOverrideEmptySearchPath(CurrentMemoryContext); + int saveNestLevel = PushEmptySearchPath(); char *defaultExprStr = deparse_expression(defaultExpr, deparseContext, false, false); - PopOverrideSearchPath(); + PopEmptySearchPath(saveNestLevel); RelationClose(relation); diff --git a/src/backend/distributed/deparser/ruleutils_14.c b/src/backend/distributed/deparser/ruleutils_14.c index b364221d8..6ab124537 100644 --- a/src/backend/distributed/deparser/ruleutils_14.c +++ b/src/backend/distributed/deparser/ruleutils_14.c @@ -53,6 +53,7 @@ #include "common/keywords.h" #include "distributed/citus_nodefuncs.h" #include "distributed/citus_ruleutils.h" +#include "distributed/namespace_utils.h" #include "executor/spi.h" #include "foreign/foreign.h" #include "funcapi.h" @@ -610,18 +611,14 @@ pg_get_rule_expr(Node *expression) { bool showImplicitCasts = true; deparse_context context; - OverrideSearchPath *overridePath = NULL; StringInfo buffer = makeStringInfo(); /* * Set search_path to NIL so that all objects outside of pg_catalog will be * schema-prefixed. pg_catalog will be added automatically when we call - * PushOverrideSearchPath(), since we set addCatalog to true; + * PushEmptySearchPath(). */ - overridePath = GetOverrideSearchPath(CurrentMemoryContext); - overridePath->schemas = NIL; - overridePath->addCatalog = true; - PushOverrideSearchPath(overridePath); + int saveNestLevel = PushEmptySearchPath(); context.buf = buffer; context.namespaces = NIL; @@ -638,7 +635,7 @@ pg_get_rule_expr(Node *expression) get_rule_expr(expression, &context, showImplicitCasts); /* revert back to original search_path */ - PopOverrideSearchPath(); + PopEmptySearchPath(saveNestLevel); return buffer->data; } @@ -1955,8 +1952,6 @@ get_query_def_extended(Query *query, StringInfo buf, List *parentnamespace, deparse_context context; deparse_namespace dpns; - OverrideSearchPath *overridePath = NULL; - /* Guard against excessively long or deeply-nested queries */ CHECK_FOR_INTERRUPTS(); check_stack_depth(); @@ -1975,12 +1970,9 @@ get_query_def_extended(Query *query, StringInfo buf, List *parentnamespace, /* * Set search_path to NIL so that all objects outside of pg_catalog will be * schema-prefixed. pg_catalog will be added automatically when we call - * PushOverrideSearchPath(), since we set addCatalog to true; + * PushEmptySearchPath(). */ - overridePath = GetOverrideSearchPath(CurrentMemoryContext); - overridePath->schemas = NIL; - overridePath->addCatalog = true; - PushOverrideSearchPath(overridePath); + int saveNestLevel = PushEmptySearchPath(); context.buf = buf; context.namespaces = lcons(&dpns, list_copy(parentnamespace)); @@ -2031,7 +2023,7 @@ get_query_def_extended(Query *query, StringInfo buf, List *parentnamespace, } /* revert back to original search_path */ - PopOverrideSearchPath(); + PopEmptySearchPath(saveNestLevel); } /* ---------- diff --git a/src/backend/distributed/deparser/ruleutils_15.c b/src/backend/distributed/deparser/ruleutils_15.c index 2dded9b01..755e0f4cd 100644 --- a/src/backend/distributed/deparser/ruleutils_15.c +++ b/src/backend/distributed/deparser/ruleutils_15.c @@ -54,6 +54,7 @@ #include "distributed/citus_nodefuncs.h" #include "distributed/citus_ruleutils.h" #include "distributed/multi_router_planner.h" +#include "distributed/namespace_utils.h" #include "executor/spi.h" #include "foreign/foreign.h" #include "funcapi.h" @@ -624,18 +625,14 @@ pg_get_rule_expr(Node *expression) { bool showImplicitCasts = true; deparse_context context; - OverrideSearchPath *overridePath = NULL; StringInfo buffer = makeStringInfo(); /* * Set search_path to NIL so that all objects outside of pg_catalog will be * schema-prefixed. pg_catalog will be added automatically when we call - * PushOverrideSearchPath(), since we set addCatalog to true; + * PushEmptySearchPath(), since we set addCatalog to true; */ - overridePath = GetOverrideSearchPath(CurrentMemoryContext); - overridePath->schemas = NIL; - overridePath->addCatalog = true; - PushOverrideSearchPath(overridePath); + int saveNestLevel = PushEmptySearchPath(); context.buf = buffer; context.namespaces = NIL; @@ -652,7 +649,7 @@ pg_get_rule_expr(Node *expression) get_rule_expr(expression, &context, showImplicitCasts); /* revert back to original search_path */ - PopOverrideSearchPath(); + PopEmptySearchPath(saveNestLevel); return buffer->data; } @@ -2038,8 +2035,6 @@ get_query_def_extended(Query *query, StringInfo buf, List *parentnamespace, deparse_context context; deparse_namespace dpns; - OverrideSearchPath *overridePath = NULL; - /* Guard against excessively long or deeply-nested queries */ CHECK_FOR_INTERRUPTS(); check_stack_depth(); @@ -2058,12 +2053,9 @@ get_query_def_extended(Query *query, StringInfo buf, List *parentnamespace, /* * Set search_path to NIL so that all objects outside of pg_catalog will be * schema-prefixed. pg_catalog will be added automatically when we call - * PushOverrideSearchPath(), since we set addCatalog to true; + * PushEmptySearchPath(). */ - overridePath = GetOverrideSearchPath(CurrentMemoryContext); - overridePath->schemas = NIL; - overridePath->addCatalog = true; - PushOverrideSearchPath(overridePath); + int saveNestLevel = PushEmptySearchPath(); context.buf = buf; context.namespaces = lcons(&dpns, list_copy(parentnamespace)); @@ -2118,7 +2110,7 @@ get_query_def_extended(Query *query, StringInfo buf, List *parentnamespace, } /* revert back to original search_path */ - PopOverrideSearchPath(); + PopEmptySearchPath(saveNestLevel); } /* ---------- diff --git a/src/backend/distributed/deparser/ruleutils_16.c b/src/backend/distributed/deparser/ruleutils_16.c index 37ba6e34b..31e8823b1 100644 --- a/src/backend/distributed/deparser/ruleutils_16.c +++ b/src/backend/distributed/deparser/ruleutils_16.c @@ -54,6 +54,7 @@ #include "distributed/citus_nodefuncs.h" #include "distributed/citus_ruleutils.h" #include "distributed/multi_router_planner.h" +#include "distributed/namespace_utils.h" #include "executor/spi.h" #include "foreign/foreign.h" #include "funcapi.h" @@ -641,18 +642,14 @@ pg_get_rule_expr(Node *expression) { bool showImplicitCasts = true; deparse_context context; - OverrideSearchPath *overridePath = NULL; StringInfo buffer = makeStringInfo(); /* * Set search_path to NIL so that all objects outside of pg_catalog will be * schema-prefixed. pg_catalog will be added automatically when we call - * PushOverrideSearchPath(), since we set addCatalog to true; + * PushEmptySearchPath(). */ - overridePath = GetOverrideSearchPath(CurrentMemoryContext); - overridePath->schemas = NIL; - overridePath->addCatalog = true; - PushOverrideSearchPath(overridePath); + int saveNestLevel = PushEmptySearchPath(); context.buf = buffer; context.namespaces = NIL; @@ -669,7 +666,7 @@ pg_get_rule_expr(Node *expression) get_rule_expr(expression, &context, showImplicitCasts); /* revert back to original search_path */ - PopOverrideSearchPath(); + PopEmptySearchPath(saveNestLevel); return buffer->data; } @@ -2052,8 +2049,6 @@ get_query_def_extended(Query *query, StringInfo buf, List *parentnamespace, deparse_context context; deparse_namespace dpns; - OverrideSearchPath *overridePath = NULL; - /* Guard against excessively long or deeply-nested queries */ CHECK_FOR_INTERRUPTS(); check_stack_depth(); @@ -2072,12 +2067,9 @@ get_query_def_extended(Query *query, StringInfo buf, List *parentnamespace, /* * Set search_path to NIL so that all objects outside of pg_catalog will be * schema-prefixed. pg_catalog will be added automatically when we call - * PushOverrideSearchPath(), since we set addCatalog to true; + * PushEmptySearchPath(). */ - overridePath = GetOverrideSearchPath(CurrentMemoryContext); - overridePath->schemas = NIL; - overridePath->addCatalog = true; - PushOverrideSearchPath(overridePath); + int saveNestLevel = PushEmptySearchPath(); context.buf = buf; context.namespaces = lcons(&dpns, list_copy(parentnamespace)); @@ -2132,7 +2124,7 @@ get_query_def_extended(Query *query, StringInfo buf, List *parentnamespace, } /* revert back to original search_path */ - PopOverrideSearchPath(); + PopEmptySearchPath(saveNestLevel); } /* ---------- diff --git a/src/backend/distributed/operations/node_protocol.c b/src/backend/distributed/operations/node_protocol.c index 14287992e..a3f7092d1 100644 --- a/src/backend/distributed/operations/node_protocol.c +++ b/src/backend/distributed/operations/node_protocol.c @@ -612,7 +612,7 @@ GetPreLoadTableCreationCommands(Oid relationId, { List *tableDDLEventList = NIL; - PushOverrideEmptySearchPath(CurrentMemoryContext); + int saveNestLevel = PushEmptySearchPath(); /* fetch table schema and column option definitions */ char *tableSchemaDef = pg_get_tableschemadef_string(relationId, @@ -665,7 +665,7 @@ GetPreLoadTableCreationCommands(Oid relationId, tableDDLEventList = list_concat(tableDDLEventList, policyCommands); /* revert back to original search_path */ - PopOverrideSearchPath(); + PopEmptySearchPath(saveNestLevel); return tableDDLEventList; } @@ -754,7 +754,7 @@ GatherIndexAndConstraintDefinitionList(Form_pg_index indexForm, List **indexDDLE int indexFlags) { /* generate fully-qualified names */ - PushOverrideEmptySearchPath(CurrentMemoryContext); + int saveNestLevel = PushEmptySearchPath(); Oid indexId = indexForm->indexrelid; bool indexImpliedByConstraint = IndexImpliedByAConstraint(indexForm); @@ -805,7 +805,7 @@ GatherIndexAndConstraintDefinitionList(Form_pg_index indexForm, List **indexDDLE } /* revert back to original search_path */ - PopOverrideSearchPath(); + PopEmptySearchPath(saveNestLevel); } diff --git a/src/backend/distributed/operations/replicate_none_dist_table_shard.c b/src/backend/distributed/operations/replicate_none_dist_table_shard.c index 945214aef..c28490367 100644 --- a/src/backend/distributed/operations/replicate_none_dist_table_shard.c +++ b/src/backend/distributed/operations/replicate_none_dist_table_shard.c @@ -158,7 +158,7 @@ NoneDistTableDropCoordinatorPlacementTable(Oid noneDistTableId) * local session because changes made to shards are allowed for Citus internal * backends anyway. */ - int save_nestlevel = NewGUCNestLevel(); + int saveNestLevel = NewGUCNestLevel(); SetLocalEnableLocalReferenceForeignKeys(false); SetLocalEnableManualChangesToShard(true); @@ -184,7 +184,7 @@ NoneDistTableDropCoordinatorPlacementTable(Oid noneDistTableId) bool localExecutionSupported = true; ExecuteUtilityTaskList(list_make1(task), localExecutionSupported); - AtEOXact_GUC(true, save_nestlevel); + AtEOXact_GUC(true, saveNestLevel); } diff --git a/src/backend/distributed/utils/namespace_utils.c b/src/backend/distributed/utils/namespace_utils.c index a97adb573..4f822b7d2 100644 --- a/src/backend/distributed/utils/namespace_utils.c +++ b/src/backend/distributed/utils/namespace_utils.c @@ -11,22 +11,33 @@ #include "postgres.h" -#include "catalog/namespace.h" -#include "distributed/citus_ruleutils.h" #include "distributed/namespace_utils.h" +#include "utils/guc.h" #include "utils/regproc.h" /* - * PushOverrideEmptySearchPath pushes search_path to be NIL and sets addCatalog to - * true so that all objects outside of pg_catalog will be schema-prefixed. - * Afterwards, PopOverrideSearchPath can be used to revert the search_path back. + * We use the equivalent of a function SET option to allow the setting to + * persist for the exact duration of the transaction, guc.c takes care of + * undoing the setting on error. + * + * We set search_path to "pg_catalog" instead of "" to expose useful utilities. + */ +int +PushEmptySearchPath() +{ + int saveNestLevel = NewGUCNestLevel(); + (void) set_config_option("search_path", "pg_catalog", + PGC_USERSET, PGC_S_SESSION, + GUC_ACTION_SAVE, true, 0, false); + return saveNestLevel; +} + + +/* + * Restore the GUC variable search_path we set in PushEmptySearchPath */ void -PushOverrideEmptySearchPath(MemoryContext memoryContext) +PopEmptySearchPath(int saveNestLevel) { - OverrideSearchPath *overridePath = GetOverrideSearchPath(memoryContext); - overridePath->schemas = NIL; - overridePath->addCatalog = true; - - PushOverrideSearchPath(overridePath); + AtEOXact_GUC(true, saveNestLevel); } diff --git a/src/include/distributed/namespace_utils.h b/src/include/distributed/namespace_utils.h index 7d64ead12..6be101d2a 100644 --- a/src/include/distributed/namespace_utils.h +++ b/src/include/distributed/namespace_utils.h @@ -10,6 +10,7 @@ #ifndef NAMESPACE_UTILS_H #define NAMESPACE_UTILS_H -extern void PushOverrideEmptySearchPath(MemoryContext memoryContext); +extern int PushEmptySearchPath(void); +extern void PopEmptySearchPath(int saveNestLevel); #endif /* NAMESPACE_UTILS_H */