From 1f18bd630a6b29b427dc5da01077e4f20fb60e01 Mon Sep 17 00:00:00 2001 From: Monty Date: Thu, 11 Jan 2018 16:38:21 +0200 Subject: MDEV-8200 aria bug with insert select and lock tables This bug happens when locking the same Aria "transactional" table (page format) more then once with LOCK TABLES and inserting into one of them with INSERT ... SELECT when the table is empty. Fixed by ensuring we don't use fast bulk insert if table is opened twice with LOCK TABLES (as this changes table->s->state) Code changes: - Added use_count to MARIA_USED_TABLES to be able to check if table is opened twice for a statement/lock table - Don't clear history or reset info->start_state if we don't have versioning. One reason for the bug was was that info->start_state was set to point to different states for the two tables. If there is no versioning info->start_state should always point to info->s->state.common. Other things: - Fixed also some typos that was noticed while scanning the code - More DBUG_PRINT --- storage/maria/ha_maria.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'storage/maria/ha_maria.cc') diff --git a/storage/maria/ha_maria.cc b/storage/maria/ha_maria.cc index 44f7b466a2a..0c41037f33e 100644 --- a/storage/maria/ha_maria.cc +++ b/storage/maria/ha_maria.cc @@ -2112,11 +2112,16 @@ void ha_maria::start_bulk_insert(ha_rows rows) safety net for now, we don't remove the test of file->state->records, because there is uncertainty on what will happen during repair if the two states disagree. + + We also have to check in case of transactional tables that the + user has not used LOCK TABLE on the table twice. */ if ((file->state->records == 0) && (share->state.state.records == 0) && can_enable_indexes && (!rows || rows >= MARIA_MIN_ROWS_TO_DISABLE_INDEXES) && - (file->lock.type == TL_WRITE || file->lock.type == TL_UNLOCK)) + (file->lock.type == TL_WRITE || file->lock.type == TL_UNLOCK) && + (!share->have_versioning || !share->now_transactional || + file->used_tables->use_count == 1)) { /** @todo for a single-row INSERT SELECT, we will go into repair, which -- cgit v1.2.1