Fix issue with multiple ANALYZE in transaction block

pull/1867/head
Marco Slot 2017-12-10 11:59:25 +01:00
parent 84957fe6e7
commit d1a470a52e
3 changed files with 23 additions and 4 deletions

View File

@ -1555,10 +1555,18 @@ ProcessVacuumStmt(VacuumStmt *vacuumStmt, const char *vacuumCommand)
taskList = VacuumTaskList(relationId, vacuumStmt); taskList = VacuumTaskList(relationId, vacuumStmt);
/* save old commit protocol to restore at xact end */ /*
Assert(SavedMultiShardCommitProtocol == COMMIT_PROTOCOL_BARE); * VACUUM commands cannot run inside a transaction block, so we use
SavedMultiShardCommitProtocol = MultiShardCommitProtocol; * the "bare" commit protocol without BEGIN/COMMIT. However, ANALYZE
MultiShardCommitProtocol = COMMIT_PROTOCOL_BARE; * commands can run inside a transaction block.
*/
if ((vacuumStmt->options & VACOPT_VACUUM) != 0)
{
/* save old commit protocol to restore at xact end */
Assert(SavedMultiShardCommitProtocol == COMMIT_PROTOCOL_BARE);
SavedMultiShardCommitProtocol = MultiShardCommitProtocol;
MultiShardCommitProtocol = COMMIT_PROTOCOL_BARE;
}
ExecuteModifyTasksWithoutResults(taskList); ExecuteModifyTasksWithoutResults(taskList);
} }

View File

@ -25,6 +25,11 @@ COPY sharded_table TO STDOUT;
COPY (SELECT COUNT(*) FROM sharded_table) TO STDOUT; COPY (SELECT COUNT(*) FROM sharded_table) TO STDOUT;
0 0
COMMIT; COMMIT;
-- ANALYZE is supported in a transaction block
BEGIN;
ANALYZE sharded_table;
ANALYZE sharded_table;
END;
-- cursors may not involve distributed tables -- cursors may not involve distributed tables
DECLARE all_sharded_rows CURSOR FOR SELECT * FROM sharded_table; DECLARE all_sharded_rows CURSOR FOR SELECT * FROM sharded_table;
ERROR: DECLARE CURSOR can only be used in transaction blocks ERROR: DECLARE CURSOR can only be used in transaction blocks

View File

@ -20,6 +20,12 @@ COPY sharded_table TO STDOUT;
COPY (SELECT COUNT(*) FROM sharded_table) TO STDOUT; COPY (SELECT COUNT(*) FROM sharded_table) TO STDOUT;
COMMIT; COMMIT;
-- ANALYZE is supported in a transaction block
BEGIN;
ANALYZE sharded_table;
ANALYZE sharded_table;
END;
-- cursors may not involve distributed tables -- cursors may not involve distributed tables
DECLARE all_sharded_rows CURSOR FOR SELECT * FROM sharded_table; DECLARE all_sharded_rows CURSOR FOR SELECT * FROM sharded_table;