From 1159996ee5902ea817e9fc5b565b7ff1cda774d6 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 22 Jul 2004 14:05:00 +0300 Subject: [PATCH] privent crash on temporary table during indexes lookup (BUG#4677) mysql-test/r/view.result: check 'use index' on view with temporary table mysql-test/t/view.test: check 'use index' on view with temporary table sql/sql_base.cc: privent crash on temporary table --- mysql-test/r/view.result | 6 ++++++ mysql-test/t/view.test | 10 ++++++++++ sql/sql_base.cc | 5 +++-- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result index 1cd80b857ab..435237bff00 100644 --- a/mysql-test/r/view.result +++ b/mysql-test/r/view.result @@ -977,3 +977,9 @@ ERROR HY000: View 'test.v1' references invalid table(s) or column(s) drop view v1; create view v1 (a,a) as select 'a','a'; ERROR 42S21: Duplicate column name 'a' +create table t1 (a int, b int); +create view v1 as select a, sum(b) from t1 group by a; +select b from v1 use index (some_index) where b=1; +ERROR 42000: Key column 'some_index' doesn't exist in table +drop view v1; +drop table t1; diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test index b6ea504bc2e..40d23da5541 100644 --- a/mysql-test/t/view.test +++ b/mysql-test/t/view.test @@ -900,3 +900,13 @@ drop view v1; # -- error 1060 create view v1 (a,a) as select 'a','a'; + +# +# check 'use index' on view with temporary table +# +create table t1 (a int, b int); +create view v1 as select a, sum(b) from t1 group by a; +-- error 1072 +select b from v1 use index (some_index) where b=1; +drop view v1; +drop table t1; diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 03074ee3ba9..799fb3cd81d 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -2555,8 +2555,9 @@ bool get_key_map_from_key_list(key_map *map, TABLE *table, map->clear_all(); while ((name=it++)) { - if ((pos= find_type(&table->keynames, name->ptr(), name->length(), 1)) <= - 0) + if (table->keynames.type_names == 0 || + (pos= find_type(&table->keynames, name->ptr(), name->length(), 1)) <= + 0) { my_error(ER_KEY_COLUMN_DOES_NOT_EXITS, MYF(0), name->c_ptr(), table->real_name);