diff --git a/src/backend/distributed/citus.control b/src/backend/distributed/citus.control index 5367c84a9..83b7cda4d 100644 --- a/src/backend/distributed/citus.control +++ b/src/backend/distributed/citus.control @@ -1,6 +1,6 @@ # Citus extension comment = 'Citus distributed database' -default_version = '11.3-1' +default_version = '11.3-2' module_pathname = '$libdir/citus' relocatable = false schema = pg_catalog diff --git a/src/backend/distributed/metadata/metadata_utility.c b/src/backend/distributed/metadata/metadata_utility.c index 9fd4290ba..4155e5b97 100644 --- a/src/backend/distributed/metadata/metadata_utility.c +++ b/src/backend/distributed/metadata/metadata_utility.c @@ -91,7 +91,8 @@ static bool DistributedTableSizeOnWorker(WorkerNode *workerNode, Oid relationId, SizeQueryType sizeQueryType, bool failOnError, uint64 *tableSize); static List * ShardIntervalsOnWorkerGroup(WorkerNode *workerNode, Oid relationId); -static char * GenerateShardStatisticsQueryForShardList(List *shardIntervalList); +static char * GenerateShardIdNameValuesForShardList(List *shardIntervalList, + bool firstValue); static char * GenerateSizeQueryForRelationNameList(List *quotedShardNames, char *sizeFunction); static char * GetWorkerPartitionedSizeUDFNameBySizeQueryType(SizeQueryType sizeQueryType); @@ -101,10 +102,10 @@ static char * GenerateAllShardStatisticsQueryForNode(WorkerNode *workerNode, static List * GenerateShardStatisticsQueryList(List *workerNodeList, List *citusTableIds); static void ErrorIfNotSuitableToGetSize(Oid relationId); static List * OpenConnectionToNodes(List *workerNodeList); -static void ReceiveShardNameAndSizeResults(List *connectionList, - Tuplestorestate *tupleStore, - TupleDesc tupleDescriptor); -static void AppendShardSizeQuery(StringInfo selectQuery, ShardInterval *shardInterval); +static void ReceiveShardIdAndSizeResults(List *connectionList, + Tuplestorestate *tupleStore, + TupleDesc tupleDescriptor); +static void AppendShardIdNameValues(StringInfo selectQuery, ShardInterval *shardInterval); static HeapTuple CreateDiskSpaceTuple(TupleDesc tupleDesc, uint64 availableBytes, uint64 totalBytes); @@ -253,7 +254,7 @@ GetNodeDiskSpaceStatsForConnection(MultiConnection *connection, uint64 *availabl /* - * citus_shard_sizes returns all shard names and their sizes. + * citus_shard_sizes returns all shard ids and their sizes. */ Datum citus_shard_sizes(PG_FUNCTION_ARGS) @@ -271,7 +272,7 @@ citus_shard_sizes(PG_FUNCTION_ARGS) TupleDesc tupleDescriptor = NULL; Tuplestorestate *tupleStore = SetupTuplestore(fcinfo, &tupleDescriptor); - ReceiveShardNameAndSizeResults(connectionList, tupleStore, tupleDescriptor); + ReceiveShardIdAndSizeResults(connectionList, tupleStore, tupleDescriptor); PG_RETURN_VOID(); } @@ -446,12 +447,12 @@ GenerateShardStatisticsQueryList(List *workerNodeList, List *citusTableIds) /* - * ReceiveShardNameAndSizeResults receives shard name and size results from the given + * ReceiveShardIdAndSizeResults receives shard id and size results from the given * connection list. */ static void -ReceiveShardNameAndSizeResults(List *connectionList, Tuplestorestate *tupleStore, - TupleDesc tupleDescriptor) +ReceiveShardIdAndSizeResults(List *connectionList, Tuplestorestate *tupleStore, + TupleDesc tupleDescriptor) { MultiConnection *connection = NULL; foreach_ptr(connection, connectionList) @@ -488,13 +489,9 @@ ReceiveShardNameAndSizeResults(List *connectionList, Tuplestorestate *tupleStore memset(values, 0, sizeof(values)); memset(isNulls, false, sizeof(isNulls)); - /* format is [0] shard id, [1] shard name, [2] size */ - char *tableName = PQgetvalue(result, rowIndex, 1); - Datum resultStringDatum = CStringGetDatum(tableName); - Datum textDatum = DirectFunctionCall1(textin, resultStringDatum); - - values[0] = textDatum; - values[1] = ParseIntField(result, rowIndex, 2); + /* format is [0] shard id, [1] size */ + values[0] = ParseIntField(result, rowIndex, 0); + values[1] = ParseIntField(result, rowIndex, 1); tuplestore_putvalues(tupleStore, tupleDescriptor, values, isNulls); } @@ -920,6 +917,12 @@ static char * GenerateAllShardStatisticsQueryForNode(WorkerNode *workerNode, List *citusTableIds) { StringInfo allShardStatisticsQuery = makeStringInfo(); + bool insertedValues = false; + + appendStringInfoString(allShardStatisticsQuery, "SELECT shard_id, "); + appendStringInfo(allShardStatisticsQuery, PG_TOTAL_RELATION_SIZE_FUNCTION, + "table_name"); + appendStringInfoString(allShardStatisticsQuery, " FROM (VALUES "); Oid relationId = InvalidOid; foreach_oid(relationId, citusTableIds) @@ -934,34 +937,49 @@ GenerateAllShardStatisticsQueryForNode(WorkerNode *workerNode, List *citusTableI { List *shardIntervalsOnNode = ShardIntervalsOnWorkerGroup(workerNode, relationId); - char *shardStatisticsQuery = - GenerateShardStatisticsQueryForShardList(shardIntervalsOnNode); - appendStringInfoString(allShardStatisticsQuery, shardStatisticsQuery); + if (list_length(shardIntervalsOnNode) == 0) + { + relation_close(relation, AccessShareLock); + continue; + } + char *shardIdNameValues = + GenerateShardIdNameValuesForShardList(shardIntervalsOnNode, + !insertedValues); + insertedValues = true; + appendStringInfoString(allShardStatisticsQuery, shardIdNameValues); relation_close(relation, AccessShareLock); } } - /* Add a dummy entry so that UNION ALL doesn't complain */ - appendStringInfo(allShardStatisticsQuery, "SELECT 0::bigint, NULL::text, 0::bigint;"); + if (!insertedValues) + { + return "SELECT 0 AS shard_id, '' AS table_name LIMIT 0"; + } + appendStringInfoString(allShardStatisticsQuery, ") t(shard_id, table_name) " + "WHERE to_regclass(table_name) IS NOT NULL"); return allShardStatisticsQuery->data; } /* - * GenerateShardStatisticsQueryForShardList generates a query that returns: - * SELECT shard_id, shard_name, shard_size for all shards in the list + * GenerateShardIdNameValuesForShardList generates a list of (shard_id, shard_name) values + * for all shards in the list */ static char * -GenerateShardStatisticsQueryForShardList(List *shardIntervalList) +GenerateShardIdNameValuesForShardList(List *shardIntervalList, bool firstValue) { StringInfo selectQuery = makeStringInfo(); ShardInterval *shardInterval = NULL; foreach_ptr(shardInterval, shardIntervalList) { - AppendShardSizeQuery(selectQuery, shardInterval); - appendStringInfo(selectQuery, " UNION ALL "); + if (!firstValue) + { + appendStringInfoString(selectQuery, ", "); + } + firstValue = false; + AppendShardIdNameValues(selectQuery, shardInterval); } return selectQuery->data; @@ -969,11 +987,10 @@ GenerateShardStatisticsQueryForShardList(List *shardIntervalList) /* - * AppendShardSizeQuery appends a query in the following form to selectQuery - * SELECT shard_id, shard_name, shard_size + * AppendShardIdNameValues appends (shard_id, shard_name) for shard */ static void -AppendShardSizeQuery(StringInfo selectQuery, ShardInterval *shardInterval) +AppendShardIdNameValues(StringInfo selectQuery, ShardInterval *shardInterval) { uint64 shardId = shardInterval->shardId; Oid schemaId = get_rel_namespace(shardInterval->relationId); @@ -985,9 +1002,7 @@ AppendShardSizeQuery(StringInfo selectQuery, ShardInterval *shardInterval) char *shardQualifiedName = quote_qualified_identifier(schemaName, shardName); char *quotedShardName = quote_literal_cstr(shardQualifiedName); - appendStringInfo(selectQuery, "SELECT " UINT64_FORMAT " AS shard_id, ", shardId); - appendStringInfo(selectQuery, "%s AS shard_name, ", quotedShardName); - appendStringInfo(selectQuery, PG_TOTAL_RELATION_SIZE_FUNCTION, quotedShardName); + appendStringInfo(selectQuery, "(" UINT64_FORMAT ", %s)", shardId, quotedShardName); } diff --git a/src/backend/distributed/operations/stage_protocol.c b/src/backend/distributed/operations/stage_protocol.c index ce9fe3f31..0cc21db3f 100644 --- a/src/backend/distributed/operations/stage_protocol.c +++ b/src/backend/distributed/operations/stage_protocol.c @@ -855,7 +855,7 @@ ProcessShardStatisticsRow(PGresult *result, int64 rowIndex, uint64 *shardId, return false; } - *shardSize = ParseIntField(result, rowIndex, 2); + *shardSize = ParseIntField(result, rowIndex, 1); return true; } diff --git a/src/backend/distributed/sql/citus--11.3-1--11.3-2.sql b/src/backend/distributed/sql/citus--11.3-1--11.3-2.sql new file mode 100644 index 000000000..e7f0864f1 --- /dev/null +++ b/src/backend/distributed/sql/citus--11.3-1--11.3-2.sql @@ -0,0 +1,9 @@ +DROP VIEW citus_shards; +DROP VIEW IF EXISTS pg_catalog.citus_tables; +DROP VIEW IF EXISTS public.citus_tables; +DROP FUNCTION citus_shard_sizes; + +#include "udfs/citus_shard_sizes/11.3-2.sql" + +#include "udfs/citus_shards/11.3-2.sql" +#include "udfs/citus_tables/11.3-2.sql" diff --git a/src/backend/distributed/sql/downgrades/citus--11.3-2--11.3-1.sql b/src/backend/distributed/sql/downgrades/citus--11.3-2--11.3-1.sql new file mode 100644 index 000000000..78dacd59a --- /dev/null +++ b/src/backend/distributed/sql/downgrades/citus--11.3-2--11.3-1.sql @@ -0,0 +1,13 @@ +DROP VIEW IF EXISTS public.citus_tables; +DROP VIEW IF EXISTS pg_catalog.citus_tables; + +DROP VIEW pg_catalog.citus_shards; +DROP FUNCTION pg_catalog.citus_shard_sizes; +#include "../udfs/citus_shard_sizes/10.0-1.sql" +-- citus_shards/11.1-1.sql tries to create citus_shards in pg_catalog but it is not allowed. +-- Here we use citus_shards/10.0-1.sql to properly create the view in citus schema and +-- then alter it to pg_catalog, so citus_shards/11.1-1.sql can REPLACE it without any errors. +#include "../udfs/citus_shards/10.0-1.sql" + +#include "../udfs/citus_tables/11.1-1.sql" +#include "../udfs/citus_shards/11.1-1.sql" diff --git a/src/backend/distributed/sql/udfs/citus_shard_sizes/11.3-2.sql b/src/backend/distributed/sql/udfs/citus_shard_sizes/11.3-2.sql new file mode 100644 index 000000000..3a647a57b --- /dev/null +++ b/src/backend/distributed/sql/udfs/citus_shard_sizes/11.3-2.sql @@ -0,0 +1,6 @@ +CREATE OR REPLACE FUNCTION pg_catalog.citus_shard_sizes(OUT shard_id int, OUT size bigint) + RETURNS SETOF RECORD + LANGUAGE C STRICT + AS 'MODULE_PATHNAME', $$citus_shard_sizes$$; + COMMENT ON FUNCTION pg_catalog.citus_shard_sizes(OUT shard_id int, OUT size bigint) + IS 'returns shards sizes across citus cluster'; diff --git a/src/backend/distributed/sql/udfs/citus_shard_sizes/latest.sql b/src/backend/distributed/sql/udfs/citus_shard_sizes/latest.sql index fd619b0a2..3a647a57b 100644 --- a/src/backend/distributed/sql/udfs/citus_shard_sizes/latest.sql +++ b/src/backend/distributed/sql/udfs/citus_shard_sizes/latest.sql @@ -1,6 +1,6 @@ -CREATE FUNCTION pg_catalog.citus_shard_sizes(OUT table_name text, OUT size bigint) +CREATE OR REPLACE FUNCTION pg_catalog.citus_shard_sizes(OUT shard_id int, OUT size bigint) RETURNS SETOF RECORD LANGUAGE C STRICT AS 'MODULE_PATHNAME', $$citus_shard_sizes$$; - COMMENT ON FUNCTION pg_catalog.citus_shard_sizes(OUT table_name text, OUT size bigint) + COMMENT ON FUNCTION pg_catalog.citus_shard_sizes(OUT shard_id int, OUT size bigint) IS 'returns shards sizes across citus cluster'; diff --git a/src/backend/distributed/sql/udfs/citus_shards/11.3-2.sql b/src/backend/distributed/sql/udfs/citus_shards/11.3-2.sql new file mode 100644 index 000000000..3b08a5463 --- /dev/null +++ b/src/backend/distributed/sql/udfs/citus_shards/11.3-2.sql @@ -0,0 +1,46 @@ +CREATE OR REPLACE VIEW citus.citus_shards AS +SELECT + pg_dist_shard.logicalrelid AS table_name, + pg_dist_shard.shardid, + shard_name(pg_dist_shard.logicalrelid, pg_dist_shard.shardid) as shard_name, + CASE WHEN partkey IS NOT NULL THEN 'distributed' WHEN repmodel = 't' THEN 'reference' ELSE 'local' END AS citus_table_type, + colocationid AS colocation_id, + pg_dist_node.nodename, + pg_dist_node.nodeport, + size as shard_size +FROM + pg_dist_shard +JOIN + pg_dist_placement +ON + pg_dist_shard.shardid = pg_dist_placement.shardid +JOIN + pg_dist_node +ON + pg_dist_placement.groupid = pg_dist_node.groupid +JOIN + pg_dist_partition +ON + pg_dist_partition.logicalrelid = pg_dist_shard.logicalrelid +LEFT JOIN + (SELECT shard_id, max(size) as size from citus_shard_sizes() GROUP BY shard_id) as shard_sizes +ON + pg_dist_shard.shardid = shard_sizes.shard_id +WHERE + pg_dist_placement.shardstate = 1 +AND + -- filter out tables owned by extensions + pg_dist_partition.logicalrelid NOT IN ( + SELECT + objid + FROM + pg_depend + WHERE + classid = 'pg_class'::regclass AND refclassid = 'pg_extension'::regclass AND deptype = 'e' + ) +ORDER BY + pg_dist_shard.logicalrelid::text, shardid +; + +ALTER VIEW citus.citus_shards SET SCHEMA pg_catalog; +GRANT SELECT ON pg_catalog.citus_shards TO public; diff --git a/src/backend/distributed/sql/udfs/citus_shards/latest.sql b/src/backend/distributed/sql/udfs/citus_shards/latest.sql index 08e039899..3b08a5463 100644 --- a/src/backend/distributed/sql/udfs/citus_shards/latest.sql +++ b/src/backend/distributed/sql/udfs/citus_shards/latest.sql @@ -1,4 +1,4 @@ -CREATE OR REPLACE VIEW pg_catalog.citus_shards AS +CREATE OR REPLACE VIEW citus.citus_shards AS SELECT pg_dist_shard.logicalrelid AS table_name, pg_dist_shard.shardid, @@ -23,7 +23,7 @@ JOIN ON pg_dist_partition.logicalrelid = pg_dist_shard.logicalrelid LEFT JOIN - (SELECT (regexp_matches(table_name,'_(\d+)$'))[1]::int as shard_id, max(size) as size from citus_shard_sizes() GROUP BY shard_id) as shard_sizes + (SELECT shard_id, max(size) as size from citus_shard_sizes() GROUP BY shard_id) as shard_sizes ON pg_dist_shard.shardid = shard_sizes.shard_id WHERE @@ -42,4 +42,5 @@ ORDER BY pg_dist_shard.logicalrelid::text, shardid ; +ALTER VIEW citus.citus_shards SET SCHEMA pg_catalog; GRANT SELECT ON pg_catalog.citus_shards TO public; diff --git a/src/backend/distributed/sql/udfs/citus_tables/11.3-2.sql b/src/backend/distributed/sql/udfs/citus_tables/11.3-2.sql new file mode 100644 index 000000000..ead0b4923 --- /dev/null +++ b/src/backend/distributed/sql/udfs/citus_tables/11.3-2.sql @@ -0,0 +1,55 @@ +DO $$ +declare +citus_tables_create_query text; +BEGIN +citus_tables_create_query=$CTCQ$ + CREATE OR REPLACE VIEW %I.citus_tables AS + SELECT + logicalrelid AS table_name, + CASE WHEN partkey IS NOT NULL THEN 'distributed' ELSE + CASE when repmodel = 't' THEN 'reference' ELSE 'local' END + END AS citus_table_type, + coalesce(column_to_column_name(logicalrelid, partkey), '') AS distribution_column, + colocationid AS colocation_id, + pg_size_pretty(table_sizes.table_size) AS table_size, + (select count(*) from pg_dist_shard where logicalrelid = p.logicalrelid) AS shard_count, + pg_get_userbyid(relowner) AS table_owner, + amname AS access_method + FROM + pg_dist_partition p + JOIN + pg_class c ON (p.logicalrelid = c.oid) + LEFT JOIN + pg_am a ON (a.oid = c.relam) + JOIN + ( + SELECT ds.logicalrelid AS table_id, SUM(css.size) AS table_size + FROM citus_shard_sizes() css, pg_dist_shard ds + WHERE css.shard_id = ds.shardid + GROUP BY ds.logicalrelid + ) table_sizes ON (table_sizes.table_id = p.logicalrelid) + WHERE + -- filter out tables owned by extensions + logicalrelid NOT IN ( + SELECT + objid + FROM + pg_depend + WHERE + classid = 'pg_class'::regclass AND refclassid = 'pg_extension'::regclass AND deptype = 'e' + ) + ORDER BY + logicalrelid::text; +$CTCQ$; + +IF EXISTS (SELECT 1 FROM pg_namespace WHERE nspname = 'public') THEN + EXECUTE format(citus_tables_create_query, 'public'); + GRANT SELECT ON public.citus_tables TO public; +ELSE + EXECUTE format(citus_tables_create_query, 'citus'); + ALTER VIEW citus.citus_tables SET SCHEMA pg_catalog; + GRANT SELECT ON pg_catalog.citus_tables TO public; +END IF; + +END; +$$; diff --git a/src/backend/distributed/sql/udfs/citus_tables/latest.sql b/src/backend/distributed/sql/udfs/citus_tables/latest.sql index ee66852a4..ead0b4923 100644 --- a/src/backend/distributed/sql/udfs/citus_tables/latest.sql +++ b/src/backend/distributed/sql/udfs/citus_tables/latest.sql @@ -11,7 +11,7 @@ citus_tables_create_query=$CTCQ$ END AS citus_table_type, coalesce(column_to_column_name(logicalrelid, partkey), '') AS distribution_column, colocationid AS colocation_id, - pg_size_pretty(citus_total_relation_size(logicalrelid, fail_on_error := false)) AS table_size, + pg_size_pretty(table_sizes.table_size) AS table_size, (select count(*) from pg_dist_shard where logicalrelid = p.logicalrelid) AS shard_count, pg_get_userbyid(relowner) AS table_owner, amname AS access_method @@ -21,6 +21,13 @@ citus_tables_create_query=$CTCQ$ pg_class c ON (p.logicalrelid = c.oid) LEFT JOIN pg_am a ON (a.oid = c.relam) + JOIN + ( + SELECT ds.logicalrelid AS table_id, SUM(css.size) AS table_size + FROM citus_shard_sizes() css, pg_dist_shard ds + WHERE css.shard_id = ds.shardid + GROUP BY ds.logicalrelid + ) table_sizes ON (table_sizes.table_id = p.logicalrelid) WHERE -- filter out tables owned by extensions logicalrelid NOT IN ( diff --git a/src/include/distributed/metadata_utility.h b/src/include/distributed/metadata_utility.h index e27f3df22..cd9c6c33d 100644 --- a/src/include/distributed/metadata_utility.h +++ b/src/include/distributed/metadata_utility.h @@ -41,7 +41,7 @@ #define WORKER_PARTITIONED_RELATION_TOTAL_SIZE_FUNCTION \ "worker_partitioned_relation_total_size(%s)" -#define SHARD_SIZES_COLUMN_COUNT (3) +#define SHARD_SIZES_COLUMN_COUNT (2) /* * Flag to keep track of whether the process is currently in a function converting the diff --git a/src/test/regress/expected/citus_update_table_statistics.out b/src/test/regress/expected/citus_update_table_statistics.out index 031104c53..21b05c138 100644 --- a/src/test/regress/expected/citus_update_table_statistics.out +++ b/src/test/regress/expected/citus_update_table_statistics.out @@ -64,11 +64,11 @@ SET citus.multi_shard_modify_mode TO sequential; SELECT citus_update_table_statistics('test_table_statistics_hash'); NOTICE: issuing BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED;SELECT assign_distributed_transaction_id(xx, xx, 'xxxxxxx'); DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx -NOTICE: issuing SELECT 981000 AS shard_id, 'public.test_table_statistics_hash_981000' AS shard_name, pg_total_relation_size('public.test_table_statistics_hash_981000') UNION ALL SELECT 981001 AS shard_id, 'public.test_table_statistics_hash_981001' AS shard_name, pg_total_relation_size('public.test_table_statistics_hash_981001') UNION ALL SELECT 981002 AS shard_id, 'public.test_table_statistics_hash_981002' AS shard_name, pg_total_relation_size('public.test_table_statistics_hash_981002') UNION ALL SELECT 981003 AS shard_id, 'public.test_table_statistics_hash_981003' AS shard_name, pg_total_relation_size('public.test_table_statistics_hash_981003') UNION ALL SELECT 981004 AS shard_id, 'public.test_table_statistics_hash_981004' AS shard_name, pg_total_relation_size('public.test_table_statistics_hash_981004') UNION ALL SELECT 981005 AS shard_id, 'public.test_table_statistics_hash_981005' AS shard_name, pg_total_relation_size('public.test_table_statistics_hash_981005') UNION ALL SELECT 981006 AS shard_id, 'public.test_table_statistics_hash_981006' AS shard_name, pg_total_relation_size('public.test_table_statistics_hash_981006') UNION ALL SELECT 981007 AS shard_id, 'public.test_table_statistics_hash_981007' AS shard_name, pg_total_relation_size('public.test_table_statistics_hash_981007') UNION ALL SELECT 0::bigint, NULL::text, 0::bigint; +NOTICE: issuing SELECT shard_id, pg_total_relation_size(table_name) FROM (VALUES (981000, 'public.test_table_statistics_hash_981000'), (981001, 'public.test_table_statistics_hash_981001'), (981002, 'public.test_table_statistics_hash_981002'), (981003, 'public.test_table_statistics_hash_981003'), (981004, 'public.test_table_statistics_hash_981004'), (981005, 'public.test_table_statistics_hash_981005'), (981006, 'public.test_table_statistics_hash_981006'), (981007, 'public.test_table_statistics_hash_981007')) t(shard_id, table_name) WHERE to_regclass(table_name) IS NOT NULL DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx NOTICE: issuing BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED;SELECT assign_distributed_transaction_id(xx, xx, 'xxxxxxx'); DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx -NOTICE: issuing SELECT 981000 AS shard_id, 'public.test_table_statistics_hash_981000' AS shard_name, pg_total_relation_size('public.test_table_statistics_hash_981000') UNION ALL SELECT 981001 AS shard_id, 'public.test_table_statistics_hash_981001' AS shard_name, pg_total_relation_size('public.test_table_statistics_hash_981001') UNION ALL SELECT 981002 AS shard_id, 'public.test_table_statistics_hash_981002' AS shard_name, pg_total_relation_size('public.test_table_statistics_hash_981002') UNION ALL SELECT 981003 AS shard_id, 'public.test_table_statistics_hash_981003' AS shard_name, pg_total_relation_size('public.test_table_statistics_hash_981003') UNION ALL SELECT 981004 AS shard_id, 'public.test_table_statistics_hash_981004' AS shard_name, pg_total_relation_size('public.test_table_statistics_hash_981004') UNION ALL SELECT 981005 AS shard_id, 'public.test_table_statistics_hash_981005' AS shard_name, pg_total_relation_size('public.test_table_statistics_hash_981005') UNION ALL SELECT 981006 AS shard_id, 'public.test_table_statistics_hash_981006' AS shard_name, pg_total_relation_size('public.test_table_statistics_hash_981006') UNION ALL SELECT 981007 AS shard_id, 'public.test_table_statistics_hash_981007' AS shard_name, pg_total_relation_size('public.test_table_statistics_hash_981007') UNION ALL SELECT 0::bigint, NULL::text, 0::bigint; +NOTICE: issuing SELECT shard_id, pg_total_relation_size(table_name) FROM (VALUES (981000, 'public.test_table_statistics_hash_981000'), (981001, 'public.test_table_statistics_hash_981001'), (981002, 'public.test_table_statistics_hash_981002'), (981003, 'public.test_table_statistics_hash_981003'), (981004, 'public.test_table_statistics_hash_981004'), (981005, 'public.test_table_statistics_hash_981005'), (981006, 'public.test_table_statistics_hash_981006'), (981007, 'public.test_table_statistics_hash_981007')) t(shard_id, table_name) WHERE to_regclass(table_name) IS NOT NULL DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx NOTICE: issuing COMMIT DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx @@ -152,11 +152,11 @@ SET citus.multi_shard_modify_mode TO sequential; SELECT citus_update_table_statistics('test_table_statistics_append'); NOTICE: issuing BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED;SELECT assign_distributed_transaction_id(xx, xx, 'xxxxxxx'); DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx -NOTICE: issuing SELECT 981008 AS shard_id, 'public.test_table_statistics_append_981008' AS shard_name, pg_total_relation_size('public.test_table_statistics_append_981008') UNION ALL SELECT 981009 AS shard_id, 'public.test_table_statistics_append_981009' AS shard_name, pg_total_relation_size('public.test_table_statistics_append_981009') UNION ALL SELECT 0::bigint, NULL::text, 0::bigint; +NOTICE: issuing SELECT shard_id, pg_total_relation_size(table_name) FROM (VALUES (981008, 'public.test_table_statistics_append_981008'), (981009, 'public.test_table_statistics_append_981009')) t(shard_id, table_name) WHERE to_regclass(table_name) IS NOT NULL DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx NOTICE: issuing BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED;SELECT assign_distributed_transaction_id(xx, xx, 'xxxxxxx'); DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx -NOTICE: issuing SELECT 981008 AS shard_id, 'public.test_table_statistics_append_981008' AS shard_name, pg_total_relation_size('public.test_table_statistics_append_981008') UNION ALL SELECT 981009 AS shard_id, 'public.test_table_statistics_append_981009' AS shard_name, pg_total_relation_size('public.test_table_statistics_append_981009') UNION ALL SELECT 0::bigint, NULL::text, 0::bigint; +NOTICE: issuing SELECT shard_id, pg_total_relation_size(table_name) FROM (VALUES (981008, 'public.test_table_statistics_append_981008'), (981009, 'public.test_table_statistics_append_981009')) t(shard_id, table_name) WHERE to_regclass(table_name) IS NOT NULL DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx NOTICE: issuing COMMIT DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx diff --git a/src/test/regress/expected/multi_extension.out b/src/test/regress/expected/multi_extension.out index b2ccf6885..930adbed5 100644 --- a/src/test/regress/expected/multi_extension.out +++ b/src/test/regress/expected/multi_extension.out @@ -1330,6 +1330,22 @@ SELECT * FROM multi_extension.print_extension_changes(); | view citus_stat_tenants_local (11 rows) +-- Test downgrade to 11.3-1 from 11.3-2 +ALTER EXTENSION citus UPDATE TO '11.3-2'; +ALTER EXTENSION citus UPDATE TO '11.3-1'; +-- Should be empty result since upgrade+downgrade should be a no-op +SELECT * FROM multi_extension.print_extension_changes(); + previous_object | current_object +--------------------------------------------------------------------- +(0 rows) + +-- Snapshot of state at 11.3-2 +ALTER EXTENSION citus UPDATE TO '11.3-2'; +SELECT * FROM multi_extension.print_extension_changes(); + previous_object | current_object +--------------------------------------------------------------------- +(0 rows) + DROP TABLE multi_extension.prev_objects, multi_extension.extension_diff; -- show running version SHOW citus.version; diff --git a/src/test/regress/sql/multi_extension.sql b/src/test/regress/sql/multi_extension.sql index 6a99dc0b4..402617dcd 100644 --- a/src/test/regress/sql/multi_extension.sql +++ b/src/test/regress/sql/multi_extension.sql @@ -591,6 +591,16 @@ SELECT * FROM multi_extension.print_extension_changes(); ALTER EXTENSION citus UPDATE TO '11.3-1'; SELECT * FROM multi_extension.print_extension_changes(); +-- Test downgrade to 11.3-1 from 11.3-2 +ALTER EXTENSION citus UPDATE TO '11.3-2'; +ALTER EXTENSION citus UPDATE TO '11.3-1'; +-- Should be empty result since upgrade+downgrade should be a no-op +SELECT * FROM multi_extension.print_extension_changes(); + +-- Snapshot of state at 11.3-2 +ALTER EXTENSION citus UPDATE TO '11.3-2'; +SELECT * FROM multi_extension.print_extension_changes(); + DROP TABLE multi_extension.prev_objects, multi_extension.extension_diff; -- show running version