Commit df7548f6 authored by Igor Babaev's avatar Igor Babaev

Fixed bug #603654.

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.
parent bc013072
......@@ -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;
......@@ -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;
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment