From 40ba88ca07fa7c38b2a0c356b57a5af7bf1f166e Mon Sep 17 00:00:00 2001 From: "sergefp@mysql.com" <> Date: Fri, 23 Sep 2005 13:43:20 +0400 Subject: [PATCH 1/2] Fix for BUG#13419: In "ref" optimizer, take into account that item=Item_func_in(x,y) is not equivalent to "x=y" when item->negated == TRUE. --- mysql-test/r/func_in.result | 9 +++++++++ mysql-test/t/func_in.test | 7 +++++++ sql/sql_select.cc | 4 ++-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/func_in.result b/mysql-test/r/func_in.result index 516d0a28a21..3cf2afc83d1 100644 --- a/mysql-test/r/func_in.result +++ b/mysql-test/r/func_in.result @@ -193,3 +193,12 @@ select * from t1 where a in (NULL, 'aa'); a aa drop table t1; +create table t1 (id int, key(id)); +insert into t1 values (1),(2),(3); +select count(*) from t1 where id not in (1); +count(*) +2 +select count(*) from t1 where id not in (1,2); +count(*) +1 +drop table t1; diff --git a/mysql-test/t/func_in.test b/mysql-test/t/func_in.test index aec2de7a467..2ffe5a2d5f7 100644 --- a/mysql-test/t/func_in.test +++ b/mysql-test/t/func_in.test @@ -102,4 +102,11 @@ insert into t1 values ('aa'), ('bb'); select * from t1 where a in (NULL, 'aa'); drop table t1; +# BUG#13419 +create table t1 (id int, key(id)); +insert into t1 values (1),(2),(3); +select count(*) from t1 where id not in (1); +select count(*) from t1 where id not in (1,2); +drop table t1; + # End of 4.1 tests diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 59b82b53b32..0d9cab6a36b 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -2140,7 +2140,6 @@ merge_key_fields(KEY_FIELD *start,KEY_FIELD *new_fields,KEY_FIELD *end, field Field used in comparision eq_func True if we used =, <=> or IS NULL value Value used for comparison with field - Is NULL for BETWEEN and IN usable_tables Tables which can be used for key optimization NOTES @@ -2325,7 +2324,8 @@ add_key_fields(KEY_FIELD **key_fields,uint *and_level, add_key_field(key_fields,*and_level,cond_func, ((Item_field*)(cond_func->key_item()->real_item()))->field, cond_func->argument_count() == 2 && - cond_func->functype() == Item_func::IN_FUNC, + cond_func->functype() == Item_func::IN_FUNC && + !((Item_func_in*)cond_func)->negated, cond_func->arguments()+1, cond_func->argument_count()-1, usable_tables); break; From d90b988da7431f3d4b83d3370e4b35a44819f0d3 Mon Sep 17 00:00:00 2001 From: "sergefp@mysql.com" <> Date: Sat, 24 Sep 2005 01:39:50 +0400 Subject: [PATCH 2/2] BUG#12232: Addressing docs team feedback: s/inequal/unequal/ --- myisam/mi_check.c | 2 +- myisam/myisamchk.c | 6 +++--- mysql-test/r/myisam.result | 4 ++-- sql/ha_myisam.cc | 2 +- sql/mysqld.cc | 8 ++++---- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/myisam/mi_check.c b/myisam/mi_check.c index 0c85b5234a1..7397ee4e204 100644 --- a/myisam/mi_check.c +++ b/myisam/mi_check.c @@ -3994,7 +3994,7 @@ void update_auto_increment_key(MI_CHECK *param, MI_INFO *info, ... The 'unique' array is collected in one sequential scan through the entire index. This is done in two places: in chk_index() and in sort_key_write(). - Statistics collection may consider NULLs as either equal or inequal (see + Statistics collection may consider NULLs as either equal or unequal (see SEARCH_NULL_ARE_NOT_EQUAL, MI_STATS_METHOD_*). Output is an array: diff --git a/myisam/myisamchk.c b/myisam/myisamchk.c index 2ffc491fc91..2dd05cf7e67 100644 --- a/myisam/myisamchk.c +++ b/myisam/myisamchk.c @@ -67,7 +67,7 @@ static const char *field_pack[]= "no zeros", "blob", "constant", "table-lockup", "always zero","varchar","unique-hash","?","?"}; -static const char *myisam_stats_method_str="nulls_inequal"; +static const char *myisam_stats_method_str="nulls_unequal"; static void get_options(int *argc,char * * *argv); static void print_version(void); @@ -339,7 +339,7 @@ static struct my_option my_long_options[] = REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"stats_method", OPT_STATS_METHOD, "Specifies how index statistics collection code should threat NULLs. " - "Possible values of name are \"nulls_inequal\" (default behavior for 4.1/5.0), and \"nulls_equal\" (emulate 4.0 behavior).", + "Possible values of name are \"nulls_unequal\" (default behavior for 4.1/5.0), and \"nulls_equal\" (emulate 4.0 behavior).", (gptr*) &myisam_stats_method_str, (gptr*) &myisam_stats_method_str, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0} @@ -471,7 +471,7 @@ static void usage(void) #include -const char *myisam_stats_method_names[] = {"nulls_inequal", "nulls_equal", +const char *myisam_stats_method_names[] = {"nulls_unequal", "nulls_equal", NullS}; TYPELIB myisam_stats_method_typelib= { array_elements(myisam_stats_method_names) - 1, "", diff --git a/mysql-test/r/myisam.result b/mysql-test/r/myisam.result index b3144a6903b..0a6f3ddc28b 100644 --- a/mysql-test/r/myisam.result +++ b/mysql-test/r/myisam.result @@ -611,7 +611,7 @@ test.t2 984116287 drop table t1, t2; show variables like 'myisam_stats_method'; Variable_name Value -myisam_stats_method nulls_inequal +myisam_stats_method nulls_unequal create table t1 (a int, key(a)); insert into t1 values (0),(1),(2),(3),(4); insert into t1 select NULL from t1; @@ -652,7 +652,7 @@ t1 1 a 1 a A 5 NULL NULL YES BTREE set myisam_stats_method=DEFAULT; show variables like 'myisam_stats_method'; Variable_name Value -myisam_stats_method nulls_inequal +myisam_stats_method nulls_unequal insert into t1 values (11); delete from t1 where a=11; analyze table t1; diff --git a/sql/ha_myisam.cc b/sql/ha_myisam.cc index 615cecb7a19..87529cc8713 100644 --- a/sql/ha_myisam.cc +++ b/sql/ha_myisam.cc @@ -39,7 +39,7 @@ const char *myisam_recover_names[] = TYPELIB myisam_recover_typelib= {array_elements(myisam_recover_names)-1,"", myisam_recover_names, NULL}; -const char *myisam_stats_method_names[] = {"nulls_inequal", "nulls_equal", +const char *myisam_stats_method_names[] = {"nulls_unequal", "nulls_equal", NullS}; TYPELIB myisam_stats_method_typelib= { array_elements(myisam_stats_method_names) - 1, "", diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 605d7d0dae6..1b931b25647 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -369,7 +369,7 @@ char *mysqld_unix_port, *opt_mysql_tmpdir; char *my_bind_addr_str; const char **errmesg; /* Error messages */ const char *myisam_recover_options_str="OFF"; -const char *myisam_stats_method_str="nulls_inequal"; +const char *myisam_stats_method_str="nulls_unequal"; const char *sql_mode_str="OFF"; /* name of reference on left espression in rewritten IN subquery */ const char *in_left_expr_name= ""; @@ -5212,7 +5212,7 @@ The minimum value for this variable is 4096.", GET_ULONG, REQUIRED_ARG, 8192*1024, 4, ~0L, 0, 1, 0}, {"myisam_stats_method", OPT_MYISAM_STATS_METHOD, "Specifies how MyISAM index statistics collection code should threat NULLs. " - "Possible values of name are \"nulls_inequal\" (default behavior for 4.1/5.0), and \"nulls_equal\" (emulate 4.0 behavior).", + "Possible values of name are \"nulls_unequal\" (default behavior for 4.1/5.0), and \"nulls_equal\" (emulate 4.0 behavior).", (gptr*) &myisam_stats_method_str, (gptr*) &myisam_stats_method_str, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"net_buffer_length", OPT_NET_BUFFER_LENGTH, @@ -5767,7 +5767,7 @@ static void mysql_init_variables(void) query_id= thread_id= 1L; strmov(server_version, MYSQL_SERVER_VERSION); myisam_recover_options_str= sql_mode_str= "OFF"; - myisam_stats_method_str= "nulls_inequal"; + myisam_stats_method_str= "nulls_unequal"; my_bind_addr = htonl(INADDR_ANY); threads.empty(); thread_cache.empty(); @@ -5818,7 +5818,7 @@ static void mysql_init_variables(void) global_system_variables.old_passwords= 0; /* - Default behavior for 4.1 and 5.0 is to treat NULL values as inequal + Default behavior for 4.1 and 5.0 is to treat NULL values as unequal when collecting index statistics for MyISAM tables. */ global_system_variables.myisam_stats_method= MI_STATS_METHOD_NULLS_NOT_EQUAL;