From 5db7246f78d62f07433b3e623e20002536ff20b2 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 7 Feb 2003 17:57:07 +0200 Subject: Fix problem in MIN/MAX optimisation (from last patch) Don't make OLD_PASSWORD() a reserved word mysql-test/r/explain.result: Test select count(*) mysql-test/r/func_crypt.result: Test old_password() mysql-test/t/explain.test: Test select count(*) mysql-test/t/func_crypt.test: Test old_password() sql/item_create.cc: Don't make OLD_PASSWORD() a reserved word sql/item_create.h: Don't make OLD_PASSWORD() a reserved word sql/lex.h: Don't make OLD_PASSWORD() a reserved word sql/opt_range.cc: Remove blank space sql/opt_sum.cc: Fix problem in MIN/MAX optimisation --- mysql-test/r/explain.result | 13 +++++++++++++ mysql-test/r/func_crypt.result | 9 ++++++--- mysql-test/t/explain.test | 8 ++++++++ mysql-test/t/func_crypt.test | 3 ++- sql/item_create.cc | 5 +++++ sql/item_create.h | 1 + sql/lex.h | 2 +- sql/opt_range.cc | 2 -- sql/opt_sum.cc | 11 +++++++++-- 9 files changed, 45 insertions(+), 9 deletions(-) diff --git a/mysql-test/r/explain.result b/mysql-test/r/explain.result index fa15165722d..d433078a251 100644 --- a/mysql-test/r/explain.result +++ b/mysql-test/r/explain.result @@ -31,3 +31,16 @@ drop table t1; explain select 1; Comment No tables used +create table t1 (a int not null); +explain select count(*) from t1; +Comment +Select tables optimized away +insert into t1 values(1); +explain select count(*) from t1; +Comment +Select tables optimized away +insert into t1 values(1); +explain select count(*) from t1; +Comment +Select tables optimized away +drop table t1; diff --git a/mysql-test/r/func_crypt.result b/mysql-test/r/func_crypt.result index cf464ec21b2..742de833bf7 100644 --- a/mysql-test/r/func_crypt.result +++ b/mysql-test/r/func_crypt.result @@ -1,6 +1,9 @@ select length(encrypt('foo', 'ff')) <> 0; length(encrypt('foo', 'ff')) <> 0 1 -select password('test'),length(encrypt('test')),encrypt('test','aa'); -password('test') length(encrypt('test')) encrypt('test','aa') -378b243e220ca493 13 aaqPiZY5xR5l. +select old_password('test'), password('test'); +old_password('test') password('test') +378b243e220ca493 378b243e220ca493 +select length(encrypt('test')), encrypt('test','aa'); +length(encrypt('test')) encrypt('test','aa') +13 aaqPiZY5xR5l. diff --git a/mysql-test/t/explain.test b/mysql-test/t/explain.test index 8a41ebe5b4f..045598e97df 100644 --- a/mysql-test/t/explain.test +++ b/mysql-test/t/explain.test @@ -20,3 +20,11 @@ explain select * from t1 ignore key (str,str,foo) where str="foo"; drop table t1; explain select 1; + +create table t1 (a int not null); +explain select count(*) from t1; +insert into t1 values(1); +explain select count(*) from t1; +insert into t1 values(1); +explain select count(*) from t1; +drop table t1; diff --git a/mysql-test/t/func_crypt.test b/mysql-test/t/func_crypt.test index 55c0d6d3b9d..f403d96e885 100644 --- a/mysql-test/t/func_crypt.test +++ b/mysql-test/t/func_crypt.test @@ -2,4 +2,5 @@ select length(encrypt('foo', 'ff')) <> 0; --replace_result $1$aa$4OSUA5cjdx0RUQ08opV27/ aaqPiZY5xR5l. -select password('test'),length(encrypt('test')),encrypt('test','aa'); +select old_password('test'), password('test'); +select length(encrypt('test')), encrypt('test','aa'); diff --git a/sql/item_create.cc b/sql/item_create.cc index a4486a0b1c7..7e082bc174c 100644 --- a/sql/item_create.cc +++ b/sql/item_create.cc @@ -307,6 +307,11 @@ Item *create_func_quarter(Item* a) return new Item_func_quarter(a); } +Item *create_func_password(Item* a) +{ + return new Item_func_password(a); +} + Item *create_func_radians(Item *a) { return new Item_func_units((char*) "radians",a,M_PI/180,0.0); diff --git a/sql/item_create.h b/sql/item_create.h index 10b404ec2fd..5381ad946ae 100644 --- a/sql/item_create.h +++ b/sql/item_create.h @@ -70,6 +70,7 @@ Item *create_func_pi(void); Item *create_func_pow(Item* a, Item *b); Item *create_func_current_user(void); Item *create_func_quarter(Item* a); +Item *create_func_password(Item* a); Item *create_func_radians(Item *a); Item *create_func_release_lock(Item* a); Item *create_func_repeat(Item* a, Item *b); diff --git a/sql/lex.h b/sql/lex.h index 64ba98b5e35..a9e44e034d0 100644 --- a/sql/lex.h +++ b/sql/lex.h @@ -260,7 +260,6 @@ static SYMBOL symbols[] = { { "NULL", SYM(NULL_SYM),0,0}, { "NUMERIC", SYM(NUMERIC_SYM),0,0}, { "OFFSET", SYM(OFFSET_SYM),0,0}, - { "OLD_PASSWORD", SYM(PASSWORD),0,0}, { "ON", SYM(ON),0,0}, { "OPEN", SYM(OPEN_SYM),0,0}, { "OPTIMIZE", SYM(OPTIMIZE),0,0}, @@ -475,6 +474,7 @@ static SYMBOL sql_functions[] = { { "NULLIF", SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_nullif)}, { "OCTET_LENGTH", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_length)}, { "OCT", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_oct)}, + { "OLD_PASSWORD", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_password)}, { "ORD", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_ord)}, { "PERIOD_ADD", SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_period_add)}, { "PERIOD_DIFF", SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_period_diff)}, diff --git a/sql/opt_range.cc b/sql/opt_range.cc index 768344ab702..0407aabc327 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -23,8 +23,6 @@ */ - - #ifdef __GNUC__ #pragma implementation // gcc: Class implementation #endif diff --git a/sql/opt_sum.cc b/sql/opt_sum.cc index d5a4149f243..41771646082 100644 --- a/sql/opt_sum.cc +++ b/sql/opt_sum.cc @@ -245,8 +245,15 @@ int opt_sum_query(TABLE_LIST *tables, List &all_fields,COND *conds) const_result=0; } } - if (used_tables != removed_tables) - const_result=0; // We didn't remove all tables + /* + If we have a where clause, we can only ignore searching in the + tables if MIN/MAX optimisation replaced all used tables + This is to not to use replaced values in case of: + SELECT MIN(key) FROM table_1, empty_table + removed_tables is != 0 if we have used MIN() or MAX(). + */ + if (removed_tables && used_tables != removed_tables) + const_result= 0; // We didn't remove all tables return const_result; } -- cgit v1.2.1