Skip to content

Commit 8a75d2b

Browse files
committed
Bug#21566735: ASSERTION `LENGTH > 0 && KEYPARTS != 0' FAILED.
An assert failure is seen in some queries which have a semijoin and use the materialization strategy. The assertion fails if either the length of the key is zero or the number of key parts is zero. This could indicate two different problems. 1) If the length is zero, there may not be a problem, as it can legitimately be zero if, for example, the key is a zero-length string. 2) If the number of key parts is zero, there is a bug, as a key must have at least one part. The patch fixes issue #1 by removing the length check in the assertion. Issue #2 happens if JOIN::update_equalities_for_sjm() doesn't recognize the expression selected from a subquery, and fails to replace it with a reference to a column in a temporary table that holds the materialized result. This causes it to not recognize it as a part of the key later, and keyparts could end up as zero. The patch fixes it by calling real_item() on the expression in order to see through Item_refs that may wrap the expression if the subquery reads from a view.
1 parent 8911403 commit 8a75d2b

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

sql/sql_optimizer.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4798,7 +4798,7 @@ bool JOIN::update_equalities_for_sjm()
47984798
uint fieldno= 0;
47994799
while ((old= it++))
48004800
{
4801-
if (old->real_item()->eq(keyuse->val, false))
4801+
if (old->real_item()->eq(keyuse->val->real_item(), false))
48024802
{
48034803
/*
48044804
Replace the expression selected from the subquery with the

sql/sql_select.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1199,7 +1199,7 @@ void calc_length_and_keyparts(Key_use *keyuse, JOIN_TAB *tab, const uint key,
11991199
}
12001200
keyuse++;
12011201
} while (keyuse->table_ref == tab->table_ref && keyuse->key == key);
1202-
DBUG_ASSERT(length > 0 && keyparts != 0);
1202+
DBUG_ASSERT(keyparts > 0);
12031203
*length_out= length;
12041204
*keyparts_out= keyparts;
12051205
}

0 commit comments

Comments
 (0)