Citus UDFs support for single shard tables (#6916)

Verify Citus UDFs work well with single shard tables

SUPPORTED
* citus_table_size
* citus_total_relation_size
* citus_relation_size
* citus_shard_sizes
* truncate_local_data_after_distributing_table
* create_distributed_function // test function colocated with a single
shard table
* undistribute_table
* alter_table_set_access_method

UNSUPPORTED - error out for single shard tables
* master_create_empty_shard
* create_distributed_table_concurrently
* create_distributed_table
* create_reference_table
* citus_add_local_table_to_metadata
* citus_split_shard_by_split_points
* alter_distributed_table
pull/6924/head
Ahmet Gedemenli 2023-05-26 17:30:05 +03:00 committed by GitHub
parent 246b054a7d
commit 1ca80813f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 748 additions and 74 deletions

View File

@ -477,8 +477,11 @@ AlterTableSetAccessMethod(TableConversionParameters *params)
EnsureTableNotReferencing(params->relationId, ALTER_TABLE_SET_ACCESS_METHOD);
EnsureTableNotReferenced(params->relationId, ALTER_TABLE_SET_ACCESS_METHOD);
EnsureTableNotForeign(params->relationId);
if (IsCitusTableType(params->relationId, DISTRIBUTED_TABLE))
if (!IsCitusTableType(params->relationId, SINGLE_SHARD_DISTRIBUTED) &&
IsCitusTableType(params->relationId, DISTRIBUTED_TABLE))
{
/* we do not support non-hash distributed tables, except single shard tables */
EnsureHashDistributedTable(params->relationId);
}
@ -1365,7 +1368,19 @@ CreateCitusTableLike(TableConversionState *con)
{
if (IsCitusTableType(con->relationId, DISTRIBUTED_TABLE))
{
CreateDistributedTableLike(con);
if (IsCitusTableType(con->relationId, SINGLE_SHARD_DISTRIBUTED))
{
ColocationParam colocationParam = {
.colocationParamType = COLOCATE_WITH_TABLE_LIKE_OPT,
.colocateWithTableName = quote_qualified_identifier(con->schemaName,
con->relationName)
};
CreateSingleShardTable(con->newRelationId, colocationParam);
}
else
{
CreateDistributedTableLike(con);
}
}
else if (IsCitusTableType(con->relationId, REFERENCE_TABLE))
{
@ -1856,6 +1871,12 @@ CheckAlterDistributedTableConversionParameters(TableConversionState *con)
"it is not a distributed table",
con->colocateWith)));
}
else if (IsCitusTableType(colocateWithTableOid, SINGLE_SHARD_DISTRIBUTED))
{
ereport(ERROR, (errmsg("cannot colocate with %s because "
"it is a single shard distributed table",
con->colocateWith)));
}
}
/* shard_count:=0 is not allowed */

View File

