Fix segfault when executing DDL via UDF

pull/3259/head
Marco Slot 2019-12-01 22:54:41 +01:00
parent 5957d731ec
commit b1b13e394e
5 changed files with 25 additions and 1 deletions

View File

@ -479,6 +479,12 @@ ExecuteQueryIntoDestReceiver(Query *query, ParamListInfo params, DestReceiver *d
{ {
int cursorOptions = CURSOR_OPT_PARALLEL_OK; int cursorOptions = CURSOR_OPT_PARALLEL_OK;
if (query->commandType == CMD_UTILITY)
{
/* can only execute DML/SELECT via this path */
ereport(ERROR, (errmsg("cannot execute utility commands")));
}
/* plan the subquery, this may be another distributed query */ /* plan the subquery, this may be another distributed query */
PlannedStmt *queryPlan = pg_plan_query(query, cursorOptions, params); PlannedStmt *queryPlan = pg_plan_query(query, cursorOptions, params);

View File

@ -252,6 +252,13 @@ SELECT * FROM squares ORDER BY x;
-- empty shard interval array should raise error -- empty shard interval array should raise error
SELECT worker_hash_partition_table(42,1,'SELECT a FROM generate_series(1,100) AS a', 'a', 23, ARRAY[0]); SELECT worker_hash_partition_table(42,1,'SELECT a FROM generate_series(1,100) AS a', 'a', 23, ARRAY[0]);
ERROR: invalid distribution column value ERROR: invalid distribution column value
-- cannot use DDL commands
select broadcast_intermediate_result('a', 'create table foo(int serial)');
ERROR: cannot execute utility commands
select broadcast_intermediate_result('a', 'prepare foo as select 1');
ERROR: cannot execute utility commands
select create_intermediate_result('a', 'create table foo(int serial)');
ERROR: cannot execute utility commands
DROP SCHEMA intermediate_results CASCADE; DROP SCHEMA intermediate_results CASCADE;
NOTICE: drop cascades to 5 other objects NOTICE: drop cascades to 5 other objects
DETAIL: drop cascades to table interesting_squares DETAIL: drop cascades to table interesting_squares

View File

@ -67,7 +67,7 @@ ERROR: column name array size: 2 and type array size: 3 do not match
SELECT worker_merge_files_into_table(:JobId, :TaskId, SELECT worker_merge_files_into_table(:JobId, :TaskId,
ARRAY['textcolumn', 'binarycolumn'], ARRAY['textcolumn', 'binarycolumn'],
ARRAY['text', 'integer']); ARRAY['text', 'integer']);
ERROR: invalid input syntax for type integer: "\x0b50" ERROR: invalid input syntax for integer: "\x0b50"
CONTEXT: COPY task_101108, line 1, column binarycolumn: "\x0b50" CONTEXT: COPY task_101108, line 1, column binarycolumn: "\x0b50"
-- Check that we fail to merge when ids are wrong -- Check that we fail to merge when ids are wrong
SELECT worker_merge_files_into_table(-1, :TaskId, SELECT worker_merge_files_into_table(-1, :TaskId,
@ -97,3 +97,6 @@ SELECT worker_merge_files_into_table(:JobId, :TaskId,
(1 row) (1 row)
-- worker_execute_sql_task should only accept queries
select worker_execute_sql_task(0,0,'create table foo(a serial)',false);
ERROR: cannot execute utility commands

View File

@ -143,4 +143,9 @@ SELECT * FROM squares ORDER BY x;
-- empty shard interval array should raise error -- empty shard interval array should raise error
SELECT worker_hash_partition_table(42,1,'SELECT a FROM generate_series(1,100) AS a', 'a', 23, ARRAY[0]); SELECT worker_hash_partition_table(42,1,'SELECT a FROM generate_series(1,100) AS a', 'a', 23, ARRAY[0]);
-- cannot use DDL commands
select broadcast_intermediate_result('a', 'create table foo(int serial)');
select broadcast_intermediate_result('a', 'prepare foo as select 1');
select create_intermediate_result('a', 'create table foo(int serial)');
DROP SCHEMA intermediate_results CASCADE; DROP SCHEMA intermediate_results CASCADE;

View File

@ -100,3 +100,6 @@ SELECT worker_merge_files_and_run_query(:JobId, -1,
SELECT worker_merge_files_into_table(:JobId, :TaskId, SELECT worker_merge_files_into_table(:JobId, :TaskId,
ARRAY['textcolumn', 'binarycolumn'], ARRAY['textcolumn', 'binarycolumn'],
ARRAY['text', 'bytea']); ARRAY['text', 'bytea']);
-- worker_execute_sql_task should only accept queries
select worker_execute_sql_task(0,0,'create table foo(a serial)',false);