Commit f66e006b authored by willhan's avatar willhan Committed by Kentoku SHIBA

fix bug for spider where using "not like" (#890)

test case:
t1 is a spider engine table;
  CREATE TABLE `t1` (
  `id` int(11) NOT NULL DEFAULT '0',
  `name` char(64) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=SPIDER

query: "select * from t1 where name  not like 'x%' " would dispatch "select xxx name name like 'x%' " to remote mysqld, is wrong
parent 8701e5b0
...@@ -2661,7 +2661,6 @@ class Item_func_like :public Item_bool_func2 ...@@ -2661,7 +2661,6 @@ class Item_func_like :public Item_bool_func2
bool escape_used_in_parsing; bool escape_used_in_parsing;
bool use_sampling; bool use_sampling;
bool negated;
DTCollation cmp_collation; DTCollation cmp_collation;
String cmp_value1, cmp_value2; String cmp_value1, cmp_value2;
...@@ -2678,6 +2677,7 @@ class Item_func_like :public Item_bool_func2 ...@@ -2678,6 +2677,7 @@ class Item_func_like :public Item_bool_func2
Item_func::Functype type, Item *value); Item_func::Functype type, Item *value);
public: public:
int escape; int escape;
bool negated;
Item_func_like(THD *thd, Item *a, Item *b, Item *escape_arg, bool escape_used): Item_func_like(THD *thd, Item *a, Item *b, Item *escape_arg, bool escape_used):
Item_bool_func2(thd, a, b), canDoTurboBM(FALSE), pattern(0), pattern_len(0), Item_bool_func2(thd, a, b), canDoTurboBM(FALSE), pattern(0), pattern_len(0),
......
for master_1
for child2
child2_1
child2_2
child2_3
for child3
child3_1
child3_2
child3_3
drop and create databases
connection master_1;
DROP DATABASE IF EXISTS auto_test_local;
CREATE DATABASE auto_test_local;
USE auto_test_local;
connection child2_1;
DROP DATABASE IF EXISTS auto_test_remote;
CREATE DATABASE auto_test_remote;
USE auto_test_remote;
create table select test
connection master_1;
DROP TABLE IF EXISTS ta_l;
CREATE TABLE ta_l (
a INT,
b CHAR(1),
c DATETIME,
PRIMARY KEY(a)
) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1
INSERT INTO ta_l (a, b, c) VALUES
(1, 'a', '2018-11-01 10:21:39'),
(2, 'b', '2015-06-30 23:59:59'),
(3, 'c', '2013-11-01 01:01:01');
spider not like bug fix test
connection master_1;
select * from ta_l where b not like 'a%';
a b c
2 b 2015-06-30 23:59:59
3 c 2013-11-01 01:01:01
connection child2_1;
SELECT argument FROM mysql.general_log WHERE argument LIKE '%select%';
argument
select t0.`a` `a`,t0.`b` `b`,t0.`c` `c` from `auto_test_remote`.`ta_r` t0 where (t0.`b` not like 'a%')
SELECT argument FROM mysql.general_log WHERE argument LIKE '%select%'
deinit
connection master_1;
DROP DATABASE IF EXISTS auto_test_local;
connection child2_1;
DROP DATABASE IF EXISTS auto_test_remote;
SET GLOBAL log_output = @old_log_output;
for master_1
for child2
child2_1
child2_2
child2_3
for child3
child3_1
child3_2
child3_3
end of test
--disable_warnings
--disable_query_log
--disable_result_log
--source test_init.inc
--enable_result_log
--enable_query_log
--echo
--echo drop and create databases
--connection master_1
DROP DATABASE IF EXISTS auto_test_local;
CREATE DATABASE auto_test_local;
USE auto_test_local;
if ($USE_CHILD_GROUP2)
{
--connection child2_1
DROP DATABASE IF EXISTS auto_test_remote;
CREATE DATABASE auto_test_remote;
USE auto_test_remote;
}
--enable_warnings
--echo
--echo create table select test
if ($USE_CHILD_GROUP2)
{
if (!$OUTPUT_CHILD_GROUP2)
{
--disable_query_log
--disable_result_log
}
--connection child2_1
if ($OUTPUT_CHILD_GROUP2)
{
--disable_query_log
echo CHILD2_1_DROP_TABLES;
echo CHILD2_1_CREATE_TABLES;
}
--disable_warnings
eval $CHILD2_1_DROP_TABLES;
--enable_warnings
eval $CHILD2_1_CREATE_TABLES;
if ($OUTPUT_CHILD_GROUP2)
{
--enable_query_log
}
if ($USE_GENERAL_LOG)
{
SET @old_log_output = @@global.log_output;
TRUNCATE TABLE mysql.general_log;
set global log_output = 'TABLE';
}
if (!$OUTPUT_CHILD_GROUP2)
{
--enable_query_log
--enable_result_log
}
}
--connection master_1
--disable_warnings
DROP TABLE IF EXISTS ta_l;
--enable_warnings
--disable_query_log
echo CREATE TABLE ta_l (
a INT,
b CHAR(1),
c DATETIME,
PRIMARY KEY(a)
) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1;
eval CREATE TABLE ta_l (
a INT,
b CHAR(1),
c DATETIME,
PRIMARY KEY(a)
) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1;
--enable_query_log
INSERT INTO ta_l (a, b, c) VALUES
(1, 'a', '2018-11-01 10:21:39'),
(2, 'b', '2015-06-30 23:59:59'),
(3, 'c', '2013-11-01 01:01:01');
--echo
--echo spider not like bug fix test
if ($USE_CHILD_GROUP2)
{
if (!$OUTPUT_CHILD_GROUP2)
{
--disable_query_log
--disable_result_log
}
--connection child2_1
if ($USE_GENERAL_LOG)
{
TRUNCATE TABLE mysql.general_log;
}
if (!$OUTPUT_CHILD_GROUP2)
{
--enable_query_log
--enable_result_log
}
}
--connection master_1
select * from ta_l where b not like 'a%';
if ($USE_CHILD_GROUP2)
{
--connection child2_1
if ($USE_GENERAL_LOG)
{
SELECT argument FROM mysql.general_log WHERE argument LIKE '%select%';
}
}
--echo
--echo deinit
--disable_warnings
--connection master_1
DROP DATABASE IF EXISTS auto_test_local;
if ($USE_CHILD_GROUP2)
{
--connection child2_1
DROP DATABASE IF EXISTS auto_test_remote;
SET GLOBAL log_output = @old_log_output;
}
--disable_query_log
--disable_result_log
--source test_deinit.inc
--enable_result_log
--enable_query_log
--enable_warnings
--echo
--echo end of test
...@@ -161,6 +161,8 @@ typedef st_spider_result SPIDER_RESULT; ...@@ -161,6 +161,8 @@ typedef st_spider_result SPIDER_RESULT;
#define SPIDER_SQL_IN_LEN (sizeof(SPIDER_SQL_IN_STR) - 1) #define SPIDER_SQL_IN_LEN (sizeof(SPIDER_SQL_IN_STR) - 1)
#define SPIDER_SQL_NOT_IN_STR "not in(" #define SPIDER_SQL_NOT_IN_STR "not in("
#define SPIDER_SQL_NOT_IN_LEN (sizeof(SPIDER_SQL_NOT_IN_STR) - 1) #define SPIDER_SQL_NOT_IN_LEN (sizeof(SPIDER_SQL_NOT_IN_STR) - 1)
#define SPIDER_SQL_NOT_LIKE_STR "not like"
#define SPIDER_SQL_NOT_LIKE_LEN (sizeof(SPIDER_SQL_NOT_LIKE_STR) - 1)
#define SPIDER_SQL_AS_CHAR_STR " as char" #define SPIDER_SQL_AS_CHAR_STR " as char"
#define SPIDER_SQL_AS_CHAR_LEN (sizeof(SPIDER_SQL_AS_CHAR_STR) - 1) #define SPIDER_SQL_AS_CHAR_LEN (sizeof(SPIDER_SQL_AS_CHAR_STR) - 1)
#define SPIDER_SQL_CAST_STR "cast(" #define SPIDER_SQL_CAST_STR "cast("
......
...@@ -4857,13 +4857,27 @@ int spider_db_mbase_util::open_item_func( ...@@ -4857,13 +4857,27 @@ int spider_db_mbase_util::open_item_func(
case Item_func::LE_FUNC: case Item_func::LE_FUNC:
case Item_func::GE_FUNC: case Item_func::GE_FUNC:
case Item_func::GT_FUNC: case Item_func::GT_FUNC:
case Item_func::LIKE_FUNC:
if (str) if (str)
{ {
func_name = (char*) item_func->func_name(); func_name = (char*) item_func->func_name();
func_name_length = strlen(func_name); func_name_length = strlen(func_name);
} }
break; break;
case Item_func::LIKE_FUNC:
if (str)
{
if (((Item_func_like *)item_func)->negated)
{
func_name = SPIDER_SQL_NOT_LIKE_STR;
func_name_length = SPIDER_SQL_NOT_LIKE_LEN;
}
else
{
func_name = (char*)item_func->func_name();
func_name_length = strlen(func_name);
}
}
break;
default: default:
THD *thd = spider->trx->thd; THD *thd = spider->trx->thd;
SPIDER_SHARE *share = spider->share; SPIDER_SHARE *share = spider->share;
......
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