@ -105,6 +105,9 @@ static void DistributeFunctionColocatedWithDistributedTable(RegProcedure funcOid
char *colocateWithTableName,
const ObjectAddress *
functionAddress);
static void DistributeFunctionColocatedWithSingleShardTable(const
ObjectAddress *functionAddress,
text *colocateWithText);
static void DistributeFunctionColocatedWithReferenceTable(const
ObjectAddress *functionAddress);
static List * FilterDistributedFunctions(GrantStmt *grantStmt);
@ -133,6 +136,7 @@ create_distributed_function(PG_FUNCTION_ARGS)
Oid distributionArgumentOid = InvalidOid;
bool colocatedWithReferenceTable = false;
bool colocatedWithSingleShardTable = false;
char *distributionArgumentName = NULL;
char *colocateWithTableName = NULL;
@ -187,6 +191,8 @@ create_distributed_function(PG_FUNCTION_ARGS)
Oid colocationRelationId = ResolveRelationId(colocateWithText, false);
colocatedWithReferenceTable = IsCitusTableType(colocationRelationId,
REFERENCE_TABLE);
colocatedWithSingleShardTable = IsCitusTableType(colocationRelationId,
SINGLE_SHARD_DISTRIBUTED);
}
}
@ -276,11 +282,16 @@ create_distributed_function(PG_FUNCTION_ARGS)
forceDelegationAddress,
functionAddress);
}
else if (!colocatedWithReferenceTable)
else if (!colocatedWithReferenceTable && !colocatedWithSingleShardTable)
{
DistributeFunctionColocatedWithDistributedTable(funcOid, colocateWithTableName,
functionAddress);
}
else if (colocatedWithSingleShardTable)
{
DistributeFunctionColocatedWithSingleShardTable(functionAddress,
colocateWithText);
}
else if (colocatedWithReferenceTable)
{
/*
@ -435,6 +446,25 @@ DistributeFunctionColocatedWithDistributedTable(RegProcedure funcOid,
}
/*
* DistributeFunctionColocatedWithSingleShardTable updates pg_dist_object records for
* a function/procedure that is colocated with a single shard table.
*/
static void
DistributeFunctionColocatedWithSingleShardTable(const ObjectAddress *functionAddress,
text *colocateWithText)
{
/* get the single shard table's colocation id */
int colocationId = TableColocationId(ResolveRelationId(colocateWithText, false));
/* set distribution argument to NULL */
int *distributionArgumentIndex = NULL;
UpdateFunctionDistributionInfo(functionAddress, distributionArgumentIndex,
&colocationId,
NULL);
}
/*
* DistributeFunctionColocatedWithReferenceTable updates pg_dist_object records for
* a function/procedure that is colocated with a reference table.
@ -641,6 +671,19 @@ EnsureFunctionCanBeColocatedWithTable(Oid functionOid, Oid distributionColumnTyp
CitusTableCacheEntry *sourceTableEntry = GetCitusTableCacheEntry(sourceRelationId);
char sourceReplicationModel = sourceTableEntry->replicationModel;
if (IsCitusTableTypeCacheEntry(sourceTableEntry, SINGLE_SHARD_DISTRIBUTED) &&
distributionColumnType != InvalidOid)
{
char *functionName = get_func_name(functionOid);
char *sourceRelationName = get_rel_name(sourceRelationId);
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot colocate function \"%s\" and table \"%s\" because "
"distribution arguments are not supported when "
"colocating with single shard distributed tables.",
functionName, sourceRelationName)));
}
if (!IsCitusTableTypeCacheEntry(sourceTableEntry, HASH_DISTRIBUTED) &&
!IsCitusTableTypeCacheEntry(sourceTableEntry, REFERENCE_TABLE))
{

View File

@ -116,7 +116,6 @@ contain_param_walker(Node *node, void *context)
PlannedStmt *
TryToDelegateFunctionCall(DistributedPlanningContext *planContext)
{
bool colocatedWithReferenceTable = false;
ShardPlacement *placement = NULL;
struct ParamWalkerContext walkerParamContext = { 0 };
bool inTransactionBlock = false;
@ -392,13 +391,6 @@ TryToDelegateFunctionCall(DistributedPlanningContext *planContext)
return NULL;
}
CitusTableCacheEntry *distTable = GetCitusTableCacheEntry(colocatedRelationId);
Var *partitionColumn = distTable->partitionColumn;
if (partitionColumn == NULL)
{
colocatedWithReferenceTable = true;
}
/*
* This can be called in queries like SELECT ... WHERE EXISTS(SELECT func()), or other
* forms of CTEs or subqueries. We don't push-down in those cases.
@ -410,14 +402,20 @@ TryToDelegateFunctionCall(DistributedPlanningContext *planContext)
return NULL;
}
if (colocatedWithReferenceTable)
CitusTableCacheEntry *distTable = GetCitusTableCacheEntry(colocatedRelationId);
if (IsCitusTableType(colocatedRelationId, REFERENCE_TABLE))
{
placement = ShardPlacementForFunctionColocatedWithReferenceTable(distTable);
}
else if (IsCitusTableType(colocatedRelationId, SINGLE_SHARD_DISTRIBUTED))
{
placement = ShardPlacementForFunctionColocatedWithSingleShardTable(distTable);
}
else
{
placement = ShardPlacementForFunctionColocatedWithDistTable(procedure,
funcExpr->args,
distTable->
partitionColumn,
distTable,
planContext->plan);
@ -570,6 +568,34 @@ ShardPlacementForFunctionColocatedWithDistTable(DistObjectCacheEntry *procedure,
}
/*
* ShardPlacementForFunctionColocatedWithSingleShardTable decides on a placement
* for delegating a function call that reads from a single shard table.
*/
ShardPlacement *
ShardPlacementForFunctionColocatedWithSingleShardTable(CitusTableCacheEntry *cacheEntry)
{
const ShardInterval *shardInterval = cacheEntry->sortedShardIntervalArray[0];
if (shardInterval == NULL)
{
ereport(DEBUG1, (errmsg("cannot push down call, failed to find shard interval")));
return NULL;
}
List *placementList = ActiveShardPlacementList(shardInterval->shardId);
if (list_length(placementList) != 1)
{
/* punt on this for now */
ereport(DEBUG1, (errmsg(
"cannot push down function call for replicated distributed tables")));
return NULL;
}
return (ShardPlacement *) linitial(placementList);
}
/*
* ShardPlacementForFunctionColocatedWithReferenceTable decides on a placement for delegating
* a function call that reads from a reference table.

View File

@ -196,6 +196,8 @@ extern bool HasOverlappingShardInterval(ShardInterval **shardIntervalArray,
Oid shardIntervalCollation,
FmgrInfo *shardIntervalSortCompareFunction);
extern ShardPlacement * ShardPlacementForFunctionColocatedWithSingleShardTable(
CitusTableCacheEntry *cacheEntry);
extern ShardPlacement * ShardPlacementForFunctionColocatedWithReferenceTable(
CitusTableCacheEntry *cacheEntry);
extern ShardPlacement * ShardPlacementForFunctionColocatedWithDistTable(

View File

@ -143,6 +143,7 @@ DEPS = {
],
worker_count=6,
),
"function_propagation": TestDeps("minimal_schedule"),
"multi_mx_modifying_xacts": TestDeps(None, ["multi_mx_create_table"]),
"multi_mx_router_planner": TestDeps(None, ["multi_mx_create_table"]),
"multi_mx_copy_data": TestDeps(None, ["multi_mx_create_table"]),

View File

@ -1020,6 +1020,16 @@ SELECT create_reference_table('reference_table');
SELECT alter_distributed_table('dist_table', colocate_with:='reference_table');
ERROR: cannot colocate with reference_table because it is not a distributed table
-- test colocating with single shard table
CREATE TABLE single_shard_table (a INT);
SELECT create_distributed_table('single_shard_table', null);
create_distributed_table
---------------------------------------------------------------------
(1 row)
SELECT alter_distributed_table('dist_table', colocate_with:='single_shard_table');
ERROR: cannot colocate with single_shard_table because it is a single shard distributed table
-- test append table
CREATE TABLE append_table (a INT);
SELECT create_distributed_table('append_table', 'a', 'append');

View File

@ -704,6 +704,25 @@ WHERE pg_dist_partition.logicalrelid = 'replicated_table_func_test_4'::regclass
t
(1 row)
-- a function cannot be colocated with a single shard distributed table when a distribution column is provided
SELECT create_distributed_table('replicated_table_func_test_3', null);
create_distributed_table
---------------------------------------------------------------------
(1 row)
SELECT create_distributed_function('eq_with_param_names(macaddr, macaddr)', 'val1', colocate_with:='replicated_table_func_test_3');
ERROR: cannot colocate function "eq_with_param_names" and table "replicated_table_func_test_3" because distribution arguments are not supported when colocating with single shard distributed tables.
SELECT undistribute_table('replicated_table_func_test_3');
NOTICE: creating a new table for function_tests.replicated_table_func_test_3
NOTICE: moving the data of function_tests.replicated_table_func_test_3
NOTICE: dropping the old function_tests.replicated_table_func_test_3
NOTICE: renaming the new table to function_tests.replicated_table_func_test_3
undistribute_table
---------------------------------------------------------------------
(1 row)
-- a function cannot be colocated with a reference table when a distribution column is provided
SELECT create_reference_table('replicated_table_func_test_3');
create_reference_table
@ -1116,6 +1135,7 @@ TRUNCATE pg_dist_node;
\c - - - :master_port
SET client_min_messages TO ERROR;
DROP USER functionuser;
DROP ROLE r1;
SELECT 1 FROM run_command_on_workers($$DROP USER functionuser$$);
?column?
---------------------------------------------------------------------

View File

@ -864,8 +864,8 @@ BEGIN;
(0 rows)
CREATE TABLE citus_local_table_to_test_func(l1 int DEFAULT func_in_transaction_for_local_table());
SET LOCAL client_min_messages TO WARNING;
SELECT 1 FROM master_add_node('localhost', :master_port, groupid => 0);
NOTICE: localhost:xxxxx is the coordinator and already contains metadata, skipping syncing the metadata
?column?
---------------------------------------------------------------------
1
@ -1097,6 +1097,14 @@ SELECT create_reference_table('tbl_to_colocate_ref');
(1 row)
-- test colocating function with single shard table
CREATE TABLE single_shard_tbl (a int);
SELECT create_distributed_table('single_shard_tbl', null);
create_distributed_table
---------------------------------------------------------------------
(1 row)
CREATE FUNCTION func_to_colocate (a int) returns int as $$select 1;$$ language sql;
-- see the empty pg_dist_object entries
SELECT distribution_argument_index, colocationid, force_delegation FROM pg_catalog.pg_dist_object WHERE objid = 'func_to_colocate'::regproc;
@ -1119,6 +1127,20 @@ SELECT distribution_argument_index, colocationid, force_delegation FROM pg_catal
| 10002 |
(1 row)
-- colocate the function with single shard table table
SELECT create_distributed_function('func_to_colocate(int)', colocate_with:='single_shard_tbl');
create_distributed_function
---------------------------------------------------------------------
(1 row)
-- see the pg_dist_object entry
SELECT distribution_argument_index, colocationid, force_delegation FROM pg_catalog.pg_dist_object WHERE objid = 'func_to_colocate'::regproc;
distribution_argument_index | colocationid | force_delegation
---------------------------------------------------------------------
| 10003 |
(1 row)
-- convert to non-delegated
SELECT create_distributed_function('func_to_colocate(int)');
create_distributed_function

View File

@ -122,6 +122,15 @@ reset citus.shard_replication_factor;
-- Set the replication model of the test table to streaming replication so that it is
-- considered as an MX table
UPDATE pg_dist_partition SET repmodel='s' WHERE logicalrelid='mx_test_table'::regclass;
-- add a single shard table and verify the creation commands are included in the activate node snapshot
CREATE TABLE single_shard_tbl(a int);
SELECT create_distributed_table('single_shard_tbl', null);
create_distributed_table
---------------------------------------------------------------------
(1 row)
INSERT INTO single_shard_tbl VALUES (1);
-- Show that the created MX table is and its sequences are included in the activate node snapshot
SELECT unnest(activate_node_snapshot()) order by 1;
unnest
@ -131,9 +140,11 @@ SELECT unnest(activate_node_snapshot()) order by 1;
ALTER SEQUENCE public.user_defined_seq OWNER TO postgres
ALTER TABLE public.mx_test_table ADD CONSTRAINT mx_test_table_col_1_key UNIQUE (col_1)
ALTER TABLE public.mx_test_table OWNER TO postgres
ALTER TABLE public.single_shard_tbl OWNER TO postgres
CALL pg_catalog.worker_drop_all_shell_tables(true)
CREATE SCHEMA IF NOT EXISTS public AUTHORIZATION pg_database_owner
CREATE TABLE public.mx_test_table (col_1 integer, col_2 text NOT NULL, col_3 bigint DEFAULT nextval('public.mx_test_table_col_3_seq'::regclass) NOT NULL, col_4 bigint DEFAULT nextval('public.user_defined_seq'::regclass)) USING heap
CREATE TABLE public.single_shard_tbl (a integer) USING heap
DELETE FROM pg_catalog.pg_dist_colocation
DELETE FROM pg_catalog.pg_dist_object
DELETE FROM pg_catalog.pg_dist_tenant_schema
@ -142,6 +153,7 @@ SELECT unnest(activate_node_snapshot()) order by 1;
DELETE FROM pg_dist_placement
DELETE FROM pg_dist_shard
DROP TABLE IF EXISTS public.mx_test_table CASCADE
DROP TABLE IF EXISTS public.single_shard_tbl CASCADE
GRANT CREATE ON SCHEMA public TO PUBLIC;
GRANT CREATE ON SCHEMA public TO pg_database_owner;
GRANT USAGE ON SCHEMA public TO PUBLIC;
@ -151,13 +163,16 @@ SELECT unnest(activate_node_snapshot()) order by 1;
RESET ROLE
SELECT alter_role_if_exists('postgres', 'ALTER ROLE postgres SET lc_messages = ''C''')
SELECT citus_internal_add_partition_metadata ('public.mx_test_table'::regclass, 'h', 'col_1', 2, 's')
SELECT citus_internal_add_partition_metadata ('public.single_shard_tbl'::regclass, 'n', NULL, 3, 's')
SELECT pg_catalog.worker_drop_sequence_dependency('public.mx_test_table');
SELECT pg_catalog.worker_drop_sequence_dependency('public.single_shard_tbl');
SELECT pg_catalog.worker_drop_sequence_dependency(logicalrelid::regclass::text) FROM pg_dist_partition
SELECT pg_catalog.worker_record_sequence_dependency('public.mx_test_table_col_3_seq'::regclass,'public.mx_test_table'::regclass,'col_3')
SELECT worker_apply_sequence_command ('CREATE SEQUENCE IF NOT EXISTS public.mx_test_table_col_3_seq AS bigint INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START WITH 1 CACHE 1 NO CYCLE','bigint')
SELECT worker_apply_sequence_command ('CREATE SEQUENCE IF NOT EXISTS public.user_defined_seq AS bigint INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START WITH 1 CACHE 1 NO CYCLE','bigint')
SELECT worker_create_or_alter_role('postgres', 'CREATE ROLE postgres SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN REPLICATION BYPASSRLS CONNECTION LIMIT 0 PASSWORD ''md5c53670dddfc3bb4b5675c7872bc2249a'' VALID UNTIL ''2052-05-05 00:00:00-07''', 'ALTER ROLE postgres SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN REPLICATION BYPASSRLS CONNECTION LIMIT 0 PASSWORD ''md5c53670dddfc3bb4b5675c7872bc2249a'' VALID UNTIL ''2052-05-05 00:00:00-07''')
SELECT worker_create_truncate_trigger('public.mx_test_table')
SELECT worker_create_truncate_trigger('public.single_shard_tbl')
SET ROLE pg_database_owner
SET ROLE pg_database_owner
SET citus.enable_ddl_propagation TO 'off'
@ -169,16 +184,22 @@ SELECT unnest(activate_node_snapshot()) order by 1;
UPDATE pg_dist_node SET isactive = TRUE WHERE nodeid = 1
UPDATE pg_dist_node SET metadatasynced = TRUE WHERE nodeid = 1
WITH colocation_group_data (colocationid, shardcount, replicationfactor, distributioncolumntype, distributioncolumncollationname, distributioncolumncollationschema) AS (VALUES (2, 8, 1, 'integer'::regtype, NULL, NULL)) SELECT pg_catalog.citus_internal_add_colocation_metadata(colocationid, shardcount, replicationfactor, distributioncolumntype, coalesce(c.oid, 0)) FROM colocation_group_data d LEFT JOIN pg_collation c ON (d.distributioncolumncollationname = c.collname AND d.distributioncolumncollationschema::regnamespace = c.collnamespace)
WITH colocation_group_data (colocationid, shardcount, replicationfactor, distributioncolumntype, distributioncolumncollationname, distributioncolumncollationschema) AS (VALUES (3, 1, 2, 0, NULL, NULL)) SELECT pg_catalog.citus_internal_add_colocation_metadata(colocationid, shardcount, replicationfactor, distributioncolumntype, coalesce(c.oid, 0)) FROM colocation_group_data d LEFT JOIN pg_collation c ON (d.distributioncolumncollationname = c.collname AND d.distributioncolumncollationschema::regnamespace = c.collnamespace)
WITH distributed_object_data(typetext, objnames, objargs, distargumentindex, colocationid, force_delegation) AS (VALUES ('database', ARRAY['regression']::text[], ARRAY[]::text[], -1, 0, false)) SELECT citus_internal_add_object_metadata(typetext, objnames, objargs, distargumentindex::int, colocationid::int, force_delegation::bool) FROM distributed_object_data;
WITH distributed_object_data(typetext, objnames, objargs, distargumentindex, colocationid, force_delegation) AS (VALUES ('role', ARRAY['postgres']::text[], ARRAY[]::text[], -1, 0, false)) SELECT citus_internal_add_object_metadata(typetext, objnames, objargs, distargumentindex::int, colocationid::int, force_delegation::bool) FROM distributed_object_data;
WITH distributed_object_data(typetext, objnames, objargs, distargumentindex, colocationid, force_delegation) AS (VALUES ('schema', ARRAY['public']::text[], ARRAY[]::text[], -1, 0, false)) SELECT citus_internal_add_object_metadata(typetext, objnames, objargs, distargumentindex::int, colocationid::int, force_delegation::bool) FROM distributed_object_data;
WITH distributed_object_data(typetext, objnames, objargs, distargumentindex, colocationid, force_delegation) AS (VALUES ('sequence', ARRAY['public', 'mx_test_table_col_3_seq']::text[], ARRAY[]::text[], -1, 0, false)) SELECT citus_internal_add_object_metadata(typetext, objnames, objargs, distargumentindex::int, colocationid::int, force_delegation::bool) FROM distributed_object_data;
WITH distributed_object_data(typetext, objnames, objargs, distargumentindex, colocationid, force_delegation) AS (VALUES ('sequence', ARRAY['public', 'user_defined_seq']::text[], ARRAY[]::text[], -1, 0, false)) SELECT citus_internal_add_object_metadata(typetext, objnames, objargs, distargumentindex::int, colocationid::int, force_delegation::bool) FROM distributed_object_data;
WITH distributed_object_data(typetext, objnames, objargs, distargumentindex, colocationid, force_delegation) AS (VALUES ('table', ARRAY['public', 'mx_test_table']::text[], ARRAY[]::text[], -1, 0, false)) SELECT citus_internal_add_object_metadata(typetext, objnames, objargs, distargumentindex::int, colocationid::int, force_delegation::bool) FROM distributed_object_data;
WITH distributed_object_data(typetext, objnames, objargs, distargumentindex, colocationid, force_delegation) AS (VALUES ('table', ARRAY['public', 'single_shard_tbl']::text[], ARRAY[]::text[], -1, 0, false)) SELECT citus_internal_add_object_metadata(typetext, objnames, objargs, distargumentindex::int, colocationid::int, force_delegation::bool) FROM distributed_object_data;
WITH placement_data(shardid, shardlength, groupid, placementid) AS (VALUES (1310000, 0, 1, 100000), (1310001, 0, 2, 100001), (1310002, 0, 1, 100002), (1310003, 0, 2, 100003), (1310004, 0, 1, 100004), (1310005, 0, 2, 100005), (1310006, 0, 1, 100006), (1310007, 0, 2, 100007)) SELECT citus_internal_add_placement_metadata(shardid, shardlength, groupid, placementid) FROM placement_data;
WITH placement_data(shardid, shardlength, groupid, placementid) AS (VALUES (1310008, 0, 2, 100008)) SELECT citus_internal_add_placement_metadata(shardid, shardlength, groupid, placementid) FROM placement_data;
WITH shard_data(relationname, shardid, storagetype, shardminvalue, shardmaxvalue) AS (VALUES ('public.mx_test_table'::regclass, 1310000, 't'::"char", '-2147483648', '-1610612737'), ('public.mx_test_table'::regclass, 1310001, 't'::"char", '-1610612736', '-1073741825'), ('public.mx_test_table'::regclass, 1310002, 't'::"char", '-1073741824', '-536870913'), ('public.mx_test_table'::regclass, 1310003, 't'::"char", '-536870912', '-1'), ('public.mx_test_table'::regclass, 1310004, 't'::"char", '0', '536870911'), ('public.mx_test_table'::regclass, 1310005, 't'::"char", '536870912', '1073741823'), ('public.mx_test_table'::regclass, 1310006, 't'::"char", '1073741824', '1610612735'), ('public.mx_test_table'::regclass, 1310007, 't'::"char", '1610612736', '2147483647')) SELECT citus_internal_add_shard_metadata(relationname, shardid, storagetype, shardminvalue, shardmaxvalue) FROM shard_data;
(51 rows)
WITH shard_data(relationname, shardid, storagetype, shardminvalue, shardmaxvalue) AS (VALUES ('public.single_shard_tbl'::regclass, 1310008, 't'::"char", NULL, NULL)) SELECT citus_internal_add_shard_metadata(relationname, shardid, storagetype, shardminvalue, shardmaxvalue) FROM shard_data;
(61 rows)
-- Drop single shard table
DROP TABLE single_shard_tbl;
-- Show that CREATE INDEX commands are included in the activate node snapshot
CREATE INDEX mx_index ON mx_test_table(col_2);
SELECT unnest(activate_node_snapshot()) order by 1;
@ -739,6 +760,14 @@ SELECT create_distributed_table('mx_query_test', 'a');
(1 row)
CREATE TABLE single_shard_tbl(a int);
SELECT create_distributed_table('single_shard_tbl', null);
create_distributed_table
---------------------------------------------------------------------
(1 row)
INSERT INTO single_shard_tbl VALUES (1);
SELECT repmodel FROM pg_dist_partition WHERE logicalrelid='mx_query_test'::regclass;
repmodel
---------------------------------------------------------------------
@ -763,6 +792,13 @@ SELECT * FROM mx_query_test ORDER BY a;
INSERT INTO mx_query_test VALUES (6, 'six', 36);
UPDATE mx_query_test SET c = 25 WHERE a = 5;
SELECT * FROM single_shard_tbl ORDER BY a;
a
---------------------------------------------------------------------
1
(1 row)
INSERT INTO single_shard_tbl VALUES (2);
\c - - - :master_port
SELECT * FROM mx_query_test ORDER BY a;
a | b | c
@ -775,8 +811,16 @@ SELECT * FROM mx_query_test ORDER BY a;
6 | six | 36
(6 rows)
SELECT * FROM single_shard_tbl ORDER BY a;
a
---------------------------------------------------------------------
1
2
(2 rows)
\c - - - :master_port
DROP TABLE mx_query_test;
DROP TABLE single_shard_tbl;
-- Check that stop_metadata_sync_to_node function sets hasmetadata of the node to false
\c - - - :master_port
SELECT start_metadata_sync_to_node('localhost', :worker_1_port);
@ -902,16 +946,16 @@ ORDER BY
logicalrelid::text, shardid;
logicalrelid | shardid | nodename | nodeport
---------------------------------------------------------------------
mx_test_schema_1.mx_table_1 | 1310020 | localhost | 57637
mx_test_schema_1.mx_table_1 | 1310021 | localhost | 57638
mx_test_schema_1.mx_table_1 | 1310022 | localhost | 57637
mx_test_schema_1.mx_table_1 | 1310023 | localhost | 57638
mx_test_schema_1.mx_table_1 | 1310024 | localhost | 57637
mx_test_schema_2.mx_table_2 | 1310025 | localhost | 57637
mx_test_schema_2.mx_table_2 | 1310026 | localhost | 57638
mx_test_schema_1.mx_table_1 | 1310025 | localhost | 57638
mx_test_schema_1.mx_table_1 | 1310026 | localhost | 57637
mx_test_schema_2.mx_table_2 | 1310027 | localhost | 57637
mx_test_schema_2.mx_table_2 | 1310028 | localhost | 57638
mx_test_schema_2.mx_table_2 | 1310029 | localhost | 57637
mx_test_schema_2.mx_table_2 | 1310030 | localhost | 57638
mx_test_schema_2.mx_table_2 | 1310031 | localhost | 57637
(10 rows)
-- Check that metadata of MX tables exist on the metadata worker
@ -953,16 +997,16 @@ ORDER BY
logicalrelid::text, shardid;
logicalrelid | shardid | nodename | nodeport
---------------------------------------------------------------------
mx_test_schema_1.mx_table_1 | 1310020 | localhost | 57637
mx_test_schema_1.mx_table_1 | 1310021 | localhost | 57638
mx_test_schema_1.mx_table_1 | 1310022 | localhost | 57637
mx_test_schema_1.mx_table_1 | 1310023 | localhost | 57638
mx_test_schema_1.mx_table_1 | 1310024 | localhost | 57637
mx_test_schema_2.mx_table_2 | 1310025 | localhost | 57637
mx_test_schema_2.mx_table_2 | 1310026 | localhost | 57638
mx_test_schema_1.mx_table_1 | 1310025 | localhost | 57638
mx_test_schema_1.mx_table_1 | 1310026 | localhost | 57637
mx_test_schema_2.mx_table_2 | 1310027 | localhost | 57637
mx_test_schema_2.mx_table_2 | 1310028 | localhost | 57638
mx_test_schema_2.mx_table_2 | 1310029 | localhost | 57637
mx_test_schema_2.mx_table_2 | 1310030 | localhost | 57638
mx_test_schema_2.mx_table_2 | 1310031 | localhost | 57637
(10 rows)
-- Check that metadata of MX tables don't exist on the non-metadata worker
@ -1576,8 +1620,8 @@ ORDER BY
nodeport;
logicalrelid | partmethod | repmodel | shardid | placementid | nodename | nodeport
---------------------------------------------------------------------
mx_ref | n | t | 1310072 | 100072 | localhost | 57637
mx_ref | n | t | 1310072 | 100073 | localhost | 57638
mx_ref | n | t | 1310074 | 100074 | localhost | 57637
mx_ref | n | t | 1310074 | 100075 | localhost | 57638
(2 rows)
SELECT shardid AS ref_table_shardid FROM pg_dist_shard WHERE logicalrelid='mx_ref'::regclass \gset
@ -1653,8 +1697,8 @@ DELETE FROM pg_dist_placement
WHERE groupid = :old_worker_2_group;
SELECT master_remove_node('localhost', :worker_2_port);
WARNING: could not find any shard placements for shardId 1310001
WARNING: could not find any shard placements for shardId 1310021
WARNING: could not find any shard placements for shardId 1310026
WARNING: could not find any shard placements for shardId 1310023
WARNING: could not find any shard placements for shardId 1310028
master_remove_node
---------------------------------------------------------------------
@ -1672,7 +1716,7 @@ FROM pg_dist_shard NATURAL JOIN pg_dist_shard_placement
WHERE logicalrelid='mx_ref'::regclass;
shardid | nodename | nodeport
---------------------------------------------------------------------
1310073 | localhost | 57637
1310075 | localhost | 57637
(1 row)
\c - - - :worker_1_port
@ -1681,7 +1725,7 @@ FROM pg_dist_shard NATURAL JOIN pg_dist_shard_placement
WHERE logicalrelid='mx_ref'::regclass;
shardid | nodename | nodeport
---------------------------------------------------------------------
1310073 | localhost | 57637
1310075 | localhost | 57637
(1 row)
\c - - - :master_port
@ -1699,7 +1743,7 @@ WHERE logicalrelid='mx_ref'::regclass
ORDER BY shardid, nodeport;
shardid | nodename | nodeport
---------------------------------------------------------------------
1310073 | localhost | 57637
1310075 | localhost | 57637
(1 row)
\c - - - :worker_1_port
@ -1709,7 +1753,7 @@ WHERE logicalrelid='mx_ref'::regclass
ORDER BY shardid, nodeport;
shardid | nodename | nodeport
---------------------------------------------------------------------
1310073 | localhost | 57637
1310075 | localhost | 57637
(1 row)
-- Get the metadata back into a consistent state
@ -1949,8 +1993,8 @@ SELECT unnest(activate_node_snapshot()) order by 1;
RESET ROLE
RESET ROLE
SELECT alter_role_if_exists('postgres', 'ALTER ROLE postgres SET lc_messages = ''C''')
SELECT citus_internal_add_partition_metadata ('mx_test_schema_1.mx_table_1'::regclass, 'h', 'col1', 5, 's')
SELECT citus_internal_add_partition_metadata ('mx_test_schema_2.mx_table_2'::regclass, 'h', 'col1', 5, 's')
SELECT citus_internal_add_partition_metadata ('mx_test_schema_1.mx_table_1'::regclass, 'h', 'col1', 7, 's')
SELECT citus_internal_add_partition_metadata ('mx_test_schema_2.mx_table_2'::regclass, 'h', 'col1', 7, 's')
SELECT citus_internal_add_partition_metadata ('mx_testing_schema.mx_test_table'::regclass, 'h', 'col_1', 2, 's')
SELECT citus_internal_add_partition_metadata ('public.dist_table_1'::regclass, 'h', 'a', 10010, 's')
SELECT citus_internal_add_partition_metadata ('public.mx_ref'::regclass, 'n', NULL, 10009, 't')
@ -2004,17 +2048,17 @@ SELECT unnest(activate_node_snapshot()) order by 1;
WITH distributed_object_data(typetext, objnames, objargs, distargumentindex, colocationid, force_delegation) AS (VALUES ('table', ARRAY['public', 'mx_ref']::text[], ARRAY[]::text[], -1, 0, false)) SELECT citus_internal_add_object_metadata(typetext, objnames, objargs, distargumentindex::int, colocationid::int, force_delegation::bool) FROM distributed_object_data;
WITH distributed_object_data(typetext, objnames, objargs, distargumentindex, colocationid, force_delegation) AS (VALUES ('table', ARRAY['public', 'test_table']::text[], ARRAY[]::text[], -1, 0, false)) SELECT citus_internal_add_object_metadata(typetext, objnames, objargs, distargumentindex::int, colocationid::int, force_delegation::bool) FROM distributed_object_data;
WITH placement_data(shardid, shardlength, groupid, placementid) AS (VALUES (1310000, 0, 1, 100000), (1310001, 0, 5, 100001), (1310002, 0, 1, 100002), (1310003, 0, 5, 100003), (1310004, 0, 1, 100004), (1310005, 0, 5, 100005), (1310006, 0, 1, 100006), (1310007, 0, 5, 100007)) SELECT citus_internal_add_placement_metadata(shardid, shardlength, groupid, placementid) FROM placement_data;
WITH placement_data(shardid, shardlength, groupid, placementid) AS (VALUES (1310020, 0, 1, 100020), (1310021, 0, 5, 100021), (1310022, 0, 1, 100022), (1310023, 0, 5, 100023), (1310024, 0, 1, 100024)) SELECT citus_internal_add_placement_metadata(shardid, shardlength, groupid, placementid) FROM placement_data;
WITH placement_data(shardid, shardlength, groupid, placementid) AS (VALUES (1310025, 0, 1, 100025), (1310026, 0, 5, 100026), (1310027, 0, 1, 100027), (1310028, 0, 5, 100028), (1310029, 0, 1, 100029)) SELECT citus_internal_add_placement_metadata(shardid, shardlength, groupid, placementid) FROM placement_data;
WITH placement_data(shardid, shardlength, groupid, placementid) AS (VALUES (1310073, 0, 1, 100074), (1310073, 0, 5, 100075)) SELECT citus_internal_add_placement_metadata(shardid, shardlength, groupid, placementid) FROM placement_data;
WITH placement_data(shardid, shardlength, groupid, placementid) AS (VALUES (1310074, 0, 1, 100076), (1310075, 0, 5, 100077), (1310076, 0, 1, 100078), (1310077, 0, 5, 100079)) SELECT citus_internal_add_placement_metadata(shardid, shardlength, groupid, placementid) FROM placement_data;
WITH placement_data(shardid, shardlength, groupid, placementid) AS (VALUES (1310083, 0, 1, 100086), (1310084, 0, 5, 100087), (1310085, 0, 1, 100088), (1310086, 0, 5, 100089)) SELECT citus_internal_add_placement_metadata(shardid, shardlength, groupid, placementid) FROM placement_data;
WITH shard_data(relationname, shardid, storagetype, shardminvalue, shardmaxvalue) AS (VALUES ('mx_test_schema_1.mx_table_1'::regclass, 1310020, 't'::"char", '-2147483648', '-1288490190'), ('mx_test_schema_1.mx_table_1'::regclass, 1310021, 't'::"char", '-1288490189', '-429496731'), ('mx_test_schema_1.mx_table_1'::regclass, 1310022, 't'::"char", '-429496730', '429496728'), ('mx_test_schema_1.mx_table_1'::regclass, 1310023, 't'::"char", '429496729', '1288490187'), ('mx_test_schema_1.mx_table_1'::regclass, 1310024, 't'::"char", '1288490188', '2147483647')) SELECT citus_internal_add_shard_metadata(relationname, shardid, storagetype, shardminvalue, shardmaxvalue) FROM shard_data;
WITH shard_data(relationname, shardid, storagetype, shardminvalue, shardmaxvalue) AS (VALUES ('mx_test_schema_2.mx_table_2'::regclass, 1310025, 't'::"char", '-2147483648', '-1288490190'), ('mx_test_schema_2.mx_table_2'::regclass, 1310026, 't'::"char", '-1288490189', '-429496731'), ('mx_test_schema_2.mx_table_2'::regclass, 1310027, 't'::"char", '-429496730', '429496728'), ('mx_test_schema_2.mx_table_2'::regclass, 1310028, 't'::"char", '429496729', '1288490187'), ('mx_test_schema_2.mx_table_2'::regclass, 1310029, 't'::"char", '1288490188', '2147483647')) SELECT citus_internal_add_shard_metadata(relationname, shardid, storagetype, shardminvalue, shardmaxvalue) FROM shard_data;
WITH placement_data(shardid, shardlength, groupid, placementid) AS (VALUES (1310022, 0, 1, 100022), (1310023, 0, 5, 100023), (1310024, 0, 1, 100024), (1310025, 0, 5, 100025), (1310026, 0, 1, 100026)) SELECT citus_internal_add_placement_metadata(shardid, shardlength, groupid, placementid) FROM placement_data;
WITH placement_data(shardid, shardlength, groupid, placementid) AS (VALUES (1310027, 0, 1, 100027), (1310028, 0, 5, 100028), (1310029, 0, 1, 100029), (1310030, 0, 5, 100030), (1310031, 0, 1, 100031)) SELECT citus_internal_add_placement_metadata(shardid, shardlength, groupid, placementid) FROM placement_data;
WITH placement_data(shardid, shardlength, groupid, placementid) AS (VALUES (1310075, 0, 1, 100076), (1310075, 0, 5, 100077)) SELECT citus_internal_add_placement_metadata(shardid, shardlength, groupid, placementid) FROM placement_data;
WITH placement_data(shardid, shardlength, groupid, placementid) AS (VALUES (1310076, 0, 1, 100078), (1310077, 0, 5, 100079), (1310078, 0, 1, 100080), (1310079, 0, 5, 100081)) SELECT citus_internal_add_placement_metadata(shardid, shardlength, groupid, placementid) FROM placement_data;
WITH placement_data(shardid, shardlength, groupid, placementid) AS (VALUES (1310085, 0, 1, 100088), (1310086, 0, 5, 100089), (1310087, 0, 1, 100090), (1310088, 0, 5, 100091)) SELECT citus_internal_add_placement_metadata(shardid, shardlength, groupid, placementid) FROM placement_data;
WITH shard_data(relationname, shardid, storagetype, shardminvalue, shardmaxvalue) AS (VALUES ('mx_test_schema_1.mx_table_1'::regclass, 1310022, 't'::"char", '-2147483648', '-1288490190'), ('mx_test_schema_1.mx_table_1'::regclass, 1310023, 't'::"char", '-1288490189', '-429496731'), ('mx_test_schema_1.mx_table_1'::regclass, 1310024, 't'::"char", '-429496730', '429496728'), ('mx_test_schema_1.mx_table_1'::regclass, 1310025, 't'::"char", '429496729', '1288490187'), ('mx_test_schema_1.mx_table_1'::regclass, 1310026, 't'::"char", '1288490188', '2147483647')) SELECT citus_internal_add_shard_metadata(relationname, shardid, storagetype, shardminvalue, shardmaxvalue) FROM shard_data;
WITH shard_data(relationname, shardid, storagetype, shardminvalue, shardmaxvalue) AS (VALUES ('mx_test_schema_2.mx_table_2'::regclass, 1310027, 't'::"char", '-2147483648', '-1288490190'), ('mx_test_schema_2.mx_table_2'::regclass, 1310028, 't'::"char", '-1288490189', '-429496731'), ('mx_test_schema_2.mx_table_2'::regclass, 1310029, 't'::"char", '-429496730', '429496728'), ('mx_test_schema_2.mx_table_2'::regclass, 1310030, 't'::"char", '429496729', '1288490187'), ('mx_test_schema_2.mx_table_2'::regclass, 1310031, 't'::"char", '1288490188', '2147483647')) SELECT citus_internal_add_shard_metadata(relationname, shardid, storagetype, shardminvalue, shardmaxvalue) FROM shard_data;
WITH shard_data(relationname, shardid, storagetype, shardminvalue, shardmaxvalue) AS (VALUES ('mx_testing_schema.mx_test_table'::regclass, 1310000, 't'::"char", '-2147483648', '-1610612737'), ('mx_testing_schema.mx_test_table'::regclass, 1310001, 't'::"char", '-1610612736', '-1073741825'), ('mx_testing_schema.mx_test_table'::regclass, 1310002, 't'::"char", '-1073741824', '-536870913'), ('mx_testing_schema.mx_test_table'::regclass, 1310003, 't'::"char", '-536870912', '-1'), ('mx_testing_schema.mx_test_table'::regclass, 1310004, 't'::"char", '0', '536870911'), ('mx_testing_schema.mx_test_table'::regclass, 1310005, 't'::"char", '536870912', '1073741823'), ('mx_testing_schema.mx_test_table'::regclass, 1310006, 't'::"char", '1073741824', '1610612735'), ('mx_testing_schema.mx_test_table'::regclass, 1310007, 't'::"char", '1610612736', '2147483647')) SELECT citus_internal_add_shard_metadata(relationname, shardid, storagetype, shardminvalue, shardmaxvalue) FROM shard_data;
WITH shard_data(relationname, shardid, storagetype, shardminvalue, shardmaxvalue) AS (VALUES ('public.dist_table_1'::regclass, 1310074, 't'::"char", '-2147483648', '-1073741825'), ('public.dist_table_1'::regclass, 1310075, 't'::"char", '-1073741824', '-1'), ('public.dist_table_1'::regclass, 1310076, 't'::"char", '0', '1073741823'), ('public.dist_table_1'::regclass, 1310077, 't'::"char", '1073741824', '2147483647')) SELECT citus_internal_add_shard_metadata(relationname, shardid, storagetype, shardminvalue, shardmaxvalue) FROM shard_data;
WITH shard_data(relationname, shardid, storagetype, shardminvalue, shardmaxvalue) AS (VALUES ('public.mx_ref'::regclass, 1310073, 't'::"char", NULL, NULL)) SELECT citus_internal_add_shard_metadata(relationname, shardid, storagetype, shardminvalue, shardmaxvalue) FROM shard_data;
WITH shard_data(relationname, shardid, storagetype, shardminvalue, shardmaxvalue) AS (VALUES ('public.test_table'::regclass, 1310083, 't'::"char", '-2147483648', '-1073741825'), ('public.test_table'::regclass, 1310084, 't'::"char", '-1073741824', '-1'), ('public.test_table'::regclass, 1310085, 't'::"char", '0', '1073741823'), ('public.test_table'::regclass, 1310086, 't'::"char", '1073741824', '2147483647')) SELECT citus_internal_add_shard_metadata(relationname, shardid, storagetype, shardminvalue, shardmaxvalue) FROM shard_data;
WITH shard_data(relationname, shardid, storagetype, shardminvalue, shardmaxvalue) AS (VALUES ('public.dist_table_1'::regclass, 1310076, 't'::"char", '-2147483648', '-1073741825'), ('public.dist_table_1'::regclass, 1310077, 't'::"char", '-1073741824', '-1'), ('public.dist_table_1'::regclass, 1310078, 't'::"char", '0', '1073741823'), ('public.dist_table_1'::regclass, 1310079, 't'::"char", '1073741824', '2147483647')) SELECT citus_internal_add_shard_metadata(relationname, shardid, storagetype, shardminvalue, shardmaxvalue) FROM shard_data;
WITH shard_data(relationname, shardid, storagetype, shardminvalue, shardmaxvalue) AS (VALUES ('public.mx_ref'::regclass, 1310075, 't'::"char", NULL, NULL)) SELECT citus_internal_add_shard_metadata(relationname, shardid, storagetype, shardminvalue, shardmaxvalue) FROM shard_data;
WITH shard_data(relationname, shardid, storagetype, shardminvalue, shardmaxvalue) AS (VALUES ('public.test_table'::regclass, 1310085, 't'::"char", '-2147483648', '-1073741825'), ('public.test_table'::regclass, 1310086, 't'::"char", '-1073741824', '-1'), ('public.test_table'::regclass, 1310087, 't'::"char", '0', '1073741823'), ('public.test_table'::regclass, 1310088, 't'::"char", '1073741824', '2147483647')) SELECT citus_internal_add_shard_metadata(relationname, shardid, storagetype, shardminvalue, shardmaxvalue) FROM shard_data;
(118 rows)
-- shouldn't work since test_table is MX

View File

@ -122,6 +122,15 @@ reset citus.shard_replication_factor;
-- Set the replication model of the test table to streaming replication so that it is
-- considered as an MX table
UPDATE pg_dist_partition SET repmodel='s' WHERE logicalrelid='mx_test_table'::regclass;
-- add a single shard table and verify the creation commands are included in the activate node snapshot
CREATE TABLE single_shard_tbl(a int);
SELECT create_distributed_table('single_shard_tbl', null);
create_distributed_table
---------------------------------------------------------------------
(1 row)
INSERT INTO single_shard_tbl VALUES (1);
-- Show that the created MX table is and its sequences are included in the activate node snapshot
SELECT unnest(activate_node_snapshot()) order by 1;
unnest
@ -131,9 +140,11 @@ SELECT unnest(activate_node_snapshot()) order by 1;
ALTER SEQUENCE public.user_defined_seq OWNER TO postgres
ALTER TABLE public.mx_test_table ADD CONSTRAINT mx_test_table_col_1_key UNIQUE (col_1)
ALTER TABLE public.mx_test_table OWNER TO postgres
ALTER TABLE public.single_shard_tbl OWNER TO postgres
CALL pg_catalog.worker_drop_all_shell_tables(true)
CREATE SCHEMA IF NOT EXISTS public AUTHORIZATION postgres
CREATE TABLE public.mx_test_table (col_1 integer, col_2 text NOT NULL, col_3 bigint DEFAULT nextval('public.mx_test_table_col_3_seq'::regclass) NOT NULL, col_4 bigint DEFAULT nextval('public.user_defined_seq'::regclass)) USING heap
CREATE TABLE public.single_shard_tbl (a integer) USING heap
DELETE FROM pg_catalog.pg_dist_colocation
DELETE FROM pg_catalog.pg_dist_object
DELETE FROM pg_catalog.pg_dist_tenant_schema
@ -142,6 +153,7 @@ SELECT unnest(activate_node_snapshot()) order by 1;
DELETE FROM pg_dist_placement
DELETE FROM pg_dist_shard
DROP TABLE IF EXISTS public.mx_test_table CASCADE
DROP TABLE IF EXISTS public.single_shard_tbl CASCADE
GRANT CREATE ON SCHEMA public TO PUBLIC;
GRANT CREATE ON SCHEMA public TO postgres;
GRANT USAGE ON SCHEMA public TO PUBLIC;
@ -151,13 +163,16 @@ SELECT unnest(activate_node_snapshot()) order by 1;
RESET ROLE
SELECT alter_role_if_exists('postgres', 'ALTER ROLE postgres SET lc_messages = ''C''')
SELECT citus_internal_add_partition_metadata ('public.mx_test_table'::regclass, 'h', 'col_1', 2, 's')
SELECT citus_internal_add_partition_metadata ('public.single_shard_tbl'::regclass, 'n', NULL, 3, 's')
SELECT pg_catalog.worker_drop_sequence_dependency('public.mx_test_table');
SELECT pg_catalog.worker_drop_sequence_dependency('public.single_shard_tbl');
SELECT pg_catalog.worker_drop_sequence_dependency(logicalrelid::regclass::text) FROM pg_dist_partition
SELECT pg_catalog.worker_record_sequence_dependency('public.mx_test_table_col_3_seq'::regclass,'public.mx_test_table'::regclass,'col_3')
SELECT worker_apply_sequence_command ('CREATE SEQUENCE IF NOT EXISTS public.mx_test_table_col_3_seq AS bigint INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START WITH 1 CACHE 1 NO CYCLE','bigint')
SELECT worker_apply_sequence_command ('CREATE SEQUENCE IF NOT EXISTS public.user_defined_seq AS bigint INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START WITH 1 CACHE 1 NO CYCLE','bigint')
SELECT worker_create_or_alter_role('postgres', 'CREATE ROLE postgres SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN REPLICATION BYPASSRLS CONNECTION LIMIT 0 PASSWORD ''md5c53670dddfc3bb4b5675c7872bc2249a'' VALID UNTIL ''2052-05-05 00:00:00-07''', 'ALTER ROLE postgres SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN REPLICATION BYPASSRLS CONNECTION LIMIT 0 PASSWORD ''md5c53670dddfc3bb4b5675c7872bc2249a'' VALID UNTIL ''2052-05-05 00:00:00-07''')
SELECT worker_create_truncate_trigger('public.mx_test_table')
SELECT worker_create_truncate_trigger('public.single_shard_tbl')
SET ROLE postgres
SET ROLE postgres
SET citus.enable_ddl_propagation TO 'off'
@ -169,16 +184,22 @@ SELECT unnest(activate_node_snapshot()) order by 1;
UPDATE pg_dist_node SET isactive = TRUE WHERE nodeid = 1
UPDATE pg_dist_node SET metadatasynced = TRUE WHERE nodeid = 1
WITH colocation_group_data (colocationid, shardcount, replicationfactor, distributioncolumntype, distributioncolumncollationname, distributioncolumncollationschema) AS (VALUES (2, 8, 1, 'integer'::regtype, NULL, NULL)) SELECT pg_catalog.citus_internal_add_colocation_metadata(colocationid, shardcount, replicationfactor, distributioncolumntype, coalesce(c.oid, 0)) FROM colocation_group_data d LEFT JOIN pg_collation c ON (d.distributioncolumncollationname = c.collname AND d.distributioncolumncollationschema::regnamespace = c.collnamespace)
WITH colocation_group_data (colocationid, shardcount, replicationfactor, distributioncolumntype, distributioncolumncollationname, distributioncolumncollationschema) AS (VALUES (3, 1, 2, 0, NULL, NULL)) SELECT pg_catalog.citus_internal_add_colocation_metadata(colocationid, shardcount, replicationfactor, distributioncolumntype, coalesce(c.oid, 0)) FROM colocation_group_data d LEFT JOIN pg_collation c ON (d.distributioncolumncollationname = c.collname AND d.distributioncolumncollationschema::regnamespace = c.collnamespace)
WITH distributed_object_data(typetext, objnames, objargs, distargumentindex, colocationid, force_delegation) AS (VALUES ('database', ARRAY['regression']::text[], ARRAY[]::text[], -1, 0, false)) SELECT citus_internal_add_object_metadata(typetext, objnames, objargs, distargumentindex::int, colocationid::int, force_delegation::bool) FROM distributed_object_data;
WITH distributed_object_data(typetext, objnames, objargs, distargumentindex, colocationid, force_delegation) AS (VALUES ('role', ARRAY['postgres']::text[], ARRAY[]::text[], -1, 0, false)) SELECT citus_internal_add_object_metadata(typetext, objnames, objargs, distargumentindex::int, colocationid::int, force_delegation::bool) FROM distributed_object_data;
WITH distributed_object_data(typetext, objnames, objargs, distargumentindex, colocationid, force_delegation) AS (VALUES ('schema', ARRAY['public']::text[], ARRAY[]::text[], -1, 0, false)) SELECT citus_internal_add_object_metadata(typetext, objnames, objargs, distargumentindex::int, colocationid::int, force_delegation::bool) FROM distributed_object_data;
WITH distributed_object_data(typetext, objnames, objargs, distargumentindex, colocationid, force_delegation) AS (VALUES ('sequence', ARRAY['public', 'mx_test_table_col_3_seq']::text[], ARRAY[]::text[], -1, 0, false)) SELECT citus_internal_add_object_metadata(typetext, objnames, objargs, distargumentindex::int, colocationid::int, force_delegation::bool) FROM distributed_object_data;
WITH distributed_object_data(typetext, objnames, objargs, distargumentindex, colocationid, force_delegation) AS (VALUES ('sequence', ARRAY['public', 'user_defined_seq']::text[], ARRAY[]::text[], -1, 0, false)) SELECT citus_internal_add_object_metadata(typetext, objnames, objargs, distargumentindex::int, colocationid::int, force_delegation::bool) FROM distributed_object_data;
WITH distributed_object_data(typetext, objnames, objargs, distargumentindex, colocationid, force_delegation) AS (VALUES ('table', ARRAY['public', 'mx_test_table']::text[], ARRAY[]::text[], -1, 0, false)) SELECT citus_internal_add_object_metadata(typetext, objnames, objargs, distargumentindex::int, colocationid::int, force_delegation::bool) FROM distributed_object_data;
WITH distributed_object_data(typetext, objnames, objargs, distargumentindex, colocationid, force_delegation) AS (VALUES ('table', ARRAY['public', 'single_shard_tbl']::text[], ARRAY[]::text[], -1, 0, false)) SELECT citus_internal_add_object_metadata(typetext, objnames, objargs, distargumentindex::int, colocationid::int, force_delegation::bool) FROM distributed_object_data;
WITH placement_data(shardid, shardlength, groupid, placementid) AS (VALUES (1310000, 0, 1, 100000), (1310001, 0, 2, 100001), (1310002, 0, 1, 100002), (1310003, 0, 2, 100003), (1310004, 0, 1, 100004), (1310005, 0, 2, 100005), (1310006, 0, 1, 100006), (1310007, 0, 2, 100007)) SELECT citus_internal_add_placement_metadata(shardid, shardlength, groupid, placementid) FROM placement_data;
WITH placement_data(shardid, shardlength, groupid, placementid) AS (VALUES (1310008, 0, 2, 100008)) SELECT citus_internal_add_placement_metadata(shardid, shardlength, groupid, placementid) FROM placement_data;
WITH shard_data(relationname, shardid, storagetype, shardminvalue, shardmaxvalue) AS (VALUES ('public.mx_test_table'::regclass, 1310000, 't'::"char", '-2147483648', '-1610612737'), ('public.mx_test_table'::regclass, 1310001, 't'::"char", '-1610612736', '-1073741825'), ('public.mx_test_table'::regclass, 1310002, 't'::"char", '-1073741824', '-536870913'), ('public.mx_test_table'::regclass, 1310003, 't'::"char", '-536870912', '-1'), ('public.mx_test_table'::regclass, 1310004, 't'::"char", '0', '536870911'), ('public.mx_test_table'::regclass, 1310005, 't'::"char", '536870912', '1073741823'), ('public.mx_test_table'::regclass, 1310006, 't'::"char", '1073741824', '1610612735'), ('public.mx_test_table'::regclass, 1310007, 't'::"char", '1610612736', '2147483647')) SELECT citus_internal_add_shard_metadata(relationname, shardid, storagetype, shardminvalue, shardmaxvalue) FROM shard_data;
(51 rows)
WITH shard_data(relationname, shardid, storagetype, shardminvalue, shardmaxvalue) AS (VALUES ('public.single_shard_tbl'::regclass, 1310008, 't'::"char", NULL, NULL)) SELECT citus_internal_add_shard_metadata(relationname, shardid, storagetype, shardminvalue, shardmaxvalue) FROM shard_data;
(61 rows)
-- Drop single shard table
DROP TABLE single_shard_tbl;
-- Show that CREATE INDEX commands are included in the activate node snapshot
CREATE INDEX mx_index ON mx_test_table(col_2);
SELECT unnest(activate_node_snapshot()) order by 1;
@ -739,6 +760,14 @@ SELECT create_distributed_table('mx_query_test', 'a');
(1 row)
CREATE TABLE single_shard_tbl(a int);
SELECT create_distributed_table('single_shard_tbl', null);
create_distributed_table
---------------------------------------------------------------------
(1 row)
INSERT INTO single_shard_tbl VALUES (1);
SELECT repmodel FROM pg_dist_partition WHERE logicalrelid='mx_query_test'::regclass;
repmodel
---------------------------------------------------------------------
@ -763,6 +792,13 @@ SELECT * FROM mx_query_test ORDER BY a;
INSERT INTO mx_query_test VALUES (6, 'six', 36);
UPDATE mx_query_test SET c = 25 WHERE a = 5;
SELECT * FROM single_shard_tbl ORDER BY a;
a
---------------------------------------------------------------------
1
(1 row)
INSERT INTO single_shard_tbl VALUES (2);
\c - - - :master_port
SELECT * FROM mx_query_test ORDER BY a;
a | b | c
@ -775,8 +811,16 @@ SELECT * FROM mx_query_test ORDER BY a;
6 | six | 36
(6 rows)
SELECT * FROM single_shard_tbl ORDER BY a;
a
---------------------------------------------------------------------
1
2
(2 rows)
\c - - - :master_port
DROP TABLE mx_query_test;
DROP TABLE single_shard_tbl;
-- Check that stop_metadata_sync_to_node function sets hasmetadata of the node to false
\c - - - :master_port
SELECT start_metadata_sync_to_node('localhost', :worker_1_port);
@ -902,16 +946,16 @@ ORDER BY
logicalrelid::text, shardid;
logicalrelid | shardid | nodename | nodeport
---------------------------------------------------------------------
mx_test_schema_1.mx_table_1 | 1310020 | localhost | 57637
mx_test_schema_1.mx_table_1 | 1310021 | localhost | 57638
mx_test_schema_1.mx_table_1 | 1310022 | localhost | 57637
mx_test_schema_1.mx_table_1 | 1310023 | localhost | 57638
mx_test_schema_1.mx_table_1 | 1310024 | localhost | 57637
mx_test_schema_2.mx_table_2 | 1310025 | localhost | 57637
mx_test_schema_2.mx_table_2 | 1310026 | localhost | 57638
mx_test_schema_1.mx_table_1 | 1310025 | localhost | 57638
mx_test_schema_1.mx_table_1 | 1310026 | localhost | 57637
mx_test_schema_2.mx_table_2 | 1310027 | localhost | 57637
mx_test_schema_2.mx_table_2 | 1310028 | localhost | 57638
mx_test_schema_2.mx_table_2 | 1310029 | localhost | 57637
mx_test_schema_2.mx_table_2 | 1310030 | localhost | 57638
mx_test_schema_2.mx_table_2 | 1310031 | localhost | 57637
(10 rows)
-- Check that metadata of MX tables exist on the metadata worker
@ -953,16 +997,16 @@ ORDER BY
logicalrelid::text, shardid;
logicalrelid | shardid | nodename | nodeport
---------------------------------------------------------------------
mx_test_schema_1.mx_table_1 | 1310020 | localhost | 57637
mx_test_schema_1.mx_table_1 | 1310021 | localhost | 57638
mx_test_schema_1.mx_table_1 | 1310022 | localhost | 57637
mx_test_schema_1.mx_table_1 | 1310023 | localhost | 57638
mx_test_schema_1.mx_table_1 | 1310024 | localhost | 57637
mx_test_schema_2.mx_table_2 | 1310025 | localhost | 57637
mx_test_schema_2.mx_table_2 | 1310026 | localhost | 57638
mx_test_schema_1.mx_table_1 | 1310025 | localhost | 57638
mx_test_schema_1.mx_table_1 | 1310026 | localhost | 57637
mx_test_schema_2.mx_table_2 | 1310027 | localhost | 57637
mx_test_schema_2.mx_table_2 | 1310028 | localhost | 57638
mx_test_schema_2.mx_table_2 | 1310029 | localhost | 57637
mx_test_schema_2.mx_table_2 | 1310030 | localhost | 57638
mx_test_schema_2.mx_table_2 | 1310031 | localhost | 57637
(10 rows)
-- Check that metadata of MX tables don't exist on the non-metadata worker
@ -1576,8 +1620,8 @@ ORDER BY
nodeport;
logicalrelid | partmethod | repmodel | shardid | placementid | nodename | nodeport
---------------------------------------------------------------------
mx_ref | n | t | 1310072 | 100072 | localhost | 57637
mx_ref | n | t | 1310072 | 100073 | localhost | 57638
mx_ref | n | t | 1310074 | 100074 | localhost | 57637
mx_ref | n | t | 1310074 | 100075 | localhost | 57638
(2 rows)
SELECT shardid AS ref_table_shardid FROM pg_dist_shard WHERE logicalrelid='mx_ref'::regclass \gset
@ -1653,8 +1697,8 @@ DELETE FROM pg_dist_placement
WHERE groupid = :old_worker_2_group;
SELECT master_remove_node('localhost', :worker_2_port);
WARNING: could not find any shard placements for shardId 1310001
WARNING: could not find any shard placements for shardId 1310021
WARNING: could not find any shard placements for shardId 1310026
WARNING: could not find any shard placements for shardId 1310023
WARNING: could not find any shard placements for shardId 1310028
master_remove_node
---------------------------------------------------------------------
@ -1672,7 +1716,7 @@ FROM pg_dist_shard NATURAL JOIN pg_dist_shard_placement
WHERE logicalrelid='mx_ref'::regclass;
shardid | nodename | nodeport
---------------------------------------------------------------------
1310073 | localhost | 57637
1310075 | localhost | 57637
(1 row)
\c - - - :worker_1_port
@ -1681,7 +1725,7 @@ FROM pg_dist_shard NATURAL JOIN pg_dist_shard_placement
WHERE logicalrelid='mx_ref'::regclass;
shardid | nodename | nodeport
---------------------------------------------------------------------
1310073 | localhost | 57637
1310075 | localhost | 57637
(1 row)
\c - - - :master_port
@ -1699,7 +1743,7 @@ WHERE logicalrelid='mx_ref'::regclass
ORDER BY shardid, nodeport;
shardid | nodename | nodeport
---------------------------------------------------------------------
1310073 | localhost | 57637
1310075 | localhost | 57637
(1 row)
\c - - - :worker_1_port
@ -1709,7 +1753,7 @@ WHERE logicalrelid='mx_ref'::regclass
ORDER BY shardid, nodeport;
shardid | nodename | nodeport
---------------------------------------------------------------------
1310073 | localhost | 57637
1310075 | localhost | 57637
(1 row)
-- Get the metadata back into a consistent state
@ -1949,8 +1993,8 @@ SELECT unnest(activate_node_snapshot()) order by 1;
RESET ROLE
RESET ROLE
SELECT alter_role_if_exists('postgres', 'ALTER ROLE postgres SET lc_messages = ''C''')
SELECT citus_internal_add_partition_metadata ('mx_test_schema_1.mx_table_1'::regclass, 'h', 'col1', 5, 's')
SELECT citus_internal_add_partition_metadata ('mx_test_schema_2.mx_table_2'::regclass, 'h', 'col1', 5, 's')
SELECT citus_internal_add_partition_metadata ('mx_test_schema_1.mx_table_1'::regclass, 'h', 'col1', 7, 's')
SELECT citus_internal_add_partition_metadata ('mx_test_schema_2.mx_table_2'::regclass, 'h', 'col1', 7, 's')
SELECT citus_internal_add_partition_metadata ('mx_testing_schema.mx_test_table'::regclass, 'h', 'col_1', 2, 's')
SELECT citus_internal_add_partition_metadata ('public.dist_table_1'::regclass, 'h', 'a', 10010, 's')
SELECT citus_internal_add_partition_metadata ('public.mx_ref'::regclass, 'n', NULL, 10009, 't')
@ -2004,17 +2048,17 @@ SELECT unnest(activate_node_snapshot()) order by 1;
WITH distributed_object_data(typetext, objnames, objargs, distargumentindex, colocationid, force_delegation) AS (VALUES ('table', ARRAY['public', 'mx_ref']::text[], ARRAY[]::text[], -1, 0, false)) SELECT citus_internal_add_object_metadata(typetext, objnames, objargs, distargumentindex::int, colocationid::int, force_delegation::bool) FROM distributed_object_data;
WITH distributed_object_data(typetext, objnames, objargs, distargumentindex, colocationid, force_delegation) AS (VALUES ('table', ARRAY['public', 'test_table']::text[], ARRAY[]::text[], -1, 0, false)) SELECT citus_internal_add_object_metadata(typetext, objnames, objargs, distargumentindex::int, colocationid::int, force_delegation::bool) FROM distributed_object_data;
WITH placement_data(shardid, shardlength, groupid, placementid) AS (VALUES (1310000, 0, 1, 100000), (1310001, 0, 5, 100001), (1310002, 0, 1, 100002), (1310003, 0, 5, 100003), (1310004, 0, 1, 100004), (1310005, 0, 5, 100005), (1310006, 0, 1, 100006), (1310007, 0, 5, 100007)) SELECT citus_internal_add_placement_metadata(shardid, shardlength, groupid, placementid) FROM placement_data;
WITH placement_data(shardid, shardlength, groupid, placementid) AS (VALUES (1310020, 0, 1, 100020), (1310021, 0, 5, 100021), (1310022, 0, 1, 100022), (1310023, 0, 5, 100023), (1310024, 0, 1, 100024)) SELECT citus_internal_add_placement_metadata(shardid, shardlength, groupid, placementid) FROM placement_data;
WITH placement_data(shardid, shardlength, groupid, placementid) AS (VALUES (1310025, 0, 1, 100025), (1310026, 0, 5, 100026), (1310027, 0, 1, 100027), (1310028, 0, 5, 100028), (1310029, 0, 1, 100029)) SELECT citus_internal_add_placement_metadata(shardid, shardlength, groupid, placementid) FROM placement_data;
WITH placement_data(shardid, shardlength, groupid, placementid) AS (VALUES (1310073, 0, 1, 100074), (1310073, 0, 5, 100075)) SELECT citus_internal_add_placement_metadata(shardid, shardlength, groupid, placementid) FROM placement_data;
WITH placement_data(shardid, shardlength, groupid, placementid) AS (VALUES (1310074, 0, 1, 100076), (1310075, 0, 5, 100077), (1310076, 0, 1, 100078), (1310077, 0, 5, 100079)) SELECT citus_internal_add_placement_metadata(shardid, shardlength, groupid, placementid) FROM placement_data;
WITH placement_data(shardid, shardlength, groupid, placementid) AS (VALUES (1310083, 0, 1, 100086), (1310084, 0, 5, 100087), (1310085, 0, 1, 100088), (1310086, 0, 5, 100089)) SELECT citus_internal_add_placement_metadata(shardid, shardlength, groupid, placementid) FROM placement_data;
WITH shard_data(relationname, shardid, storagetype, shardminvalue, shardmaxvalue) AS (VALUES ('mx_test_schema_1.mx_table_1'::regclass, 1310020, 't'::"char", '-2147483648', '-1288490190'), ('mx_test_schema_1.mx_table_1'::regclass, 1310021, 't'::"char", '-1288490189', '-429496731'), ('mx_test_schema_1.mx_table_1'::regclass, 1310022, 't'::"char", '-429496730', '429496728'), ('mx_test_schema_1.mx_table_1'::regclass, 1310023, 't'::"char", '429496729', '1288490187'), ('mx_test_schema_1.mx_table_1'::regclass, 1310024, 't'::"char", '1288490188', '2147483647')) SELECT citus_internal_add_shard_metadata(relationname, shardid, storagetype, shardminvalue, shardmaxvalue) FROM shard_data;
WITH shard_data(relationname, shardid, storagetype, shardminvalue, shardmaxvalue) AS (VALUES ('mx_test_schema_2.mx_table_2'::regclass, 1310025, 't'::"char", '-2147483648', '-1288490190'), ('mx_test_schema_2.mx_table_2'::regclass, 1310026, 't'::"char", '-1288490189', '-429496731'), ('mx_test_schema_2.mx_table_2'::regclass, 1310027, 't'::"char", '-429496730', '429496728'), ('mx_test_schema_2.mx_table_2'::regclass, 1310028, 't'::"char", '429496729', '1288490187'), ('mx_test_schema_2.mx_table_2'::regclass, 1310029, 't'::"char", '1288490188', '2147483647')) SELECT citus_internal_add_shard_metadata(relationname, shardid, storagetype, shardminvalue, shardmaxvalue) FROM shard_data;
WITH placement_data(shardid, shardlength, groupid, placementid) AS (VALUES (1310022, 0, 1, 100022), (1310023, 0, 5, 100023), (1310024, 0, 1, 100024), (1310025, 0, 5, 100025), (1310026, 0, 1, 100026)) SELECT citus_internal_add_placement_metadata(shardid, shardlength, groupid, placementid) FROM placement_data;
WITH placement_data(shardid, shardlength, groupid, placementid) AS (VALUES (1310027, 0, 1, 100027), (1310028, 0, 5, 100028), (1310029, 0, 1, 100029), (1310030, 0, 5, 100030), (1310031, 0, 1, 100031)) SELECT citus_internal_add_placement_metadata(shardid, shardlength, groupid, placementid) FROM placement_data;
WITH placement_data(shardid, shardlength, groupid, placementid) AS (VALUES (1310075, 0, 1, 100076), (1310075, 0, 5, 100077)) SELECT citus_internal_add_placement_metadata(shardid, shardlength, groupid, placementid) FROM placement_data;
WITH placement_data(shardid, shardlength, groupid, placementid) AS (VALUES (1310076, 0, 1, 100078), (1310077, 0, 5, 100079), (1310078, 0, 1, 100080), (1310079, 0, 5, 100081)) SELECT citus_internal_add_placement_metadata(shardid, shardlength, groupid, placementid) FROM placement_data;
WITH placement_data(shardid, shardlength, groupid, placementid) AS (VALUES (1310085, 0, 1, 100088), (1310086, 0, 5, 100089), (1310087, 0, 1, 100090), (1310088, 0, 5, 100091)) SELECT citus_internal_add_placement_metadata(shardid, shardlength, groupid, placementid) FROM placement_data;
WITH shard_data(relationname, shardid, storagetype, shardminvalue, shardmaxvalue) AS (VALUES ('mx_test_schema_1.mx_table_1'::regclass, 1310022, 't'::"char", '-2147483648', '-1288490190'), ('mx_test_schema_1.mx_table_1'::regclass, 1310023, 't'::"char", '-1288490189', '-429496731'), ('mx_test_schema_1.mx_table_1'::regclass, 1310024, 't'::"char", '-429496730', '429496728'), ('mx_test_schema_1.mx_table_1'::regclass, 1310025, 't'::"char", '429496729', '1288490187'), ('mx_test_schema_1.mx_table_1'::regclass, 1310026, 't'::"char", '1288490188', '2147483647')) SELECT citus_internal_add_shard_metadata(relationname, shardid, storagetype, shardminvalue, shardmaxvalue) FROM shard_data;
WITH shard_data(relationname, shardid, storagetype, shardminvalue, shardmaxvalue) AS (VALUES ('mx_test_schema_2.mx_table_2'::regclass, 1310027, 't'::"char", '-2147483648', '-1288490190'), ('mx_test_schema_2.mx_table_2'::regclass, 1310028, 't'::"char", '-1288490189', '-429496731'), ('mx_test_schema_2.mx_table_2'::regclass, 1310029, 't'::"char", '-429496730', '429496728'), ('mx_test_schema_2.mx_table_2'::regclass, 1310030, 't'::"char", '429496729', '1288490187'), ('mx_test_schema_2.mx_table_2'::regclass, 1310031, 't'::"char", '1288490188', '2147483647')) SELECT citus_internal_add_shard_metadata(relationname, shardid, storagetype, shardminvalue, shardmaxvalue) FROM shard_data;
WITH shard_data(relationname, shardid, storagetype, shardminvalue, shardmaxvalue) AS (VALUES ('mx_testing_schema.mx_test_table'::regclass, 1310000, 't'::"char", '-2147483648', '-1610612737'), ('mx_testing_schema.mx_test_table'::regclass, 1310001, 't'::"char", '-1610612736', '-1073741825'), ('mx_testing_schema.mx_test_table'::regclass, 1310002, 't'::"char", '-1073741824', '-536870913'), ('mx_testing_schema.mx_test_table'::regclass, 1310003, 't'::"char", '-536870912', '-1'), ('mx_testing_schema.mx_test_table'::regclass, 1310004, 't'::"char", '0', '536870911'), ('mx_testing_schema.mx_test_table'::regclass, 1310005, 't'::"char", '536870912', '1073741823'), ('mx_testing_schema.mx_test_table'::regclass, 1310006, 't'::"char", '1073741824', '1610612735'), ('mx_testing_schema.mx_test_table'::regclass, 1310007, 't'::"char", '1610612736', '2147483647')) SELECT citus_internal_add_shard_metadata(relationname, shardid, storagetype, shardminvalue, shardmaxvalue) FROM shard_data;
WITH shard_data(relationname, shardid, storagetype, shardminvalue, shardmaxvalue) AS (VALUES ('public.dist_table_1'::regclass, 1310074, 't'::"char", '-2147483648', '-1073741825'), ('public.dist_table_1'::regclass, 1310075, 't'::"char", '-1073741824', '-1'), ('public.dist_table_1'::regclass, 1310076, 't'::"char", '0', '1073741823'), ('public.dist_table_1'::regclass, 1310077, 't'::"char", '1073741824', '2147483647')) SELECT citus_internal_add_shard_metadata(relationname, shardid, storagetype, shardminvalue, shardmaxvalue) FROM shard_data;
WITH shard_data(relationname, shardid, storagetype, shardminvalue, shardmaxvalue) AS (VALUES ('public.mx_ref'::regclass, 1310073, 't'::"char", NULL, NULL)) SELECT citus_internal_add_shard_metadata(relationname, shardid, storagetype, shardminvalue, shardmaxvalue) FROM shard_data;
WITH shard_data(relationname, shardid, storagetype, shardminvalue, shardmaxvalue) AS (VALUES ('public.test_table'::regclass, 1310083, 't'::"char", '-2147483648', '-1073741825'), ('public.test_table'::regclass, 1310084, 't'::"char", '-1073741824', '-1'), ('public.test_table'::regclass, 1310085, 't'::"char", '0', '1073741823'), ('public.test_table'::regclass, 1310086, 't'::"char", '1073741824', '2147483647')) SELECT citus_internal_add_shard_metadata(relationname, shardid, storagetype, shardminvalue, shardmaxvalue) FROM shard_data;
WITH shard_data(relationname, shardid, storagetype, shardminvalue, shardmaxvalue) AS (VALUES ('public.dist_table_1'::regclass, 1310076, 't'::"char", '-2147483648', '-1073741825'), ('public.dist_table_1'::regclass, 1310077, 't'::"char", '-1073741824', '-1'), ('public.dist_table_1'::regclass, 1310078, 't'::"char", '0', '1073741823'), ('public.dist_table_1'::regclass, 1310079, 't'::"char", '1073741824', '2147483647')) SELECT citus_internal_add_shard_metadata(relationname, shardid, storagetype, shardminvalue, shardmaxvalue) FROM shard_data;
WITH shard_data(relationname, shardid, storagetype, shardminvalue, shardmaxvalue) AS (VALUES ('public.mx_ref'::regclass, 1310075, 't'::"char", NULL, NULL)) SELECT citus_internal_add_shard_metadata(relationname, shardid, storagetype, shardminvalue, shardmaxvalue) FROM shard_data;
WITH shard_data(relationname, shardid, storagetype, shardminvalue, shardmaxvalue) AS (VALUES ('public.test_table'::regclass, 1310085, 't'::"char", '-2147483648', '-1073741825'), ('public.test_table'::regclass, 1310086, 't'::"char", '-1073741824', '-1'), ('public.test_table'::regclass, 1310087, 't'::"char", '0', '1073741823'), ('public.test_table'::regclass, 1310088, 't'::"char", '1073741824', '2147483647')) SELECT citus_internal_add_shard_metadata(relationname, shardid, storagetype, shardminvalue, shardmaxvalue) FROM shard_data;
(118 rows)
-- shouldn't work since test_table is MX

View File

@ -40,6 +40,14 @@ select create_distributed_table('mx_call_dist_table_bigint', 'id');
(1 row)
insert into mx_call_dist_table_bigint values (1,1),(1,2),(2,2),(3,3),(3,4);
create table mx_call_dist_table_single_shard(id int, val int);
select create_distributed_table('mx_call_dist_table_single_shard', null);
create_distributed_table
---------------------------------------------------------------------
(1 row)
insert into mx_call_dist_table_single_shard values (2,7),(1,8),(2,8),(1,8),(2,8);
create table mx_call_dist_table_ref(id int, val int);
select create_reference_table('mx_call_dist_table_ref');
create_reference_table
@ -348,6 +356,20 @@ DEBUG: pushing down the function call
28
(1 row)
-- We support colocating with single shard tables
select colocate_proc_with_table('mx_call_func', 'mx_call_dist_table_single_shard'::regclass, 1);
colocate_proc_with_table
---------------------------------------------------------------------
(1 row)
select mx_call_func(2, 0);
DEBUG: pushing down the function call
mx_call_func
---------------------------------------------------------------------
28
(1 row)
-- We don't currently support colocating with replicated tables
select colocate_proc_with_table('mx_call_func', 'mx_call_dist_table_replica'::regclass, 1);
colocate_proc_with_table
@ -803,4 +825,4 @@ SET search_path TO multi_mx_function_call_delegation, public;
RESET client_min_messages;
\set VERBOSITY terse
DROP SCHEMA multi_mx_function_call_delegation CASCADE;
NOTICE: drop cascades to 16 other objects
NOTICE: drop cascades to 17 other objects

View File

@ -40,6 +40,14 @@ select create_distributed_table('mx_call_dist_table_bigint', 'id');
(1 row)
insert into mx_call_dist_table_bigint values (1,1),(1,2),(2,2),(3,3),(3,4);
create table mx_call_dist_table_single_shard(id int, val int);
select create_distributed_table('mx_call_dist_table_single_shard', null);
create_distributed_table
---------------------------------------------------------------------
(1 row)
insert into mx_call_dist_table_single_shard values (2,7),(1,8),(2,8),(1,8),(2,8);
create table mx_call_dist_table_ref(id int, val int);
select create_reference_table('mx_call_dist_table_ref');
create_reference_table
@ -348,6 +356,20 @@ DEBUG: pushing down the function call
28
(1 row)
-- We support colocating with single shard tables
select colocate_proc_with_table('mx_call_func', 'mx_call_dist_table_single_shard'::regclass, 1);
colocate_proc_with_table
---------------------------------------------------------------------
(1 row)
select mx_call_func(2, 0);
DEBUG: pushing down the function call
mx_call_func
---------------------------------------------------------------------
28
(1 row)
-- We don't currently support colocating with replicated tables
select colocate_proc_with_table('mx_call_func', 'mx_call_dist_table_replica'::regclass, 1);
colocate_proc_with_table
@ -803,4 +825,4 @@ SET search_path TO multi_mx_function_call_delegation, public;
RESET client_min_messages;
\set VERBOSITY terse
DROP SCHEMA multi_mx_function_call_delegation CASCADE;
NOTICE: drop cascades to 16 other objects
NOTICE: drop cascades to 17 other objects

View File

@ -0,0 +1,240 @@
CREATE SCHEMA null_dist_key_udfs;
SET search_path TO null_dist_key_udfs;
SET citus.next_shard_id TO 1820000;
SET citus.shard_count TO 32;
SET citus.shard_replication_factor TO 1;
ALTER SEQUENCE pg_catalog.pg_dist_colocationid_seq RESTART 198000;
SET client_min_messages TO ERROR;
SELECT 1 FROM citus_add_node('localhost', :master_port, groupid=>0);
?column?
---------------------------------------------------------------------
1
(1 row)
RESET client_min_messages;
-- test some other udf's with single shard tables
CREATE TABLE null_dist_key_table(a int);
SELECT create_distributed_table('null_dist_key_table', null, colocate_with=>'none', distribution_type=>null);
create_distributed_table
---------------------------------------------------------------------
(1 row)
SELECT truncate_local_data_after_distributing_table('null_dist_key_table');
truncate_local_data_after_distributing_table
---------------------------------------------------------------------
(1 row)
-- should work --
-- insert some data & create an index for table size udf's
INSERT INTO null_dist_key_table VALUES (1), (2), (3);
CREATE INDEX null_dist_key_idx ON null_dist_key_table(a);
SELECT citus_table_size('null_dist_key_table');
citus_table_size
---------------------------------------------------------------------
8192
(1 row)
SELECT citus_total_relation_size('null_dist_key_table');
citus_total_relation_size
---------------------------------------------------------------------
24576
(1 row)
SELECT citus_relation_size('null_dist_key_table');
citus_relation_size
---------------------------------------------------------------------
8192
(1 row)
SELECT * FROM pg_catalog.citus_shard_sizes() WHERE table_name LIKE '%null_dist_key_table%';
table_name | size
---------------------------------------------------------------------
null_dist_key_udfs.null_dist_key_table_1820000 | 24576
(1 row)
BEGIN;
SELECT lock_relation_if_exists('null_dist_key_table', 'ACCESS SHARE');
lock_relation_if_exists
---------------------------------------------------------------------
t
(1 row)
SELECT count(*) FROM pg_locks where relation='null_dist_key_table'::regclass;
count
---------------------------------------------------------------------
1
(1 row)
COMMIT;
SELECT partmethod, repmodel FROM pg_dist_partition WHERE logicalrelid = 'null_dist_key_table'::regclass;
partmethod | repmodel
---------------------------------------------------------------------
n | s
(1 row)
SELECT master_get_table_ddl_events('null_dist_key_table');
master_get_table_ddl_events
---------------------------------------------------------------------
CREATE TABLE null_dist_key_udfs.null_dist_key_table (a integer) USING heap
ALTER TABLE null_dist_key_udfs.null_dist_key_table OWNER TO postgres
CREATE INDEX null_dist_key_idx ON null_dist_key_udfs.null_dist_key_table USING btree (a)
(3 rows)
SELECT column_to_column_name(logicalrelid, partkey)
FROM pg_dist_partition WHERE logicalrelid = 'null_dist_key_table'::regclass;
column_to_column_name
---------------------------------------------------------------------
(1 row)
SELECT column_name_to_column('null_dist_key_table', 'a');
column_name_to_column
---------------------------------------------------------------------
{VAR :varno 1 :varattno 1 :vartype 23 :vartypmod -1 :varcollid 0 :varlevelsup 0 :varnosyn 1 :varattnosyn 1 :location -1}
(1 row)
SELECT master_update_shard_statistics(shardid)
FROM (SELECT shardid FROM pg_dist_shard WHERE logicalrelid='null_dist_key_table'::regclass) as shardid;
master_update_shard_statistics
---------------------------------------------------------------------
8192
(1 row)
SELECT truncate_local_data_after_distributing_table('null_dist_key_table');
truncate_local_data_after_distributing_table
---------------------------------------------------------------------
(1 row)
-- should return a single element array that only includes its own shard id
SELECT shardid=unnest(get_colocated_shard_array(shardid))
FROM (SELECT shardid FROM pg_dist_shard WHERE logicalrelid='null_dist_key_table'::regclass) as shardid;
?column?
---------------------------------------------------------------------
t
(1 row)
BEGIN;
SELECT master_remove_partition_metadata('null_dist_key_table'::regclass::oid, 'null_dist_key_udfs', 'null_dist_key_table');
master_remove_partition_metadata
---------------------------------------------------------------------
(1 row)
-- should print 0
select count(*) from pg_dist_partition where logicalrelid='null_dist_key_table'::regclass;
count
---------------------------------------------------------------------
0
(1 row)
ROLLBACK;
-- should fail --
SELECT update_distributed_table_colocation('null_dist_key_table', colocate_with => 'none');
ERROR: relation null_dist_key_table should be a hash distributed table
SELECT master_create_empty_shard('null_dist_key_table');
ERROR: relation "null_dist_key_table" is a single shard table
DETAIL: We currently don't support creating shards on single shard tables
-- return true
SELECT citus_table_is_visible('null_dist_key_table'::regclass::oid);
citus_table_is_visible
---------------------------------------------------------------------
t
(1 row)
-- return false
SELECT relation_is_a_known_shard('null_dist_key_table');
relation_is_a_known_shard
---------------------------------------------------------------------
f
(1 row)
-- return | false | true |
SELECT citus_table_is_visible(tableName::regclass::oid), relation_is_a_known_shard(tableName::regclass)
FROM (SELECT tableName FROM pg_catalog.pg_tables WHERE tablename LIKE 'null_dist_key_table%') as tableName;
citus_table_is_visible | relation_is_a_known_shard
---------------------------------------------------------------------
t | f
(1 row)
-- should fail, maybe support in the future
SELECT create_reference_table('null_dist_key_table');
ERROR: table "null_dist_key_table" is already distributed
SELECT create_distributed_table('null_dist_key_table', 'a');
ERROR: table "null_dist_key_table" is already distributed
SELECT create_distributed_table_concurrently('null_dist_key_table', 'a');
ERROR: table "null_dist_key_table" is already distributed
SELECT citus_add_local_table_to_metadata('null_dist_key_table');
ERROR: table "null_dist_key_table" is already distributed
-- test altering distribution column, fails for single shard tables
SELECT alter_distributed_table('null_dist_key_table', distribution_column := 'a');
ERROR: relation null_dist_key_table should be a hash distributed table
-- test altering shard count, fails for single shard tables
SELECT alter_distributed_table('null_dist_key_table', shard_count := 6);
ERROR: relation null_dist_key_table should be a hash distributed table
-- test shard splitting udf, fails for single shard tables
SELECT nodeid AS worker_1_node FROM pg_dist_node WHERE nodeport=:worker_1_port \gset
SELECT nodeid AS worker_2_node FROM pg_dist_node WHERE nodeport=:worker_2_port \gset
SELECT citus_split_shard_by_split_points(
1820000,
ARRAY['-1073741826'],
ARRAY[:worker_1_node, :worker_2_node],
'block_writes');
ERROR: Cannot split shard as operation is only supported for hash distributed tables.
SELECT colocationid FROM pg_dist_partition WHERE logicalrelid::text LIKE '%null_dist_key_table%';
colocationid
---------------------------------------------------------------------
198000
(1 row)
-- test alter_table_set_access_method and verify it doesn't change the colocation id
SELECT alter_table_set_access_method('null_dist_key_table', 'columnar');
NOTICE: creating a new table for null_dist_key_udfs.null_dist_key_table
NOTICE: moving the data of null_dist_key_udfs.null_dist_key_table
NOTICE: dropping the old null_dist_key_udfs.null_dist_key_table
NOTICE: renaming the new table to null_dist_key_udfs.null_dist_key_table
alter_table_set_access_method
---------------------------------------------------------------------
(1 row)
SELECT colocationid FROM pg_dist_partition WHERE logicalrelid::text LIKE '%null_dist_key_table%';
colocationid
---------------------------------------------------------------------
198000
(1 row)
-- undistribute
SELECT undistribute_table('null_dist_key_table');
NOTICE: creating a new table for null_dist_key_udfs.null_dist_key_table
NOTICE: moving the data of null_dist_key_udfs.null_dist_key_table
NOTICE: dropping the old null_dist_key_udfs.null_dist_key_table
NOTICE: renaming the new table to null_dist_key_udfs.null_dist_key_table
undistribute_table
---------------------------------------------------------------------
(1 row)
-- verify that the metadata is gone
SELECT COUNT(*) = 0 FROM pg_dist_partition WHERE logicalrelid::text LIKE '%null_dist_key_table%';
?column?
---------------------------------------------------------------------
t
(1 row)
SELECT COUNT(*) = 0 FROM pg_dist_placement WHERE shardid IN (SELECT shardid FROM pg_dist_shard WHERE logicalrelid::text LIKE '%null_dist_key_table%');
?column?
---------------------------------------------------------------------
t
(1 row)
SELECT COUNT(*) = 0 FROM pg_dist_shard WHERE logicalrelid::text LIKE '%null_dist_key_table%';
?column?
---------------------------------------------------------------------
t
(1 row)
DROP SCHEMA null_dist_key_udfs CASCADE;
NOTICE: drop cascades to table null_dist_key_table

View File

@ -1,6 +1,7 @@
-- Tests to check propagation of all view commands
CREATE SCHEMA view_prop_schema;
SET search_path to view_prop_schema;
SET citus.next_shard_id TO 1420195;
-- Check creating views depending on different types of tables
-- and from multiple schemas
-- Check the most basic one
@ -411,7 +412,7 @@ DROP TABLE view_table_2 CASCADE;
NOTICE: drop cascades to 2 other objects
DETAIL: drop cascades to view prop_view_2
drop cascades to constraint f_key_for_local_table on table view_table_3
NOTICE: drop cascades to constraint f_key_for_local_table_1410200 on table view_prop_schema.view_table_3_1410200
NOTICE: drop cascades to constraint f_key_for_local_table_1420200 on table view_prop_schema.view_table_3_1420200
CONTEXT: SQL statement "SELECT citus_drop_all_shards(v_obj.objid, v_obj.schema_name, v_obj.object_name, drop_shards_metadata_only := false)"
PL/pgSQL function citus_drop_trigger() line XX at PERFORM
NOTICE: removing table view_prop_schema.view_table_3 from metadata as it is not connected to any reference tables via foreign keys
@ -935,5 +936,7 @@ DETAIL: "view vv3" circularly depends itself, resolve circular dependency first
RESET citus.enable_unsupported_feature_messages;
RESET citus.enforce_object_restrictions_for_local_objects;
SET client_min_messages TO ERROR;
DROP TABLE public.parent_1, public.employees CASCADE;
DROP SCHEMA view_prop_schema_inner CASCADE;
DROP SCHEMA view_prop_schema, axx CASCADE;
DROP ROLE view_creation_user, alter_view_user, grant_view_user;

View File

@ -33,6 +33,7 @@ test: ref_citus_local_fkeys
test: alter_database_owner
test: distributed_triggers
test: create_single_shard_table
test: single_shard_table_udfs
test: schema_based_sharding
test: multi_test_catalog_views

View File

@ -386,6 +386,11 @@ CREATE TABLE reference_table (a INT);
SELECT create_reference_table('reference_table');
SELECT alter_distributed_table('dist_table', colocate_with:='reference_table');
-- test colocating with single shard table
CREATE TABLE single_shard_table (a INT);
SELECT create_distributed_table('single_shard_table', null);
SELECT alter_distributed_table('dist_table', colocate_with:='single_shard_table');
-- test append table
CREATE TABLE append_table (a INT);
SELECT create_distributed_table('append_table', 'a', 'append');

View File

@ -419,6 +419,11 @@ FROM pg_dist_partition, pg_catalog.pg_dist_object as objects
WHERE pg_dist_partition.logicalrelid = 'replicated_table_func_test_4'::regclass AND
objects.objid = 'eq_with_param_names(macaddr, macaddr)'::regprocedure;
-- a function cannot be colocated with a single shard distributed table when a distribution column is provided
SELECT create_distributed_table('replicated_table_func_test_3', null);
SELECT create_distributed_function('eq_with_param_names(macaddr, macaddr)', 'val1', colocate_with:='replicated_table_func_test_3');
SELECT undistribute_table('replicated_table_func_test_3');
-- a function cannot be colocated with a reference table when a distribution column is provided
SELECT create_reference_table('replicated_table_func_test_3');
SELECT create_distributed_function('eq_with_param_names(macaddr, macaddr)', 'val1', colocate_with:='replicated_table_func_test_3');
@ -704,6 +709,7 @@ TRUNCATE pg_dist_node;
SET client_min_messages TO ERROR;
DROP USER functionuser;
DROP ROLE r1;
SELECT 1 FROM run_command_on_workers($$DROP USER functionuser$$);
-- sync metadata again

View File

@ -565,6 +565,7 @@ BEGIN;
SELECT pg_identify_object_as_address(classid, objid, objsubid) from pg_catalog.pg_dist_object where objid = 'function_propagation_schema.func_in_transaction_for_local_table'::regproc::oid;
CREATE TABLE citus_local_table_to_test_func(l1 int DEFAULT func_in_transaction_for_local_table());
SET LOCAL client_min_messages TO WARNING;
SELECT 1 FROM master_add_node('localhost', :master_port, groupid => 0);
SELECT citus_add_local_table_to_metadata('citus_local_table_to_test_func');
@ -717,6 +718,9 @@ SELECT create_distributed_table('tbl_to_colocate', 'a');
-- first test colocating function with a ref table
CREATE TABLE tbl_to_colocate_ref (a int);
SELECT create_reference_table('tbl_to_colocate_ref');
-- test colocating function with single shard table
CREATE TABLE single_shard_tbl (a int);
SELECT create_distributed_table('single_shard_tbl', null);
CREATE FUNCTION func_to_colocate (a int) returns int as $$select 1;$$ language sql;
-- see the empty pg_dist_object entries
@ -727,6 +731,11 @@ SELECT create_distributed_function('func_to_colocate(int)', colocate_with:='tbl_
-- see the pg_dist_object entry
SELECT distribution_argument_index, colocationid, force_delegation FROM pg_catalog.pg_dist_object WHERE objid = 'func_to_colocate'::regproc;
-- colocate the function with single shard table table
SELECT create_distributed_function('func_to_colocate(int)', colocate_with:='single_shard_tbl');
-- see the pg_dist_object entry
SELECT distribution_argument_index, colocationid, force_delegation FROM pg_catalog.pg_dist_object WHERE objid = 'func_to_colocate'::regproc;
-- convert to non-delegated
SELECT create_distributed_function('func_to_colocate(int)');
-- show that the pg_dist_object fields are gone

View File

@ -62,9 +62,17 @@ reset citus.shard_replication_factor;
-- considered as an MX table
UPDATE pg_dist_partition SET repmodel='s' WHERE logicalrelid='mx_test_table'::regclass;
-- add a single shard table and verify the creation commands are included in the activate node snapshot
CREATE TABLE single_shard_tbl(a int);
SELECT create_distributed_table('single_shard_tbl', null);
INSERT INTO single_shard_tbl VALUES (1);
-- Show that the created MX table is and its sequences are included in the activate node snapshot
SELECT unnest(activate_node_snapshot()) order by 1;
-- Drop single shard table
DROP TABLE single_shard_tbl;
-- Show that CREATE INDEX commands are included in the activate node snapshot
CREATE INDEX mx_index ON mx_test_table(col_2);
SELECT unnest(activate_node_snapshot()) order by 1;
@ -187,6 +195,10 @@ SELECT 1 FROM citus_activate_node('localhost', :worker_1_port);
CREATE TABLE mx_query_test (a int, b text, c int);
SELECT create_distributed_table('mx_query_test', 'a');
CREATE TABLE single_shard_tbl(a int);
SELECT create_distributed_table('single_shard_tbl', null);
INSERT INTO single_shard_tbl VALUES (1);
SELECT repmodel FROM pg_dist_partition WHERE logicalrelid='mx_query_test'::regclass;
INSERT INTO mx_query_test VALUES (1, 'one', 1);
@ -200,11 +212,16 @@ SELECT * FROM mx_query_test ORDER BY a;
INSERT INTO mx_query_test VALUES (6, 'six', 36);
UPDATE mx_query_test SET c = 25 WHERE a = 5;
SELECT * FROM single_shard_tbl ORDER BY a;
INSERT INTO single_shard_tbl VALUES (2);
\c - - - :master_port
SELECT * FROM mx_query_test ORDER BY a;
SELECT * FROM single_shard_tbl ORDER BY a;
\c - - - :master_port
DROP TABLE mx_query_test;
DROP TABLE single_shard_tbl;
-- Check that stop_metadata_sync_to_node function sets hasmetadata of the node to false
\c - - - :master_port

View File

@ -28,6 +28,10 @@ create table mx_call_dist_table_bigint(id bigint, val bigint);
select create_distributed_table('mx_call_dist_table_bigint', 'id');
insert into mx_call_dist_table_bigint values (1,1),(1,2),(2,2),(3,3),(3,4);
create table mx_call_dist_table_single_shard(id int, val int);
select create_distributed_table('mx_call_dist_table_single_shard', null);
insert into mx_call_dist_table_single_shard values (2,7),(1,8),(2,8),(1,8),(2,8);
create table mx_call_dist_table_ref(id int, val int);
select create_reference_table('mx_call_dist_table_ref');
insert into mx_call_dist_table_ref values (2,7),(1,8),(2,8),(1,8),(2,8);
@ -157,6 +161,10 @@ select mx_call_func(2, 0);
select colocate_proc_with_table('mx_call_func', 'mx_call_dist_table_ref'::regclass, 1);
select mx_call_func(2, 0);
-- We support colocating with single shard tables
select colocate_proc_with_table('mx_call_func', 'mx_call_dist_table_single_shard'::regclass, 1);
select mx_call_func(2, 0);
-- We don't currently support colocating with replicated tables
select colocate_proc_with_table('mx_call_func', 'mx_call_dist_table_replica'::regclass, 1);
select mx_call_func(2, 0);

View File

@ -0,0 +1,105 @@
CREATE SCHEMA null_dist_key_udfs;
SET search_path TO null_dist_key_udfs;
SET citus.next_shard_id TO 1820000;
SET citus.shard_count TO 32;
SET citus.shard_replication_factor TO 1;
ALTER SEQUENCE pg_catalog.pg_dist_colocationid_seq RESTART 198000;
SET client_min_messages TO ERROR;
SELECT 1 FROM citus_add_node('localhost', :master_port, groupid=>0);
RESET client_min_messages;
-- test some other udf's with single shard tables
CREATE TABLE null_dist_key_table(a int);
SELECT create_distributed_table('null_dist_key_table', null, colocate_with=>'none', distribution_type=>null);
SELECT truncate_local_data_after_distributing_table('null_dist_key_table');
-- should work --
-- insert some data & create an index for table size udf's
INSERT INTO null_dist_key_table VALUES (1), (2), (3);
CREATE INDEX null_dist_key_idx ON null_dist_key_table(a);
SELECT citus_table_size('null_dist_key_table');
SELECT citus_total_relation_size('null_dist_key_table');
SELECT citus_relation_size('null_dist_key_table');
SELECT * FROM pg_catalog.citus_shard_sizes() WHERE table_name LIKE '%null_dist_key_table%';
BEGIN;
SELECT lock_relation_if_exists('null_dist_key_table', 'ACCESS SHARE');
SELECT count(*) FROM pg_locks where relation='null_dist_key_table'::regclass;
COMMIT;
SELECT partmethod, repmodel FROM pg_dist_partition WHERE logicalrelid = 'null_dist_key_table'::regclass;
SELECT master_get_table_ddl_events('null_dist_key_table');
SELECT column_to_column_name(logicalrelid, partkey)
FROM pg_dist_partition WHERE logicalrelid = 'null_dist_key_table'::regclass;
SELECT column_name_to_column('null_dist_key_table', 'a');
SELECT master_update_shard_statistics(shardid)
FROM (SELECT shardid FROM pg_dist_shard WHERE logicalrelid='null_dist_key_table'::regclass) as shardid;
SELECT truncate_local_data_after_distributing_table('null_dist_key_table');
-- should return a single element array that only includes its own shard id
SELECT shardid=unnest(get_colocated_shard_array(shardid))
FROM (SELECT shardid FROM pg_dist_shard WHERE logicalrelid='null_dist_key_table'::regclass) as shardid;
BEGIN;
SELECT master_remove_partition_metadata('null_dist_key_table'::regclass::oid, 'null_dist_key_udfs', 'null_dist_key_table');
-- should print 0
select count(*) from pg_dist_partition where logicalrelid='null_dist_key_table'::regclass;
ROLLBACK;
-- should fail --
SELECT update_distributed_table_colocation('null_dist_key_table', colocate_with => 'none');
SELECT master_create_empty_shard('null_dist_key_table');
-- return true
SELECT citus_table_is_visible('null_dist_key_table'::regclass::oid);
-- return false
SELECT relation_is_a_known_shard('null_dist_key_table');
-- return | false | true |
SELECT citus_table_is_visible(tableName::regclass::oid), relation_is_a_known_shard(tableName::regclass)
FROM (SELECT tableName FROM pg_catalog.pg_tables WHERE tablename LIKE 'null_dist_key_table%') as tableName;
-- should fail, maybe support in the future
SELECT create_reference_table('null_dist_key_table');
SELECT create_distributed_table('null_dist_key_table', 'a');
SELECT create_distributed_table_concurrently('null_dist_key_table', 'a');
SELECT citus_add_local_table_to_metadata('null_dist_key_table');
-- test altering distribution column, fails for single shard tables
SELECT alter_distributed_table('null_dist_key_table', distribution_column := 'a');
-- test altering shard count, fails for single shard tables
SELECT alter_distributed_table('null_dist_key_table', shard_count := 6);
-- test shard splitting udf, fails for single shard tables
SELECT nodeid AS worker_1_node FROM pg_dist_node WHERE nodeport=:worker_1_port \gset
SELECT nodeid AS worker_2_node FROM pg_dist_node WHERE nodeport=:worker_2_port \gset
SELECT citus_split_shard_by_split_points(
1820000,
ARRAY['-1073741826'],
ARRAY[:worker_1_node, :worker_2_node],
'block_writes');
SELECT colocationid FROM pg_dist_partition WHERE logicalrelid::text LIKE '%null_dist_key_table%';
-- test alter_table_set_access_method and verify it doesn't change the colocation id
SELECT alter_table_set_access_method('null_dist_key_table', 'columnar');
SELECT colocationid FROM pg_dist_partition WHERE logicalrelid::text LIKE '%null_dist_key_table%';
-- undistribute
SELECT undistribute_table('null_dist_key_table');
-- verify that the metadata is gone
SELECT COUNT(*) = 0 FROM pg_dist_partition WHERE logicalrelid::text LIKE '%null_dist_key_table%';
SELECT COUNT(*) = 0 FROM pg_dist_placement WHERE shardid IN (SELECT shardid FROM pg_dist_shard WHERE logicalrelid::text LIKE '%null_dist_key_table%');
SELECT COUNT(*) = 0 FROM pg_dist_shard WHERE logicalrelid::text LIKE '%null_dist_key_table%';
DROP SCHEMA null_dist_key_udfs CASCADE;

View File

@ -1,6 +1,7 @@
-- Tests to check propagation of all view commands
CREATE SCHEMA view_prop_schema;
SET search_path to view_prop_schema;
SET citus.next_shard_id TO 1420195;
-- Check creating views depending on different types of tables
-- and from multiple schemas
@ -542,5 +543,7 @@ CREATE OR REPLACE VIEW vv3 as SELECT * FROM vv4;
RESET citus.enable_unsupported_feature_messages;
RESET citus.enforce_object_restrictions_for_local_objects;
SET client_min_messages TO ERROR;
DROP TABLE public.parent_1, public.employees CASCADE;
DROP SCHEMA view_prop_schema_inner CASCADE;
DROP SCHEMA view_prop_schema, axx CASCADE;
DROP ROLE view_creation_user, alter_view_user, grant_view_user;