diff --git a/src/backend/distributed/sql/citus--10.0-2--10.0-3.sql b/src/backend/distributed/sql/citus--10.0-2--10.0-3.sql new file mode 100644 index 000000000..d4f1312fb --- /dev/null +++ b/src/backend/distributed/sql/citus--10.0-2--10.0-3.sql @@ -0,0 +1,10 @@ +-- citus--10.0-2--10.0-3 + +#include "udfs/citus_update_table_statistics/10.0-3.sql" + +CREATE OR REPLACE FUNCTION master_update_table_statistics(relation regclass) +RETURNS VOID + LANGUAGE C STRICT + AS 'MODULE_PATHNAME', $$citus_update_table_statistics$$; +COMMENT ON FUNCTION pg_catalog.master_update_table_statistics(regclass) + IS 'updates shard statistics of the given table'; diff --git a/src/backend/distributed/sql/citus--10.0-2--10.1-1.sql b/src/backend/distributed/sql/citus--10.0-3--10.1-1.sql similarity index 52% rename from src/backend/distributed/sql/citus--10.0-2--10.1-1.sql rename to src/backend/distributed/sql/citus--10.0-3--10.1-1.sql index 81ed2427a..0ffc957f4 100644 --- a/src/backend/distributed/sql/citus--10.0-2--10.1-1.sql +++ b/src/backend/distributed/sql/citus--10.0-3--10.1-1.sql @@ -1,4 +1,4 @@ --- citus--10.0-2--10.1-1 +-- citus--10.0-3--10.1-1 -- bump version to 10.1-1 diff --git a/src/backend/distributed/sql/citus--8.0-1.sql b/src/backend/distributed/sql/citus--8.0-1.sql index eced5cc60..5647e01fd 100644 --- a/src/backend/distributed/sql/citus--8.0-1.sql +++ b/src/backend/distributed/sql/citus--8.0-1.sql @@ -1394,11 +1394,22 @@ COMMENT ON FUNCTION master_update_node(node_id int, new_node_name text, new_node -- shard statistics CREATE OR REPLACE FUNCTION master_update_table_statistics(relation regclass) -RETURNS VOID - LANGUAGE C STRICT - AS 'MODULE_PATHNAME', $$citus_update_table_statistics$$; -COMMENT ON FUNCTION pg_catalog.master_update_table_statistics(regclass) - IS 'updates shard statistics of the given table'; +RETURNS VOID AS $$ +DECLARE + colocated_tables regclass[]; +BEGIN + SELECT get_colocated_table_array(relation) INTO colocated_tables; + + PERFORM + master_update_shard_statistics(shardid) + FROM + pg_dist_shard + WHERE + logicalrelid = ANY (colocated_tables); +END; +$$ LANGUAGE 'plpgsql'; +COMMENT ON FUNCTION master_update_table_statistics(regclass) + IS 'updates shard statistics of the given table and its colocated tables'; CREATE OR REPLACE FUNCTION get_colocated_shard_array(bigint) RETURNS BIGINT[] diff --git a/src/backend/distributed/sql/downgrades/citus--10.0-3--10.0-2.sql b/src/backend/distributed/sql/downgrades/citus--10.0-3--10.0-2.sql new file mode 100644 index 000000000..f75a4642f --- /dev/null +++ b/src/backend/distributed/sql/downgrades/citus--10.0-3--10.0-2.sql @@ -0,0 +1,24 @@ +-- citus--10.0-3--10.0-2 +-- this is a downgrade path that will revert the changes made in citus--10.0-2--10.0-3.sql + +DROP FUNCTION pg_catalog.citus_update_table_statistics(regclass); + +#include "../udfs/citus_update_table_statistics/10.0-1.sql" + +CREATE OR REPLACE FUNCTION master_update_table_statistics(relation regclass) +RETURNS VOID AS $$ +DECLARE + colocated_tables regclass[]; +BEGIN + SELECT get_colocated_table_array(relation) INTO colocated_tables; + + PERFORM + master_update_shard_statistics(shardid) + FROM + pg_dist_shard + WHERE + logicalrelid = ANY (colocated_tables); +END; +$$ LANGUAGE 'plpgsql'; +COMMENT ON FUNCTION master_update_table_statistics(regclass) + IS 'updates shard statistics of the given table and its colocated tables'; diff --git a/src/backend/distributed/sql/downgrades/citus--10.1-1--10.0-2.sql b/src/backend/distributed/sql/downgrades/citus--10.1-1--10.0-2.sql deleted file mode 100644 index 1e45067f9..000000000 --- a/src/backend/distributed/sql/downgrades/citus--10.1-1--10.0-2.sql +++ /dev/null @@ -1,3 +0,0 @@ --- citus--10.1-1--10.0-2 --- this is an empty downgrade path since citus--10.0-2--10.1-1.sql is empty for now - diff --git a/src/backend/distributed/sql/downgrades/citus--10.1-1--10.0-3.sql b/src/backend/distributed/sql/downgrades/citus--10.1-1--10.0-3.sql new file mode 100644 index 000000000..85785da52 --- /dev/null +++ b/src/backend/distributed/sql/downgrades/citus--10.1-1--10.0-3.sql @@ -0,0 +1,3 @@ +-- citus--10.1-1--10.0-2 +-- this is an empty downgrade path since citus--10.0-3--10.1-1.sql is empty for now + diff --git a/src/backend/distributed/sql/udfs/citus_update_table_statistics/10.0-1.sql b/src/backend/distributed/sql/udfs/citus_update_table_statistics/10.0-1.sql index d4e07d24d..13f4a680e 100644 --- a/src/backend/distributed/sql/udfs/citus_update_table_statistics/10.0-1.sql +++ b/src/backend/distributed/sql/udfs/citus_update_table_statistics/10.0-1.sql @@ -1,6 +1,17 @@ CREATE FUNCTION pg_catalog.citus_update_table_statistics(relation regclass) - RETURNS VOID - LANGUAGE C STRICT - AS 'MODULE_PATHNAME', $$citus_update_table_statistics$$; +RETURNS VOID AS $$ +DECLARE + colocated_tables regclass[]; +BEGIN + SELECT get_colocated_table_array(relation) INTO colocated_tables; + + PERFORM + master_update_shard_statistics(shardid) + FROM + pg_dist_shard + WHERE + logicalrelid = ANY (colocated_tables); +END; +$$ LANGUAGE 'plpgsql'; COMMENT ON FUNCTION pg_catalog.citus_update_table_statistics(regclass) - IS 'updates shard statistics of the given table'; + IS 'updates shard statistics of the given table and its colocated tables'; diff --git a/src/backend/distributed/sql/udfs/citus_update_table_statistics/10.0-3.sql b/src/backend/distributed/sql/udfs/citus_update_table_statistics/10.0-3.sql new file mode 100644 index 000000000..753b1ce7f --- /dev/null +++ b/src/backend/distributed/sql/udfs/citus_update_table_statistics/10.0-3.sql @@ -0,0 +1,6 @@ +CREATE OR REPLACE FUNCTION pg_catalog.citus_update_table_statistics(relation regclass) + RETURNS VOID + LANGUAGE C STRICT + AS 'MODULE_PATHNAME', $$citus_update_table_statistics$$; +COMMENT ON FUNCTION pg_catalog.citus_update_table_statistics(regclass) + IS 'updates shard statistics of the given table'; diff --git a/src/backend/distributed/sql/udfs/citus_update_table_statistics/latest.sql b/src/backend/distributed/sql/udfs/citus_update_table_statistics/latest.sql index d4e07d24d..753b1ce7f 100644 --- a/src/backend/distributed/sql/udfs/citus_update_table_statistics/latest.sql +++ b/src/backend/distributed/sql/udfs/citus_update_table_statistics/latest.sql @@ -1,4 +1,4 @@ -CREATE FUNCTION pg_catalog.citus_update_table_statistics(relation regclass) +CREATE OR REPLACE FUNCTION pg_catalog.citus_update_table_statistics(relation regclass) RETURNS VOID LANGUAGE C STRICT AS 'MODULE_PATHNAME', $$citus_update_table_statistics$$;