Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
762 changes: 758 additions & 4 deletions src/backend/distributed/commands/table.c

Large diffs are not rendered by default.

21 changes: 19 additions & 2 deletions src/backend/distributed/commands/utility_hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,24 @@ citus_ProcessUtility(PlannedStmt *pstmt,

PG_TRY();
{
citus_ProcessUtilityInternal(pstmt, queryString, context, params, queryEnv, dest,
completionTag);
/*
* For CREATE TABLE AS SELECT with auto-distribution enabled,
* try the optimized path that avoids pulling data through the
* coordinator. If successful, skip normal CTAS processing.
*/
bool ctasHandled = false;
if (context == PROCESS_UTILITY_TOPLEVEL &&
IsA(parsetree, CreateTableAsStmt))
{
ctasHandled = TryOptimizeCTASForAutoDistribution(
(CreateTableAsStmt *) parsetree, queryString);
}

if (!ctasHandled)
{
citus_ProcessUtilityInternal(pstmt, queryString, context, params,
queryEnv, dest, completionTag);
}

if (UtilityHookLevel == 1)
{
Expand All @@ -370,6 +386,7 @@ citus_ProcessUtility(PlannedStmt *pstmt,
* to create a tenant schema table or a Citus managed table.
*/
if (context == PROCESS_UTILITY_TOPLEVEL &&
!ctasHandled &&
(IsA(parsetree, CreateStmt) ||
IsA(parsetree, CreateForeignTableStmt) ||
IsA(parsetree, CreateTableAsStmt)))
Expand Down
15 changes: 15 additions & 0 deletions src/backend/distributed/shared_library_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -1251,6 +1251,21 @@ RegisterCitusConfigVariables(void)
GUC_STANDARD,
ErrorIfNotASuitableDeadlockFactor, NULL, NULL);

DefineCustomStringVariable(
"citus.distribution_columns",
gettext_noop("Sets a priority list of distribution columns for new tables."),
gettext_noop("A comma-separated list of column names in priority order "
"(e.g. 'tenant_id,customer_id,department'). When a new table "
"is created, Citus walks the list in order and distributes "
"the table by the first column name that exists in the table. "
"Applies to CREATE TABLE and CREATE TABLE AS SELECT. "
"Set to empty string to disable."),
&DistributionColumns,
"",
PGC_USERSET,
GUC_STANDARD,
CheckDistributionColumns, AssignDistributionColumns, NULL);

DefineCustomBoolVariable(
"citus.enable_alter_database_owner",
gettext_noop("Enables propagating ALTER DATABASE ... OWNER TO ... statements to "
Expand Down
7 changes: 7 additions & 0 deletions src/include/distributed/commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@

extern bool AddAllLocalTablesToMetadata;
extern bool EnableSchemaBasedSharding;
extern char *DistributionColumns;
extern List *ParsedDistributionColumns;

extern bool CheckDistributionColumns(char **newval, void **extra, GucSource source);
extern void AssignDistributionColumns(const char *newval, void *extra);

/* controlled via GUC, should be accessed via EnableLocalReferenceForeignKeys() */
extern bool EnableLocalReferenceForeignKeys;
Expand Down Expand Up @@ -669,6 +674,8 @@ extern char * GetAlterColumnWithNextvalDefaultCmd(Oid sequenceOid, Oid relationI
char *colname, bool missingTableOk);

extern void ErrorIfTableHasIdentityColumn(Oid relationId);
extern bool TryOptimizeCTASForAutoDistribution(CreateTableAsStmt *ctasStmt,
const char *queryString);
extern void ConvertNewTableIfNecessary(Node *createStmt);
extern void ConvertToTenantTableIfNecessary(AlterObjectSchemaStmt *alterObjectSchemaStmt);

Expand Down
6 changes: 5 additions & 1 deletion src/test/regress/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ vanilla_diffs_file = $(citus_abs_srcdir)/pg_vanilla_outputs/$(MAJORVERSION)/regr
# intermediate, for muscle memory backward compatibility.
check: check-full check-enterprise-full
# check-full triggers all tests that ought to be run routinely
check-full: check-multi check-multi-mx check-multi-1 check-multi-1-create-citus check-operations check-add-backup-node check-follower-cluster check-isolation check-failure check-split check-vanilla check-columnar check-columnar-isolation check-pg-upgrade check-arbitrary-configs check-citus-upgrade check-citus-upgrade-mixed check-citus-upgrade-local check-citus-upgrade-mixed-local check-pytest check-query-generator check-tap
check-full: check-multi check-multi-mx check-multi-1 check-multi-1-create-citus check-post-citus14 check-operations check-add-backup-node check-follower-cluster check-isolation check-failure check-split check-vanilla check-columnar check-columnar-isolation check-pg-upgrade check-arbitrary-configs check-citus-upgrade check-citus-upgrade-mixed check-citus-upgrade-local check-citus-upgrade-mixed-local check-pytest check-query-generator check-tap
# check-enterprise-full triggers all enterprise specific tests
check-enterprise-full: check-enterprise check-enterprise-isolation check-enterprise-failure check-enterprise-isolation-logicalrep-1 check-enterprise-isolation-logicalrep-2 check-enterprise-isolation-logicalrep-3

Expand Down Expand Up @@ -173,6 +173,10 @@ check-multi-1: all
$(pg_regress_multi_check) --load-extension=citus \
-- $(MULTI_REGRESS_OPTS) --schedule=$(citus_abs_srcdir)/multi_1_schedule $(EXTRA_TESTS)

check-post-citus14: all
$(pg_regress_multi_check) --load-extension=citus \
-- $(MULTI_REGRESS_OPTS) --schedule=$(citus_abs_srcdir)/post_citus14_schedule $(EXTRA_TESTS)

check-multi-1-create-citus: all
$(pg_regress_multi_check) --load-extension=citus \
-- $(MULTI_REGRESS_OPTS) --schedule=$(citus_abs_srcdir)/multi_1_create_citus_schedule $(EXTRA_TESTS)
Expand Down
Loading
Loading