From 306173771294c5b699d8187253dc4e8ec77e7103 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eren=20Ba=C5=9Fak?= Date: Thu, 10 Aug 2017 10:56:59 +0300 Subject: [PATCH 1/3] Define Some Utility Functions This change declares two new functions: `master_update_table_statistics` updates the statistics of shards belong to the given table as well as its colocated tables. `get_colocated_shard_array` returns the ids of colocated shards of a given shard. --- src/backend/distributed/Makefile | 4 +- .../distributed/citus--7.0-10--7.0-11.sql | 30 ++++++++++++++ src/backend/distributed/citus.control | 2 +- .../distributed/test/colocation_utils.c | 39 +------------------ .../distributed/test/generate_ddl_commands.c | 1 + src/backend/distributed/test/metadata_sync.c | 1 + .../distributed/test/prune_shard_list.c | 1 + .../distributed/test/test_helper_functions.c | 39 ------------------- .../distributed/utils/colocation_utils.c | 39 +++++++++++++++++++ src/backend/distributed/utils/listutils.c | 21 ++++++++++ src/include/distributed/listutils.h | 4 +- .../distributed/test_helper_functions.h | 2 - .../expected/multi_colocation_utils.out | 4 -- src/test/regress/expected/multi_extension.out | 1 + .../regress/sql/multi_colocation_utils.sql | 5 --- src/test/regress/sql/multi_extension.sql | 1 + 16 files changed, 103 insertions(+), 91 deletions(-) create mode 100644 src/backend/distributed/citus--7.0-10--7.0-11.sql delete mode 100644 src/backend/distributed/test/test_helper_functions.c diff --git a/src/backend/distributed/Makefile b/src/backend/distributed/Makefile index c8d38eba3..e97169c6c 100644 --- a/src/backend/distributed/Makefile +++ b/src/backend/distributed/Makefile @@ -11,7 +11,7 @@ EXTVERSIONS = 5.0 5.0-1 5.0-2 \ 6.0-1 6.0-2 6.0-3 6.0-4 6.0-5 6.0-6 6.0-7 6.0-8 6.0-9 6.0-10 6.0-11 6.0-12 6.0-13 6.0-14 6.0-15 6.0-16 6.0-17 6.0-18 \ 6.1-1 6.1-2 6.1-3 6.1-4 6.1-5 6.1-6 6.1-7 6.1-8 6.1-9 6.1-10 6.1-11 6.1-12 6.1-13 6.1-14 6.1-15 6.1-16 6.1-17 \ 6.2-1 6.2-2 6.2-3 6.2-4 \ - 7.0-1 7.0-2 7.0-3 7.0-4 7.0-5 7.0-6 7.0-7 7.0-8 7.0-9 7.0-10 + 7.0-1 7.0-2 7.0-3 7.0-4 7.0-5 7.0-6 7.0-7 7.0-8 7.0-9 7.0-10 7.0-11 # All citus--*.sql files in the source directory DATA = $(patsubst $(citus_abs_srcdir)/%.sql,%.sql,$(wildcard $(citus_abs_srcdir)/$(EXTENSION)--*--*.sql)) @@ -159,6 +159,8 @@ $(EXTENSION)--7.0-9.sql: $(EXTENSION)--7.0-8.sql $(EXTENSION)--7.0-8--7.0-9.sql cat $^ > $@ $(EXTENSION)--7.0-10.sql: $(EXTENSION)--7.0-9.sql $(EXTENSION)--7.0-9--7.0-10.sql cat $^ > $@ +$(EXTENSION)--7.0-11.sql: $(EXTENSION)--7.0-10.sql $(EXTENSION)--7.0-10--7.0-11.sql + cat $^ > $@ NO_PGXS = 1 diff --git a/src/backend/distributed/citus--7.0-10--7.0-11.sql b/src/backend/distributed/citus--7.0-10--7.0-11.sql new file mode 100644 index 000000000..b67ddba6f --- /dev/null +++ b/src/backend/distributed/citus--7.0-10--7.0-11.sql @@ -0,0 +1,30 @@ +/* citus-7.0-10--7.0-11 */ + +SET search_path = 'pg_catalog'; + +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'; + +CREATE OR REPLACE FUNCTION get_colocated_shard_array(bigint) + RETURNS BIGINT[] + LANGUAGE C STRICT + AS 'citus', $$get_colocated_shard_array$$; +COMMENT ON FUNCTION get_colocated_shard_array(bigint) + IS 'returns the array of colocated shards of the given shard'; + +RESET search_path; diff --git a/src/backend/distributed/citus.control b/src/backend/distributed/citus.control index a45005c00..756c98ce6 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 = '7.0-10' +default_version = '7.0-11' module_pathname = '$libdir/citus' relocatable = false schema = pg_catalog diff --git a/src/backend/distributed/test/colocation_utils.c b/src/backend/distributed/test/colocation_utils.c index 416522b1d..ae81243a3 100644 --- a/src/backend/distributed/test/colocation_utils.c +++ b/src/backend/distributed/test/colocation_utils.c @@ -15,6 +15,7 @@ #include "catalog/pg_type.h" #include "distributed/colocation_utils.h" +#include "distributed/listutils.h" #include "distributed/metadata_cache.h" #include "distributed/test_helper_functions.h" /* IWYU pragma: keep */ @@ -24,7 +25,6 @@ PG_FUNCTION_INFO_V1(get_table_colocation_id); PG_FUNCTION_INFO_V1(tables_colocated); PG_FUNCTION_INFO_V1(shards_colocated); PG_FUNCTION_INFO_V1(get_colocated_table_array); -PG_FUNCTION_INFO_V1(get_colocated_shard_array); PG_FUNCTION_INFO_V1(find_shard_interval_index); @@ -108,43 +108,6 @@ get_colocated_table_array(PG_FUNCTION_ARGS) } -/* - * get_colocated_shards_array returns array of shards ids which are co-located with given - * shard. - */ -Datum -get_colocated_shard_array(PG_FUNCTION_ARGS) -{ - uint32 shardId = PG_GETARG_UINT32(0); - ShardInterval *shardInterval = LoadShardInterval(shardId); - - ArrayType *colocatedShardsArrayType = NULL; - List *colocatedShardList = ColocatedShardIntervalList(shardInterval); - ListCell *colocatedShardCell = NULL; - int colocatedShardCount = list_length(colocatedShardList); - Datum *colocatedShardsDatumArray = palloc0(colocatedShardCount * sizeof(Datum)); - Oid arrayTypeId = OIDOID; - int colocatedShardIndex = 0; - - foreach(colocatedShardCell, colocatedShardList) - { - ShardInterval *colocatedShardInterval = (ShardInterval *) lfirst( - colocatedShardCell); - uint64 colocatedShardId = colocatedShardInterval->shardId; - - Datum colocatedShardDatum = Int64GetDatum(colocatedShardId); - - colocatedShardsDatumArray[colocatedShardIndex] = colocatedShardDatum; - colocatedShardIndex++; - } - - colocatedShardsArrayType = DatumArrayToArrayType(colocatedShardsDatumArray, - colocatedShardCount, arrayTypeId); - - PG_RETURN_ARRAYTYPE_P(colocatedShardsArrayType); -} - - /* * find_shard_interval_index finds index of given shard in sorted shard interval list. */ diff --git a/src/backend/distributed/test/generate_ddl_commands.c b/src/backend/distributed/test/generate_ddl_commands.c index 44bbea4ad..aabac2a84 100644 --- a/src/backend/distributed/test/generate_ddl_commands.c +++ b/src/backend/distributed/test/generate_ddl_commands.c @@ -17,6 +17,7 @@ #include #include "catalog/pg_type.h" +#include "distributed/listutils.h" #include "distributed/master_protocol.h" #include "distributed/test_helper_functions.h" /* IWYU pragma: keep */ #include "lib/stringinfo.h" diff --git a/src/backend/distributed/test/metadata_sync.c b/src/backend/distributed/test/metadata_sync.c index ced8f8465..f47fe3adb 100644 --- a/src/backend/distributed/test/metadata_sync.c +++ b/src/backend/distributed/test/metadata_sync.c @@ -14,6 +14,7 @@ #include "fmgr.h" #include "catalog/pg_type.h" +#include "distributed/listutils.h" #include "distributed/metadata_sync.h" #include "distributed/test_helper_functions.h" /* IWYU pragma: keep */ #include "utils/array.h" diff --git a/src/backend/distributed/test/prune_shard_list.c b/src/backend/distributed/test/prune_shard_list.c index d68ebe516..288c01472 100644 --- a/src/backend/distributed/test/prune_shard_list.c +++ b/src/backend/distributed/test/prune_shard_list.c @@ -18,6 +18,7 @@ #include "access/stratnum.h" #include "catalog/pg_type.h" +#include "distributed/listutils.h" #include "distributed/metadata_cache.h" #include "distributed/master_metadata_utility.h" #include "distributed/multi_join_order.h" diff --git a/src/backend/distributed/test/test_helper_functions.c b/src/backend/distributed/test/test_helper_functions.c deleted file mode 100644 index 43f1a8fcb..000000000 --- a/src/backend/distributed/test/test_helper_functions.c +++ /dev/null @@ -1,39 +0,0 @@ -/*------------------------------------------------------------------------- - * - * test/src/test_helper_functions.c - * - * This file contains helper functions used in many Citus tests. - * - * Copyright (c) 2014-2016, Citus Data, Inc. - * - *------------------------------------------------------------------------- - */ - -#include "postgres.h" -#include "c.h" - -#include - -#include "distributed/test_helper_functions.h" /* IWYU pragma: keep */ -#include "utils/array.h" -#include "utils/lsyscache.h" - - -/* - * DatumArrayToArrayType converts the provided Datum array (of the specified - * length and type) into an ArrayType suitable for returning from a UDF. - */ -ArrayType * -DatumArrayToArrayType(Datum *datumArray, int datumCount, Oid datumTypeId) -{ - ArrayType *arrayObject = NULL; - int16 typeLength = 0; - bool typeByValue = false; - char typeAlignment = 0; - - get_typlenbyvalalign(datumTypeId, &typeLength, &typeByValue, &typeAlignment); - arrayObject = construct_array(datumArray, datumCount, datumTypeId, - typeLength, typeByValue, typeAlignment); - - return arrayObject; -} diff --git a/src/backend/distributed/utils/colocation_utils.c b/src/backend/distributed/utils/colocation_utils.c index e12ce4313..7a494f753 100644 --- a/src/backend/distributed/utils/colocation_utils.c +++ b/src/backend/distributed/utils/colocation_utils.c @@ -17,6 +17,7 @@ #include "access/htup_details.h" #include "access/xact.h" #include "catalog/indexing.h" +#include "catalog/pg_type.h" #include "commands/sequence.h" #include "distributed/colocation_utils.h" #include "distributed/listutils.h" @@ -52,6 +53,7 @@ static void DeleteColocationGroup(uint32 colocationId); /* exports for SQL callable functions */ PG_FUNCTION_INFO_V1(mark_tables_colocated); +PG_FUNCTION_INFO_V1(get_colocated_shard_array); /* @@ -91,6 +93,43 @@ mark_tables_colocated(PG_FUNCTION_ARGS) } +/* + * get_colocated_shards_array returns array of shards ids which are co-located with given + * shard. + */ +Datum +get_colocated_shard_array(PG_FUNCTION_ARGS) +{ + uint32 shardId = PG_GETARG_UINT32(0); + ShardInterval *shardInterval = LoadShardInterval(shardId); + + ArrayType *colocatedShardsArrayType = NULL; + List *colocatedShardList = ColocatedShardIntervalList(shardInterval); + ListCell *colocatedShardCell = NULL; + int colocatedShardCount = list_length(colocatedShardList); + Datum *colocatedShardsDatumArray = palloc0(colocatedShardCount * sizeof(Datum)); + Oid arrayTypeId = OIDOID; + int colocatedShardIndex = 0; + + foreach(colocatedShardCell, colocatedShardList) + { + ShardInterval *colocatedShardInterval = (ShardInterval *) lfirst( + colocatedShardCell); + uint64 colocatedShardId = colocatedShardInterval->shardId; + + Datum colocatedShardDatum = Int64GetDatum(colocatedShardId); + + colocatedShardsDatumArray[colocatedShardIndex] = colocatedShardDatum; + colocatedShardIndex++; + } + + colocatedShardsArrayType = DatumArrayToArrayType(colocatedShardsDatumArray, + colocatedShardCount, arrayTypeId); + + PG_RETURN_ARRAYTYPE_P(colocatedShardsArrayType); +} + + /* * MarkTablesColocated puts both tables to same colocation group. If the * source table is in INVALID_COLOCATION_ID group, then it creates a new diff --git a/src/backend/distributed/utils/listutils.c b/src/backend/distributed/utils/listutils.c index 49528a28b..56224eaac 100644 --- a/src/backend/distributed/utils/listutils.c +++ b/src/backend/distributed/utils/listutils.c @@ -13,6 +13,7 @@ #include "c.h" #include "port.h" +#include "utils/lsyscache.h" #include "distributed/listutils.h" #include "nodes/pg_list.h" #include "utils/memutils.h" @@ -81,3 +82,23 @@ PointerArrayFromList(List *pointerList) return pointerArray; } + + +/* + * DatumArrayToArrayType converts the provided Datum array (of the specified + * length and type) into an ArrayType suitable for returning from a UDF. + */ +ArrayType * +DatumArrayToArrayType(Datum *datumArray, int datumCount, Oid datumTypeId) +{ + ArrayType *arrayObject = NULL; + int16 typeLength = 0; + bool typeByValue = false; + char typeAlignment = 0; + + get_typlenbyvalalign(datumTypeId, &typeLength, &typeByValue, &typeAlignment); + arrayObject = construct_array(datumArray, datumCount, datumTypeId, + typeLength, typeByValue, typeAlignment); + + return arrayObject; +} diff --git a/src/include/distributed/listutils.h b/src/include/distributed/listutils.h index 66b433fed..4d205f046 100644 --- a/src/include/distributed/listutils.h +++ b/src/include/distributed/listutils.h @@ -16,12 +16,14 @@ #include "c.h" #include "nodes/pg_list.h" +#include "utils/array.h" /* utility functions declaration shared within this module */ extern List * SortList(List *pointerList, int (*ComparisonFunction)(const void *, const void *)); extern void ** PointerArrayFromList(List *pointerList); - +extern ArrayType * DatumArrayToArrayType(Datum *datumArray, int datumCount, + Oid datumTypeId); #endif /* CITUS_LISTUTILS_H */ diff --git a/src/include/distributed/test_helper_functions.h b/src/include/distributed/test_helper_functions.h index 5087d6ad6..b25b90c6b 100644 --- a/src/include/distributed/test_helper_functions.h +++ b/src/include/distributed/test_helper_functions.h @@ -28,8 +28,6 @@ /* function declarations for generic test functions */ -extern ArrayType * DatumArrayToArrayType(Datum *datumArray, int datumCount, - Oid datumTypeId); extern void SetConnectionStatus(PGconn *connection, ConnStatusType status); /* fake FDW for use in tests */ diff --git a/src/test/regress/expected/multi_colocation_utils.out b/src/test/regress/expected/multi_colocation_utils.out index efe140527..d43250d06 100644 --- a/src/test/regress/expected/multi_colocation_utils.out +++ b/src/test/regress/expected/multi_colocation_utils.out @@ -48,10 +48,6 @@ CREATE FUNCTION shards_colocated(bigint, bigint) RETURNS bool AS 'citus' LANGUAGE C STRICT; -CREATE FUNCTION get_colocated_shard_array(bigint) - RETURNS BIGINT[] - AS 'citus' - LANGUAGE C STRICT; CREATE FUNCTION find_shard_interval_index(bigint) RETURNS int AS 'citus' diff --git a/src/test/regress/expected/multi_extension.out b/src/test/regress/expected/multi_extension.out index fbe2ea8dd..58cfbe626 100644 --- a/src/test/regress/expected/multi_extension.out +++ b/src/test/regress/expected/multi_extension.out @@ -120,6 +120,7 @@ ALTER EXTENSION citus UPDATE TO '7.0-7'; ALTER EXTENSION citus UPDATE TO '7.0-8'; ALTER EXTENSION citus UPDATE TO '7.0-9'; ALTER EXTENSION citus UPDATE TO '7.0-10'; +ALTER EXTENSION citus UPDATE TO '7.0-11'; -- show running version SHOW citus.version; citus.version diff --git a/src/test/regress/sql/multi_colocation_utils.sql b/src/test/regress/sql/multi_colocation_utils.sql index 1957910b1..c4ed46479 100644 --- a/src/test/regress/sql/multi_colocation_utils.sql +++ b/src/test/regress/sql/multi_colocation_utils.sql @@ -57,11 +57,6 @@ CREATE FUNCTION shards_colocated(bigint, bigint) AS 'citus' LANGUAGE C STRICT; -CREATE FUNCTION get_colocated_shard_array(bigint) - RETURNS BIGINT[] - AS 'citus' - LANGUAGE C STRICT; - CREATE FUNCTION find_shard_interval_index(bigint) RETURNS int AS 'citus' diff --git a/src/test/regress/sql/multi_extension.sql b/src/test/regress/sql/multi_extension.sql index 8581f6805..dd5f7fc2a 100644 --- a/src/test/regress/sql/multi_extension.sql +++ b/src/test/regress/sql/multi_extension.sql @@ -120,6 +120,7 @@ ALTER EXTENSION citus UPDATE TO '7.0-7'; ALTER EXTENSION citus UPDATE TO '7.0-8'; ALTER EXTENSION citus UPDATE TO '7.0-9'; ALTER EXTENSION citus UPDATE TO '7.0-10'; +ALTER EXTENSION citus UPDATE TO '7.0-11'; -- show running version SHOW citus.version; From f9470329e544a930d67aa6e5147ca6f6b9ed42cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eren=20Ba=C5=9Fak?= Date: Thu, 10 Aug 2017 12:41:59 +0300 Subject: [PATCH 2/3] Remove test_helper_functions.h inclusions --- src/backend/distributed/test/colocation_utils.c | 1 - src/backend/distributed/test/create_shards.c | 1 - src/backend/distributed/test/deparse_shard_query.c | 1 - src/backend/distributed/test/distribution_metadata.c | 1 - src/backend/distributed/test/fake_fdw.c | 1 - src/backend/distributed/test/generate_ddl_commands.c | 1 - src/backend/distributed/test/metadata_sync.c | 1 - src/backend/distributed/test/prune_shard_list.c | 1 - 8 files changed, 8 deletions(-) diff --git a/src/backend/distributed/test/colocation_utils.c b/src/backend/distributed/test/colocation_utils.c index ae81243a3..8d24bdf9b 100644 --- a/src/backend/distributed/test/colocation_utils.c +++ b/src/backend/distributed/test/colocation_utils.c @@ -17,7 +17,6 @@ #include "distributed/colocation_utils.h" #include "distributed/listutils.h" #include "distributed/metadata_cache.h" -#include "distributed/test_helper_functions.h" /* IWYU pragma: keep */ /* declarations for dynamic loading */ diff --git a/src/backend/distributed/test/create_shards.c b/src/backend/distributed/test/create_shards.c index b9ea38baa..a97f0d614 100644 --- a/src/backend/distributed/test/create_shards.c +++ b/src/backend/distributed/test/create_shards.c @@ -17,7 +17,6 @@ #include #include "distributed/listutils.h" -#include "distributed/test_helper_functions.h" /* IWYU pragma: keep */ #include "lib/stringinfo.h" #include "nodes/pg_list.h" diff --git a/src/backend/distributed/test/deparse_shard_query.c b/src/backend/distributed/test/deparse_shard_query.c index abccca4af..55c75de4a 100644 --- a/src/backend/distributed/test/deparse_shard_query.c +++ b/src/backend/distributed/test/deparse_shard_query.c @@ -21,7 +21,6 @@ #include "distributed/citus_ruleutils.h" #include "distributed/insert_select_planner.h" #include "distributed/multi_router_planner.h" -#include "distributed/test_helper_functions.h" /* IWYU pragma: keep */ #include "lib/stringinfo.h" #include "nodes/makefuncs.h" #include "nodes/nodes.h" diff --git a/src/backend/distributed/test/distribution_metadata.c b/src/backend/distributed/test/distribution_metadata.c index fcdd85997..cae3d2eea 100644 --- a/src/backend/distributed/test/distribution_metadata.c +++ b/src/backend/distributed/test/distribution_metadata.c @@ -28,7 +28,6 @@ #include "distributed/multi_physical_planner.h" #include "distributed/pg_dist_shard.h" #include "distributed/resource_lock.h" -#include "distributed/test_helper_functions.h" /* IWYU pragma: keep */ #include "lib/stringinfo.h" #include "nodes/pg_list.h" #include "nodes/primnodes.h" diff --git a/src/backend/distributed/test/fake_fdw.c b/src/backend/distributed/test/fake_fdw.c index 8fd3eab91..7fa966da4 100644 --- a/src/backend/distributed/test/fake_fdw.c +++ b/src/backend/distributed/test/fake_fdw.c @@ -16,7 +16,6 @@ #include -#include "distributed/test_helper_functions.h" /* IWYU pragma: keep */ #include "executor/tuptable.h" #include "foreign/fdwapi.h" #include "nodes/execnodes.h" diff --git a/src/backend/distributed/test/generate_ddl_commands.c b/src/backend/distributed/test/generate_ddl_commands.c index aabac2a84..9b6503caf 100644 --- a/src/backend/distributed/test/generate_ddl_commands.c +++ b/src/backend/distributed/test/generate_ddl_commands.c @@ -19,7 +19,6 @@ #include "catalog/pg_type.h" #include "distributed/listutils.h" #include "distributed/master_protocol.h" -#include "distributed/test_helper_functions.h" /* IWYU pragma: keep */ #include "lib/stringinfo.h" #include "nodes/makefuncs.h" #include "nodes/nodes.h" diff --git a/src/backend/distributed/test/metadata_sync.c b/src/backend/distributed/test/metadata_sync.c index f47fe3adb..d1e574bc1 100644 --- a/src/backend/distributed/test/metadata_sync.c +++ b/src/backend/distributed/test/metadata_sync.c @@ -16,7 +16,6 @@ #include "catalog/pg_type.h" #include "distributed/listutils.h" #include "distributed/metadata_sync.h" -#include "distributed/test_helper_functions.h" /* IWYU pragma: keep */ #include "utils/array.h" #include "utils/builtins.h" diff --git a/src/backend/distributed/test/prune_shard_list.c b/src/backend/distributed/test/prune_shard_list.c index 288c01472..b5a2f49ea 100644 --- a/src/backend/distributed/test/prune_shard_list.c +++ b/src/backend/distributed/test/prune_shard_list.c @@ -24,7 +24,6 @@ #include "distributed/multi_join_order.h" #include "distributed/multi_physical_planner.h" #include "distributed/resource_lock.h" -#include "distributed/test_helper_functions.h" /* IWYU pragma: keep */ #include "distributed/shard_pruning.h" #include "nodes/pg_list.h" #include "nodes/primnodes.h" From deb89cb9ce33c88fd4b58fec12f1f3bea2c0b926 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eren=20Ba=C5=9Fak?= Date: Thu, 10 Aug 2017 14:00:44 +0300 Subject: [PATCH 3/3] Delete tesh_helper_functions.h --- .../distributed/test_helper_functions.h | 71 ------------------- 1 file changed, 71 deletions(-) delete mode 100644 src/include/distributed/test_helper_functions.h diff --git a/src/include/distributed/test_helper_functions.h b/src/include/distributed/test_helper_functions.h deleted file mode 100644 index b25b90c6b..000000000 --- a/src/include/distributed/test_helper_functions.h +++ /dev/null @@ -1,71 +0,0 @@ -/*------------------------------------------------------------------------- - * - * test/include/test_helper_functions.h - * - * Declarations for public functions and types related to unit testing - * functionality. - * - * Copyright (c) 2014-2016, Citus Data, Inc. - * - *------------------------------------------------------------------------- - */ - -#ifndef CITUS_TEST_HELPER_FUNCTIONS_H -#define CITUS_TEST_HELPER_FUNCTIONS_H - -#include "postgres.h" -#include "c.h" -#include "fmgr.h" -#include "libpq-fe.h" - -#include "utils/array.h" - - -/* SQL statements for testing */ -#define POPULATE_TEMP_TABLE "CREATE TEMPORARY TABLE numbers " \ - "AS SELECT * FROM generate_series(1, 100);" -#define COUNT_TEMP_TABLE "SELECT COUNT(*) FROM numbers;" - - -/* function declarations for generic test functions */ -extern void SetConnectionStatus(PGconn *connection, ConnStatusType status); - -/* fake FDW for use in tests */ -extern Datum fake_fdw_handler(PG_FUNCTION_ARGS); - -/* function declarations for exercising connection functions */ -extern Datum initialize_remote_temp_table(PG_FUNCTION_ARGS); -extern Datum count_remote_temp_table_rows(PG_FUNCTION_ARGS); -extern Datum get_and_purge_connection(PG_FUNCTION_ARGS); -extern Datum connect_and_purge_connection(PG_FUNCTION_ARGS); -extern Datum set_connection_status_bad(PG_FUNCTION_ARGS); - -/* function declarations for exercising metadata functions */ -extern Datum load_shard_id_array(PG_FUNCTION_ARGS); -extern Datum load_shard_interval_array(PG_FUNCTION_ARGS); -extern Datum load_shard_placement_array(PG_FUNCTION_ARGS); -extern Datum partition_column_id(PG_FUNCTION_ARGS); -extern Datum partition_type(PG_FUNCTION_ARGS); -extern Datum is_distributed_table(PG_FUNCTION_ARGS); -extern Datum distributed_tables_exist(PG_FUNCTION_ARGS); -extern Datum column_name_to_column(PG_FUNCTION_ARGS); -extern Datum column_name_to_column_id(PG_FUNCTION_ARGS); -extern Datum create_monolithic_shard_row(PG_FUNCTION_ARGS); -extern Datum next_shard_id(PG_FUNCTION_ARGS); -extern Datum acquire_shared_shard_lock(PG_FUNCTION_ARGS); - -/* function declarations for exercising ddl generation functions */ -extern Datum table_ddl_command_array(PG_FUNCTION_ARGS); - -/* function declarations for exercising shard creation functions */ -extern Datum sort_names(PG_FUNCTION_ARGS); - -/* function declarations for exercising shard pruning functions */ -extern Datum prune_using_no_values(PG_FUNCTION_ARGS); -extern Datum prune_using_single_value(PG_FUNCTION_ARGS); -extern Datum prune_using_either_value(PG_FUNCTION_ARGS); -extern Datum prune_using_both_values(PG_FUNCTION_ARGS); -extern Datum debug_equality_expression(PG_FUNCTION_ARGS); - - -#endif /* CITUS_TEST_HELPER_FUNCTIONS_H */