Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions test/distributed/cases/fulltext/fulltext_query_shapes.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
set experimental_fulltext_index = 1;
drop database if exists ft_query_shapes;
create database ft_query_shapes;
use ft_query_shapes;
create table articles (
id int primary key,
title varchar(255),
content text,
author_id int,
fulltext index ft_articles(title, content) with parser gojieba
);
insert into articles values
(1, 'Database Guide', 'database search engine', 1),
(2, 'Vector Guide', 'vector search engine', 2),
(3, 'Transaction Guide', 'database transaction engine', 1),
(4, 'Mixed Guide', 'database vector integration', 2);
select distinct author_id
from articles
where match(title, content) against('+database' in boolean mode);
➤ author_id[4,32,0] 𝄀
1 𝄀
2
select author_id, count(*) as matched_count
from articles
where match(title, content) against('+database' in boolean mode)
group by author_id;
➤ author_id[4,32,0] ¦ matched_count[-5,64,0] 𝄀
1 ¦ 2 𝄀
2 ¦ 1
select author_id, count(*) as matched_count
from articles
where match(title, content) against('+database' in boolean mode)
group by author_id
having count(*) > 1;
➤ author_id[4,32,0] ¦ matched_count[-5,64,0] 𝄀
1 ¦ 2
with matched as (
select id from articles
where match(title, content) against('+database' in boolean mode)
)
select count(*) from matched;
➤ count(*)[-5,64,0] 𝄀
3
select count(*)
from (
select id from articles
where match(title, content) against('+database' in boolean mode)
) as matched;
➤ count(*)[-5,64,0] 𝄀
3
select id from articles
where id > 1
and match(title, content) against('+database' in boolean mode)
order by id;
➤ id[4,32,0] 𝄀
3 𝄀
4
select distinct author_id
from articles
where match(title, content) against('+database' in boolean mode)
order by author_id;
[unknown result because it is related to issue#25890]
select id from articles
where id in (
select id from articles
where match(title, content) against('+database' in boolean mode)
)
order by id;
[unknown result because it is related to issue#25891]
drop database ft_query_shapes;
79 changes: 79 additions & 0 deletions test/distributed/cases/fulltext/fulltext_query_shapes.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
-- Fulltext SQL composability and optimizer rewrite coverage.

set experimental_fulltext_index = 1;

drop database if exists ft_query_shapes;
create database ft_query_shapes;
use ft_query_shapes;

create table articles (
id int primary key,
title varchar(255),
content text,
author_id int,
fulltext index ft_articles(title, content) with parser gojieba
);

insert into articles values
(1, 'Database Guide', 'database search engine', 1),
(2, 'Vector Guide', 'vector search engine', 2),
(3, 'Transaction Guide', 'database transaction engine', 1),
(4, 'Mixed Guide', 'database vector integration', 2);

-- DISTINCT is supported when MATCH is rewritten at the source scan.
-- @sortkey:0
select distinct author_id
from articles
where match(title, content) against('+database' in boolean mode);

-- GROUP BY and HAVING preserve the rewritten fulltext input.
-- @sortkey:0
select author_id, count(*) as matched_count
from articles
where match(title, content) against('+database' in boolean mode)
group by author_id;

select author_id, count(*) as matched_count
from articles
where match(title, content) against('+database' in boolean mode)
group by author_id
having count(*) > 1;

-- Nested CTE and derived-table consumers are supported.
with matched as (
select id from articles
where match(title, content) against('+database' in boolean mode)
)
select count(*) from matched;

select count(*)
from (
select id from articles
where match(title, content) against('+database' in boolean mode)
) as matched;

-- Ordinary predicates combine with MATCH.
select id from articles
where id > 1
and match(title, content) against('+database' in boolean mode)
order by id;

-- #25890: remove the tags and add positive output after optimizer support lands.
-- @bvt:issue#25890
select distinct author_id
from articles
where match(title, content) against('+database' in boolean mode)
order by author_id;
-- @bvt:issue

-- #25891: remove the tags and add positive output after optimizer support lands.
-- @bvt:issue#25891
select id from articles
where id in (
select id from articles
where match(title, content) against('+database' in boolean mode)
)
order by id;
-- @bvt:issue

drop database ft_query_shapes;
186 changes: 186 additions & 0 deletions test/distributed/cases/fulltext/gojieba_precise.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
set experimental_fulltext_index = 1;
drop database if exists ft_gojieba_precise;
create database ft_gojieba_precise;
use ft_gojieba_precise;
select f.pos, f.word
from (
select cast(column_0 as bigint) as id, column_1 as body
from (values row(1, '我来到北京清华大学'))
) as src
cross apply fulltext_index_tokenize('{"parser":"gojieba"}', 23, id, body) as f;
➤ pos[4,32,0] ¦ word[12,-1,0] 𝄀
0 ¦ 我 𝄀
3 ¦ 来到 𝄀
9 ¦ 北京 𝄀
15 ¦ 清华大学 𝄀
4 ¦ __DocLen
select f.pos, f.word
from (
select cast(column_0 as bigint) as id, column_1 as body
from (values row(1, 'Hello, WORLD! MatrixOne数据库'))
) as src
cross apply fulltext_index_tokenize('{"parser":"gojieba"}', 23, id, body) as f;
➤ pos[4,32,0] ¦ word[12,-1,0] 𝄀
0 ¦ hello 𝄀
7 ¦ world 𝄀
14 ¦ matrixone 𝄀
23 ¦ 数据库 𝄀
4 ¦ __DocLen
select f.pos, f.word
from (
select cast(column_0 as bigint) as id, column_1 as body
from (values row(1, 'abcdefghijklmnopqrstuvwxyzabcd'))
) as src
cross apply fulltext_index_tokenize('{"parser":"gojieba"}', 23, id, body) as f;
➤ pos[4,32,0] ¦ word[12,-1,0] 𝄀
0 ¦ abcdefghijklmnopqrstuvw 𝄀
1 ¦ __DocLen
select f.pos, f.word
from (
select cast(column_0 as bigint) as id, column_1 as body
from (values row(1, 'red red red'))
) as src
cross apply fulltext_index_tokenize('{"parser":"gojieba"}', 23, id, body) as f;
➤ pos[4,32,0] ¦ word[12,-1,0] 𝄀
0 ¦ red 𝄀
4 ¦ red 𝄀
8 ¦ red 𝄀
3 ¦ __DocLen
select f.pos, f.word
from (
select cast(column_0 as bigint) as id, column_1 as body, column_2 as title
from (values row(1, '我来到北京', 'MatrixOne 数据库'))
) as src
cross apply fulltext_index_tokenize('{"parser":"gojieba"}', 23, id, body, title) as f;
➤ pos[4,32,0] ¦ word[12,-1,0] 𝄀
0 ¦ 我 𝄀
3 ¦ 来到 𝄀
9 ¦ 北京 𝄀
16 ¦ matrixone 𝄀
26 ¦ 数据库 𝄀
5 ¦ __DocLen
select f.pos, f.word
from (
select cast(column_0 as bigint) as id, column_1 as body
from (values row(1, '他来到了网易杭研大厦'))
) as src
cross apply fulltext_index_tokenize('{"parser":"gojieba"}', 23, id, body) as f;
➤ pos[4,32,0] ¦ word[12,-1,0] 𝄀
0 ¦ 他 𝄀
3 ¦ 来到 𝄀
9 ¦ 了 𝄀
12 ¦ 网易 𝄀
18 ¦ 杭 𝄀
21 ¦ 研 𝄀
24 ¦ 大厦 𝄀
7 ¦ __DocLen
select count(*)
from (
select cast(column_0 as bigint) as id, column_1 as body
from (values row(1, ' '))
) as src
cross apply fulltext_index_tokenize('{"parser":"gojieba"}', 23, id, body) as f;
➤ count(*)[-5,64,0] 𝄀
0
select count(*)
from (
select cast(column_0 as bigint) as id, column_1 as body
from (values row(1, ',。!?;:、()【】'))
) as src
cross apply fulltext_index_tokenize('{"parser":"gojieba"}', 23, id, body) as f;
➤ count(*)[-5,64,0] 𝄀
0
select count(*)
from (
select cast(column_0 as bigint) as id, column_1 as body
from (values row(1, ''))
) as src
cross apply fulltext_index_tokenize('{"parser":"gojieba"}', 23, id, body) as f;
➤ count(*)[-5,64,0] 𝄀
0
select count(*)
from (
select cast(column_0 as bigint) as id, cast(column_1 as varchar) as body
from (values row(1, null))
) as src
cross apply fulltext_index_tokenize('{"parser":"gojieba"}', 23, id, body) as f;
➤ count(*)[-5,64,0] 𝄀
0
create table docs (
id int primary key,
title varchar(255),
body text,
tag int
);
insert into docs values
(1, 'TitleOnlyToken', '', 0),
(2, 'NullTitleToken', null, 0),
(3, '', 'BodyOnlyToken', 0),
(4, null, 'NullBodyToken', 0),
(5, '校园', '我来到北京', 0),
(6, null, null, 0);
create fulltext index ft_docs on docs(title, body) with parser gojieba;
select id from docs
where match(title, body) against('+titleonlytoken' in boolean mode)
order by id;
➤ id[4,32,0] 𝄀
1
select id from docs
where match(title, body) against('+nulltitletoken' in boolean mode)
order by id;
➤ id[4,32,0]
select id from docs
where match(title, body) against('+bodyonlytoken' in boolean mode)
order by id;
➤ id[4,32,0] 𝄀
3
select id from docs
where match(title, body) against('+nullbodytoken' in boolean mode)
order by id;
➤ id[4,32,0]
select id from docs
where match(title, body) against('"校园我来到"' in boolean mode)
order by id;
➤ id[4,32,0]
select id from docs
where match(title, body) against('+titleonlytoken +titleonlytoken' in boolean mode)
order by id;
➤ id[4,32,0] 𝄀
1
select id from docs
where match(title, body) against('+titleonlytoken +bodyonlytoken' in boolean mode)
order by id;
➤ id[4,32,0]
select id from docs
where match(title, body) against('' in boolean mode);
SQL parser error: You have an error in your SQL syntax; check the manual that corresponds to your MatrixOne server version for the right syntax to use. SQL syntax error: AGAINST('pattern') pattern is empty. at line 2 column 53 near ");";
update docs set tag = 7 where id = 1;
select id, tag from docs
where match(title, body) against('+titleonlytoken' in boolean mode);
➤ id[4,32,0] ¦ tag[4,32,0] 𝄀
1 ¦ 7
update docs set title = 'LifecycleTitle', body = 'LifecycleBody' where id = 6;
select id from docs
where match(title, body) against('+lifecycletitle +lifecyclebody' in boolean mode);
➤ id[4,32,0] 𝄀
6
update docs set title = null where id = 6;
select id from docs
where match(title, body) against('+lifecyclebody' in boolean mode);
➤ id[4,32,0]
update docs set title = '' where id = 6;
select id from docs
where match(title, body) against('+lifecyclebody' in boolean mode);
➤ id[4,32,0] 𝄀
6
truncate table docs;
select count(*) from docs
where match(title, body) against('+titleonlytoken' in boolean mode);
➤ count(*)[-5,64,0] 𝄀
0
insert into docs values (7, 'AfterTruncate', 'RestoredToken', 0);
select id from docs
where match(title, body) against('+aftertruncate +restoredtoken' in boolean mode);
➤ id[4,32,0] 𝄀
7
drop database ft_gojieba_precise;
Loading
Loading