Skip to content

Commit a1d235e

Browse files
committed
Bug#35105404: Server crashes with signal 11 and asserts in temptable
code. Problem: The problem lies in the way MIN/MAX optimization is done. In the early part of optimization, we try to check whether we can simply get the minimum or maximum value directly from the index. For this, we need a key. For derived tables, the key is only updated in the later part of optimization, when we call JOIN::make_join_plan. As a result, the MIN/MAX optimization will not be picked, so it won't Assert on first call. But when the procedure is called a second time, the keys are updated in keys_in_use_for_query, and the MIN/MAX optimization picks the index. However, we run into trouble when we try to initialize the index, because the temporary table handler is not yet opened. The table handler will only be opened and closed during the execution phase. This arrangement of code led to an assert. Solution: At the end of each execution, clear the variables keys_in_use_for_query, keys_in_use_for_group_by, and keys_in_use_for_order_by for a temp table. With that, the next execution will follow the same path as the first. There was a github contribution from Nicholas Othieno. We have taken different approach to the fix. Change-Id: I31107674ffff4e790f4ce269d5197d22c173d29d
1 parent 85699a0 commit a1d235e

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

sql/sql_union.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2020,8 +2020,12 @@ static void cleanup_tmp_tables(Table_ref *list) {
20202020
tl->table = nullptr;
20212021
} else {
20222022
// Clear indexes added during optimization, keep possible unique index
2023-
tl->table->s->keys = tl->table->s->is_distinct ? 1 : 0;
2024-
tl->table->s->first_unused_tmp_key = 0;
2023+
TABLE *t = tl->table;
2024+
t->s->keys = t->s->is_distinct ? 1 : 0;
2025+
t->s->first_unused_tmp_key = 0;
2026+
t->keys_in_use_for_query.clear_all();
2027+
t->keys_in_use_for_group_by.clear_all();
2028+
t->keys_in_use_for_order_by.clear_all();
20252029
}
20262030
}
20272031
}

0 commit comments

Comments
 (0)