Skip to content

Commit

Permalink
add alter table drop fulltext index case. (#21261)
Browse files Browse the repository at this point in the history
add alter table drop fulltext index case

Approved by: @heni02
  • Loading branch information
Ariznawlll authored Jan 20, 2025
1 parent cc9ad9e commit 38c394d
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 43 deletions.
50 changes: 41 additions & 9 deletions test/distributed/cases/fulltext/fulltext2.result
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ Rapier Abigail F Human Resources 38
create fulltext index ftidx on fulltext01 (LastName, FirstName);
alter table fulltext01 add column newcolumn decimal after LastName;
show create table fulltext01;

Table Create Table
fulltext01 CREATE TABLE `fulltext01` (\n `LastName` char(10) NOT NULL,\n `newcolumn` decimal(38,0) DEFAULT NULL,\n `FirstName` char(10) DEFAULT NULL,\n `Gender` char(1) DEFAULT NULL,\n `DepartmentName` char(20) DEFAULT NULL,\n `Age` int DEFAULT NULL,\n PRIMARY KEY (`LastName`),\n FULLTEXT `ftidx`(`LastName`,`FirstName`)\n)
select * from fulltext01;
lastname newcolumn firstname gender departmentname age
Gilbert null Kevin M Tool Design 33
Expand Down Expand Up @@ -60,7 +61,8 @@ employeenumber lastname firstname extension email officecode r
create fulltext index f01 on employees (LastName, FirstName);
alter table employees drop column LastName;
show create table employees;

Table Create Table
employees CREATE TABLE `employees` (\n `employeeNumber` int NOT NULL,\n `firstName` varchar(50) NOT NULL,\n `extension` varchar(10) NOT NULL,\n `email` varchar(100) NOT NULL,\n `officeCode` varchar(10) NOT NULL,\n `reportsTo` int DEFAULT NULL,\n `jobTitle` varchar(50) NOT NULL,\n PRIMARY KEY (`employeeNumber`),\n FULLTEXT `f01`(`firstName`)\n)
select * from employees;
employeenumber firstname extension email officecode reportsto jobtitle
1002 Diane x5800 [email protected] 1 null President
Expand All @@ -80,7 +82,8 @@ insert into t1 values(4, 'ab_def');
create fulltext index f02 on t1 (col2);
alter table t1 modify column col2 text;
show create table t1;

Table Create Table
t1 CREATE TABLE `t1` (\n `col1` int NOT NULL,\n `col2` text DEFAULT NULL,\n PRIMARY KEY (`col1`),\n FULLTEXT `f02`(`col2`)\n)
select * from t1;
col1 col2
1 abcdef
Expand Down Expand Up @@ -126,7 +129,7 @@ col1 col2 col3
2 3 e4r34f
create fulltext index f01 on ab01 (col2);
create fulltext index f02 on ab01 (col2);

not supported: Fulltext index are not allowed to use the same column
drop table ab01;
drop table if exists char01;
create table char01 (col1 varchar(200) primary key , col2 char(10));
Expand All @@ -139,7 +142,8 @@ col1 col2
alter table char01 add fulltext index f01(col1);
alter table char01 add fulltext index f02(col2);
show create table char01;

Table Create Table
char01 CREATE TABLE `char01` (\n `col1` varchar(200) NOT NULL,\n `col2` char(10) DEFAULT NULL,\n PRIMARY KEY (`col1`),\n FULLTEXT `f01`(`col1`),\n FULLTEXT `f02`(`col2`)\n)
drop table char01;
drop table if exists ab02;
create table ab02 (a bigint unsigned not null, primary key(a));
Expand Down Expand Up @@ -235,7 +239,8 @@ insert into prepare_fulltext values (1, 11), (2, 22), (3, 33);
prepare stmt1 from 'create fulltext index f06 on prepare_fulltext (a)';
execute stmt1;
show create table prepare_fulltext;

Table Create Table
prepare_fulltext CREATE TABLE `prepare_fulltext` (\n `a` char(1) NOT NULL,\n `b` varchar(20) DEFAULT NULL,\n PRIMARY KEY (`a`),\n FULLTEXT `f06`(`a`)\n)
select * from prepare_fulltext;
a b
1 11
Expand All @@ -253,7 +258,8 @@ execute stmt4;
prepare stmt3 from 'alter table pro add fulltext index pro2(name)';
execute stmt3;
show create table pro;

Table Create Table
pro CREATE TABLE `pro` (\n `id` int NOT NULL AUTO_INCREMENT,\n `name` varchar(255) DEFAULT NULL,\n `details` json DEFAULT NULL,\n PRIMARY KEY (`id`),\n FULLTEXT `pro1`(`details`) WITH PARSER json,\n FULLTEXT `pro2`(`name`)\n)
insert into pro (name, details) values('手机', '{"brand": "Apple", "model": "iPhone 12", "price": 800}');
select * from pro;
id name details
Expand All @@ -271,7 +277,8 @@ PRIMARY KEY (`col1`),
fulltext(col5)
);
show create table test_table;

