If a virtual column was used in the ORDER BY clause of a query
and some of the columns this virtual column was based upon were
not referenced anywhere in the query then the execution of the
query could cause an assertion failure.
It happened because in this case the bitmap of the columns used
for ordering keys was not formed correctly.
This commit is contained in:
Igor Babaev 2010-07-13 10:45:23 -07:00
parent 73be27c07f
commit 683154d1fa
3 changed files with 30 additions and 1 deletions

View File

@ -35,3 +35,13 @@ a int NOT NULL DEFAULT '0',
v double AS ((1, a)) VIRTUAL
);
ERROR HY000: Expression for computed column cannot return a row
CREATE TABLE t1 (
a CHAR(255) BINARY NOT NULL DEFAULT 0,
b CHAR(255) BINARY NOT NULL DEFAULT 0,
v CHAR(255) BINARY AS (CONCAT(a,b)) VIRTUAL );
INSERT INTO t1(a,b) VALUES ('4','7'), ('4','6');
SELECT 1 AS C FROM t1 ORDER BY v;
C
1
1
DROP TABLE t1;

View File

@ -30,6 +30,18 @@ CREATE TABLE t1 (
v double AS ((1, a)) VIRTUAL
);
#
# Bug#603654: Virtual column in ORDER BY, no other references of table columns
#
CREATE TABLE t1 (
a CHAR(255) BINARY NOT NULL DEFAULT 0,
b CHAR(255) BINARY NOT NULL DEFAULT 0,
v CHAR(255) BINARY AS (CONCAT(a,b)) VIRTUAL );
INSERT INTO t1(a,b) VALUES ('4','7'), ('4','6');
SELECT 1 AS C FROM t1 ORDER BY v;
DROP TABLE t1;

View File

@ -1009,7 +1009,14 @@ static void register_used_fields(SORTPARAM *param)
if ((field= sort_field->field))
{
if (field->table == table)
bitmap_set_bit(bitmap, field->field_index);
{
if (field->vcol_info)
{
Item *vcol_item= field->vcol_info->expr_item;
vcol_item->walk(&Item::register_field_in_read_map, 1, (uchar *) 0);
}
bitmap_set_bit(bitmap, field->field_index);
}
}
else
{ // Item