Skip to content

Commit

Permalink
fix(tianmu): When executing SELECT..WHERE NAME LIKE %_, it failed(sto…
Browse files Browse the repository at this point in the history
…neatom#1157)

1. Handle the result set error caused by character transfer(stoneatom#1157)(stoneatom#1162)
2. Handle the result set problem caused by ESCAPE keyword(stoneatom#1162)
  • Loading branch information
konghaiya committed Dec 30, 2022
1 parent a137b3e commit 4b3a605
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 1 deletion.
37 changes: 37 additions & 0 deletions mysql-test/suite/tianmu/r/issue1157.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
DROP DATABASE IF EXISTS issue1157_test;
CREATE DATABASE issue1157_test;
USE issue1157_test;
CREATE TABLE st(
`id` BIGINT(20) NOT NULL AUTO_INCREMENT,
`name` VARCHAR(255) DEFAULT NULL,
`uid` VARCHAR(11) DEFAULT NULL,
PRIMARY KEY (`id`)
)engine=tianmu;
INSERT INTO st (NAME,uid) VALUES('%a','world');
INSERT INTO st (NAME,uid) VALUES('%_','world');
SELECT * FROM st WHERE NAME LIKE "a%a_" ESCAPE 'a';
id name uid
SELECT * FROM st WHERE NAME LIKE "\%\_";
id name uid
SELECT * FROM st WHERE NAME LIKE "\%_";
id name uid
1 %a world
2 %_ world
SELECT * FROM st WHERE NAME LIKE "a%_" ESCAPE 'a';
id name uid
1 %a world
2 %_ world
drop table st;
create table st2(id int ,column_2 varchar(10),column_3 varchar(10))engine=tianmu;
insert into st2 values(1,'_a\\\\','111111');
insert into st2 values(2,'12%','%12%');
insert into st2 values(3,'a_a','a%');
insert into st2 values(4,'_a\\','_12%');
insert into st2 values(5,'\\a','\\\\_a%12%');
select * from st2 where column_2 like '%_a\\\%';
id column_2 column_3
1 _a\\ 111111
select * from st2 where column_2 like '%?_a?\%' escape '?';
id column_2 column_3
drop table st2;
DROP DATABASE issue1157_test;
45 changes: 45 additions & 0 deletions mysql-test/suite/tianmu/t/issue1157.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
--source include/have_tianmu.inc

--disable_warnings
DROP DATABASE IF EXISTS issue1157_test;
--enable_warnings

CREATE DATABASE issue1157_test;
USE issue1157_test;


CREATE TABLE st(
`id` BIGINT(20) NOT NULL AUTO_INCREMENT,
`name` VARCHAR(255) DEFAULT NULL,
`uid` VARCHAR(11) DEFAULT NULL,
PRIMARY KEY (`id`)
)engine=tianmu;

INSERT INTO st (NAME,uid) VALUES('%a','world');
INSERT INTO st (NAME,uid) VALUES('%_','world');

SELECT * FROM st WHERE NAME LIKE "a%a_" ESCAPE 'a';

SELECT * FROM st WHERE NAME LIKE "\%\_";

SELECT * FROM st WHERE NAME LIKE "\%_";

SELECT * FROM st WHERE NAME LIKE "a%_" ESCAPE 'a';

drop table st;


create table st2(id int ,column_2 varchar(10),column_3 varchar(10))engine=tianmu;
insert into st2 values(1,'_a\\\\','111111');
insert into st2 values(2,'12%','%12%');
insert into st2 values(3,'a_a','a%');
insert into st2 values(4,'_a\\','_12%');
insert into st2 values(5,'\\a','\\\\_a%12%');

select * from st2 where column_2 like '%_a\\\%';

select * from st2 where column_2 like '%?_a?\%' escape '?';

drop table st2;

DROP DATABASE issue1157_test;
6 changes: 5 additions & 1 deletion storage/tianmu/core/tianmu_attr_exqp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,8 +484,12 @@ void TianmuAttr::EvaluatePack_Like_UTF(MIUpdatingIterator &mit, int dim, Descrip
types::BString pattern;
d.val1.vc->GetValueString(pattern, mit);
size_t min_len = 0; // the number of fixed characters
/*
When calculating the length of the matching string,
need to exclude wildcard characters and characters in ESCAPE
*/
for (uint i = 0; i < pattern.len_; i++)
if (pattern[i] != '%')
if (pattern[i] != '%' && pattern[i] != '\\' && pattern[i] != d.like_esc)
min_len++;
std::unordered_set<uint16_t> possible_ids;
bool use_trie = false;
Expand Down

0 comments on commit 4b3a605

Please sign in to comment.