Table Create Table
test_table CREATE TABLE `test_table` (\n `col1` int NOT NULL AUTO_INCREMENT,\n `col2` float DEFAULT NULL,\n `col3` bool DEFAULT NULL,\n `col4` date DEFAULT NULL,\n `col5` varchar(255) DEFAULT NULL,\n `col6` text DEFAULT NULL,\n PRIMARY KEY (`col1`),\n FULLTEXT (`col5`)\n)
load data infile '$resources/load_data/test_1.csv' into table test_table fields terminated by ',' parallel 'true';
select * from test_table;
col1 col2 col3 col4 col5 col6
Expand Down Expand Up @@ -367,7 +374,8 @@ true 2 var 2020-09-07 2020-09-07 00:00:00 2020-09-07 00:00:00
true 3 var 2020-09-07 2020-09-07 00:00:00 2020-09-07 00:00:00 18 121.11 ["1", 2, null, false, true, {"q": 1}] 1az null null
true 4 var 2020-09-07 2020-09-07 00:00:00 2020-09-07 00:00:00 18 121.11 {"b": ["a", "b", {"q": 4}], "c": 1} 1qaz null null
show create table t1;

Table Create Table
t1 CREATE TABLE `t1` (\n `col1` bool DEFAULT NULL,\n `col2` int NOT NULL,\n `col3` varchar(100) DEFAULT NULL,\n `col4` date DEFAULT NULL,\n `col5` datetime DEFAULT NULL,\n `col6` timestamp NULL DEFAULT NULL,\n `col7` decimal(38,0) DEFAULT NULL,\n `col8` float DEFAULT NULL,\n `col9` json DEFAULT NULL,\n `col10` text DEFAULT NULL,\n `col11` json DEFAULT NULL,\n `col12` bool DEFAULT NULL,\n PRIMARY KEY (`col2`),\n FULLTEXT `f06`(`col9`)\n)
drop table t1;
drop table if exists articles;
create table articles (
Expand Down Expand Up @@ -608,4 +616,28 @@ where match(comment_text) AGAINST ('全文索引' IN NATURAL LANGUAGE MODE);

drop table comments;
drop table posts;
drop table if exists fulltext_test01;
create table `fulltext_test01` (
`col1` bigint default NULL,
`col2` int not null,
`col3` varchar(200) default NULL,
`col4` varchar(200) default NULL,
PRIMARY KEY (`col2`),
FULLTEXT f01(`col3`) WITH PARSER ngram
);
load data infile '$resources/external_table_file/zhwiki.txt' into table fulltext_test01 fields terminated by ':' ESCAPED BY '\t' lines terminated by '\n';
show create table fulltext_test01;
Table Create Table
fulltext_test01 CREATE TABLE `fulltext_test01` (\n `col1` bigint DEFAULT NULL,\n `col2` int NOT NULL,\n `col3` varchar(200) DEFAULT NULL,\n `col4` varchar(200) DEFAULT NULL,\n PRIMARY KEY (`col2`),\n FULLTEXT `f01`(`col3`) WITH PARSER ngram\n)
alter table fulltext_test01 drop index f01;
show create table fulltext_test01;
Table Create Table
fulltext_test01 CREATE TABLE `fulltext_test01` (\n `col1` bigint DEFAULT NULL,\n `col2` int NOT NULL,\n `col3` varchar(200) DEFAULT NULL,\n `col4` varchar(200) DEFAULT NULL,\n PRIMARY KEY (`col2`)\n)
select * from fulltext_test01;
col1 col2 col3 col4
608 1 Wikipedia 上载纪录/存档/2002年
608 2 Wikipedia 删除纪录/档案馆/2004年3月
608 26 Wikipedia 繁简分歧词表
608 31 Wikipedia 宣告/2005年
drop table fulltext_test01;
drop database test_fulltext;
34 changes: 16 additions & 18 deletions test/distributed/cases/fulltext/fulltext2.sql
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ select * from fulltext01;

create fulltext index ftidx on fulltext01 (LastName, FirstName);
alter table fulltext01 add column newcolumn decimal after LastName;
-- @bvt:issue#20613
show create table fulltext01;
-- @bvt:issue
select * from fulltext01;
truncate fulltext01;
drop table fulltext01;
Expand All @@ -51,9 +49,7 @@ insert into employees(employeeNumber,lastName,firstName,extension,email,officeCo
select * from employees;
create fulltext index f01 on employees (LastName, FirstName);
alter table employees drop column LastName;
-- @bvt:issue#20613
show create table employees;
-- @bvt:issue
select * from employees;
select count(*) from employees;
truncate employees;
Expand All @@ -70,9 +66,7 @@ insert into t1 values(3, 'a_cdef');
insert into t1 values(4, 'ab_def');
create fulltext index f02 on t1 (col2);
alter table t1 modify column col2 text;
-- @bvt:issue#20613
show create table t1;
-- @bvt:issue
select * from t1;
drop table t1;

Expand Down Expand Up @@ -109,9 +103,7 @@ insert into ab01 values (1,2,'da');
insert into ab01 values (2,3,'e4r34f');
select * from ab01;
create fulltext index f01 on ab01 (col2);
-- @bvt:issue#20123
create fulltext index f02 on ab01 (col2);
-- @bvt:issue
drop table ab01;


Expand All @@ -124,9 +116,7 @@ insert into char01 values ('32jhbfchjecmwd%^&^(*&)UJHFRE%^T&YUHIJKNM', null);
select * from char01;
alter table char01 add fulltext index f01(col1);
alter table char01 add fulltext index f02(col2);
-- @bvt:issue#20613
show create table char01;
-- @bvt:issue
drop table char01;


Expand Down Expand Up @@ -208,9 +198,7 @@ create table prepare_fulltext (a char primary key , b varchar(20));
insert into prepare_fulltext values (1, 11), (2, 22), (3, 33);
prepare stmt1 from 'create fulltext index f06 on prepare_fulltext (a)';
execute stmt1;
-- @bvt:issue#20613
show create table prepare_fulltext;
-- @bvt:issue
select * from prepare_fulltext;
drop table prepare_fulltext;

Expand All @@ -227,9 +215,7 @@ prepare stmt4 from 'alter table pro add fulltext index pro1(details) with PARSER
execute stmt4;
prepare stmt3 from 'alter table pro add fulltext index pro2(name)';
execute stmt3;
-- @bvt:issue#20613
show create table pro;
-- @bvt:issue
insert into pro (name, details) values('手机', '{"brand": "Apple", "model": "iPhone 12", "price": 800}');
select * from pro;
drop table pro;
Expand All @@ -248,9 +234,7 @@ col6 text,
PRIMARY KEY (`col1`),
fulltext(col5)
);
-- @bvt:issue#20613
show create table test_table;
-- @bvt:issue
load data infile '$resources/load_data/test_1.csv' into table test_table fields terminated by ',' parallel 'true';
select * from test_table;
drop table test_table;
Expand Down Expand Up @@ -291,9 +275,7 @@ create table t1(
create fulltext index f06 on t1(col9);
load data infile {'filepath'='$resources/load_data/jsonline_object01.jl','format'='jsonline','jsondata'='object'} into table t1;
select * from t1;
-- @bvt:issue#20613
show create table t1;
-- @bvt:issue
drop table t1;


Expand Down Expand Up @@ -522,4 +504,20 @@ drop table posts;



drop table if exists fulltext_test01;
create table `fulltext_test01` (
`col1` bigint default NULL,
`col2` int not null,
`col3` varchar(200) default NULL,
`col4` varchar(200) default NULL,
PRIMARY KEY (`col2`),
FULLTEXT f01(`col3`) WITH PARSER ngram
);
load data infile '$resources/external_table_file/zhwiki.txt' into table fulltext_test01 fields terminated by ':' ESCAPED BY '\t' lines terminated by '\n';
show create table fulltext_test01;
alter table fulltext_test01 drop index f01;
show create table fulltext_test01;
select * from fulltext_test01;
drop table fulltext_test01;

drop database test_fulltext;
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,13 @@ drop snapshot spsp01;
show snapshots;
SNAPSHOT_NAME TIMESTAMP SNAPSHOT_LEVEL ACCOUNT_NAME DATABASE_NAME TABLE_NAME
drop database if exists sp_test01;

create database sp_test01;

use sp_test01;

drop table if exists partition01;

create table partition01 (
emp_no int not null,
birth_date date not null,
Expand All @@ -134,30 +138,40 @@ partition p02 values less than (200001),
partition p03 values less than (300001),
partition p04 values less than (400001)
);

insert into partition01 values (9001,'1980-12-17', 'SMITH', 'CLERK', 'F', '2008-12-17'),
(9002,'1981-02-20', 'ALLEN', 'SALESMAN', 'F', '2008-02-20');

drop snapshot if exists spsp02;

create snapshot spsp02 for database sp_test01;

show snapshots;
SNAPSHOT_NAME TIMESTAMP SNAPSHOT_LEVEL ACCOUNT_NAME DATABASE_NAME TABLE_NAME
spsp02 2024-12-30 09:08:58.518045 database sys sp_test01
delete from partition01 where birth_date = '1980-12-17';

select * from partition01;
emp_no birth_date first_name last_name gender hire_date
9002 1981-02-20 ALLEN SALESMAN F 2008-02-20
restore account sys database sp_test01 from snapshot spsp02 ;

select * from partition01;
emp_no birth_date first_name last_name gender hire_date
9001 1980-12-17 SMITH CLERK F 2008-12-17
9002 1981-02-20 ALLEN SALESMAN F 2008-02-20
drop table partition01;

restore account sys database sp_test01 table partition01 from snapshot spsp02;

select * from partition01;
emp_no birth_date first_name last_name gender hire_date
9001 1980-12-17 SMITH CLERK F 2008-12-17
9002 1981-02-20 ALLEN SALESMAN F 2008-02-20
drop database sp_test01;

drop snapshot spsp02;

drop database if exists sp_test02;
create database sp_test02;
use sp_test02;
Expand All @@ -166,7 +180,7 @@ drop snapshot if exists `SELECT`;
create snapshot `SELECT` for database sp_test02;
show snapshots;
SNAPSHOT_NAME TIMESTAMP SNAPSHOT_LEVEL ACCOUNT_NAME DATABASE_NAME TABLE_NAME
select 2024-12-30 09:08:59.159408 database sys sp_test02
select 2025-01-17 03:40:58.952534 database sys sp_test02
select sname, level, account_name, database_name, table_name from mo_catalog.mo_snapshots;
sname level account_name database_name table_name
select database sys sp_test02
Expand All @@ -180,7 +194,7 @@ drop snapshot if exists AUTO_INCREMENT;
create snapshot AUTO_INCREMENT for database sp_test03;
show snapshots;
SNAPSHOT_NAME TIMESTAMP SNAPSHOT_LEVEL ACCOUNT_NAME DATABASE_NAME TABLE_NAME
auto_increment 2024-12-30 09:08:59.409431 database sys sp_test03
auto_increment 2025-01-17 03:40:59.225357 database sys sp_test03
select sname, level, account_name, database_name, table_name from mo_catalog.mo_snapshots;
sname level account_name database_name table_name
auto_increment database sys sp_test03
Expand Down Expand Up @@ -236,8 +250,8 @@ create snapshot spsp02 for database db02;
create snapshot spsp03 for table db02 table01;
show snapshots;
SNAPSHOT_NAME TIMESTAMP SNAPSHOT_LEVEL ACCOUNT_NAME DATABASE_NAME TABLE_NAME
spsp03 2024-12-30 09:09:00.460849 table sys db02 table01
spsp02 2024-12-30 09:09:00.424832 database sys db02
spsp03 2025-01-17 03:41:00.18732 table sys db02 table01
spsp02 2025-01-17 03:41:00.160928 database sys db02
select sname, level, account_name, database_name, table_name from mo_catalog.mo_snapshots where level = 'database';
sname level account_name database_name table_name
spsp02 database sys db02
Expand Down Expand Up @@ -268,21 +282,18 @@ drop database db10;
drop role role1;
drop user user1;
use mo_catalog;

drop table if exists t1;

create cluster table t1(a int);

insert into t1 values(1,6),(2,6),(3,6);

select * from t1;

a account_id
1 6
2 6
3 6
drop snapshot if exists spsp07;

create snapshot spsp07 for table mo_catalog t1;

internal error: can not create snapshot for cluster table mo_catalog.t1
drop table t1;

drop database if exists db10;
create database db10;
use db10;
Expand Down Expand Up @@ -468,14 +479,14 @@ col1 load_file(col2)
1 1000-01-01,0001-01-01,1970-01-01 00:00:01,0\n9999-12-31,9999-12-31,2038-01-19,1\n
select * from test01;
col1 col2
1 file:///Users/ariznawl/matrixone/test/distributed/resources/load_data/time_date_1.csv
1 file:///Users/ariznawl/code/matrixone/test/distributed/resources/load_data/time_date_1.csv
drop snapshot if exists spsp10;
create snapshot spsp10 for database db10;
drop table test01;
restore account sys database db10 table test01 from snapshot spsp10;
select * from db10.test01;
col1 col2
1 file:///Users/ariznawl/matrixone/test/distributed/resources/load_data/time_date_1.csv
1 file:///Users/ariznawl/code/matrixone/test/distributed/resources/load_data/time_date_1.csv
drop database db10;
drop snapshot spsp10;
drop account acc01;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ drop user user1;


-- create snapshot for cluster table
-- @bvt:issue#21006
use mo_catalog;
drop table if exists t1;
create cluster table t1(a int);
Expand All @@ -251,7 +250,6 @@ select * from t1;
drop snapshot if exists spsp07;
create snapshot spsp07 for table mo_catalog t1;
drop table t1;
-- @bvt:issue



Expand Down
4 changes: 4 additions & 0 deletions test/distributed/resources/external_table_file/zhwiki.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
608:1:Wikipedia:上载纪录/存档/2002年
608:2:Wikipedia:删除纪录/档案馆/2004年3月
608:26:Wikipedia:繁简分歧词表
608:31:Wikipedia:宣告/2005年

0 comments on commit 38c394d

Please sign in to comment.