Commit d1ca1c1f authored by Alexander Barkov's avatar Alexander Barkov

MDEV-7001 Bad result for NOT NOT STRCMP('a','b') and NOT NOT NULLIF(2,3)

The bug is not very important per se, but it was helpful to move
Item_func_strcmp out of Item_bool_func2 (to Item_int_func),
for the purposes of "MDEV-4912 Add a plugin to field types (column types)".
parent 4dec4e11
...@@ -320,3 +320,20 @@ id select_type table type possible_keys key key_len ref rows filtered Extra ...@@ -320,3 +320,20 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
Warnings: Warnings:
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (not((`test`.`t1`.`a` + 0))) Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (not((`test`.`t1`.`a` + 0)))
drop table t1; drop table t1;
#
# Start of 10.0 tests
#
#
# MDEV-7001 Bad result for NOT NOT STRCMP('a','b') and NOT NOT NULLIF(2,3)
#
SELECT NOT NOT strcmp('a','b');
NOT NOT strcmp('a','b')
1
EXPLAIN EXTENDED SELECT NOT NOT strcmp('a','b');
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
Note 1003 select (strcmp('a','b') <> 0) AS `NOT NOT strcmp('a','b')`
#
# End of 10.0 tests
#
...@@ -382,3 +382,15 @@ CREATE TABLE t2 (d DATE) ENGINE=MyISAM; ...@@ -382,3 +382,15 @@ CREATE TABLE t2 (d DATE) ENGINE=MyISAM;
SELECT * FROM t1,t2 WHERE 1 IS NOT NULL AND t1.b IS NULL; SELECT * FROM t1,t2 WHERE 1 IS NOT NULL AND t1.b IS NULL;
a b c d a b c d
DROP TABLE t1,t2; DROP TABLE t1,t2;
#
# Start of 10.0 tests
#
#
# MDEV-7001 Bad result for NOT NOT STRCMP('a','b') and NOT NOT NULLIF(2,3)
#
SELECT NOT NOT NULLIF(2,3);
NOT NOT NULLIF(2,3)
1
#
# End of 10.0 tests
#
...@@ -180,3 +180,17 @@ select * from t1 where not (a+0); ...@@ -180,3 +180,17 @@ select * from t1 where not (a+0);
explain extended select * from t1 where not (a+0); explain extended select * from t1 where not (a+0);
drop table t1; drop table t1;
--echo #
--echo # Start of 10.0 tests
--echo #
--echo #
--echo # MDEV-7001 Bad result for NOT NOT STRCMP('a','b') and NOT NOT NULLIF(2,3)
--echo #
SELECT NOT NOT strcmp('a','b');
EXPLAIN EXTENDED SELECT NOT NOT strcmp('a','b');
--echo #
--echo # End of 10.0 tests
--echo #
...@@ -295,3 +295,16 @@ CREATE TABLE t2 (d DATE) ENGINE=MyISAM; ...@@ -295,3 +295,16 @@ CREATE TABLE t2 (d DATE) ENGINE=MyISAM;
SELECT * FROM t1,t2 WHERE 1 IS NOT NULL AND t1.b IS NULL; SELECT * FROM t1,t2 WHERE 1 IS NOT NULL AND t1.b IS NULL;
DROP TABLE t1,t2; DROP TABLE t1,t2;
--echo #
--echo # Start of 10.0 tests
--echo #
--echo #
--echo # MDEV-7001 Bad result for NOT NOT STRCMP('a','b') and NOT NOT NULLIF(2,3)
--echo #
SELECT NOT NOT NULLIF(2,3);
--echo #
--echo # End of 10.0 tests
--echo #
...@@ -164,6 +164,12 @@ public: ...@@ -164,6 +164,12 @@ public:
default: return "UNKNOWN"; default: return "UNKNOWN";
} }
} }
int sortcmp(const String *s, const String *t) const
{
return collation->coll->strnncollsp(collation,
(uchar *) s->ptr(), s->length(),
(uchar *) t->ptr(), t->length(), 0);
}
}; };
/*************************************************************************/ /*************************************************************************/
......
...@@ -1970,14 +1970,14 @@ longlong Item_func_lt::val_int() ...@@ -1970,14 +1970,14 @@ longlong Item_func_lt::val_int()
longlong Item_func_strcmp::val_int() longlong Item_func_strcmp::val_int()
{ {
DBUG_ASSERT(fixed == 1); DBUG_ASSERT(fixed == 1);
String *a=args[0]->val_str(&cmp.value1); String *a= args[0]->val_str(&value1);
String *b=args[1]->val_str(&cmp.value2); String *b= args[1]->val_str(&value2);
if (!a || !b) if (!a || !b)
{ {
null_value=1; null_value=1;
return 0; return 0;
} }
int value= sortcmp(a,b,cmp.cmp_collation.collation); int value= cmp_collation.sortcmp(a, b);
null_value=0; null_value=0;
return !value ? 0 : (value < 0 ? (longlong) -1 : (longlong) 1); return !value ? 0 : (value < 0 ? (longlong) -1 : (longlong) 1);
} }
......
...@@ -695,21 +695,18 @@ public: ...@@ -695,21 +695,18 @@ public:
}; };
class Item_func_strcmp :public Item_bool_func2 class Item_func_strcmp :public Item_int_func
{ {
String value1, value2;
DTCollation cmp_collation;
public: public:
Item_func_strcmp(Item *a,Item *b) :Item_bool_func2(a,b) {} Item_func_strcmp(Item *a,Item *b) :Item_int_func(a,b) {}
longlong val_int(); longlong val_int();
optimize_type select_optimize() const { return OPTIMIZE_NONE; } uint decimal_precision() const { return 1; }
const char *func_name() const { return "strcmp"; } const char *func_name() const { return "strcmp"; }
virtual inline void print(String *str, enum_query_type query_type)
{
Item_func::print(str, query_type);
}
void fix_length_and_dec() void fix_length_and_dec()
{ {
Item_bool_func2::fix_length_and_dec(); agg_arg_charsets_for_comparison(cmp_collation, args, 2);
fix_char_length(2); // returns "1" or "0" or "-1" fix_char_length(2); // returns "1" or "0" or "-1"
} }
}; };
...@@ -803,6 +800,7 @@ public: ...@@ -803,6 +800,7 @@ public:
Item_func_nullif(Item *a,Item *b) Item_func_nullif(Item *a,Item *b)
:Item_bool_func2(a,b), cached_result_type(INT_RESULT) :Item_bool_func2(a,b), cached_result_type(INT_RESULT)
{} {}
bool is_bool_func() { return false; }
double val_real(); double val_real();
longlong val_int(); longlong val_int();
String *val_str(String *str); String *val_str(String *str);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment