From 683154d1fa6249a8bfcde4bb9227570c452ea802 Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Tue, 13 Jul 2010 10:45:23 -0700 Subject: [PATCH] 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. --- mysql-test/suite/vcol/r/vcol_misc.result | 10 ++++++++++ mysql-test/suite/vcol/t/vcol_misc.test | 12 ++++++++++++ sql/filesort.cc | 9 ++++++++- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/mysql-test/suite/vcol/r/vcol_misc.result b/mysql-test/suite/vcol/r/vcol_misc.result index 896dd6fa654..fe41e7e65f3 100644 --- a/mysql-test/suite/vcol/r/vcol_misc.result +++ b/mysql-test/suite/vcol/r/vcol_misc.result @@ -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; diff --git a/mysql-test/suite/vcol/t/vcol_misc.test b/mysql-test/suite/vcol/t/vcol_misc.test index 06a9313edd3..2ed08a69fa2 100644 --- a/mysql-test/suite/vcol/t/vcol_misc.test +++ b/mysql-test/suite/vcol/t/vcol_misc.test @@ -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; diff --git a/sql/filesort.cc b/sql/filesort.cc index 33c838f1bcb..270f0f1ac37 100644 --- a/sql/filesort.cc +++ b/sql/filesort.cc @@ -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