From 0a9badeca4aae7afe7a6f7028c11cf22dbfd6aaa Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 14 Nov 2005 22:10:34 +0300 Subject: [PATCH] Fix bug #14816 test_if_order_by_key() expected only Item_fields. test_if_order_by_key() expected only Item_fields to be in order->item, thus failing to find available index on view's field, which results in reported error. Now test_if_order_by_key() calls order->item->real_item() to get field for choosing index. sql/sql_select.cc: Fix bug #14816 test_if_order_by_key() expected only Item_fields. Make test_if_order_by_key() use real_item() to get field. mysql-test/r/view.result: Test case for bug#14816 test_if_order_by_key() expected only Item_fields. mysql-test/t/view.test: Test case for bug#14816 test_if_order_by_key() expected only Item_fields. --- mysql-test/r/view.result | 8 ++++++++ mysql-test/t/view.test | 10 ++++++++++ sql/sql_select.cc | 2 +- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result index 97df059c86a..bc0e00dfffb 100644 --- a/mysql-test/r/view.result +++ b/mysql-test/r/view.result @@ -2385,3 +2385,11 @@ show create view v1; View Create View v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY INVOKER VIEW `v1` AS select 1 AS `1` drop view v1; +create table t1 (id INT, primary key(id)); +insert into t1 values (1),(2); +create view v1 as select * from t1; +explain select id from v1 order by id; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 index NULL PRIMARY 4 NULL 2 Using index +drop view v1; +drop table t1; diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test index 5addcd2570d..32c6eefb830 100644 --- a/mysql-test/t/view.test +++ b/mysql-test/t/view.test @@ -2253,3 +2253,13 @@ drop view v1; create definer = current_user sql security invoker view v1 as select 1; show create view v1; drop view v1; + +# +# Bug #14816 test_if_order_by_key() expected only Item_fields. +# +create table t1 (id INT, primary key(id)); +insert into t1 values (1),(2); +create view v1 as select * from t1; +explain select id from v1 order by id; +drop view v1; +drop table t1; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 44c4ec998bb..b65e25335fc 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -10988,7 +10988,7 @@ static int test_if_order_by_key(ORDER *order, TABLE *table, uint idx, for (; order ; order=order->next, const_key_parts>>=1) { - Field *field=((Item_field*) (*order->item))->field; + Field *field=((Item_field*) (*order->item)->real_item())->field; int flag; /*