diff options
author | unknown <bell@sanja.is.com.ua> | 2002-11-28 09:11:35 +0200 |
---|---|---|
committer | unknown <bell@sanja.is.com.ua> | 2002-11-28 09:11:35 +0200 |
commit | 0afea4007744dba7b4c7afacf9afc3b48ec84e97 (patch) | |
tree | 4145a19ad125ca3f6ebe89fe6beae56d3cc5b62c | |
parent | c53dd15db8ac6d744e58662d15239d3444b954a6 (diff) | |
download | mariadb-git-0afea4007744dba7b4c7afacf9afc3b48ec84e97.tar.gz |
Item_func_equal made uniform
mysql-test/r/row_test.result:
Equal test
mysql-test/t/row_test.test:
Equal test
-rw-r--r-- | mysql-test/r/row_test.result | 6 | ||||
-rw-r--r-- | mysql-test/t/row_test.test | 2 | ||||
-rw-r--r-- | sql/item_cmpfunc.cc | 101 | ||||
-rw-r--r-- | sql/item_cmpfunc.h | 8 | ||||
-rw-r--r-- | sql/item_func.h | 6 | ||||
-rw-r--r-- | sql/mysqld.cc | 6 |
6 files changed, 71 insertions, 58 deletions
diff --git a/mysql-test/r/row_test.result b/mysql-test/r/row_test.result index fa7739904d7..bd162e35f86 100644 --- a/mysql-test/r/row_test.result +++ b/mysql-test/r/row_test.result @@ -22,6 +22,12 @@ SELECT (1,2,3)>=(1+1,2,3); SELECT (1,2,3)<>(1+1,2,3); (1,2,3)<>(1+1,2,3) 1 +SELECT (NULL,2,3)=(NULL,2,3); +(NULL,2,3)=(NULL,2,3) +NULL +SELECT (NULL,2,3)<=>(NULL,2,3); +(NULL,2,3)<=>(NULL,2,3) +1 SELECT (1,2,(3,4,5))=(1,2,(3,4,5)); (1,2,(3,4,5))=(1,2,(3,4,5)) 1 diff --git a/mysql-test/t/row_test.test b/mysql-test/t/row_test.test index 8be347cf5fc..24df2dd1b20 100644 --- a/mysql-test/t/row_test.test +++ b/mysql-test/t/row_test.test @@ -6,6 +6,8 @@ SELECT (1,2,3)>(1+1,2,3); SELECT (1,2,3)<=(1+1,2,3); SELECT (1,2,3)>=(1+1,2,3); SELECT (1,2,3)<>(1+1,2,3); +SELECT (NULL,2,3)=(NULL,2,3); +SELECT (NULL,2,3)<=>(NULL,2,3); SELECT (1,2,(3,4,5))=(1,2,(3,4,5)); SELECT ('test',2,3.33)=('test',2,3.33); -- error 1239 diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index 9f3457d8b8d..06dc3fca89d 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -88,7 +88,6 @@ static bool convert_constant_item(Field *field, Item **item) return 0; } - void Item_bool_func2::fix_length_and_dec() { max_length=1; // Function returns 0 or 1 @@ -130,20 +129,9 @@ void Item_bool_func2::fix_length_and_dec() int Arg_comparator::set_compare_func(Item_bool_func2 *item, Item_result type) { owner= item; - switch (type) - { - case STRING_RESULT: - func= &Arg_comparator::compare_string; - break; - case REAL_RESULT: - func= &Arg_comparator::compare_real; - break; - case INT_RESULT: - func= &Arg_comparator::compare_int; - break; - case ROW_RESULT: - { - func= &Arg_comparator::compare_row; + func= comparator_matrix[type][owner->equal]; + if (type == ROW_RESULT) + { uint n= args[0]->cols(); if (n != args[1]->cols()) { @@ -164,8 +152,6 @@ int Arg_comparator::set_compare_func(Item_bool_func2 *item, Item_result type) current_thd->fatal_error= 1; return 1; } - break; - } } return 0; } @@ -185,6 +171,18 @@ int Arg_comparator::compare_string() return -1; } +int Arg_comparator::compare_e_string() +{ + String *res1,*res2; + res1= args[0]->val_str(&owner->tmp_value1); + res2= args[1]->val_str(&owner->tmp_value2); + if (!res1 || !res2) + return test(res1 == res2); + return (owner->binary() ? test(stringcmp(res1, res2) == 0) : + test(sortcmp(res1, res2) == 0)); +} + + int Arg_comparator::compare_real() { double val1= args[0]->val(); @@ -203,6 +201,14 @@ int Arg_comparator::compare_real() return -1; } +int Arg_comparator::compare_e_real() +{ + double val1= args[0]->val(); + double val2= args[1]->val(); + if (args[0]->null_value || args[1]->null_value) + return test(args[0]->null_value && args[1]->null_value); + return test(val1 == val2); +} int Arg_comparator::compare_int() { @@ -222,6 +228,16 @@ int Arg_comparator::compare_int() return -1; } +int Arg_comparator::compare_e_int() +{ + longlong val1= args[0]->val_int(); + longlong val2= args[1]->val_int(); + if (args[0]->null_value || args[1]->null_value) + return test(args[0]->null_value && args[1]->null_value); + return test(val1 == val2); +} + + int Arg_comparator::compare_row() { int res= 0; @@ -236,6 +252,19 @@ int Arg_comparator::compare_row() return res; } +int Arg_comparator::compare_e_row() +{ + int res= 0; + uint n= args[0]->cols(); + for (uint i= 0; i<n; i++) + { + if ((res= comparators[i].compare())) + return 1; + } + return 1; +} + + longlong Item_func_eq::val_int() { int value= arg_store.compare(); @@ -247,49 +276,15 @@ longlong Item_func_eq::val_int() void Item_func_equal::fix_length_and_dec() { Item_bool_func2::fix_length_and_dec(); - cmp_result_type=item_cmp_type(args[0]->result_type(),args[1]->result_type()); maybe_null=null_value=0; + set_cmp_func(); } longlong Item_func_equal::val_int() { - switch (cmp_result_type) { - case STRING_RESULT: - { - String *res1,*res2; - res1=args[0]->val_str(&tmp_value1); - res2=args[1]->val_str(&tmp_value2); - if (!res1 || !res2) - return test(res1 == res2); - return (binary() ? test(stringcmp(res1,res2) == 0) : - test(sortcmp(res1,res2) == 0)); - } - case REAL_RESULT: - { - double val1=args[0]->val(); - double val2=args[1]->val(); - if (args[0]->null_value || args[1]->null_value) - return test(args[0]->null_value && args[1]->null_value); - return test(val1 == val2); - } - case INT_RESULT: - { - longlong val1=args[0]->val_int(); - longlong val2=args[1]->val_int(); - if (args[0]->null_value || args[1]->null_value) - return test(args[0]->null_value && args[1]->null_value); - return test(val1 == val2); - } - case ROW_RESULT: - { - my_error(ER_WRONG_USAGE, MYF(0), "row", "<=>"); - return 0; - } - } - return 0; // Impossible + return arg_store.compare(); } - longlong Item_func_ne::val_int() { int value= arg_store.compare(); diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h index b9511e82e32..ca03d02aa77 100644 --- a/sql/item_cmpfunc.h +++ b/sql/item_cmpfunc.h @@ -34,8 +34,9 @@ class Item_bool_func2 :public Item_int_func { /* Bool with 2 string args */ protected: String tmp_value1,tmp_value2; + bool equal; public: - Item_bool_func2(Item *a,Item *b) :Item_int_func(a,b) {} + Item_bool_func2(Item *a,Item *b) :Item_int_func(a,b), equal(0) {} void fix_length_and_dec(); void set_cmp_func() { @@ -85,11 +86,10 @@ public: const char *func_name() const { return "="; } }; -class Item_func_equal :public Item_bool_func2 +class Item_func_equal :public Item_bool_rowready_func2 { - Item_result cmp_result_type; public: - Item_func_equal(Item *a,Item *b) :Item_bool_func2(a,b) { }; + Item_func_equal(Item *a,Item *b) :Item_bool_rowready_func2(a,b) { equal=1; }; longlong val_int(); void fix_length_and_dec(); enum Functype functype() const { return EQUAL_FUNC; } diff --git a/sql/item_func.h b/sql/item_func.h index 61bac374152..e3b5fa3445a 100644 --- a/sql/item_func.h +++ b/sql/item_func.h @@ -55,6 +55,12 @@ public: int compare_real(); // compare args[0] & args[1] int compare_int(); // compare args[0] & args[1] int compare_row(); // compare args[0] & args[1] + int compare_e_string(); // compare args[0] & args[1] + int compare_e_real(); // compare args[0] & args[1] + int compare_e_int(); // compare args[0] & args[1] + int compare_e_row(); // compare args[0] & args[1] + + static arg_cmp_func comparator_matrix [4][2]; friend class Item_func; }; diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 86da0e846a0..b45caac5ab6 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -337,7 +337,11 @@ ulong query_cache_size=0; ulong query_cache_limit=0; Query_cache query_cache; #endif - +arg_cmp_func Arg_comparator::comparator_matrix[4][2] = +{{&Arg_comparator::compare_string, &Arg_comparator::compare_e_string}, + {&Arg_comparator::compare_real, &Arg_comparator::compare_e_real}, + {&Arg_comparator::compare_int, &Arg_comparator::compare_e_int}, + {&Arg_comparator::compare_row, &Arg_comparator::compare_e_row}}; #ifdef HAVE_SMEM static char *shared_memory_base_name=default_shared_memory_base_name; static bool opt_enable_shared_memory = 0; |