diff --git a/contrib/babelfishpg_tsql/src/guc.c b/contrib/babelfishpg_tsql/src/guc.c index 70412e6bc8..2d1a30f03c 100644 --- a/contrib/babelfishpg_tsql/src/guc.c +++ b/contrib/babelfishpg_tsql/src/guc.c @@ -9,6 +9,7 @@ #include "pltsql.h" #include "pl_explain.h" #include "miscadmin.h" +#include "access/parallel.h" #define PLTSQL_SESSION_ISOLATION_LEVEL "default_transaction_isolation" #define PLTSQL_TRANSACTION_ISOLATION_LEVEL "transaction_isolation" @@ -380,6 +381,30 @@ static bool check_tsql_version (char **newval, void **extra, GucSource source) static void assign_enable_pg_hint (bool newval, void *extra) { + /* + * Parallel workers send data to the leader, not the client. They always + * send data using pg_hint_plan.enable_hint_plan. + */ + if (IsParallelWorker()) + { + /* + * During parallel worker startup, we want to accept the leader's + * hint_plan setting so that anyone who looks at the value in + * the worker sees the same value that they would see in the leader. + */ + if (InitializingParallelWorker) + return; + + /* + * A change other than during startup, for example due to a SET clause + * attached to a function definition, should be rejected, as there is + * nothing we can do inside the worker to make it take effect. + */ + ereport(ERROR, + (errcode(ERRCODE_INVALID_TRANSACTION_STATE), + errmsg("cannot change enable_hint_plan during a parallel operation"))); + } + if (newval) { /* Will throw an error if pg_hint_plan is not installed */ diff --git a/test/JDBC/expected/BABEL-4294-vu-cleanup.out b/test/JDBC/expected/BABEL-4294-vu-cleanup.out new file mode 100644 index 0000000000..27908b4de2 --- /dev/null +++ b/test/JDBC/expected/BABEL-4294-vu-cleanup.out @@ -0,0 +1,9 @@ + +-- Test to check if initialisation of Parallel Worker crash when babelfishpg_tsql.enable_pg_hint is set +drop table babel_4294_t1; +drop table babel_4294_t2; +drop table babel_4294_t3; +go + +drop table babel_4294_t4; +go diff --git a/test/JDBC/expected/BABEL-4294-vu-prepare.out b/test/JDBC/expected/BABEL-4294-vu-prepare.out new file mode 100644 index 0000000000..de31202caf --- /dev/null +++ b/test/JDBC/expected/BABEL-4294-vu-prepare.out @@ -0,0 +1,20 @@ + +-- Test to check if initialisation of Parallel Worker crash when babelfishpg_tsql.enable_pg_hint is set +create table babel_4294_t1(id INT, val int); +create table babel_4294_t2(babel_4294_t1_id INT, val int); +create table babel_4294_t3(babel_4294_t1_id INT, val int); +go + +insert into babel_4294_t1 values (1, 10), (2, 20), (3, 30); +insert into babel_4294_t2 values (1, 11), (2, 12), (3, 13); +insert into babel_4294_t3 values (1, 99), (2, 77), (3, 55); +go +~~ROW COUNT: 3~~ + +~~ROW COUNT: 3~~ + +~~ROW COUNT: 3~~ + + +create table babel_4294_t4(id INT, val int); +go diff --git a/test/JDBC/expected/BABEL-4294-vu-verify.out b/test/JDBC/expected/BABEL-4294-vu-verify.out new file mode 100644 index 0000000000..26eb15be04 --- /dev/null +++ b/test/JDBC/expected/BABEL-4294-vu-verify.out @@ -0,0 +1,56 @@ + +-- Test to check if initialisation of Parallel Worker crash when babelfishpg_tsql.enable_pg_hint is set +/* + * Set the enable_pg_hint, try to create parallel worker + */ +exec sp_babelfish_configure 'enable_pg_hint', 'on', 'server' +go + +select COUNT( babel_4294_t3.val), babel_4294_t2.val from babel_4294_t1 +inner join babel_4294_t2 on babel_4294_t1.id = babel_4294_t2.babel_4294_t1_id +inner join babel_4294_t3 on babel_4294_t1.id = babel_4294_t3.babel_4294_t1_id +GROUP BY babel_4294_t2.val +UNION ALL +select COUNT( babel_4294_t3.val), babel_4294_t2.val from babel_4294_t1 +inner join babel_4294_t2 on babel_4294_t1.id = babel_4294_t2.babel_4294_t1_id +inner join babel_4294_t3 on babel_4294_t1.id = babel_4294_t3.babel_4294_t1_id +GROUP BY babel_4294_t2.val +go +~~START~~ +int#!#int +1#!#11 +1#!#13 +1#!#12 +1#!#11 +1#!#13 +1#!#12 +~~END~~ + + +-- Used force parallel mode to create a parallel worker +select set_config('force_parallel_mode', '1', false) +go +~~START~~ +text +on +~~END~~ + + +-- to check if parallel worker generated for following query, will crash or not +select * from babel_4294_t4 +go +~~START~~ +int#!#int +~~END~~ + + +select set_config('force_parallel_mode', '0', false) +go +~~START~~ +text +off +~~END~~ + + +exec sp_babelfish_configure 'enable_pg_hint', 'off', 'server' +go diff --git a/test/JDBC/input/pg_hint_plan/BABEL-4294-vu-cleanup.sql b/test/JDBC/input/pg_hint_plan/BABEL-4294-vu-cleanup.sql new file mode 100644 index 0000000000..9a5b6bb6f8 --- /dev/null +++ b/test/JDBC/input/pg_hint_plan/BABEL-4294-vu-cleanup.sql @@ -0,0 +1,9 @@ +-- Test to check if initialisation of Parallel Worker crash when babelfishpg_tsql.enable_pg_hint is set + +drop table babel_4294_t1; +drop table babel_4294_t2; +drop table babel_4294_t3; +go + +drop table babel_4294_t4; +go \ No newline at end of file diff --git a/test/JDBC/input/pg_hint_plan/BABEL-4294-vu-prepare.sql b/test/JDBC/input/pg_hint_plan/BABEL-4294-vu-prepare.sql new file mode 100644 index 0000000000..3cff14194b --- /dev/null +++ b/test/JDBC/input/pg_hint_plan/BABEL-4294-vu-prepare.sql @@ -0,0 +1,14 @@ +-- Test to check if initialisation of Parallel Worker crash when babelfishpg_tsql.enable_pg_hint is set + +create table babel_4294_t1(id INT, val int); +create table babel_4294_t2(babel_4294_t1_id INT, val int); +create table babel_4294_t3(babel_4294_t1_id INT, val int); +go + +insert into babel_4294_t1 values (1, 10), (2, 20), (3, 30); +insert into babel_4294_t2 values (1, 11), (2, 12), (3, 13); +insert into babel_4294_t3 values (1, 99), (2, 77), (3, 55); +go + +create table babel_4294_t4(id INT, val int); +go \ No newline at end of file diff --git a/test/JDBC/input/pg_hint_plan/BABEL-4294-vu-verify.sql b/test/JDBC/input/pg_hint_plan/BABEL-4294-vu-verify.sql new file mode 100644 index 0000000000..cdd1e3daef --- /dev/null +++ b/test/JDBC/input/pg_hint_plan/BABEL-4294-vu-verify.sql @@ -0,0 +1,32 @@ +-- Test to check if initialisation of Parallel Worker crash when babelfishpg_tsql.enable_pg_hint is set +/* + * Set the enable_pg_hint, try to create parallel worker + */ + +exec sp_babelfish_configure 'enable_pg_hint', 'on', 'server' +go + +select COUNT( babel_4294_t3.val), babel_4294_t2.val from babel_4294_t1 +inner join babel_4294_t2 on babel_4294_t1.id = babel_4294_t2.babel_4294_t1_id +inner join babel_4294_t3 on babel_4294_t1.id = babel_4294_t3.babel_4294_t1_id +GROUP BY babel_4294_t2.val +UNION ALL +select COUNT( babel_4294_t3.val), babel_4294_t2.val from babel_4294_t1 +inner join babel_4294_t2 on babel_4294_t1.id = babel_4294_t2.babel_4294_t1_id +inner join babel_4294_t3 on babel_4294_t1.id = babel_4294_t3.babel_4294_t1_id +GROUP BY babel_4294_t2.val +go + +-- Used force parallel mode to create a parallel worker +select set_config('force_parallel_mode', '1', false) +go + +-- to check if parallel worker generated for following query, will crash or not +select * from babel_4294_t4 +go + +select set_config('force_parallel_mode', '0', false) +go + +exec sp_babelfish_configure 'enable_pg_hint', 'off', 'server' +go \ No newline at end of file