Fix upgrade and downgrade paths for master/citus_update_table_statistics (#4805)

pull/4791/head
Naisila Puka 2021-03-11 14:52:40 +03:00 committed by GitHub
parent 69f09556fd
commit 71a9f45513
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 76 additions and 14 deletions

View File

@ -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';

View File

@ -1,4 +1,4 @@
-- citus--10.0-2--10.1-1
-- citus--10.0-3--10.1-1
-- bump version to 10.1-1

View File

@ -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[]

View File

@ -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';

View File

@ -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

View File

@ -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

View File

@ -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';

View File

@ -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';

View File

@ -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$$;