Skip to content

Commit

Permalink
Merge branch 'main' into circleci-gha-migration
Browse files Browse the repository at this point in the history
  • Loading branch information
gokhangulbiz authored Sep 11, 2023
2 parents 2493890 + d628a4c commit 7a5325f
Show file tree
Hide file tree
Showing 49 changed files with 2,286 additions and 117 deletions.
9 changes: 4 additions & 5 deletions src/backend/distributed/commands/alter_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,13 @@
#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"
#include "distributed/shared_library_init.h"
#include "distributed/shard_utils.h"
#include "distributed/tenant_schema_metadata.h"
#include "distributed/worker_protocol.h"
#include "distributed/worker_transaction.h"
#include "executor/spi.h"
Expand Down Expand Up @@ -1764,10 +1766,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
Expand All @@ -1779,7 +1778,7 @@ CreateMaterializedViewDDLCommand(Oid matViewOid)
char *viewDefinition = TextDatumGetCString(viewDefinitionDatum);

PopActiveSnapshot();
PopOverrideSearchPath();
PopEmptySearchPath(saveNestLevel);

appendStringInfo(query, "AS %s", viewDefinition);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1478,11 +1478,20 @@ InsertMetadataForCitusLocalTable(Oid citusLocalTableId, uint64 shardId,
static void
FinalizeCitusLocalTableCreation(Oid relationId)
{
#if PG_VERSION_NUM >= PG_VERSION_16

/*
* PG16+ supports truncate triggers on foreign tables
*/
if (RegularTable(relationId) || IsForeignTable(relationId))
#else

/*
* If it is a foreign table, then skip creating citus truncate trigger
* as foreign tables do not support truncate triggers.
*/
if (RegularTable(relationId))
#endif
{
CreateTruncateTrigger(relationId);
}
Expand Down
11 changes: 10 additions & 1 deletion src/backend/distributed/commands/collation.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,16 @@ CreateCollationDDLInternal(Oid collationId, Oid *collowner, char **quotedCollati
pfree(collcollate);
pfree(collctype);
#endif

#if PG_VERSION_NUM >= PG_VERSION_16
char *collicurules = NULL;
datum = SysCacheGetAttr(COLLOID, heapTuple, Anum_pg_collation_collicurules, &isnull);
if (!isnull)
{
collicurules = TextDatumGetCString(datum);
appendStringInfo(&collationNameDef, ", rules = %s",
quote_literal_cstr(collicurules));
}
#endif
if (!collisdeterministic)
{
appendStringInfoString(&collationNameDef, ", deterministic = false");
Expand Down
10 changes: 10 additions & 0 deletions src/backend/distributed/commands/create_distributed_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -1256,8 +1256,17 @@ CreateCitusTable(Oid relationId, CitusTableType tableType,
colocationId, citusTableParams.replicationModel,
autoConverted);

#if PG_VERSION_NUM >= PG_VERSION_16

/*
* PG16+ supports truncate triggers on foreign tables
*/
if (RegularTable(relationId) || IsForeignTable(relationId))
#else

/* foreign tables do not support TRUNCATE trigger */
if (RegularTable(relationId))
#endif
{
CreateTruncateTrigger(relationId);
}
Expand Down Expand Up @@ -1659,6 +1668,7 @@ PropagatePrerequisiteObjectsForDistributedTable(Oid relationId)
ObjectAddress *tableAddress = palloc0(sizeof(ObjectAddress));
ObjectAddressSet(*tableAddress, RelationRelationId, relationId);
EnsureAllObjectDependenciesExistOnAllNodes(list_make1(tableAddress));
TrackPropagatedTableAndSequences(relationId);
}


Expand Down
34 changes: 27 additions & 7 deletions src/backend/distributed/commands/dependencies.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,35 @@ EnsureDependenciesExistOnAllNodes(const ObjectAddress *target)
dependency->objectSubId, ExclusiveLock);
}

WorkerNode *workerNode = NULL;
foreach_ptr(workerNode, workerNodeList)

/*
* We need to propagate dependencies via the current user's metadata connection if
* any dependency for the target is created in the current transaction. Our assumption
* is that if we rely on a dependency created in the current transaction, then the
* current user, most probably, has permissions to create the target object as well.
* Note that, user still may not be able to create the target due to no permissions
* for any of its dependencies. But this is ok since it should be rare.
*
* If we opted to use a separate superuser connection for the target, then we would
* have visibility issues since propagated dependencies would be invisible to
* the separate connection until we locally commit.
*/
if (HasAnyDependencyInPropagatedObjects(target))
{
const char *nodeName = workerNode->workerName;
uint32 nodePort = workerNode->workerPort;
SendCommandListToWorkersWithMetadata(ddlCommands);
}
else
{
WorkerNode *workerNode = NULL;
foreach_ptr(workerNode, workerNodeList)
{
const char *nodeName = workerNode->workerName;
uint32 nodePort = workerNode->workerPort;

SendCommandListToWorkerOutsideTransaction(nodeName, nodePort,
CitusExtensionOwnerName(),
ddlCommands);
SendCommandListToWorkerOutsideTransaction(nodeName, nodePort,
CitusExtensionOwnerName(),
ddlCommands);
}
}

/*
Expand Down
1 change: 1 addition & 0 deletions src/backend/distributed/commands/drop_distributed_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "distributed/coordinator_protocol.h"
#include "distributed/metadata_sync.h"
#include "distributed/multi_partitioning_utils.h"
#include "distributed/tenant_schema_metadata.h"
#include "distributed/worker_transaction.h"
#include "utils/builtins.h"
#include "utils/lsyscache.h"
Expand Down
8 changes: 4 additions & 4 deletions src/backend/distributed/commands/extension.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);


/*
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/backend/distributed/commands/foreign_constraint.c
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,7 @@ GetForeignConstraintCommandsInternal(Oid relationId, int flags)

List *foreignKeyCommands = NIL;

PushOverrideEmptySearchPath(CurrentMemoryContext);
int saveNestLevel = PushEmptySearchPath();

Oid foreignKeyOid = InvalidOid;
foreach_oid(foreignKeyOid, foreignKeyOids)
Expand All @@ -906,7 +906,7 @@ GetForeignConstraintCommandsInternal(Oid relationId, int flags)
}

/* revert back to original search_path */
PopOverrideSearchPath();
PopEmptySearchPath(saveNestLevel);

return foreignKeyCommands;
}
Expand Down
5 changes: 2 additions & 3 deletions src/backend/distributed/commands/function.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 7a5325f

Please sign in to comment.