mirror of https://github.com/citusdata/citus.git
Implement PushOverrideEmptySearchPath (#3874)
To reduce code duplication, implement function that pushes search_path to be NIL and sets addCatalog to true so that all objects outside of pg_catalog will be schema-prefixed.pull/3859/head^2
parent
8b39d12846
commit
f7224a12f2
|
@ -26,6 +26,7 @@
|
|||
#include "distributed/listutils.h"
|
||||
#include "distributed/master_protocol.h"
|
||||
#include "distributed/multi_join_order.h"
|
||||
#include "distributed/namespace_utils.h"
|
||||
#include "distributed/reference_table_utils.h"
|
||||
#include "distributed/version_compat.h"
|
||||
#include "utils/fmgroids.h"
|
||||
|
@ -469,15 +470,7 @@ GetForeignConstraintCommandsInternal(Oid relationId, int flags)
|
|||
|
||||
List *foreignKeyCommands = NIL;
|
||||
|
||||
/*
|
||||
* 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;
|
||||
*/
|
||||
OverrideSearchPath *overridePath = GetOverrideSearchPath(CurrentMemoryContext);
|
||||
overridePath->schemas = NIL;
|
||||
overridePath->addCatalog = true;
|
||||
PushOverrideSearchPath(overridePath);
|
||||
PushOverrideEmptySearchPath(CurrentMemoryContext);
|
||||
|
||||
Oid foreignKeyOid = InvalidOid;
|
||||
foreach_oid(foreignKeyOid, foreignKeyOids)
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
#include "distributed/metadata/pg_dist_object.h"
|
||||
#include "distributed/metadata_sync.h"
|
||||
#include "distributed/multi_executor.h"
|
||||
#include "distributed/namespace_utils.h"
|
||||
#include "distributed/relation_access_tracking.h"
|
||||
#include "distributed/worker_create_or_replace.h"
|
||||
#include "distributed/worker_transaction.h"
|
||||
|
@ -561,7 +562,6 @@ UpdateFunctionDistributionInfo(const ObjectAddress *distAddress,
|
|||
char *
|
||||
GetFunctionDDLCommand(const RegProcedure funcOid, bool useCreateOrReplace)
|
||||
{
|
||||
OverrideSearchPath *overridePath = NULL;
|
||||
char *createFunctionSQL = NULL;
|
||||
|
||||
if (get_func_prokind(funcOid) == PROKIND_AGGREGATE)
|
||||
|
@ -572,16 +572,8 @@ GetFunctionDDLCommand(const RegProcedure funcOid, bool useCreateOrReplace)
|
|||
{
|
||||
Datum sqlTextDatum = (Datum) 0;
|
||||
|
||||
/*
|
||||
* 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;
|
||||
*/
|
||||
overridePath = GetOverrideSearchPath(CurrentMemoryContext);
|
||||
overridePath->schemas = NIL;
|
||||
overridePath->addCatalog = true;
|
||||
PushOverrideEmptySearchPath(CurrentMemoryContext);
|
||||
|
||||
PushOverrideSearchPath(overridePath);
|
||||
sqlTextDatum = DirectFunctionCall1(pg_get_functiondef,
|
||||
ObjectIdGetDatum(funcOid));
|
||||
createFunctionSQL = TextDatumGetCString(sqlTextDatum);
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "distributed/commands.h"
|
||||
#include "distributed/listutils.h"
|
||||
#include "distributed/metadata_cache.h"
|
||||
#include "distributed/namespace_utils.h"
|
||||
#include "utils/fmgroids.h"
|
||||
#include "utils/lsyscache.h"
|
||||
|
||||
|
@ -38,15 +39,7 @@ GetExplicitTriggerCommandList(Oid relationId)
|
|||
{
|
||||
List *createTriggerCommandList = NIL;
|
||||
|
||||
/*
|
||||
* 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;
|
||||
*/
|
||||
OverrideSearchPath *overridePath = GetOverrideSearchPath(CurrentMemoryContext);
|
||||
overridePath->schemas = NIL;
|
||||
overridePath->addCatalog = true;
|
||||
PushOverrideSearchPath(overridePath);
|
||||
PushOverrideEmptySearchPath(CurrentMemoryContext);
|
||||
|
||||
List *triggerIdList = GetExplicitTriggerIdList(relationId);
|
||||
|
||||
|
|
|
@ -52,6 +52,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"
|
||||
|
@ -465,18 +466,9 @@ 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;
|
||||
*/
|
||||
overridePath = GetOverrideSearchPath(CurrentMemoryContext);
|
||||
overridePath->schemas = NIL;
|
||||
overridePath->addCatalog = true;
|
||||
PushOverrideSearchPath(overridePath);
|
||||
PushOverrideEmptySearchPath(CurrentMemoryContext);
|
||||
|
||||
context.buf = buffer;
|
||||
context.namespaces = NIL;
|
||||
|
@ -1925,8 +1917,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();
|
||||
|
@ -1942,15 +1932,7 @@ get_query_def_extended(Query *query, StringInfo buf, List *parentnamespace,
|
|||
*/
|
||||
AcquireRewriteLocks(query, false, false);
|
||||
|
||||
/*
|
||||
* 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;
|
||||
*/
|
||||
overridePath = GetOverrideSearchPath(CurrentMemoryContext);
|
||||
overridePath->schemas = NIL;
|
||||
overridePath->addCatalog = true;
|
||||
PushOverrideSearchPath(overridePath);
|
||||
PushOverrideEmptySearchPath(CurrentMemoryContext);
|
||||
|
||||
context.buf = buf;
|
||||
context.namespaces = lcons(&dpns, list_copy(parentnamespace));
|
||||
|
|
|
@ -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"
|
||||
|
@ -465,18 +466,9 @@ 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;
|
||||
*/
|
||||
overridePath = GetOverrideSearchPath(CurrentMemoryContext);
|
||||
overridePath->schemas = NIL;
|
||||
overridePath->addCatalog = true;
|
||||
PushOverrideSearchPath(overridePath);
|
||||
PushOverrideEmptySearchPath(CurrentMemoryContext);
|
||||
|
||||
context.buf = buffer;
|
||||
context.namespaces = NIL;
|
||||
|
@ -1925,8 +1917,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();
|
||||
|
@ -1942,15 +1932,7 @@ get_query_def_extended(Query *query, StringInfo buf, List *parentnamespace,
|
|||
*/
|
||||
AcquireRewriteLocks(query, false, false);
|
||||
|
||||
/*
|
||||
* 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;
|
||||
*/
|
||||
overridePath = GetOverrideSearchPath(CurrentMemoryContext);
|
||||
overridePath->schemas = NIL;
|
||||
overridePath->addCatalog = true;
|
||||
PushOverrideSearchPath(overridePath);
|
||||
PushOverrideEmptySearchPath(CurrentMemoryContext);
|
||||
|
||||
context.buf = buf;
|
||||
context.namespaces = lcons(&dpns, list_copy(parentnamespace));
|
||||
|
|
|
@ -46,6 +46,7 @@
|
|||
#include "distributed/master_protocol.h"
|
||||
#include "distributed/metadata_cache.h"
|
||||
#include "distributed/metadata_sync.h"
|
||||
#include "distributed/namespace_utils.h"
|
||||
#include "distributed/pg_dist_shard.h"
|
||||
#include "distributed/worker_manager.h"
|
||||
#include "foreign/foreign.h"
|
||||
|
@ -590,15 +591,7 @@ GetTableCreationCommands(Oid relationId, bool includeSequenceDefaults)
|
|||
{
|
||||
List *tableDDLEventList = NIL;
|
||||
|
||||
/*
|
||||
* 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;
|
||||
*/
|
||||
OverrideSearchPath *overridePath = GetOverrideSearchPath(CurrentMemoryContext);
|
||||
overridePath->schemas = NIL;
|
||||
overridePath->addCatalog = true;
|
||||
PushOverrideSearchPath(overridePath);
|
||||
PushOverrideEmptySearchPath(CurrentMemoryContext);
|
||||
|
||||
/* if foreign table, fetch extension and server definitions */
|
||||
char tableType = get_rel_relkind(relationId);
|
||||
|
@ -649,15 +642,7 @@ GetTableIndexAndConstraintCommands(Oid relationId)
|
|||
ScanKeyData scanKey[1];
|
||||
int scanKeyCount = 1;
|
||||
|
||||
/*
|
||||
* 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;
|
||||
*/
|
||||
OverrideSearchPath *overridePath = GetOverrideSearchPath(CurrentMemoryContext);
|
||||
overridePath->schemas = NIL;
|
||||
overridePath->addCatalog = true;
|
||||
PushOverrideSearchPath(overridePath);
|
||||
PushOverrideEmptySearchPath(CurrentMemoryContext);
|
||||
|
||||
/* open system catalog and scan all indexes that belong to this table */
|
||||
Relation pgIndex = heap_open(IndexRelationId, AccessShareLock);
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* namespace_utils.c
|
||||
*
|
||||
* Utility functions related to namespace changes.
|
||||
*
|
||||
* Copyright (c) Citus Data, Inc.
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include "postgres.h"
|
||||
|
||||
#include "catalog/namespace.h"
|
||||
#include "distributed/namespace_utils.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.
|
||||
*/
|
||||
void
|
||||
PushOverrideEmptySearchPath(MemoryContext memoryContext)
|
||||
{
|
||||
OverrideSearchPath *overridePath = GetOverrideSearchPath(memoryContext);
|
||||
overridePath->schemas = NIL;
|
||||
overridePath->addCatalog = true;
|
||||
|
||||
PushOverrideSearchPath(overridePath);
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* namespace_utils.h
|
||||
* Utility function declarations related to namespace changes.
|
||||
*
|
||||
* Copyright (c) Citus Data, Inc.
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#ifndef NAMESPACE_UTILS_H
|
||||
#define NAMESPACE_UTILS_H
|
||||
|
||||
extern void PushOverrideEmptySearchPath(MemoryContext memoryContext);
|
||||
|
||||
#endif /* NAMESPACE_UTILS_H */
|
Loading…
Reference in New Issue