summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Paquier2012-07-06 05:52:17 +0000
committerMichael Paquier2012-07-06 05:52:17 +0000
commit249129ee4d405c35c12e911b993eae2a19ba767a (patch)
tree905a4d37bbe0e77c24fef8a0927f9a422a554bb4 /src
parent7c113772a540cc2282ecca031cea953f53f0fe88 (diff)
Refactor regression tests xc_misc, xc_FQS and xc_FQS_join
Those tests are using a similar PL/PGSQL function to create tables with a node list, being transparent on the cluster structure. This function was created 3 times. Now this function is created in another test called xc_create_function launched before all the others. A table name conflict has been resolved in xc_misc to allow this test to run in parallel with the other XC-related tests.
Diffstat (limited to 'src')
-rw-r--r--src/test/regress/expected/xc_FQS.out64
-rw-r--r--src/test/regress/expected/xc_FQS_join.out86
-rw-r--r--src/test/regress/expected/xc_create_function.out44
-rw-r--r--src/test/regress/expected/xc_misc.out57
-rw-r--r--src/test/regress/parallel_schedule14
-rw-r--r--src/test/regress/serial_schedule1
-rw-r--r--src/test/regress/sql/xc_FQS.sql50
-rw-r--r--src/test/regress/sql/xc_FQS_join.sql60
-rw-r--r--src/test/regress/sql/xc_create_function.sql45
-rw-r--r--src/test/regress/sql/xc_misc.sql54
10 files changed, 180 insertions, 295 deletions
diff --git a/src/test/regress/expected/xc_FQS.out b/src/test/regress/expected/xc_FQS.out
index 169ae5ab31..561cdc0b74 100644
--- a/src/test/regress/expected/xc_FQS.out
+++ b/src/test/regress/expected/xc_FQS.out
@@ -1,45 +1,12 @@
+--
+-- XC_FQS
+--
-- This file contains tests for Fast Query Shipping (FQS) for queries involving
-- a single table
--- A function to create table on specified nodes
-create or replace function cr_table(tab_schema varchar, nodenums int[], distribution varchar) returns void language plpgsql as $$
-declare
- cr_command varchar;
- nodes varchar[];
- nodename varchar;
- nodenames_query varchar;
- nodenames varchar;
- node int;
- sep varchar;
- tmp_node int;
- num_nodes int;
-begin
- nodenames_query := 'SELECT node_name FROM pgxc_node WHERE node_type = ''D''';
- cr_command := 'CREATE TABLE ' || tab_schema || ' DISTRIBUTE BY ' || distribution || ' TO NODE ';
- for nodename in execute nodenames_query loop
- nodes := array_append(nodes, nodename);
- end loop;
- nodenames := '';
- sep := '';
- num_nodes := array_length(nodes, 1);
- foreach node in array nodenums loop
- tmp_node := node;
- if (tmp_node < 1 or tmp_node > num_nodes) then
- tmp_node := tmp_node % num_nodes;
- if (tmp_node < 1) then
- tmp_node := num_nodes;
- end if;
- end if;
- nodenames := nodenames || sep || nodes[tmp_node];
- sep := ', ';
- end loop;
- cr_command := cr_command || nodenames;
- execute cr_command;
-end;
-$$;
-- Testset 1 for distributed table (by round robin)
-select cr_table('tab1_rr(val int, val2 int)', '{1, 2, 3}'::int[], 'round robin');
- cr_table
-----------
+select create_table_nodes('tab1_rr(val int, val2 int)', '{1, 2, 3}'::int[], 'round robin', NULL);
+ create_table_nodes
+--------------------
(1 row)
@@ -382,9 +349,9 @@ select * from tab1_rr where val = 7;
(0 rows)
-- Testset 2 for distributed tables (by hash)
-select cr_table('tab1_hash(val int, val2 int)', '{1, 2, 3}'::int[], 'hash(val)');
- cr_table
-----------
+select create_table_nodes('tab1_hash(val int, val2 int)', '{1, 2, 3}'::int[], 'hash(val)', NULL);
+ create_table_nodes
+--------------------
(1 row)
@@ -720,9 +687,9 @@ select * from tab1_hash where val = 7;
(0 rows)
-- Testset 3 for distributed tables (by modulo)
-select cr_table('tab1_modulo(val int, val2 int)', '{1, 2, 3}'::int[], 'modulo(val)');
- cr_table
-----------
+select create_table_nodes('tab1_modulo(val int, val2 int)', '{1, 2, 3}'::int[], 'modulo(val)', NULL);
+ create_table_nodes
+--------------------
(1 row)
@@ -1059,9 +1026,9 @@ select * from tab1_modulo where val = 7;
-- Testset 4 for replicated tables, for replicated tables, unless the expression
-- is itself unshippable, any query involving a single replicated table is shippable
-select cr_table('tab1_replicated(val int, val2 int)', '{1, 2, 3}'::int[], 'replication');
- cr_table
-----------
+select create_table_nodes('tab1_replicated(val int, val2 int)', '{1, 2, 3}'::int[], 'replication', NULL);
+ create_table_nodes
+--------------------
(1 row)
@@ -1262,4 +1229,3 @@ drop table tab1_rr;
drop table tab1_hash;
drop table tab1_modulo;
drop table tab1_replicated;
-drop function cr_table(varchar, int[], varchar);
diff --git a/src/test/regress/expected/xc_FQS_join.out b/src/test/regress/expected/xc_FQS_join.out
index a0848b8b4a..bfe196aaf0 100644
--- a/src/test/regress/expected/xc_FQS_join.out
+++ b/src/test/regress/expected/xc_FQS_join.out
@@ -1,85 +1,48 @@
+--
+-- XC_FQS_JOIN
+--
-- This file contains testcases for JOINs, it does not test the expressions
-- create the tables first
--- A function to create table on specified nodes
-create or replace function cr_table(tab_schema varchar, nodenums int[], distribution varchar, cmd_suffix varchar)
-returns void language plpgsql as $$
-declare
- cr_command varchar;
- nodes varchar[];
- nodename varchar;
- nodenames_query varchar;
- nodenames varchar;
- node int;
- sep varchar;
- tmp_node int;
- num_nodes int;
-begin
- nodenames_query := 'SELECT node_name FROM pgxc_node WHERE node_type = ''D''';
- cr_command := 'CREATE TABLE ' || tab_schema || ' DISTRIBUTE BY ' || distribution || ' TO NODE ';
- for nodename in execute nodenames_query loop
- nodes := array_append(nodes, nodename);
- end loop;
- nodenames := '';
- sep := '';
- num_nodes := array_length(nodes, 1);
- foreach node in array nodenums loop
- tmp_node := node;
- if (tmp_node < 1 or tmp_node > num_nodes) then
- tmp_node := tmp_node % num_nodes;
- if (tmp_node < 1) then
- tmp_node := num_nodes;
- end if;
- end if;
- nodenames := nodenames || sep || nodes[tmp_node];
- sep := ', ';
- end loop;
- cr_command := cr_command || nodenames;
- if (cmd_suffix is not null) then
- cr_command := cr_command || ' ' || cmd_suffix;
- end if;
- execute cr_command;
-end;
-$$;
-select cr_table('tab1_rep (val int, val2 int)', '{1, 2, 3}'::int[], 'replication', NULL);
- cr_table
-----------
+select create_table_nodes('tab1_rep (val int, val2 int)', '{1, 2, 3}'::int[], 'replication', NULL);
+ create_table_nodes
+--------------------
(1 row)
insert into tab1_rep (select * from generate_series(1, 5) a, generate_series(1, 5) b);
-select cr_table('tab2_rep', '{2, 3, 4}'::int[], 'replication', 'as select * from tab1_rep');
- cr_table
-----------
+select create_table_nodes('tab2_rep', '{2, 3, 4}'::int[], 'replication', 'as select * from tab1_rep');
+ create_table_nodes
+--------------------
(1 row)
-select cr_table('tab3_rep', '{1, 3}'::int[], 'replication', 'as select * from tab1_rep');
- cr_table
-----------
+select create_table_nodes('tab3_rep', '{1, 3}'::int[], 'replication', 'as select * from tab1_rep');
+ create_table_nodes
+--------------------
(1 row)
-select cr_table('tab4_rep', '{2, 4}'::int[], 'replication', 'as select * from tab1_rep');
- cr_table
-----------
+select create_table_nodes('tab4_rep', '{2, 4}'::int[], 'replication', 'as select * from tab1_rep');
+ create_table_nodes
+--------------------
(1 row)
-select cr_table('tab1_mod', '{1, 2, 3}'::int[], 'modulo(val)', 'as select * from tab1_rep');
- cr_table
-----------
+select create_table_nodes('tab1_mod', '{1, 2, 3}'::int[], 'modulo(val)', 'as select * from tab1_rep');
+ create_table_nodes
+--------------------
(1 row)
-select cr_table('tab2_mod', '{2, 4}'::int[], 'modulo(val)', 'as select * from tab1_rep');
- cr_table
-----------
+select create_table_nodes('tab2_mod', '{2, 4}'::int[], 'modulo(val)', 'as select * from tab1_rep');
+ create_table_nodes
+--------------------
(1 row)
-select cr_table('tab3_mod', '{1, 2, 3}'::int[], 'modulo(val)', 'as select * from tab1_rep');
- cr_table
-----------
+select create_table_nodes('tab3_mod', '{1, 2, 3}'::int[], 'modulo(val)', 'as select * from tab1_rep');
+ create_table_nodes
+--------------------
(1 row)
@@ -546,4 +509,3 @@ drop table tab3_rep;
drop table tab4_rep;
drop table tab1_mod;
drop table tab2_mod;
-drop function cr_table(varchar, int[], varchar, varchar);
diff --git a/src/test/regress/expected/xc_create_function.out b/src/test/regress/expected/xc_create_function.out
new file mode 100644
index 0000000000..ca0bfe0cd6
--- /dev/null
+++ b/src/test/regress/expected/xc_create_function.out
@@ -0,0 +1,44 @@
+--
+-- XC_CREATE_FUNCTIONS
+--
+-- Create a couple of functions used by Postgres-XC tests
+-- A function to create table on specified nodes
+create or replace function create_table_nodes(tab_schema varchar, nodenums int[], distribution varchar, cmd_suffix varchar)
+returns void language plpgsql as $$
+declare
+ cr_command varchar;
+ nodes varchar[];
+ nodename varchar;
+ nodenames_query varchar;
+ nodenames varchar;
+ node int;
+ sep varchar;
+ tmp_node int;
+ num_nodes int;
+begin
+ nodenames_query := 'SELECT node_name FROM pgxc_node WHERE node_type = ''D''';
+ cr_command := 'CREATE TABLE ' || tab_schema || ' DISTRIBUTE BY ' || distribution || ' TO NODE ';
+ for nodename in execute nodenames_query loop
+ nodes := array_append(nodes, nodename);
+ end loop;
+ nodenames := '';
+ sep := '';
+ num_nodes := array_length(nodes, 1);
+ foreach node in array nodenums loop
+ tmp_node := node;
+ if (tmp_node < 1 or tmp_node > num_nodes) then
+ tmp_node := tmp_node % num_nodes;
+ if (tmp_node < 1) then
+ tmp_node := num_nodes;
+ end if;
+ end if;
+ nodenames := nodenames || sep || nodes[tmp_node];
+ sep := ', ';
+ end loop;
+ cr_command := cr_command || nodenames;
+ if (cmd_suffix is not null) then
+ cr_command := cr_command || ' ' || cmd_suffix;
+ end if;
+ execute cr_command;
+end;
+$$;
diff --git a/src/test/regress/expected/xc_misc.out b/src/test/regress/expected/xc_misc.out
index ffea2dbe61..9f11ff59b0 100644
--- a/src/test/regress/expected/xc_misc.out
+++ b/src/test/regress/expected/xc_misc.out
@@ -1,39 +1,6 @@
--- A function to create table on specified nodes
-create or replace function cr_table(tab_schema varchar, nodenums int[], distribution varchar) returns void language plpgsql as $$
-declare
- cr_command varchar;
- nodes varchar[];
- nodename varchar;
- nodenames_query varchar;
- nodenames varchar;
- node int;
- sep varchar;
- tmp_node int;
- num_nodes int;
-begin
- nodenames_query := 'SELECT node_name FROM pgxc_node WHERE node_type = ''D''';
- cr_command := 'CREATE TABLE ' || tab_schema || ' DISTRIBUTE BY ' || distribution || ' TO NODE ';
- for nodename in execute nodenames_query loop
- nodes := array_append(nodes, nodename);
- end loop;
- nodenames := '';
- sep := '';
- num_nodes := array_length(nodes, 1);
- foreach node in array nodenums loop
- tmp_node := node;
- if (tmp_node < 1 or tmp_node > num_nodes) then
- tmp_node := tmp_node % num_nodes;
- if (tmp_node < 1) then
- tmp_node := num_nodes;
- end if;
- end if;
- nodenames := nodenames || sep || nodes[tmp_node];
- sep := ', ';
- end loop;
- cr_command := cr_command || nodenames;
- execute cr_command;
-end;
-$$;
+--
+-- XC_MISC
+--
-- A function to return a unified data node name given a node identifer
create or replace function get_unified_node_name(node_ident int) returns varchar language plpgsql as $$
declare
@@ -54,14 +21,14 @@ begin
end;
$$;
-- Test the system column added by XC called xc_node_id, used to find which tuples belong to which data node
-select cr_table('t1(a int, b int)', '{1, 2}'::int[], 'modulo(a)');
- cr_table
-----------
+select create_table_nodes('t1_misc(a int, b int)', '{1, 2}'::int[], 'modulo(a)', NULL);
+ create_table_nodes
+--------------------
(1 row)
-insert into t1 values(1,11),(2,11),(3,11),(4,22),(5,22),(6,33),(7,44),(8,44);
-select get_unified_node_name(xc_node_id),* from t1 order by a;
+insert into t1_misc values(1,11),(2,11),(3,11),(4,22),(5,22),(6,33),(7,44),(8,44);
+select get_unified_node_name(xc_node_id),* from t1_misc order by a;
get_unified_node_name | a | b
-----------------------+---+----
NODE_2 | 1 | 11
@@ -74,7 +41,7 @@ select get_unified_node_name(xc_node_id),* from t1 order by a;
NODE_1 | 8 | 44
(8 rows)
-select get_unified_node_name(xc_node_id),* from t1 where xc_node_id > 0 order by a;
+select get_unified_node_name(xc_node_id),* from t1_misc where xc_node_id > 0 order by a;
get_unified_node_name | a | b
-----------------------+---+----
NODE_2 | 1 | 11
@@ -83,11 +50,11 @@ select get_unified_node_name(xc_node_id),* from t1 where xc_node_id > 0 order by
NODE_2 | 7 | 44
(4 rows)
-create table t2(a int , xc_node_id int) distribute by modulo(a);
+create table t2_misc(a int , xc_node_id int) distribute by modulo(a);
ERROR: column name "xc_node_id" conflicts with a system column name
-create table t2(a int , b int) distribute by modulo(xc_node_id);
+create table t2_misc(a int , b int) distribute by modulo(xc_node_id);
ERROR: Invalid distribution column specified
-drop table t1;
+drop table t1_misc;
-- Test an SQL function with multiple statements in it including a utility statement.
create table my_tab1 (a int);
insert into my_tab1 values(1);
diff --git a/src/test/regress/parallel_schedule b/src/test/regress/parallel_schedule
index 8057d9f90a..5da84f621e 100644
--- a/src/test/regress/parallel_schedule
+++ b/src/test/regress/parallel_schedule
@@ -103,12 +103,16 @@ test: plancache limit plpgsql copy2 temp domain rangefuncs prepare without_oid c
# run stats by itself because its delay may be insufficient under heavy load
test: stats
-#Postgres-XC additional tests, they can be run in parallel
-test: xc_groupby xc_distkey xc_having xc_temp xc_remote xc_FQS xc_FQS_join xc_copy xc_for_update xc_alter_table xc_sequence
+# ----------
+# Postgres-XC additional tests
+# ----------
+# This creates functions used by tests xc_misc, xc_FQS and xc_FQS_join
+test: xc_create_function
+# Those ones can be run in parallel
+test: xc_groupby xc_distkey xc_having xc_temp xc_remote xc_FQS xc_FQS_join xc_copy xc_for_update xc_alter_table xc_sequence xc_misc
-#Cluster setting related test is independant
+# Cluster setting related test is independant
test: xc_node
-test: xc_misc
-#Additional tests for prepared xacts
+# Additional tests for prepared xacts
test: xc_prepared_xacts
diff --git a/src/test/regress/serial_schedule b/src/test/regress/serial_schedule
index e3b4736902..78a2f4385e 100644
--- a/src/test/regress/serial_schedule
+++ b/src/test/regress/serial_schedule
@@ -127,6 +127,7 @@ test: largeobject
test: with
test: xml
test: stats
+test: xc_create_function
test: xc_groupby
test: xc_distkey
test: xc_having
diff --git a/src/test/regress/sql/xc_FQS.sql b/src/test/regress/sql/xc_FQS.sql
index 3a5479311b..c36179fa01 100644
--- a/src/test/regress/sql/xc_FQS.sql
+++ b/src/test/regress/sql/xc_FQS.sql
@@ -1,45 +1,12 @@
+--
+-- XC_FQS
+--
+
-- This file contains tests for Fast Query Shipping (FQS) for queries involving
-- a single table
--- A function to create table on specified nodes
-create or replace function cr_table(tab_schema varchar, nodenums int[], distribution varchar) returns void language plpgsql as $$
-declare
- cr_command varchar;
- nodes varchar[];
- nodename varchar;
- nodenames_query varchar;
- nodenames varchar;
- node int;
- sep varchar;
- tmp_node int;
- num_nodes int;
-begin
- nodenames_query := 'SELECT node_name FROM pgxc_node WHERE node_type = ''D''';
- cr_command := 'CREATE TABLE ' || tab_schema || ' DISTRIBUTE BY ' || distribution || ' TO NODE ';
- for nodename in execute nodenames_query loop
- nodes := array_append(nodes, nodename);
- end loop;
- nodenames := '';
- sep := '';
- num_nodes := array_length(nodes, 1);
- foreach node in array nodenums loop
- tmp_node := node;
- if (tmp_node < 1 or tmp_node > num_nodes) then
- tmp_node := tmp_node % num_nodes;
- if (tmp_node < 1) then
- tmp_node := num_nodes;
- end if;
- end if;
- nodenames := nodenames || sep || nodes[tmp_node];
- sep := ', ';
- end loop;
- cr_command := cr_command || nodenames;
- execute cr_command;
-end;
-$$;
-
-- Testset 1 for distributed table (by round robin)
-select cr_table('tab1_rr(val int, val2 int)', '{1, 2, 3}'::int[], 'round robin');
+select create_table_nodes('tab1_rr(val int, val2 int)', '{1, 2, 3}'::int[], 'round robin', NULL);
insert into tab1_rr values (1, 2);
insert into tab1_rr values (2, 4);
insert into tab1_rr values (5, 3);
@@ -105,7 +72,7 @@ explain (costs off, verbose on, nodes off) delete from tab1_rr where val = 7;
select * from tab1_rr where val = 7;
-- Testset 2 for distributed tables (by hash)
-select cr_table('tab1_hash(val int, val2 int)', '{1, 2, 3}'::int[], 'hash(val)');
+select create_table_nodes('tab1_hash(val int, val2 int)', '{1, 2, 3}'::int[], 'hash(val)', NULL);
insert into tab1_hash values (1, 2);
insert into tab1_hash values (2, 4);
insert into tab1_hash values (5, 3);
@@ -170,7 +137,7 @@ explain (costs off, verbose on, nodes off) delete from tab1_hash where val = 7;
select * from tab1_hash where val = 7;
-- Testset 3 for distributed tables (by modulo)
-select cr_table('tab1_modulo(val int, val2 int)', '{1, 2, 3}'::int[], 'modulo(val)');
+select create_table_nodes('tab1_modulo(val int, val2 int)', '{1, 2, 3}'::int[], 'modulo(val)', NULL);
insert into tab1_modulo values (1, 2);
insert into tab1_modulo values (2, 4);
insert into tab1_modulo values (5, 3);
@@ -236,7 +203,7 @@ select * from tab1_modulo where val = 7;
-- Testset 4 for replicated tables, for replicated tables, unless the expression
-- is itself unshippable, any query involving a single replicated table is shippable
-select cr_table('tab1_replicated(val int, val2 int)', '{1, 2, 3}'::int[], 'replication');
+select create_table_nodes('tab1_replicated(val int, val2 int)', '{1, 2, 3}'::int[], 'replication', NULL);
insert into tab1_replicated values (1, 2);
insert into tab1_replicated values (2, 4);
insert into tab1_replicated values (5, 3);
@@ -274,4 +241,3 @@ drop table tab1_rr;
drop table tab1_hash;
drop table tab1_modulo;
drop table tab1_replicated;
-drop function cr_table(varchar, int[], varchar);
diff --git a/src/test/regress/sql/xc_FQS_join.sql b/src/test/regress/sql/xc_FQS_join.sql
index fd7daa3b9d..9419c720a9 100644
--- a/src/test/regress/sql/xc_FQS_join.sql
+++ b/src/test/regress/sql/xc_FQS_join.sql
@@ -1,54 +1,18 @@
+--
+-- XC_FQS_JOIN
+--
+
-- This file contains testcases for JOINs, it does not test the expressions
-- create the tables first
--- A function to create table on specified nodes
-create or replace function cr_table(tab_schema varchar, nodenums int[], distribution varchar, cmd_suffix varchar)
-returns void language plpgsql as $$
-declare
- cr_command varchar;
- nodes varchar[];
- nodename varchar;
- nodenames_query varchar;
- nodenames varchar;
- node int;
- sep varchar;
- tmp_node int;
- num_nodes int;
-begin
- nodenames_query := 'SELECT node_name FROM pgxc_node WHERE node_type = ''D''';
- cr_command := 'CREATE TABLE ' || tab_schema || ' DISTRIBUTE BY ' || distribution || ' TO NODE ';
- for nodename in execute nodenames_query loop
- nodes := array_append(nodes, nodename);
- end loop;
- nodenames := '';
- sep := '';
- num_nodes := array_length(nodes, 1);
- foreach node in array nodenums loop
- tmp_node := node;
- if (tmp_node < 1 or tmp_node > num_nodes) then
- tmp_node := tmp_node % num_nodes;
- if (tmp_node < 1) then
- tmp_node := num_nodes;
- end if;
- end if;
- nodenames := nodenames || sep || nodes[tmp_node];
- sep := ', ';
- end loop;
- cr_command := cr_command || nodenames;
- if (cmd_suffix is not null) then
- cr_command := cr_command || ' ' || cmd_suffix;
- end if;
- execute cr_command;
-end;
-$$;
-select cr_table('tab1_rep (val int, val2 int)', '{1, 2, 3}'::int[], 'replication', NULL);
+select create_table_nodes('tab1_rep (val int, val2 int)', '{1, 2, 3}'::int[], 'replication', NULL);
insert into tab1_rep (select * from generate_series(1, 5) a, generate_series(1, 5) b);
-select cr_table('tab2_rep', '{2, 3, 4}'::int[], 'replication', 'as select * from tab1_rep');
-select cr_table('tab3_rep', '{1, 3}'::int[], 'replication', 'as select * from tab1_rep');
-select cr_table('tab4_rep', '{2, 4}'::int[], 'replication', 'as select * from tab1_rep');
-select cr_table('tab1_mod', '{1, 2, 3}'::int[], 'modulo(val)', 'as select * from tab1_rep');
-select cr_table('tab2_mod', '{2, 4}'::int[], 'modulo(val)', 'as select * from tab1_rep');
-select cr_table('tab3_mod', '{1, 2, 3}'::int[], 'modulo(val)', 'as select * from tab1_rep');
+select create_table_nodes('tab2_rep', '{2, 3, 4}'::int[], 'replication', 'as select * from tab1_rep');
+select create_table_nodes('tab3_rep', '{1, 3}'::int[], 'replication', 'as select * from tab1_rep');
+select create_table_nodes('tab4_rep', '{2, 4}'::int[], 'replication', 'as select * from tab1_rep');
+select create_table_nodes('tab1_mod', '{1, 2, 3}'::int[], 'modulo(val)', 'as select * from tab1_rep');
+select create_table_nodes('tab2_mod', '{2, 4}'::int[], 'modulo(val)', 'as select * from tab1_rep');
+select create_table_nodes('tab3_mod', '{1, 2, 3}'::int[], 'modulo(val)', 'as select * from tab1_rep');
-- Join involving replicated tables only, all of them should be shippable
select * from tab1_rep, tab2_rep where tab1_rep.val = tab2_rep.val and
@@ -157,4 +121,4 @@ drop table tab3_rep;
drop table tab4_rep;
drop table tab1_mod;
drop table tab2_mod;
-drop function cr_table(varchar, int[], varchar, varchar);
+
diff --git a/src/test/regress/sql/xc_create_function.sql b/src/test/regress/sql/xc_create_function.sql
new file mode 100644
index 0000000000..76ce96381e
--- /dev/null
+++ b/src/test/regress/sql/xc_create_function.sql
@@ -0,0 +1,45 @@
+--
+-- XC_CREATE_FUNCTIONS
+--
+
+-- Create a couple of functions used by Postgres-XC tests
+-- A function to create table on specified nodes
+create or replace function create_table_nodes(tab_schema varchar, nodenums int[], distribution varchar, cmd_suffix varchar)
+returns void language plpgsql as $$
+declare
+ cr_command varchar;
+ nodes varchar[];
+ nodename varchar;
+ nodenames_query varchar;
+ nodenames varchar;
+ node int;
+ sep varchar;
+ tmp_node int;
+ num_nodes int;
+begin
+ nodenames_query := 'SELECT node_name FROM pgxc_node WHERE node_type = ''D''';
+ cr_command := 'CREATE TABLE ' || tab_schema || ' DISTRIBUTE BY ' || distribution || ' TO NODE ';
+ for nodename in execute nodenames_query loop
+ nodes := array_append(nodes, nodename);
+ end loop;
+ nodenames := '';
+ sep := '';
+ num_nodes := array_length(nodes, 1);
+ foreach node in array nodenums loop
+ tmp_node := node;
+ if (tmp_node < 1 or tmp_node > num_nodes) then
+ tmp_node := tmp_node % num_nodes;
+ if (tmp_node < 1) then
+ tmp_node := num_nodes;
+ end if;
+ end if;
+ nodenames := nodenames || sep || nodes[tmp_node];
+ sep := ', ';
+ end loop;
+ cr_command := cr_command || nodenames;
+ if (cmd_suffix is not null) then
+ cr_command := cr_command || ' ' || cmd_suffix;
+ end if;
+ execute cr_command;
+end;
+$$;
diff --git a/src/test/regress/sql/xc_misc.sql b/src/test/regress/sql/xc_misc.sql
index ed85a369f1..94abc30b84 100644
--- a/src/test/regress/sql/xc_misc.sql
+++ b/src/test/regress/sql/xc_misc.sql
@@ -1,39 +1,6 @@
--- A function to create table on specified nodes
-create or replace function cr_table(tab_schema varchar, nodenums int[], distribution varchar) returns void language plpgsql as $$
-declare
- cr_command varchar;
- nodes varchar[];
- nodename varchar;
- nodenames_query varchar;
- nodenames varchar;
- node int;
- sep varchar;
- tmp_node int;
- num_nodes int;
-begin
- nodenames_query := 'SELECT node_name FROM pgxc_node WHERE node_type = ''D''';
- cr_command := 'CREATE TABLE ' || tab_schema || ' DISTRIBUTE BY ' || distribution || ' TO NODE ';
- for nodename in execute nodenames_query loop
- nodes := array_append(nodes, nodename);
- end loop;
- nodenames := '';
- sep := '';
- num_nodes := array_length(nodes, 1);
- foreach node in array nodenums loop
- tmp_node := node;
- if (tmp_node < 1 or tmp_node > num_nodes) then
- tmp_node := tmp_node % num_nodes;
- if (tmp_node < 1) then
- tmp_node := num_nodes;
- end if;
- end if;
- nodenames := nodenames || sep || nodes[tmp_node];
- sep := ', ';
- end loop;
- cr_command := cr_command || nodenames;
- execute cr_command;
-end;
-$$;
+--
+-- XC_MISC
+--
-- A function to return a unified data node name given a node identifer
create or replace function get_unified_node_name(node_ident int) returns varchar language plpgsql as $$
@@ -57,18 +24,18 @@ $$;
-- Test the system column added by XC called xc_node_id, used to find which tuples belong to which data node
-select cr_table('t1(a int, b int)', '{1, 2}'::int[], 'modulo(a)');
-insert into t1 values(1,11),(2,11),(3,11),(4,22),(5,22),(6,33),(7,44),(8,44);
+select create_table_nodes('t1_misc(a int, b int)', '{1, 2}'::int[], 'modulo(a)', NULL);
+insert into t1_misc values(1,11),(2,11),(3,11),(4,22),(5,22),(6,33),(7,44),(8,44);
-select get_unified_node_name(xc_node_id),* from t1 order by a;
+select get_unified_node_name(xc_node_id),* from t1_misc order by a;
-select get_unified_node_name(xc_node_id),* from t1 where xc_node_id > 0 order by a;
+select get_unified_node_name(xc_node_id),* from t1_misc where xc_node_id > 0 order by a;
-create table t2(a int , xc_node_id int) distribute by modulo(a);
+create table t2_misc(a int , xc_node_id int) distribute by modulo(a);
-create table t2(a int , b int) distribute by modulo(xc_node_id);
+create table t2_misc(a int , b int) distribute by modulo(xc_node_id);
-drop table t1;
+drop table t1_misc;
-- Test an SQL function with multiple statements in it including a utility statement.
@@ -155,4 +122,3 @@ drop table grand_parent;
drop table c_11;
drop table t_22;
drop table t_11;
-