1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-30 16:24:05 +03:00

Bug#12540545 61101: ASSERTION FAILURE IN THREAD 1256741184 IN FILE /BUILDDIR/BUILD/BUILD/MYSQ

The assertion in innodb is triggered in this way:
1. mysql server does lookup on the primary key with full key,
   innodb decides to not store cursor position because
   "any index_next/prev call will return EOF anyway"
2. server asks innodb to return any next record in the index and the
   assertion is triggered because no cursor position is stored.

It happens when a unique search (match_mode=ROW_SEL_EXACT)
in the clustered index is performed. InnoDB has never stored
the cursor position after a unique key lookup in the
clustered index because storing the position is an expensive
operation. The bug was introduced by 
WL3220 'Loose index scan for aggregate functions'.

The fix is to disallow loose index scan optimization
for AGG_FUNC(DISTINCT ...) if GROUP_MIN_MAX quick select
uses clustered key.
This commit is contained in:
Sergey Glukhov
2011-10-19 16:07:14 +04:00
parent ec56c16c4b
commit e022f65be4
3 changed files with 56 additions and 0 deletions

View File

@ -9318,6 +9318,11 @@ cost_group_min_max(TABLE* table, KEY *index_info, uint used_key_parts,
except MIN and MAX. For queries with DISTINCT, aggregate functions
are allowed.
SA5. The select list in DISTINCT queries should not contain expressions.
SA6. Clustered index can not be used by GROUP_MIN_MAX quick select
for AGG_FUNC(DISTINCT ...) optimization because cursor position is
never stored after a unique key lookup in the clustered index and
furhter index_next/prev calls can not be used. So loose index scan
optimization can not be used in this case.
GA1. If Q has a GROUP BY clause, then GA is a prefix of I. That is, if
G_i = A_j => i = j.
GA2. If Q has a DISTINCT clause, then there is a permutation of SA that
@ -9804,6 +9809,13 @@ get_best_group_min_max(PARAM *param, SEL_TREE *tree, double read_time)
Field::itMBR : Field::itRAW))
DBUG_RETURN(NULL);
/*
Check (SA6) if clustered key is used
*/
if (is_agg_distinct && index == table->s->primary_key &&
table->file->primary_key_is_clustered())
DBUG_RETURN(NULL);
/* The query passes all tests, so construct a new TRP object. */
read_plan= new (param->mem_root)
TRP_GROUP_MIN_MAX(have_min, have_max, is_agg_distinct,