MDEV-13626 Merge InnoDB test cases from MySQL 5.7

This imports and adapts a number of MySQL 5.7 test cases that are
applicable to MariaDB.

Some tests for old bug fixes are not that relevant because the code
has been refactored since then (especially starting with
MariaDB Server 10.6), and the tests would not reproduce the
original bug if the fix was reverted.

In the test innodb_fts.opt, there are many duplicate MATCH ranks, which
would make the results nondeterministic. The test was stabilized by
changing some LIMIT clauses or by adding sorted_result in those cases
where the purpose of a test was to show that no sorting took place
in the server.

In the test innodb_fts.phrase, MySQL 5.7 would generate FTS_DOC_ID that
are 1 larger than in MariaDB. In innodb_fts.index_table the difference is 2.
This is because in MariaDB, fts_get_next_doc_id() post-increments
cache->next_doc_id, while MySQL 5.7 pre-increments it.

Reviewed by: Thirunarayanan Balathandayuthapani
This commit is contained in:
Marko Mäkelä 2023-11-08 12:17:14 +02:00
parent 2447172afb
commit 228b7e4db5
101 changed files with 15119 additions and 126 deletions

View file

@ -13,3 +13,32 @@ key(f1,f2(1))
)ENGINE=INNODB;
REPLACE INTO t1(f3) VALUES (1),(1);
DROP TABLE t1;
#Create and alter table examples for full column index followed by prefix index.
CREATE TABLE t1(
f1 VARCHAR(100),
f2 char(2),
KEY(f1,f2),
KEY(f1(5)))ENGINE=INNODB;
REPLACE INTO t1(f2) VALUES (1),(1);
ALTER TABLE t1 ADD INDEX(f2,f1);
DROP TABLE t1;
#Create and alter table examples for small prefix index followed by large
#prefix index.
CREATE TABLE t1(
f1 VARCHAR(100),
f2 char(2),
KEY(f1(5),f2),
KEY(f1(10)))ENGINE=INNODB;
REPLACE INTO t1(f2) VALUES (1),(1);
ALTER TABLE t1 ADD INDEX(f2,f1);
DROP TABLE t1;
#Create and alter table examples for prefix index followed by full column
#index.
CREATE TABLE t1(
f1 VARCHAR(100),
f2 char(2),
KEY(f1(5),f2),
KEY(f1))ENGINE=INNODB;
REPLACE INTO t1(f2) VALUES (1),(1);
ALTER TABLE t1 ADD INDEX(f2,f1);
DROP TABLE t1;

View file

@ -20,3 +20,46 @@ REPLACE INTO t1(f3) VALUES (1),(1);
DROP TABLE t1;
--echo #Create and alter table examples for full column index followed by prefix index.
CREATE TABLE t1(
f1 VARCHAR(100),
f2 char(2),
KEY(f1,f2),
KEY(f1(5)))ENGINE=INNODB;
REPLACE INTO t1(f2) VALUES (1),(1);
ALTER TABLE t1 ADD INDEX(f2,f1);
DROP TABLE t1;
--echo #Create and alter table examples for small prefix index followed by large
--echo #prefix index.
CREATE TABLE t1(
f1 VARCHAR(100),
f2 char(2),
KEY(f1(5),f2),
KEY(f1(10)))ENGINE=INNODB;
REPLACE INTO t1(f2) VALUES (1),(1);
ALTER TABLE t1 ADD INDEX(f2,f1);
DROP TABLE t1;
--echo #Create and alter table examples for prefix index followed by full column
--echo #index.
CREATE TABLE t1(
f1 VARCHAR(100),
f2 char(2),
KEY(f1(5),f2),
KEY(f1))ENGINE=INNODB;
REPLACE INTO t1(f2) VALUES (1),(1);
ALTER TABLE t1 ADD INDEX(f2,f1);
DROP TABLE t1;

View file

@ -0,0 +1,31 @@
#
# Bug #19471516 SERVER CRASHES WHEN EXECUTING ALTER TABLE ADD
# FOREIGN KEY
#
CREATE TABLE `parent` (`parent_id` INT, PRIMARY KEY (`parent_id`));
CREATE TABLE `child1` (`id` INT ,`child1_fk1` INT, `child1_fk2` INT,
PRIMARY KEY (`id`));
CREATE TABLE `child2` (`id` INT, `child2_fk1` INT, `child2_fk2` INT,
PRIMARY KEY (`id`));
CREATE TABLE `child3` (`id` INT , `child3_fk1` INT, PRIMARY KEY (`id`));
ALTER TABLE `child1` ADD FOREIGN KEY (`child1_fk1`) REFERENCES `parent`
(`parent_id`);
ALTER TABLE `child1` ADD FOREIGN KEY (`child1_fk1`) REFERENCES
`parent` (`parent_id`);
ALTER TABLE `child1` ADD FOREIGN KEY (`child1_fk2`) REFERENCES `parent`
(`parent_id`);
ALTER TABLE `child2` ADD FOREIGN KEY (`child2_fk1`) REFERENCES `parent`
(`parent_id`);
ALTER TABLE `child2` ADD FOREIGN KEY (`child2_fk2`) REFERENCES `parent`
(`parent_id`);
ALTER TABLE `child3` ADD FOREIGN KEY (`child3_fk1`) REFERENCES `parent`
(`parent_id`);
ALTER TABLE `child1` ADD FOREIGN KEY (`child1_fk2`) REFERENCES
`parent` (`parent_id`);
ALTER TABLE `child2` ADD FOREIGN KEY (`child2_fk1`) REFERENCES
`parent` (`parent_id`);
ALTER TABLE `child2` ADD FOREIGN KEY (`child2_fk2`) REFERENCES
`parent` (`parent_id`);
ALTER TABLE `child3` ADD FOREIGN KEY (`child3_fk1`) REFERENCES
`parent` (`parent_id`);
drop table child3, child2, child1, parent;

View file

@ -0,0 +1,76 @@
create table t1 (f1 int primary key) engine=innodb;
create table t2 (f1 int primary key,
constraint c1 foreign key (f1) references t1(f1)
on update cascade
on delete cascade) engine=innodb;
create table t3 (f1 int primary key,
constraint c2 foreign key (f1) references t1(f1)
on update cascade
on delete cascade) engine=innodb;
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`f1` int(11) NOT NULL,
PRIMARY KEY (`f1`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
show create table t2;
Table Create Table
t2 CREATE TABLE `t2` (
`f1` int(11) NOT NULL,
PRIMARY KEY (`f1`),
CONSTRAINT `c1` FOREIGN KEY (`f1`) REFERENCES `t1` (`f1`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
show create table t3;
Table Create Table
t3 CREATE TABLE `t3` (
`f1` int(11) NOT NULL,
PRIMARY KEY (`f1`),
CONSTRAINT `c2` FOREIGN KEY (`f1`) REFERENCES `t1` (`f1`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
insert into t1 values (1);
insert into t1 values (2);
insert into t1 values (3);
insert into t2 values (1);
insert into t2 values (2);
insert into t2 values (3);
insert into t3 values (1);
insert into t3 values (2);
insert into t3 values (3);
select f1 from t1;
f1
1
2
3
select f1 from t2;
f1
1
2
3
select f1 from t3;
f1
1
2
3
set @save_dbug = @@debug_dbug;
set debug_dbug = '+d,dml_cascade_only_once';
set debug_dbug = '+d,row_upd_cascade_lock_wait_err';
update t1 set f1 = 100 where f1 = 2;
select f1 from t1;
f1
1
3
100
select f1 from t2;
f1
1
3
100
select f1 from t3;
f1
1
3
100
set debug_dbug = @save_dbug;
drop table t2;
drop table t3;
drop table t1;

View file

@ -0,0 +1,72 @@
SET @old_innodb_file_per_table = @@innodb_file_per_table;
SET GLOBAL innodb_file_per_table = 1;
SELECT @@innodb_file_per_table;
@@innodb_file_per_table
1
CREATE TABLE t1 (
col_1 CHAR (255),
col_2 VARCHAR (255)
) ENGINE = InnoDB;
CREATE INDEX idx1 ON t1(col_1);
CREATE INDEX idx2 ON t1(col_2);
SHOW INDEXES FROM t1;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
t1 1 idx1 1 col_1 A 0 NULL NULL YES BTREE
t1 1 idx2 1 col_2 A 0 NULL NULL YES BTREE
INSERT INTO t1 VALUES ("col1_00001", "col2_00001"), ("col1_00002", "col2_00002");
SHOW INDEXES FROM t1;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
t1 1 idx1 1 col_1 A 2 NULL NULL YES BTREE
t1 1 idx2 1 col_2 A 2 NULL NULL YES BTREE
ANALYZE TABLE t1;
Table Op Msg_type Msg_text
test.t1 analyze status Engine-independent statistics collected
test.t1 analyze status OK
SHOW INDEXES FROM t1;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
t1 1 idx1 1 col_1 A 2 NULL NULL YES BTREE
t1 1 idx2 1 col_2 A 2 NULL NULL YES BTREE
FLUSH TABLES t1 FOR EXPORT;
backup: t1
UNLOCK TABLES;
DROP TABLE t1;
CREATE TABLE t1 (
col_1 CHAR (255),
col_2 VARCHAR (255)
) ENGINE = InnoDB STATS_PERSISTENT=1;
CREATE INDEX idx1 ON t1(col_1);
CREATE INDEX idx2 ON t1(col_2);
SHOW INDEXES FROM t1;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
t1 1 idx1 1 col_1 A 0 NULL NULL YES BTREE
t1 1 idx2 1 col_2 A 0 NULL NULL YES BTREE
INSERT INTO t1 VALUES ("col1_00001", "col2_00001");
SHOW INDEXES FROM t1;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
t1 1 idx1 1 col_1 A 1 NULL NULL YES BTREE
t1 1 idx2 1 col_2 A 1 NULL NULL YES BTREE
SET STATEMENT use_stat_tables=never FOR
ANALYZE TABLE t1;
Table Op Msg_type Msg_text
test.t1 analyze status OK
SHOW INDEXES FROM t1;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
t1 1 idx1 1 col_1 A 1 NULL NULL YES BTREE
t1 1 idx2 1 col_2 A 1 NULL NULL YES BTREE
ALTER TABLE t1 DISCARD TABLESPACE;
restore: t1 .ibd and .cfg files
ALTER TABLE t1 IMPORT TABLESPACE;
SHOW INDEXES FROM t1;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
t1 1 idx1 1 col_1 A 2 NULL NULL YES BTREE
t1 1 idx2 1 col_2 A 2 NULL NULL YES BTREE
SET STATEMENT use_stat_tables=never FOR
ANALYZE TABLE t1;
Table Op Msg_type Msg_text
test.t1 analyze status OK
SHOW INDEXES FROM t1;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
t1 1 idx1 1 col_1 A 2 NULL NULL YES BTREE
t1 1 idx2 1 col_2 A 2 NULL NULL YES BTREE
DROP TABLE t1;
SET GLOBAL innodb_file_per_table = @old_innodb_file_per_table;

View file

@ -0,0 +1,23 @@
connect stop_purge,localhost,root;
START TRANSACTION WITH CONSISTENT SNAPSHOT;
connection default;
CREATE TABLE t1(a INT PRIMARY KEY, b VARCHAR(1024))
ENGINE=InnoDB STATS_PERSISTENT=1;
INSERT INTO t1 VALUES (1,REPEAT('b',1024));
SELECT index_length FROM information_schema.tables
WHERE table_schema = 'test' AND table_name = 't1';
index_length
0
ALTER TABLE t1 ADD INDEX b (b(800));
SELECT FLOOR(index_length/@@innodb_page_size) FROM information_schema.tables
WHERE table_schema = 'test' AND table_name = 't1';
FLOOR(index_length/@@innodb_page_size)
1
ALTER TABLE t1 ADD INDEX ba (b(800),a);
SELECT FLOOR(index_length/@@innodb_page_size) FROM information_schema.tables
WHERE table_schema = 'test' AND table_name = 't1';
FLOOR(index_length/@@innodb_page_size)
2
disconnect stop_purge;
DROP TABLE t1;
# End of 10.4 tests

View file

@ -1,4 +1,24 @@
call mtr.add_suppression("Innodb: Cannot add field.*row size is");
SET SESSION innodb_strict_mode=ON;
CREATE TABLE t1(a int PRIMARY KEY) ENGINE=InnoDB ROW_FORMAT=COMPRESSED;
ERROR HY000: Can't create table `test`.`t1` (errno: 140 "Wrong create options")
CREATE TABLE t1(a int PRIMARY KEY) ENGINE=InnoDB KEY_BLOCK_SIZE=4;
ERROR HY000: Can't create table `test`.`t1` (errno: 140 "Wrong create options")
SET SESSION innodb_strict_mode=OFF;
CREATE TABLE t1(a int PRIMARY KEY) ENGINE=InnoDB ROW_FORMAT=COMPRESSED;
Warnings:
Warning 1478 InnoDB: Cannot create a COMPRESSED table when innodb_page_size > 16k. Assuming ROW_FORMAT=DYNAMIC.
SHOW WARNINGS;
Level Code Message
Warning 1478 InnoDB: Cannot create a COMPRESSED table when innodb_page_size > 16k. Assuming ROW_FORMAT=DYNAMIC.
DROP TABLE t1;
CREATE TABLE t1(a int PRIMARY KEY) ENGINE=InnoDB KEY_BLOCK_SIZE=4;
Warnings:
Warning 1478 InnoDB: Cannot create a COMPRESSED table when innodb_page_size > 16k. Assuming ROW_FORMAT=DYNAMIC.
SHOW WARNINGS;
Level Code Message
Warning 1478 InnoDB: Cannot create a COMPRESSED table when innodb_page_size > 16k. Assuming ROW_FORMAT=DYNAMIC.
DROP TABLE t1;
# Test 1) Show the page size from Information Schema
SELECT variable_value FROM information_schema.global_status
WHERE LOWER(variable_name) = 'innodb_page_size';

View file

@ -1,4 +1,24 @@
call mtr.add_suppression('InnoDB: Cannot add field.*because after adding it, the row size is');
SET SESSION innodb_strict_mode=ON;
CREATE TABLE t1(a int PRIMARY KEY) ENGINE=InnoDB ROW_FORMAT=COMPRESSED;
ERROR HY000: Can't create table `test`.`t1` (errno: 140 "Wrong create options")
CREATE TABLE t1(a int PRIMARY KEY) ENGINE=InnoDB KEY_BLOCK_SIZE=4;
ERROR HY000: Can't create table `test`.`t1` (errno: 140 "Wrong create options")
SET SESSION innodb_strict_mode=OFF;
CREATE TABLE t1(a int PRIMARY KEY) ENGINE=InnoDB ROW_FORMAT=COMPRESSED;
Warnings:
Warning 1478 InnoDB: Cannot create a COMPRESSED table when innodb_page_size > 16k. Assuming ROW_FORMAT=DYNAMIC.
SHOW WARNINGS;
Level Code Message
Warning 1478 InnoDB: Cannot create a COMPRESSED table when innodb_page_size > 16k. Assuming ROW_FORMAT=DYNAMIC.
DROP TABLE t1;
CREATE TABLE t1(a int PRIMARY KEY) ENGINE=InnoDB KEY_BLOCK_SIZE=4;
Warnings:
Warning 1478 InnoDB: Cannot create a COMPRESSED table when innodb_page_size > 16k. Assuming ROW_FORMAT=DYNAMIC.
SHOW WARNINGS;
Level Code Message
Warning 1478 InnoDB: Cannot create a COMPRESSED table when innodb_page_size > 16k. Assuming ROW_FORMAT=DYNAMIC.
DROP TABLE t1;
# Test 1) Show the page size from Information Schema
SELECT variable_value FROM information_schema.global_status
WHERE LOWER(variable_name) = 'innodb_page_size';

View file

@ -0,0 +1,62 @@
CREATE TABLE t1 (c1 INT , c2 CHAR(10), PRIMARY KEY (c1)) ENGINE = InnoDB;
INSERT INTO t1 VALUES(0, "0");
INSERT INTO t1 VALUES(1, "1");
INSERT INTO t1 VALUES(2, "2");
INSERT INTO t1 VALUES(3, "3");
connect con1,localhost,root,,;
connect con2,localhost,root,,;
connect con3,localhost,root,,;
connect con4,localhost,root,,;
connect con5,localhost,root,,;
connect con6,localhost,root,,;
connection default;
SET AUTOCOMMIT=0;
BEGIN;
SELECT * FROM t1 FOR UPDATE;
c1 c2
0 0
1 1
2 2
3 3
SELECT * FROM t1 WHERE c1 <= 3;
c1 c2
0 0
1 1
2 2
3 3
connection default;
SET DEBUG_SYNC='now WAIT_FOR waiting4';
SET DEBUG_SYNC= 'RESET';
SELECT trx_state, trx_query, trx_autocommit_non_locking
FROM INFORMATION_SCHEMA.INNODB_TRX
WHERE trx_state = 'LOCK WAIT'
ORDER BY trx_query;
trx_state trx_query trx_autocommit_non_locking
LOCK WAIT SELECT COUNT(*) FROM t1 LOCK IN SHARE MODE 0
LOCK WAIT SELECT COUNT(*) FROM t1 WHERE c1 >= 0 0
INSERT INTO t1 VALUES(4, '4');
COMMIT;
connection con6;
SELECT * FROM t1 WHERE c1 <= 4;
c1 c2
0 0
1 1
2 2
3 3
XA END '1';
XA PREPARE '1';
XA ROLLBACK '1';
disconnect con6;
disconnect con2;
disconnect con3;
disconnect con5;
connection con1;
COUNT(*)
5
disconnect con1;
connection con4;
COUNT(*)
5
disconnect con4;
connection default;
DROP TABLE t1;

View file

@ -1090,3 +1090,59 @@ ALTER TABLE t1 ADD COLUMN b DATETIME NOT NULL, LOCK=NONE;
# Cleanup
SET @@SQL_MODE= @OLD_SQL_MODE;
DROP TABLE t1;
#
# Bug#20977779 CANNOT IMPORT TABLES CONTAINING PREFIX INDEXES
#
CREATE TABLE t1 (c1 VARCHAR(32), c2 VARCHAR(32), c3 VARCHAR(32),
PRIMARY KEY (c1, c2, c3))
ENGINE=InnoDB;
ALTER TABLE t1 ADD INDEX ind1(c1(5), c2, c3);
ALTER TABLE t1 ADD INDEX ind2(c3, c1(10), c2);
ALTER TABLE t1 ADD INDEX ind3(c2, c3, c1(20));
INSERT INTO t1 VALUES ('Test Data -1', 'Test Data -2', 'Test Data -3');
# Test with 2ndary index having prefix
FLUSH TABLES test.t1 FOR EXPORT;
UNLOCK TABLES;
ALTER TABLE test.t1 DISCARD TABLESPACE;
ALTER TABLE test.t1 IMPORT TABLESPACE;
CHECK TABLE test.t1;
Table Op Msg_type Msg_text
test.t1 check status OK
SHOW CREATE TABLE test.t1;
Table Create Table
t1 CREATE TABLE `t1` (
`c1` varchar(32) NOT NULL,
`c2` varchar(32) NOT NULL,
`c3` varchar(32) NOT NULL,
PRIMARY KEY (`c1`,`c2`,`c3`),
KEY `ind1` (`c1`(5),`c2`,`c3`),
KEY `ind2` (`c3`,`c1`(10),`c2`),
KEY `ind3` (`c2`,`c3`,`c1`(20))
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
SELECT * FROM test.t1;
c1 c2 c3
Test Data -1 Test Data -2 Test Data -3
# Test with PK & 2ndary index with prefix
ALTER TABLE t1 DROP PRIMARY KEY, ADD PRIMARY KEY(c1(5), c2(10), c3(20));
FLUSH TABLES test.t1 FOR EXPORT;
UNLOCK TABLES;
ALTER TABLE test.t1 DISCARD TABLESPACE;
ALTER TABLE test.t1 IMPORT TABLESPACE;
CHECK TABLE test.t1;
Table Op Msg_type Msg_text
test.t1 check status OK
SHOW CREATE TABLE test.t1;
Table Create Table
t1 CREATE TABLE `t1` (
`c1` varchar(32) NOT NULL,
`c2` varchar(32) NOT NULL,
`c3` varchar(32) NOT NULL,
PRIMARY KEY (`c1`(5),`c2`(10),`c3`(20)),
KEY `ind1` (`c1`(5),`c2`,`c3`),
KEY `ind2` (`c3`,`c1`(10),`c2`),
KEY `ind3` (`c2`,`c3`,`c1`(20))
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
SELECT * FROM test.t1;
c1 c2 c3
Test Data -1 Test Data -2 Test Data -3
DROP TABLE t1;

View file

@ -618,3 +618,39 @@ test/e d a 0
test/fw c a 0
DROP TABLE t2;
DROP TABLE t3;
# Bug #17449901 TABLE DISAPPEARS WHEN ALTERING
# WITH FOREIGN KEY CHECKS OFF
create table t1(f1 int,primary key(f1))engine=innodb;
create table t2(f2 int,f3 int,key t(f2,f3),foreign key(f2) references t1(f1))engine=innodb;
SET foreign_key_checks=0;
drop index t on t2;
drop table t2;
drop table t1;
create table t1(f1 int ,primary key(f1))engine=innodb;
create table t2(f2 int,f3 int, key t(f2),foreign key(f2) references t1(f1))engine=innodb;
SET foreign_key_checks = 0;
alter table t2 drop key t,algorithm=inplace;
show create table t2;
Table Create Table
t2 CREATE TABLE `t2` (
`f2` int(11) DEFAULT NULL,
`f3` int(11) DEFAULT NULL,
CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`f2`) REFERENCES `t1` (`f1`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
drop table t2;
drop table t1;
create table t1(f1 int ,primary key(f1))engine=innodb;
create table t2(f2 int,f3 int, key t(f2),key t1(f2,f3),
foreign key(f2) references t1(f1))engine=innodb;
SET foreign_key_checks = 0;
alter table t2 drop key t,algorithm=inplace;
show create table t2;
Table Create Table
t2 CREATE TABLE `t2` (
`f2` int(11) DEFAULT NULL,
`f3` int(11) DEFAULT NULL,
KEY `t1` (`f2`,`f3`),
CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`f2`) REFERENCES `t1` (`f1`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
drop table t2;
drop table t1;

View file

@ -0,0 +1,124 @@
#
# Bug #21025880 DUPLICATE UK VALUES IN READ-COMMITTED(AGAIN)
#
SET @save_frequency = @@GLOBAL.innodb_purge_rseg_truncate_frequency;
SET GLOBAL innodb_purge_rseg_truncate_frequency=1;
CREATE TABLE t1 (
a INT NOT NULL,
b INT NOT NULL,
PRIMARY KEY(b),
UNIQUE KEY(a))
ENGINE=INNODB;
SET @old_innodb_stats_auto_recalc = @@innodb_stats_auto_recalc;
SET GLOBAL innodb_stats_auto_recalc = OFF;
connect purge_control,localhost,root;
START TRANSACTION WITH CONSISTENT SNAPSHOT;
connection default;
SET @old_tx_isolation = @@tx_isolation;
SET GLOBAL tx_isolation = 'READ-COMMITTED';
SET @old_innodb_lock_wait_timeout = @@innodb_lock_wait_timeout;
SET GLOBAL innodb_lock_wait_timeout = 1;
connect con1,localhost,root,,;
INSERT INTO t1 VALUES (1,1),(2,2);
DELETE FROM t1;
SET debug_sync = 'row_ins_sec_index_entry_dup_locks_created SIGNAL
con1_locks_done WAIT_FOR con1_go';
SET debug_sync = 'ha_commit_trans_after_acquire_commit_lock SIGNAL
con1_insert_done WAIT_FOR con1_finish';
REPLACE INTO t1 VALUES (1,2);
connect con2,localhost,root,,;
SET debug_sync = 'now WAIT_FOR con1_locks_done';
SET debug_sync = 'lock_wait_suspend_thread_enter SIGNAL con2_blocked
WAIT_FOR con2_go';
SET debug_sync = 'ha_commit_trans_after_acquire_commit_lock
WAIT_FOR con2_finish';
SET debug_sync = 'ib_after_row_insert SIGNAL con2_insert_done';
REPLACE INTO t1 VALUES (1,3);
connection default;
SET debug_sync = 'now WAIT_FOR con2_blocked';
connection purge_control;
COMMIT;
disconnect purge_control;
connection default;
InnoDB 0 transactions not purged
SET debug_sync = 'now SIGNAL con2_go WAIT_FOR con2_insert_done';
SET debug_sync = 'now SIGNAL con1_go WAIT_FOR con1_insert_done';
SET debug_sync = 'now SIGNAL con1_finish';
connection con1;
disconnect con1;
connection default;
SET debug_sync = 'now SIGNAL con2_finish';
connection con2;
disconnect con2;
connection default;
SET DEBUG_SYNC= 'RESET';
SELECT * FROM t1;
a b
1 2
CHECK TABLE t1;
Table Op Msg_type Msg_text
test.t1 check status OK
DROP TABLE t1;
SET GLOBAL innodb_stats_auto_recalc = @old_innodb_stats_auto_recalc;
SET GLOBAL tx_isolation = @old_tx_isolation;
SET GLOBAL innodb_lock_wait_timeout = @old_innodb_lock_wait_timeout;
CREATE TABLE t1 (
a INT NOT NULL,
b INT NOT NULL,
PRIMARY KEY(b),
UNIQUE KEY(a))
ENGINE=INNODB;
SET @old_innodb_stats_auto_recalc = @@innodb_stats_auto_recalc;
SET GLOBAL innodb_stats_auto_recalc = OFF;
connect purge_control,localhost,root;
START TRANSACTION WITH CONSISTENT SNAPSHOT;
connection default;
SET @old_tx_isolation = @@tx_isolation;
SET GLOBAL tx_isolation = 'READ-COMMITTED';
SET @old_innodb_lock_wait_timeout = @@innodb_lock_wait_timeout;
SET GLOBAL innodb_lock_wait_timeout = 1;
connect con1,localhost,root,,;
INSERT INTO t1 VALUES (1,1),(2,2);
DELETE FROM t1;
SET debug_sync = 'row_ins_sec_index_entry_dup_locks_created SIGNAL
con1_locks_done WAIT_FOR con1_go';
SET debug_sync = 'ha_commit_trans_after_acquire_commit_lock SIGNAL
con1_insert_done WAIT_FOR con1_finish';
INSERT INTO t1 values (1,2) ON DUPLICATE KEY UPDATE a=2;
connect con2,localhost,root,,;
SET debug_sync = 'now WAIT_FOR con1_locks_done';
SET debug_sync = 'lock_wait_suspend_thread_enter SIGNAL con2_blocked
WAIT_FOR con2_go';
SET debug_sync = 'ha_commit_trans_after_acquire_commit_lock
WAIT_FOR con2_finish';
SET debug_sync = 'ib_after_row_insert SIGNAL con2_insert_done';
REPLACE INTO t1 VALUES (1,3);
connection default;
SET debug_sync = 'now WAIT_FOR con2_blocked';
connection purge_control;
COMMIT;
disconnect purge_control;
connection default;
InnoDB 0 transactions not purged
SET debug_sync = 'now SIGNAL con2_go WAIT_FOR con2_insert_done';
SET debug_sync = 'now SIGNAL con1_go WAIT_FOR con1_insert_done';
SET debug_sync = 'now SIGNAL con1_finish';
connection con1;
disconnect con1;
connection default;
SET debug_sync = 'now SIGNAL con2_finish';
connection con2;
disconnect con2;
connection default;
SET DEBUG_SYNC= 'RESET';
SELECT * FROM t1;
a b
1 2
CHECK TABLE t1;
Table Op Msg_type Msg_text
test.t1 check status OK
DROP TABLE t1;
SET GLOBAL innodb_stats_auto_recalc = @old_innodb_stats_auto_recalc;
SET GLOBAL tx_isolation = @old_tx_isolation;
SET GLOBAL innodb_lock_wait_timeout = @old_innodb_lock_wait_timeout;
SET GLOBAL innodb_purge_rseg_truncate_frequency=@save_frequency;

View file

@ -9,9 +9,6 @@ INSERT INTO t2 VALUES(1, "b");
INSERT INTO t2 VALUES(2, "c");
INSERT INTO t2 VALUES(3, "d");
connect con1,localhost,root,,;
connect con2,localhost,root,,;
connection con1;
'T1'
SET AUTOCOMMIT=0;
BEGIN;
SELECT * FROM t2;
@ -21,7 +18,6 @@ c1 c2
2 c
3 d
connection default;
'T2'
SET AUTOCOMMIT=0;
BEGIN;
SELECT * FROM t1;
@ -30,8 +26,7 @@ c1 c2
1 1
2 2
3 3
connection con2;
'T3'
connect con2,localhost,root,,;
SET AUTOCOMMIT=0;
SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;
BEGIN;
@ -48,7 +43,6 @@ c1 c2
2 c
3 d
connection con1;
'T1'
UPDATE t2 SET c1 = c1 + 100;
SELECT * FROM t2;
c1 c2
@ -58,7 +52,6 @@ c1 c2
103 d
COMMIT;
connection default;
'T2'
UPDATE t1 SET c1 = c1 + 100;
SELECT * FROM t1;
c1 c2
@ -68,42 +61,29 @@ c1 c2
103 3
COMMIT;
connection con2;
'T3'
SET DEBUG_SYNC='row_search_for_mysql_before_return WAIT_FOR waiting1';
SELECT * FROM t1;;
connection default;
'T2'
SET DEBUG_SYNC='now SIGNAL waiting1';
'Signalled T3'
connection con2;
'T3'
c1 c2
0 0
1 1
2 2
3 3
connection con2;
'T3'
SET DEBUG_SYNC='row_search_for_mysql_before_return WAIT_FOR waiting1';
SELECT * FROM t2;;
connection default;
'T2'
SET DEBUG_SYNC='now SIGNAL waiting1';
'Signalled T3'
connection con2;
'T3'
c1 c2
0 a
1 b
2 c
3 d
connection default;
disconnect con1;
disconnect con2;
connect con1,localhost,root,,;
connect con2,localhost,root,,;
connection con1;
'T1'
SET AUTOCOMMIT=0;
BEGIN;
SELECT * FROM t1;
@ -113,7 +93,6 @@ c1 c2
102 2
103 3
connection default;
'T2'
SET AUTOCOMMIT=0;
BEGIN;
SELECT * FROM t2;
@ -131,7 +110,6 @@ c1 c2
203 d
COMMIT;
connection con2;
'T3'
SET AUTOCOMMIT=0;
SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;
BEGIN;
@ -148,7 +126,6 @@ c1 c2
202 c
203 d
connection con1;
'T1'
UPDATE t1 SET c1 = c1 + 100;
SELECT * FROM t1;
c1 c2
@ -158,44 +135,34 @@ c1 c2
203 3
COMMIT;
connection con2;
'T3'
SET DEBUG_SYNC='row_select_wait WAIT_FOR waiting1';
SELECT * FROM t1;;
connection con1;
'T2'
SET DEBUG_SYNC='now SIGNAL waiting1';
'Signalled T3'
connection con2;
'T3'
c1 c2
100 0
101 1
102 2
103 3
connection con2;
'T3'
SET DEBUG_SYNC='row_select_wait WAIT_FOR waiting1';
SELECT * FROM t2;;
connection default;
'T2'
SET DEBUG_SYNC='now SIGNAL waiting1';
'Signalled T3'
connection con2;
'T3'
c1 c2
200 a
201 b
202 c
203 d
connection default;
disconnect con1;
disconnect con2;
connection default;
DROP TABLE t1;
DROP TABLE t2;
#
# Bug 21433768: NON-REPEATABLE READ WITH REPEATABLE READ ISOLATION
#
connect con1,localhost,root,,;
connection con1;
CREATE TABLE t1(col1 INT PRIMARY KEY, col2 INT) ENGINE = InnoDB;
INSERT INTO t1 values (1, 0), (2, 0);
SELECT * FROM t1 ORDER BY col1;
@ -218,5 +185,5 @@ SET DEBUG_SYNC = 'now SIGNAL s2';
connection con1;
disconnect con1;
connection default;
DROP TABLE t1;
SET DEBUG_SYNC= 'RESET';
DROP TABLE t1;

View file

@ -0,0 +1,90 @@
SET @save_timeout=@@GLOBAL.innodb_lock_wait_timeout;
SET GLOBAL innodb_lock_wait_timeout=100000000;
DESCRIBE INFORMATION_SCHEMA.INNODB_TRX;
Field Type Null Key Default Extra
trx_id varchar(18) NO NULL
trx_state varchar(13) NO NULL
trx_started datetime NO NULL
trx_requested_lock_id varchar(81) YES NULL
trx_wait_started datetime YES NULL
trx_weight bigint(21) unsigned NO NULL
trx_mysql_thread_id bigint(21) unsigned NO NULL
trx_query varchar(1024) YES NULL
trx_operation_state varchar(64) YES NULL
trx_tables_in_use bigint(21) unsigned NO NULL
trx_tables_locked bigint(21) unsigned NO NULL
trx_lock_structs bigint(21) unsigned NO NULL
trx_lock_memory_bytes bigint(21) unsigned NO NULL
trx_rows_locked bigint(21) unsigned NO NULL
trx_rows_modified bigint(21) unsigned NO NULL
trx_concurrency_tickets bigint(21) unsigned NO NULL
trx_isolation_level varchar(16) NO NULL
trx_unique_checks int(1) NO NULL
trx_foreign_key_checks int(1) NO NULL
trx_last_foreign_key_error varchar(256) YES NULL
trx_is_read_only int(1) NO NULL
trx_autocommit_non_locking int(1) NO NULL
CREATE TABLE t1 (
c01 INT,
c02 INT,
PRIMARY KEY (c01)
) ENGINE=INNODB STATS_AUTO_RECALC=0;
INSERT INTO t1 VALUES
(1,2),(2,4),(3,6),(4,8);
CREATE TABLE t2 (
c01 INT,
c02 INT,
PRIMARY KEY (c01),
FOREIGN KEY fk1 (c02) REFERENCES t1 (c01)
) ENGINE=INNODB STATS_AUTO_RECALC=0;
INSERT INTO t2 VALUES
(1,1),(2,2),(3,3);
connect con_trx,localhost,root,,;
connect con_verify_innodb_trx,localhost,root,,;
connection con_trx;
SET autocommit=0;
INSERT INTO t1 VALUES (5,10);
SELECT * FROM t1 FOR UPDATE;
c01 c02
1 2
2 4
3 6
4 8
5 10
connection con_verify_innodb_trx;
SELECT trx_state, trx_weight, trx_tables_in_use, trx_tables_locked,
trx_rows_locked, trx_rows_modified, trx_concurrency_tickets,
trx_isolation_level, trx_unique_checks, trx_foreign_key_checks
FROM INFORMATION_SCHEMA.INNODB_TRX;
trx_state trx_weight trx_tables_in_use trx_tables_locked trx_rows_locked trx_rows_modified trx_concurrency_tickets trx_isolation_level trx_unique_checks trx_foreign_key_checks
RUNNING 3 0 1 6 1 0 REPEATABLE READ 1 1
connection con_trx;
ROLLBACK;
SET FOREIGN_KEY_CHECKS = 0;
SET UNIQUE_CHECKS = 0;
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
BEGIN;
INSERT INTO t1 VALUES (6,12);
connection con_verify_innodb_trx;
SELECT trx_isolation_level, trx_unique_checks, trx_foreign_key_checks
FROM INFORMATION_SCHEMA.INNODB_TRX;
trx_isolation_level trx_unique_checks trx_foreign_key_checks
SERIALIZABLE 0 0
connection con_trx;
ROLLBACK;
SET FOREIGN_KEY_CHECKS = 1;
SET UNIQUE_CHECKS = 1;
BEGIN;
INSERT INTO t2 VALUES (4,10);
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `fk1` FOREIGN KEY (`c02`) REFERENCES `t1` (`c01`))
disconnect con_trx;
connection con_verify_innodb_trx;
SELECT trx_state, trx_isolation_level, trx_last_foreign_key_error
FROM INFORMATION_SCHEMA.INNODB_TRX;
trx_state trx_isolation_level trx_last_foreign_key_error
RUNNING REPEATABLE READ `test`.`t2`, CONSTRAINT `fk1` FOREIGN KEY (`c02`) REFERENCES `t1` (`c01`)
disconnect con_verify_innodb_trx;
connection default;
DROP TABLE t2;
DROP TABLE t1;
SET GLOBAL innodb_lock_wait_timeout=@save_timeout;

View file

@ -1,2 +1,3 @@
FOUND 1 /\[Warning\] InnoDB: innodb_open_files 1000000 should not be greater than the open_files_limit [0-9]+/ in mysqld.1.err
CREATE TABLE t1 ENGINE=InnoDB AS SELECT * FROM mysql.help_topic;
DROP TABLE t1;

View file

@ -0,0 +1,44 @@
CREATE TABLE autorecalc (a INT, PRIMARY KEY (a)) ENGINE=INNODB;
SELECT n_rows, clustered_index_size FROM mysql.innodb_table_stats WHERE table_name = 'autorecalc';
n_rows 0
clustered_index_size 1
SELECT index_name, stat_name, stat_value FROM mysql.innodb_index_stats WHERE table_name = 'autorecalc';
index_name PRIMARY
stat_name n_diff_pfx01
stat_value 0
index_name PRIMARY
stat_name n_leaf_pages
stat_value 1
index_name PRIMARY
stat_name size
stat_value 1
INSERT INTO autorecalc VALUES (1);
INSERT INTO autorecalc VALUES (2);
SELECT n_rows, clustered_index_size FROM mysql.innodb_table_stats WHERE table_name = 'autorecalc';
n_rows 2
clustered_index_size 1
SELECT index_name, stat_name, stat_value FROM mysql.innodb_index_stats WHERE table_name = 'autorecalc';
index_name PRIMARY
stat_name n_diff_pfx01
stat_value 2
index_name PRIMARY
stat_name n_leaf_pages
stat_value 1
index_name PRIMARY
stat_name size
stat_value 1
DELETE FROM autorecalc;
SELECT n_rows, clustered_index_size FROM mysql.innodb_table_stats WHERE table_name = 'autorecalc';
n_rows 0
clustered_index_size 1
SELECT index_name, stat_name, stat_value FROM mysql.innodb_index_stats WHERE table_name = 'autorecalc';
index_name PRIMARY
stat_name n_diff_pfx01
stat_value 0
index_name PRIMARY
stat_name n_leaf_pages
stat_value 1
index_name PRIMARY
stat_name size
stat_value 1
DROP TABLE autorecalc;

View file

@ -0,0 +1,34 @@
CREATE TABLE arddl (a INT, b INT, PRIMARY KEY (a)) ENGINE=INNODB;
INSERT INTO arddl VALUES (1, 10);
INSERT INTO arddl VALUES (2, 10);
ALTER TABLE arddl ADD INDEX (b);
SELECT n_rows FROM mysql.innodb_table_stats WHERE table_name = 'arddl' ORDER BY 1;
n_rows 2
SELECT index_name, stat_name, stat_value FROM mysql.innodb_index_stats WHERE table_name = 'arddl' AND index_name = 'PRIMARY' ORDER BY 1, 2, 3;
index_name PRIMARY
stat_name n_diff_pfx01
stat_value 2
index_name PRIMARY
stat_name n_leaf_pages
stat_value 1
index_name PRIMARY
stat_name size
stat_value 1
DROP TABLE arddl;
CREATE TABLE arddl (a INT, b INT, PRIMARY KEY (a), KEY (b)) ENGINE=INNODB;
INSERT INTO arddl VALUES (3, 10);
INSERT INTO arddl VALUES (4, 10);
ALTER TABLE arddl DROP INDEX b;
SELECT n_rows FROM mysql.innodb_table_stats WHERE table_name = 'arddl' ORDER BY 1;
n_rows 2
SELECT index_name, stat_name, stat_value FROM mysql.innodb_index_stats WHERE table_name = 'arddl' AND index_name = 'PRIMARY' ORDER BY 1, 2, 3;
index_name PRIMARY
stat_name n_diff_pfx01
stat_value 2
index_name PRIMARY
stat_name n_leaf_pages
stat_value 1
index_name PRIMARY
stat_name size
stat_value 1
DROP TABLE arddl;

View file

@ -0,0 +1,202 @@
SELECT table_name, n_rows FROM mysql.innodb_table_stats WHERE table_name LIKE 'ar_%' ORDER BY table_name;
table_name n_rows
ar_1001 0
ar_1002 0
ar_1003 0
ar_1004 0
ar_1005 0
ar_1006 0
ar_1007 0
ar_1008 0
ar_1009 0
ar_1010 0
ar_1011 0
ar_1012 0
ar_1013 0
ar_1014 0
ar_1015 0
ar_1016 0
ar_1017 0
ar_1018 0
ar_1019 0
ar_1020 0
ar_1021 0
ar_1022 0
ar_1023 0
ar_1024 0
ar_1025 0
ar_1026 0
ar_1027 0
ar_1028 0
ar_1029 0
ar_1030 0
ar_1031 0
ar_1032 0
ar_1033 0
ar_1034 0
ar_1035 0
ar_1036 0
ar_1037 0
ar_1038 0
ar_1039 0
ar_1040 0
ar_1041 0
ar_1042 0
ar_1043 0
ar_1044 0
ar_1045 0
ar_1046 0
ar_1047 0
ar_1048 0
ar_1049 0
ar_1050 0
ar_1051 0
ar_1052 0
ar_1053 0
ar_1054 0
ar_1055 0
ar_1056 0
ar_1057 0
ar_1058 0
ar_1059 0
ar_1060 0
ar_1061 0
ar_1062 0
ar_1063 0
ar_1064 0
ar_1065 0
ar_1066 0
ar_1067 0
ar_1068 0
ar_1069 0
ar_1070 0
ar_1071 0
ar_1072 0
ar_1073 0
ar_1074 0
ar_1075 0
ar_1076 0
ar_1077 0
ar_1078 0
ar_1079 0
ar_1080 0
ar_1081 0
ar_1082 0
ar_1083 0
ar_1084 0
ar_1085 0
ar_1086 0
ar_1087 0
ar_1088 0
ar_1089 0
ar_1090 0
ar_1091 0
ar_1092 0
ar_1093 0
ar_1094 0
ar_1095 0
ar_1096 0
ar_1097 0
ar_1098 0
ar_1099 0
ar_1100 0
ar_1101 0
ar_1102 0
ar_1103 0
ar_1104 0
ar_1105 0
ar_1106 0
ar_1107 0
ar_1108 0
ar_1109 0
ar_1110 0
ar_1111 0
ar_1112 0
ar_1113 0
ar_1114 0
ar_1115 0
ar_1116 0
ar_1117 0
ar_1118 0
ar_1119 0
ar_1120 0
ar_1121 0
ar_1122 0
ar_1123 0
ar_1124 0
ar_1125 0
ar_1126 0
ar_1127 0
ar_1128 0
ar_1129 0
ar_1130 0
ar_1131 0
ar_1132 0
ar_1133 0
ar_1134 0
ar_1135 0
ar_1136 0
ar_1137 0
ar_1138 0
ar_1139 0
ar_1140 0
ar_1141 0
ar_1142 0
ar_1143 0
ar_1144 0
ar_1145 0
ar_1146 0
ar_1147 0
ar_1148 0
ar_1149 0
ar_1150 0
ar_1151 0
ar_1152 0
ar_1153 0
ar_1154 0
ar_1155 0
ar_1156 0
ar_1157 0
ar_1158 0
ar_1159 0
ar_1160 0
ar_1161 0
ar_1162 0
ar_1163 0
ar_1164 0
ar_1165 0
ar_1166 0
ar_1167 0
ar_1168 0
ar_1169 0
ar_1170 0
ar_1171 0
ar_1172 0
ar_1173 0
ar_1174 0
ar_1175 0
ar_1176 0
ar_1177 0
ar_1178 0
ar_1179 0
ar_1180 0
ar_1181 0
ar_1182 0
ar_1183 0
ar_1184 0
ar_1185 0
ar_1186 0
ar_1187 0
ar_1188 0
ar_1189 0
ar_1190 0
ar_1191 0
ar_1192 0
ar_1193 0
ar_1194 0
ar_1195 0
ar_1196 0
ar_1197 0
ar_1198 0
ar_1199 0
ar_1200 0

View file

@ -0,0 +1,57 @@
Test with default setting
CREATE TABLE t (a INT, PRIMARY KEY (a)) ENGINE=INNODB;
SELECT COUNT(*) FROM mysql.innodb_table_stats WHERE table_name = 't';
COUNT(*) 1
SELECT COUNT(*) FROM mysql.innodb_index_stats WHERE table_name = 't';
COUNT(*) 3
FLUSH TABLE t;
DELETE FROM mysql.innodb_index_stats WHERE table_name = 't';
DELETE FROM mysql.innodb_table_stats WHERE table_name = 't';
SELECT COUNT(*) FROM mysql.innodb_table_stats WHERE table_name = 't';
COUNT(*) 0
SELECT COUNT(*) FROM mysql.innodb_index_stats WHERE table_name = 't';
COUNT(*) 0
SELECT * FROM t;
SELECT COUNT(*) FROM mysql.innodb_table_stats WHERE table_name = 't';
COUNT(*) 1
SELECT COUNT(*) FROM mysql.innodb_index_stats WHERE table_name = 't';
COUNT(*) 3
DROP TABLE t;
Test with explicit enable
CREATE TABLE t (a INT, PRIMARY KEY (a)) ENGINE=INNODB STATS_AUTO_RECALC=1;
SELECT COUNT(*) FROM mysql.innodb_table_stats WHERE table_name = 't';
COUNT(*) 1
SELECT COUNT(*) FROM mysql.innodb_index_stats WHERE table_name = 't';
COUNT(*) 3
FLUSH TABLE t;
DELETE FROM mysql.innodb_index_stats WHERE table_name = 't';
DELETE FROM mysql.innodb_table_stats WHERE table_name = 't';
SELECT COUNT(*) FROM mysql.innodb_table_stats WHERE table_name = 't';
COUNT(*) 0
SELECT COUNT(*) FROM mysql.innodb_index_stats WHERE table_name = 't';
COUNT(*) 0
SELECT * FROM t;
SELECT COUNT(*) FROM mysql.innodb_table_stats WHERE table_name = 't';
COUNT(*) 1
SELECT COUNT(*) FROM mysql.innodb_index_stats WHERE table_name = 't';
COUNT(*) 3
DROP TABLE t;
Test with explicit disable
CREATE TABLE t (a INT, PRIMARY KEY (a)) ENGINE=INNODB STATS_AUTO_RECALC=0;
SELECT COUNT(*) FROM mysql.innodb_table_stats WHERE table_name = 't';
COUNT(*) 1
SELECT COUNT(*) FROM mysql.innodb_index_stats WHERE table_name = 't';
COUNT(*) 3
FLUSH TABLE t;
DELETE FROM mysql.innodb_index_stats WHERE table_name = 't';
DELETE FROM mysql.innodb_table_stats WHERE table_name = 't';
SELECT COUNT(*) FROM mysql.innodb_table_stats WHERE table_name = 't';
COUNT(*) 0
SELECT COUNT(*) FROM mysql.innodb_index_stats WHERE table_name = 't';
COUNT(*) 0
SELECT * FROM t;
SELECT COUNT(*) FROM mysql.innodb_table_stats WHERE table_name = 't';
COUNT(*) 0
SELECT COUNT(*) FROM mysql.innodb_index_stats WHERE table_name = 't';
COUNT(*) 0
DROP TABLE t;

View file

@ -0,0 +1,10 @@
CREATE TABLE bug18384390 (
id INT AUTO_INCREMENT PRIMARY KEY,
txt VARCHAR(10000)
) ENGINE=INNODB STATS_PERSISTENT=1 STATS_AUTO_RECALC=0;
INSERT INTO bug18384390 (txt) SELECT REPEAT('0', 10000) FROM seq_1_to_1024;
set use_stat_tables=never;
ANALYZE TABLE bug18384390;
Table Op Msg_type Msg_text
test.bug18384390 analyze status OK
DROP TABLE bug18384390;

View file

@ -0,0 +1,34 @@
@@ -18,7 +18,7 @@
test.test_ps_flag analyze status OK
SELECT COUNT(*) AS cnt_after FROM mysql.innodb_table_stats WHERE table_name = 'test_ps_flag';
cnt_after
-1
+0
DROP TABLE test_ps_flag;
CREATE TABLE test_ps_flag (a INT) ENGINE=INNODB STATS_PERSISTENT=default;
SHOW CREATE TABLE test_ps_flag;
@@ -37,7 +37,7 @@
test.test_ps_flag analyze status OK
SELECT COUNT(*) AS cnt_after FROM mysql.innodb_table_stats WHERE table_name = 'test_ps_flag';
cnt_after
-1
+0
DROP TABLE test_ps_flag;
=====
=== Test ANALYZE behavior after creation with explicit PS=OFF
@@ -142,7 +142,7 @@
test.test_ps_flag analyze status OK
SELECT COUNT(*) AS cnt_after FROM mysql.innodb_table_stats WHERE table_name = 'test_ps_flag';
cnt_after
-1
+0
DROP TABLE test_ps_flag;
=====
=== Test ANALYZE behavior after creation with explicit PS=ON,
@@ -203,5 +203,5 @@
test.test_ps_flag analyze status OK
SELECT COUNT(*) AS cnt_after FROM mysql.innodb_table_stats WHERE table_name = 'test_ps_flag';
cnt_after
-1
+0
DROP TABLE test_ps_flag;

View file

@ -0,0 +1,207 @@
=====
=== Test ANALYZE behavior after default creation
=====
CREATE TABLE test_ps_flag (a INT) ENGINE=INNODB;
SHOW CREATE TABLE test_ps_flag;
Table Create Table
test_ps_flag CREATE TABLE `test_ps_flag` (
`a` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
DELETE FROM mysql.innodb_index_stats WHERE table_name = 'test_ps_flag';
DELETE FROM mysql.innodb_table_stats WHERE table_name = 'test_ps_flag';
SELECT COUNT(*) AS cnt_before FROM mysql.innodb_table_stats WHERE table_name = 'test_ps_flag';
cnt_before
0
SET STATEMENT use_stat_tables=never FOR
ANALYZE TABLE test_ps_flag;
Table Op Msg_type Msg_text
test.test_ps_flag analyze status OK
SELECT COUNT(*) AS cnt_after FROM mysql.innodb_table_stats WHERE table_name = 'test_ps_flag';
cnt_after
1
DROP TABLE test_ps_flag;
CREATE TABLE test_ps_flag (a INT) ENGINE=INNODB STATS_PERSISTENT=default;
SHOW CREATE TABLE test_ps_flag;
Table Create Table
test_ps_flag CREATE TABLE `test_ps_flag` (
`a` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
DELETE FROM mysql.innodb_index_stats WHERE table_name = 'test_ps_flag';
DELETE FROM mysql.innodb_table_stats WHERE table_name = 'test_ps_flag';
SELECT COUNT(*) AS cnt_before FROM mysql.innodb_table_stats WHERE table_name = 'test_ps_flag';
cnt_before
0
SET STATEMENT use_stat_tables=never FOR
ANALYZE TABLE test_ps_flag;
Table Op Msg_type Msg_text
test.test_ps_flag analyze status OK
SELECT COUNT(*) AS cnt_after FROM mysql.innodb_table_stats WHERE table_name = 'test_ps_flag';
cnt_after
1
DROP TABLE test_ps_flag;
=====
=== Test ANALYZE behavior after creation with explicit PS=OFF
=====
CREATE TABLE test_ps_flag (a INT) ENGINE=INNODB STATS_PERSISTENT=0;
SHOW CREATE TABLE test_ps_flag;
Table Create Table
test_ps_flag CREATE TABLE `test_ps_flag` (
`a` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci STATS_PERSISTENT=0
DELETE FROM mysql.innodb_index_stats WHERE table_name = 'test_ps_flag';
DELETE FROM mysql.innodb_table_stats WHERE table_name = 'test_ps_flag';
SELECT COUNT(*) AS cnt_before FROM mysql.innodb_table_stats WHERE table_name = 'test_ps_flag';
cnt_before
0
SET STATEMENT use_stat_tables=never FOR
ANALYZE TABLE test_ps_flag;
Table Op Msg_type Msg_text
test.test_ps_flag analyze status OK
SELECT COUNT(*) AS cnt_after FROM mysql.innodb_table_stats WHERE table_name = 'test_ps_flag';
cnt_after
0
DROP TABLE test_ps_flag;
=====
=== Test ANALYZE behavior after creation with explicit PS=ON
=====
CREATE TABLE test_ps_flag (a INT) ENGINE=INNODB STATS_PERSISTENT=1;
SHOW CREATE TABLE test_ps_flag;
Table Create Table
test_ps_flag CREATE TABLE `test_ps_flag` (
`a` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci STATS_PERSISTENT=1
DELETE FROM mysql.innodb_index_stats WHERE table_name = 'test_ps_flag';
DELETE FROM mysql.innodb_table_stats WHERE table_name = 'test_ps_flag';
SELECT COUNT(*) AS cnt_before FROM mysql.innodb_table_stats WHERE table_name = 'test_ps_flag';
cnt_before
0
SET STATEMENT use_stat_tables=never FOR
ANALYZE TABLE test_ps_flag;
Table Op Msg_type Msg_text
test.test_ps_flag analyze status OK
SELECT COUNT(*) AS cnt_after FROM mysql.innodb_table_stats WHERE table_name = 'test_ps_flag';
cnt_after
1
DROP TABLE test_ps_flag;
=====
=== Test ANALYZE behavior after creation with explicit PS=OFF,
=== then ALTER to ON, then ALTER to OFF, then ALTER to default
=====
CREATE TABLE test_ps_flag (a INT) ENGINE=INNODB STATS_PERSISTENT=0;
ALTER TABLE test_ps_flag STATS_PERSISTENT=1;
# restart
SHOW CREATE TABLE test_ps_flag;
Table Create Table
test_ps_flag CREATE TABLE `test_ps_flag` (
`a` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci STATS_PERSISTENT=1
DELETE FROM mysql.innodb_index_stats WHERE table_name = 'test_ps_flag';
DELETE FROM mysql.innodb_table_stats WHERE table_name = 'test_ps_flag';
SELECT COUNT(*) AS cnt_before FROM mysql.innodb_table_stats WHERE table_name = 'test_ps_flag';
cnt_before
0
SET STATEMENT use_stat_tables=never FOR
ANALYZE TABLE test_ps_flag;
Table Op Msg_type Msg_text
test.test_ps_flag analyze status OK
SELECT COUNT(*) AS cnt_after FROM mysql.innodb_table_stats WHERE table_name = 'test_ps_flag';
cnt_after
1
ALTER TABLE test_ps_flag STATS_PERSISTENT=0;
SHOW CREATE TABLE test_ps_flag;
Table Create Table
test_ps_flag CREATE TABLE `test_ps_flag` (
`a` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci STATS_PERSISTENT=0
DELETE FROM mysql.innodb_index_stats WHERE table_name = 'test_ps_flag';
DELETE FROM mysql.innodb_table_stats WHERE table_name = 'test_ps_flag';
SELECT COUNT(*) AS cnt_before FROM mysql.innodb_table_stats WHERE table_name = 'test_ps_flag';
cnt_before
0
SET STATEMENT use_stat_tables=never FOR
ANALYZE TABLE test_ps_flag;
Table Op Msg_type Msg_text
test.test_ps_flag analyze status OK
SELECT COUNT(*) AS cnt_after FROM mysql.innodb_table_stats WHERE table_name = 'test_ps_flag';
cnt_after
0
ALTER TABLE test_ps_flag STATS_PERSISTENT=default;
SHOW CREATE TABLE test_ps_flag;
Table Create Table
test_ps_flag CREATE TABLE `test_ps_flag` (
`a` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
DELETE FROM mysql.innodb_index_stats WHERE table_name = 'test_ps_flag';
DELETE FROM mysql.innodb_table_stats WHERE table_name = 'test_ps_flag';
SELECT COUNT(*) AS cnt_before FROM mysql.innodb_table_stats WHERE table_name = 'test_ps_flag';
cnt_before
0
SET STATEMENT use_stat_tables=never FOR
ANALYZE TABLE test_ps_flag;
Table Op Msg_type Msg_text
test.test_ps_flag analyze status OK
SELECT COUNT(*) AS cnt_after FROM mysql.innodb_table_stats WHERE table_name = 'test_ps_flag';
cnt_after
1
DROP TABLE test_ps_flag;
=====
=== Test ANALYZE behavior after creation with explicit PS=ON,
=== then ALTER to OFF, then ALTER to ON, then ALTER to default
=====
CREATE TABLE test_ps_flag (a INT) ENGINE=INNODB STATS_PERSISTENT=1;
ALTER TABLE test_ps_flag STATS_PERSISTENT=0;
# restart
SHOW CREATE TABLE test_ps_flag;
Table Create Table
test_ps_flag CREATE TABLE `test_ps_flag` (
`a` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci STATS_PERSISTENT=0
DELETE FROM mysql.innodb_index_stats WHERE table_name = 'test_ps_flag';
DELETE FROM mysql.innodb_table_stats WHERE table_name = 'test_ps_flag';
SELECT COUNT(*) AS cnt_before FROM mysql.innodb_table_stats WHERE table_name = 'test_ps_flag';
cnt_before
0
SET STATEMENT use_stat_tables=never FOR
ANALYZE TABLE test_ps_flag;
Table Op Msg_type Msg_text
test.test_ps_flag analyze status OK
SELECT COUNT(*) AS cnt_after FROM mysql.innodb_table_stats WHERE table_name = 'test_ps_flag';
cnt_after
0
ALTER TABLE test_ps_flag STATS_PERSISTENT=1;
SHOW CREATE TABLE test_ps_flag;
Table Create Table
test_ps_flag CREATE TABLE `test_ps_flag` (
`a` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci STATS_PERSISTENT=1
DELETE FROM mysql.innodb_index_stats WHERE table_name = 'test_ps_flag';
DELETE FROM mysql.innodb_table_stats WHERE table_name = 'test_ps_flag';
SELECT COUNT(*) AS cnt_before FROM mysql.innodb_table_stats WHERE table_name = 'test_ps_flag';
cnt_before
0
SET STATEMENT use_stat_tables=never FOR
ANALYZE TABLE test_ps_flag;
Table Op Msg_type Msg_text
test.test_ps_flag analyze status OK
SELECT COUNT(*) AS cnt_after FROM mysql.innodb_table_stats WHERE table_name = 'test_ps_flag';
cnt_after
1
ALTER TABLE test_ps_flag STATS_PERSISTENT=default;
SHOW CREATE TABLE test_ps_flag;
Table Create Table
test_ps_flag CREATE TABLE `test_ps_flag` (
`a` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
DELETE FROM mysql.innodb_index_stats WHERE table_name = 'test_ps_flag';
DELETE FROM mysql.innodb_table_stats WHERE table_name = 'test_ps_flag';
SELECT COUNT(*) AS cnt_before FROM mysql.innodb_table_stats WHERE table_name = 'test_ps_flag';
cnt_before
0
SET STATEMENT use_stat_tables=never FOR
ANALYZE TABLE test_ps_flag;
Table Op Msg_type Msg_text
test.test_ps_flag analyze status OK
SELECT COUNT(*) AS cnt_after FROM mysql.innodb_table_stats WHERE table_name = 'test_ps_flag';
cnt_after
1
DROP TABLE test_ps_flag;

View file

@ -10,9 +10,9 @@ CREATE TABLE t1 (id SERIAL, val INT UNSIGNED NOT NULL, KEY(val))
ENGINE=INNODB STATS_PERSISTENT=1,STATS_AUTO_RECALC=1;
CREATE TABLE t2 LIKE t1;
INSERT INTO t1 (val) SELECT 4 FROM seq_1_to_16;
SET STATEMENT use_stat_tables=never FOR
ANALYZE TABLE t1;
Table Op Msg_type Msg_text
test.t1 analyze status Engine-independent statistics collected
test.t1 analyze status OK
connect con1, localhost, root,,;
START TRANSACTION;
@ -91,7 +91,7 @@ COUNT(*)
# ha_innobase::records_in_range() would count the delete-marked records.
EXPLAIN SELECT * FROM t1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index NULL val 4 NULL 16 Using index
1 SIMPLE t1 index NULL val 4 NULL 1 Using index
ROLLBACK;
EXPLAIN SELECT * FROM t1;
id select_type table type possible_keys key key_len ref rows Extra
@ -106,3 +106,25 @@ SET GLOBAL innodb_stats_include_delete_marked = @saved_include_delete_marked;
SET GLOBAL innodb_stats_traditional = @saved_traditional;
SET GLOBAL innodb_stats_modified_counter = @saved_modified_counter;
SET GLOBAL innodb_purge_rseg_truncate_frequency = @saved_frequency;
CREATE TABLE bug12429573 (i INTEGER PRIMARY KEY, j INTEGER, KEY(j))
ENGINE=INNODB STATS_PERSISTENT=1;
SET STATEMENT use_stat_tables=never FOR
ANALYZE TABLE bug12429573;
Table Op Msg_type Msg_text
test.bug12429573 analyze status OK
SELECT last_update INTO @last FROM mysql.innodb_table_stats
WHERE table_name = 'bug12429573';
SELECT * FROM mysql.innodb_index_stats
WHERE table_name = 'bug12429573' AND last_update!=@last;
database_name table_name index_name last_update stat_name stat_value sample_size stat_description
SET STATEMENT use_stat_tables=never FOR
ANALYZE TABLE bug12429573;
Table Op Msg_type Msg_text
test.bug12429573 analyze status OK
SELECT * FROM mysql.innodb_table_stats
WHERE table_name = 'bug12429573' AND last_update=@last;
database_name table_name last_update n_rows clustered_index_size sum_of_other_index_sizes
SELECT * FROM mysql.innodb_index_stats
WHERE table_name = 'bug12429573' AND last_update=@last;
database_name table_name index_name last_update stat_name stat_value sample_size stat_description
DROP TABLE bug12429573;

View file

@ -0,0 +1,29 @@
SET GLOBAL innodb_stats_persistent_sample_pages=17;
CREATE TABLE test_ps_sample_pages_used (
a VARCHAR(512), PRIMARY KEY (a)
) ENGINE=INNODB STATS_SAMPLE_PAGES=default;
BEGIN;
COMMIT;
ANALYZE TABLE test_ps_sample_pages_used;
Table Op Msg_type Msg_text
test.test_ps_sample_pages_used analyze status Engine-independent statistics collected
test.test_ps_sample_pages_used analyze status OK
SELECT stat_name, stat_value FROM mysql.innodb_index_stats
WHERE table_name='test_ps_sample_pages_used' AND stat_name='n_leaf_pages';
stat_name stat_value
n_leaf_pages 37
SELECT sample_size FROM mysql.innodb_index_stats
WHERE table_name='test_ps_sample_pages_used' AND stat_name='n_diff_pfx01';
sample_size
17
ALTER TABLE test_ps_sample_pages_used STATS_SAMPLE_PAGES=14;
ANALYZE TABLE test_ps_sample_pages_used;
Table Op Msg_type Msg_text
test.test_ps_sample_pages_used analyze status Engine-independent statistics collected
test.test_ps_sample_pages_used analyze status OK
SELECT sample_size FROM mysql.innodb_index_stats
WHERE table_name='test_ps_sample_pages_used' AND stat_name='n_diff_pfx01';
sample_size
14
DROP TABLE test_ps_sample_pages_used;
SET GLOBAL innodb_stats_persistent_sample_pages=default;

View file

@ -0,0 +1,82 @@
CREATE TABLE test_ps_auto_recalc (a INT, PRIMARY KEY (a)) ENGINE=INNODB;
SHOW CREATE TABLE test_ps_auto_recalc;
Table test_ps_auto_recalc
Create Table CREATE TABLE `test_ps_auto_recalc` (
`a` int(11) NOT NULL,
PRIMARY KEY (`a`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
SELECT create_options FROM information_schema.tables
WHERE table_name='test_ps_auto_recalc';
create_options
ALTER TABLE test_ps_auto_recalc STATS_AUTO_RECALC=1;
# restart
SHOW CREATE TABLE test_ps_auto_recalc;
Table test_ps_auto_recalc
Create Table CREATE TABLE `test_ps_auto_recalc` (
`a` int(11) NOT NULL,
PRIMARY KEY (`a`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci STATS_AUTO_RECALC=1
SELECT create_options FROM information_schema.tables
WHERE table_name='test_ps_auto_recalc';
create_options stats_auto_recalc=1
DROP TABLE test_ps_auto_recalc;
CREATE TABLE test_ps_auto_recalc (a INT, PRIMARY KEY (a)) ENGINE=INNODB
STATS_AUTO_RECALC=default;
SHOW CREATE TABLE test_ps_auto_recalc;
Table test_ps_auto_recalc
Create Table CREATE TABLE `test_ps_auto_recalc` (
`a` int(11) NOT NULL,
PRIMARY KEY (`a`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
SELECT create_options FROM information_schema.tables
WHERE table_name='test_ps_auto_recalc';
create_options
DROP TABLE test_ps_auto_recalc;
CREATE TABLE test_ps_auto_recalc (a INT, PRIMARY KEY (a)) ENGINE=INNODB
STATS_AUTO_RECALC=0;
# restart
SHOW CREATE TABLE test_ps_auto_recalc;
Table test_ps_auto_recalc
Create Table CREATE TABLE `test_ps_auto_recalc` (
`a` int(11) NOT NULL,
PRIMARY KEY (`a`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci STATS_AUTO_RECALC=0
SELECT create_options FROM information_schema.tables
WHERE table_name='test_ps_auto_recalc';
create_options stats_auto_recalc=0
ALTER TABLE test_ps_auto_recalc STATS_AUTO_RECALC=1;
# restart
SHOW CREATE TABLE test_ps_auto_recalc;
Table test_ps_auto_recalc
Create Table CREATE TABLE `test_ps_auto_recalc` (
`a` int(11) NOT NULL,
PRIMARY KEY (`a`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci STATS_AUTO_RECALC=1
SELECT create_options FROM information_schema.tables
WHERE table_name='test_ps_auto_recalc';
create_options stats_auto_recalc=1
DROP TABLE test_ps_auto_recalc;
CREATE TABLE test_ps_auto_recalc (a INT, PRIMARY KEY (a)) ENGINE=INNODB
STATS_AUTO_RECALC=1;
# restart
SHOW CREATE TABLE test_ps_auto_recalc;
Table test_ps_auto_recalc
Create Table CREATE TABLE `test_ps_auto_recalc` (
`a` int(11) NOT NULL,
PRIMARY KEY (`a`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci STATS_AUTO_RECALC=1
SELECT create_options FROM information_schema.tables
WHERE table_name='test_ps_auto_recalc';
create_options stats_auto_recalc=1
ALTER TABLE test_ps_auto_recalc STATS_AUTO_RECALC=0;
# restart
SHOW CREATE TABLE test_ps_auto_recalc;
Table test_ps_auto_recalc
Create Table CREATE TABLE `test_ps_auto_recalc` (
`a` int(11) NOT NULL,
PRIMARY KEY (`a`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci STATS_AUTO_RECALC=0
SELECT create_options FROM information_schema.tables
WHERE table_name='test_ps_auto_recalc';
create_options stats_auto_recalc=0
DROP TABLE test_ps_auto_recalc;

View file

@ -0,0 +1,95 @@
CREATE TABLE test_ps_sample_pages (a INT, PRIMARY KEY (a)) ENGINE=INNODB;
SHOW CREATE TABLE test_ps_sample_pages;
Table test_ps_sample_pages
Create Table CREATE TABLE `test_ps_sample_pages` (
`a` int(11) NOT NULL,
PRIMARY KEY (`a`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
SELECT create_options FROM information_schema.tables
WHERE table_name='test_ps_sample_pages';
create_options
ALTER TABLE test_ps_sample_pages STATS_SAMPLE_PAGES=12345;
# restart
SHOW CREATE TABLE test_ps_sample_pages;
Table test_ps_sample_pages
Create Table CREATE TABLE `test_ps_sample_pages` (
`a` int(11) NOT NULL,
PRIMARY KEY (`a`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci STATS_SAMPLE_PAGES=12345
SELECT create_options FROM information_schema.tables
WHERE table_name='test_ps_sample_pages';
create_options stats_sample_pages=12345
DROP TABLE test_ps_sample_pages;
CREATE TABLE test_ps_sample_pages (a INT, PRIMARY KEY (a)) ENGINE=INNODB
STATS_SAMPLE_PAGES=default;
SHOW CREATE TABLE test_ps_sample_pages;
Table test_ps_sample_pages
Create Table CREATE TABLE `test_ps_sample_pages` (
`a` int(11) NOT NULL,
PRIMARY KEY (`a`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
SELECT create_options FROM information_schema.tables
WHERE table_name='test_ps_sample_pages';
create_options
DROP TABLE test_ps_sample_pages;
CREATE TABLE test_ps_sample_pages (a INT, PRIMARY KEY (a)) ENGINE=INNODB
STATS_SAMPLE_PAGES=-5;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '-5' at line 2
CREATE TABLE test_ps_sample_pages (a INT, PRIMARY KEY (a)) ENGINE=INNODB
STATS_SAMPLE_PAGES=0;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '0' at line 2
CREATE TABLE test_ps_sample_pages (a INT, PRIMARY KEY (a)) ENGINE=INNODB
STATS_SAMPLE_PAGES=67000;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '67000' at line 2
CREATE TABLE test_ps_sample_pages (a INT, PRIMARY KEY (a)) ENGINE=INNODB
STATS_SAMPLE_PAGES=670000;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '670000' at line 2
CREATE TABLE test_ps_sample_pages (a INT, PRIMARY KEY (a)) ENGINE=INNODB
STATS_SAMPLE_PAGES=65536;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '65536' at line 2
CREATE TABLE test_ps_sample_pages (a INT, PRIMARY KEY (a)) ENGINE=INNODB
STATS_SAMPLE_PAGES=65535;
SHOW CREATE TABLE test_ps_sample_pages;
Table test_ps_sample_pages
Create Table CREATE TABLE `test_ps_sample_pages` (
`a` int(11) NOT NULL,
PRIMARY KEY (`a`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci STATS_SAMPLE_PAGES=65535
DROP TABLE test_ps_sample_pages;
CREATE TABLE test_ps_sample_pages (a INT, PRIMARY KEY (a)) ENGINE=INNODB
STATS_SAMPLE_PAGES=1;
# restart
SHOW CREATE TABLE test_ps_sample_pages;
Table test_ps_sample_pages
Create Table CREATE TABLE `test_ps_sample_pages` (
`a` int(11) NOT NULL,
PRIMARY KEY (`a`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci STATS_SAMPLE_PAGES=1
SELECT create_options FROM information_schema.tables
WHERE table_name='test_ps_sample_pages';
create_options stats_sample_pages=1
DROP TABLE test_ps_sample_pages;
CREATE TABLE test_ps_sample_pages (a INT, PRIMARY KEY (a)) ENGINE=INNODB
STATS_SAMPLE_PAGES=5678;
# restart
SHOW CREATE TABLE test_ps_sample_pages;
Table test_ps_sample_pages
Create Table CREATE TABLE `test_ps_sample_pages` (
`a` int(11) NOT NULL,
PRIMARY KEY (`a`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci STATS_SAMPLE_PAGES=5678
SELECT create_options FROM information_schema.tables
WHERE table_name='test_ps_sample_pages';
create_options stats_sample_pages=5678
ALTER TABLE test_ps_sample_pages STATS_SAMPLE_PAGES=default;
# restart
SHOW CREATE TABLE test_ps_sample_pages;
Table test_ps_sample_pages
Create Table CREATE TABLE `test_ps_sample_pages` (
`a` int(11) NOT NULL,
PRIMARY KEY (`a`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
SELECT create_options FROM information_schema.tables
WHERE table_name='test_ps_sample_pages';
create_options
DROP TABLE test_ps_sample_pages;

View file

@ -0,0 +1,5 @@
CREATE TABLE t (c INT) ENGINE=INNODB;
SET @save_dbug = @@debug_dbug;
SET debug_dbug = '+d,test_ut_format_name';
DROP TABLE t;
SET debug_dbug = @save_dbug;

View file

@ -0,0 +1,8 @@
@@ -39,7 +39,7 @@
WHERE
table_name='records_in_range_test' AND stat_name = 'size';
index_name stat_name stat_value
-PRIMARY size 1
+PRIMARY size 5
SET @save_dbug = @@debug_dbug;
SET DEBUG_DBUG='+d,print_btr_estimate_n_rows_in_range_return_value';

View file

@ -0,0 +1,8 @@
@@ -39,7 +39,7 @@
WHERE
table_name='records_in_range_test' AND stat_name = 'size';
index_name stat_name stat_value
-PRIMARY size 1
+PRIMARY size 3
SET @save_dbug = @@debug_dbug;
SET DEBUG_DBUG='+d,print_btr_estimate_n_rows_in_range_return_value';

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,134 @@
#
# Test the limits of a file-per-table tablespace name. MySQL combines
# the database name with the table name to make a unique table name.
#
SET default_storage_engine=InnoDB;
#
# MySQL limits each database and tablename identifier to 64 characters
# of up to 3 bytes per character, corresponding to 192 bytes.
#
CREATE DATABASE `this_sixty_five_byte_name_is_too_long____________________________`;
ERROR 42000: Incorrect database name 'this_sixty_five_byte_name_is_too_long____________________________'
CREATE DATABASE `this_sixty_four_byte_name_is_not_too_long_______________________`;
USE `this_sixty_four_byte_name_is_not_too_long_______________________`;
#
# A 64 character tablename can be created in a 64 character database name
#
CREATE TABLE `this_sixty_four_byte_name_is_not_too_long_______________________`.`this_sixty_four_byte_name_is_not_too_long_______________________` (a SERIAL);
#
# A 65 character tablename is too long.
#
CREATE TABLE `test`.`this_sixty_five_byte_name_is_too_long____________________________` (a SERIAL);
ERROR 42000: Incorrect table name 'this_sixty_five_byte_name_is_too_long____________________________'
CREATE TABLE `this_sixty_four_byte_name_is_not_too_long_______________________`.`this_sixty_five_byte_name_is_too_long____________________________` (a SERIAL);
ERROR 42000: Incorrect table name 'this_sixty_five_byte_name_is_too_long____________________________'
#
# Non-non-filename-safe characters like '#' are expanded to '@0023'.
# On many file systems, such as Linux extfs, you can create a database name
# that expands to up to 255 bytes long.
# `##################################################_long` is expanded to
# (50 * 5) + 5 = 255.
#
CREATE DATABASE `##################################################_long`;;
USE `##################################################_long`;
#
# This 256-byte name is only one byte longer but fails with an error code
# from the stat operation.
# `##################################################_long_` is expanded to
# (50 * 5) + 6 = 256.
#
CREATE DATABASE `##################################################_long_`;
ERROR HY000: Can't get stat of './##################################################_long_' (Errcode: ## "File name too long")
#
# This 300-byte name which is the longest name that gets an error code
# from the stat operation.
# `###########################################################_long` is expanded to
# (59 * 5) + 5 = 300.
#
CREATE DATABASE `###########################################################_long`;
ERROR HY000: Can't get stat of './###########################################################_long' (Errcode: ## "File name too long")
#
# This 301-byte name which is only one byte longer but fails with ER_TOO_LONG_IDENT.
# `###########################################################_long_` is expanded to
# (59 * 5) + 6 = 301.
#
CREATE DATABASE `###########################################################_long_`;
ERROR 42000: Incorrect database name '###########################################################_long_'
USE test;
#
# An expanded table name is limited to 251 bytes
#
CREATE TABLE `test`.`#################################################_long_` (a SERIAL);
#
# A 252-byte tablename is too long
#
CREATE TABLE `test`.`#################################################_long___` (a SERIAL);
ERROR HY000: Can't create table `test`.`#################################################_long___` (errno: ## "File name too long")
CREATE DATABASE twenty_byte_db_name_;
USE `twenty_byte_db_name_`;
#
# A 251 byte expanded table name will fit with a longer database name
#
CREATE TABLE `twenty_byte_db_name_`.`#################################################_long_` (a SERIAL);
#
# A 252 byte expanded table name is also too long in a longer database name
#
CREATE TABLE `twenty_byte_db_name_`.`#################################################_long___` (a SERIAL);
ERROR HY000: Can't create table `twenty_byte_db_name_`.`#################################################_long___` (errno: ## "File name too long")
#
# Another limitation is a 512 byte length to an expanded path that includes
# the datadir which is './' in this test, the expanded database name,
# the directory separator '/', the expanded table name, and the file extension.
# './long_db_name.long_250_byte_table_name.frm'
# 2+ 255 +1+ 250 +1+3 = 512
#
CREATE TABLE `##################################################_long`.`#################################################_long` (a SERIAL);
CREATE TABLE `##################################################_long`.`#################################################_long_` (a SERIAL);
ERROR HY000: Long database name and identifier for object resulted in path length exceeding 512 characters. Path: './@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023_long/@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@
SHOW WARNINGS;
Level Code Message
Error 1860 Long database name and identifier for object resulted in path length exceeding 512 characters. Path: './@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023_long/@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@
#
# Show the successfully created databases and tables
#
---- list_files MYSQLD_DATADIR/test
#################################################_long_.frm
#################################################_long_.ibd
db.opt
---- list_files MYSQLD_DATADIR/this_sixty_four_byte_name_is_not_too_long_______________________
db.opt
this_sixty_four_byte_name_is_not_too_long_______________________.frm
this_sixty_four_byte_name_is_not_too_long_______________________.ibd
---- list_files MYSQLD_DATADIR/##################################################_long
#################################################_long.frm
#################################################_long.ibd
db.opt
SELECT name FROM information_schema.innodb_sys_tables WHERE name LIKE '%long%';
name
##################################################_long/#################################################_long
test/#################################################_long_
this_sixty_four_byte_name_is_not_too_long_______________________/this_sixty_four_byte_name_is_not_too_long_______________________
twenty_byte_db_name_/#################################################_long_
SELECT name FROM information_schema.innodb_sys_tablespaces WHERE name LIKE '%long%';
name
this_sixty_four_byte_name_is_not_too_long_______________________/this_sixty_four_byte_name_is_not_too_long_______________________
test/#################################################_long_
twenty_byte_db_name_/#################################################_long_
##################################################_long/#################################################_long
SELECT path FROM information_schema.innodb_sys_datafiles WHERE path LIKE '%long%';
path
./this_sixty_four_byte_name_is_not_too_long_______________________/this_sixty_four_byte_name_is_not_too_long_______________________.ibd
./test/#################################################_long_.ibd
./twenty_byte_db_name_/#################################################_long_.ibd
./##################################################_long/#################################################_long.ibd
SELECT file_name, tablespace_name FROM information_schema.files WHERE file_name LIKE '%long%';
#
# Cleanup
#
DROP TABLE `this_sixty_four_byte_name_is_not_too_long_______________________`.`this_sixty_four_byte_name_is_not_too_long_______________________`;
DROP TABLE `test`.`#################################################_long_`;
DROP TABLE `twenty_byte_db_name_`.`#################################################_long_`;
DROP TABLE `##################################################_long`.`#################################################_long`;
DROP DATABASE `this_sixty_four_byte_name_is_not_too_long_______________________`;
DROP DATABASE `##################################################_long`;
DROP DATABASE `twenty_byte_db_name_`;

View file

@ -0,0 +1,51 @@
#
# Test the limits of a file-per-table tablespace name. MySQL combines
# the database name with the table name to make a unique table name.
#
SET default_storage_engine=InnoDB;
#
# MySQL limits each database and tablename identifier to 64 characters
# of up to 3 bytes per character, corresponding to 192 bytes.
#
CREATE DATABASE `this_sixty_five_byte_name_is_too_long____________________________`;
ERROR 42000: Incorrect database name 'this_sixty_five_byte_name_is_too_long____________________________'
CREATE DATABASE `this_sixty_four_byte_name_is_not_too_long_______________________`;
USE `this_sixty_four_byte_name_is_not_too_long_______________________`;
#
# A 64 character tablename can be created in a 64 character database name
#
CREATE TABLE `this_sixty_four_byte_name_is_not_too_long_______________________`.`this_sixty_four_byte_name_is_not_too_long_______________________` (a SERIAL);
#
# A 65 character tablename is too long.
#
CREATE TABLE `test`.`this_sixty_five_byte_name_is_too_long____________________________` (a SERIAL);
ERROR 42000: Incorrect table name 'this_sixty_five_byte_name_is_too_long____________________________'
CREATE TABLE `this_sixty_four_byte_name_is_not_too_long_______________________`.`this_sixty_five_byte_name_is_too_long____________________________` (a SERIAL);
ERROR 42000: Incorrect table name 'this_sixty_five_byte_name_is_too_long____________________________'
#
# Show the successfully created database and table
#
SHOW CREATE TABLE `this_sixty_four_byte_name_is_not_too_long_______________________`.`this_sixty_four_byte_name_is_not_too_long_______________________`;
Table Create Table
this_sixty_four_byte_name_is_not_too_long_______________________ CREATE TABLE `this_sixty_four_byte_name_is_not_too_long_______________________` (
`a` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
UNIQUE KEY `a` (`a`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
---- list_files MYSQLD_DATADIR/this_sixty_four_byte_name_is_not_too_long_______________________
db.opt
this_sixty_four_byte_name_is_not_too_long_______________________.frm
this_sixty_four_byte_name_is_not_too_long_______________________.ibd
SELECT name FROM information_schema.innodb_sys_tables WHERE name LIKE '%long%';
name
this_sixty_four_byte_name_is_not_too_long_______________________/this_sixty_four_byte_name_is_not_too_long_______________________
SELECT name FROM information_schema.innodb_sys_tablespaces WHERE name LIKE '%long%';
name
this_sixty_four_byte_name_is_not_too_long_______________________/this_sixty_four_byte_name_is_not_too_long_______________________
SELECT path FROM information_schema.innodb_sys_datafiles WHERE path LIKE '%long%';
path
.\this_sixty_four_byte_name_is_not_too_long_______________________\this_sixty_four_byte_name_is_not_too_long_______________________.ibd
SELECT file_name, tablespace_name FROM information_schema.files WHERE file_name LIKE '%long%';
#
# Cleanup
#
DROP DATABASE `this_sixty_four_byte_name_is_not_too_long_______________________`;

View file

@ -0,0 +1,38 @@
--source include/have_innodb.inc
--echo #
--echo # Bug #19471516 SERVER CRASHES WHEN EXECUTING ALTER TABLE ADD
--echo # FOREIGN KEY
--echo #
CREATE TABLE `parent` (`parent_id` INT, PRIMARY KEY (`parent_id`));
CREATE TABLE `child1` (`id` INT ,`child1_fk1` INT, `child1_fk2` INT,
PRIMARY KEY (`id`));
CREATE TABLE `child2` (`id` INT, `child2_fk1` INT, `child2_fk2` INT,
PRIMARY KEY (`id`));
CREATE TABLE `child3` (`id` INT , `child3_fk1` INT, PRIMARY KEY (`id`));
ALTER TABLE `child1` ADD FOREIGN KEY (`child1_fk1`) REFERENCES `parent`
(`parent_id`);
ALTER TABLE `child1` ADD FOREIGN KEY (`child1_fk1`) REFERENCES
`parent` (`parent_id`);
ALTER TABLE `child1` ADD FOREIGN KEY (`child1_fk2`) REFERENCES `parent`
(`parent_id`);
ALTER TABLE `child2` ADD FOREIGN KEY (`child2_fk1`) REFERENCES `parent`
(`parent_id`);
ALTER TABLE `child2` ADD FOREIGN KEY (`child2_fk2`) REFERENCES `parent`
(`parent_id`);
ALTER TABLE `child3` ADD FOREIGN KEY (`child3_fk1`) REFERENCES `parent`
(`parent_id`);
ALTER TABLE `child1` ADD FOREIGN KEY (`child1_fk2`) REFERENCES
`parent` (`parent_id`);
ALTER TABLE `child2` ADD FOREIGN KEY (`child2_fk1`) REFERENCES
`parent` (`parent_id`);
ALTER TABLE `child2` ADD FOREIGN KEY (`child2_fk2`) REFERENCES
`parent` (`parent_id`);
ALTER TABLE `child3` ADD FOREIGN KEY (`child3_fk1`) REFERENCES
`parent` (`parent_id`);
drop table child3, child2, child1, parent;

View file

@ -0,0 +1,45 @@
--source include/have_innodb.inc
--source include/have_debug.inc
create table t1 (f1 int primary key) engine=innodb;
create table t2 (f1 int primary key,
constraint c1 foreign key (f1) references t1(f1)
on update cascade
on delete cascade) engine=innodb;
create table t3 (f1 int primary key,
constraint c2 foreign key (f1) references t1(f1)
on update cascade
on delete cascade) engine=innodb;
show create table t1;
show create table t2;
show create table t3;
insert into t1 values (1);
insert into t1 values (2);
insert into t1 values (3);
insert into t2 values (1);
insert into t2 values (2);
insert into t2 values (3);
insert into t3 values (1);
insert into t3 values (2);
insert into t3 values (3);
select f1 from t1;
select f1 from t2;
select f1 from t3;
set @save_dbug = @@debug_dbug;
set debug_dbug = '+d,dml_cascade_only_once';
set debug_dbug = '+d,row_upd_cascade_lock_wait_err';
update t1 set f1 = 100 where f1 = 2;
select f1 from t1;
select f1 from t2;
select f1 from t3;
set debug_dbug = @save_dbug;
drop table t2;
drop table t3;
drop table t1;

View file

@ -0,0 +1,81 @@
#
# BUG#20125349 - PERSISTANT STATS IS NOT UPDATED WHEN TTS IS IMPORTED.
#
--source include/not_embedded.inc
--source include/have_innodb.inc
--source include/not_valgrind.inc # MDEV-32725 FIXME
let MYSQLD_DATADIR =`SELECT @@datadir`;
SET @old_innodb_file_per_table = @@innodb_file_per_table;
SET GLOBAL innodb_file_per_table = 1;
SELECT @@innodb_file_per_table;
CREATE TABLE t1 (
col_1 CHAR (255),
col_2 VARCHAR (255)
) ENGINE = InnoDB;
CREATE INDEX idx1 ON t1(col_1);
CREATE INDEX idx2 ON t1(col_2);
SHOW INDEXES FROM t1;
INSERT INTO t1 VALUES ("col1_00001", "col2_00001"), ("col1_00002", "col2_00002");
SHOW INDEXES FROM t1;
ANALYZE TABLE t1;
SHOW INDEXES FROM t1;
FLUSH TABLES t1 FOR EXPORT;
perl;
do "$ENV{MTR_SUITE_DIR}/../innodb/include/innodb-util.pl";
ib_backup_tablespaces("test", "t1");
EOF
UNLOCK TABLES;
DROP TABLE t1;
CREATE TABLE t1 (
col_1 CHAR (255),
col_2 VARCHAR (255)
) ENGINE = InnoDB STATS_PERSISTENT=1;
CREATE INDEX idx1 ON t1(col_1);
CREATE INDEX idx2 ON t1(col_2);
SHOW INDEXES FROM t1;
INSERT INTO t1 VALUES ("col1_00001", "col2_00001");
SHOW INDEXES FROM t1;
SET STATEMENT use_stat_tables=never FOR
ANALYZE TABLE t1;
SHOW INDEXES FROM t1;
ALTER TABLE t1 DISCARD TABLESPACE;
perl;
do "$ENV{MTR_SUITE_DIR}/../innodb/include/innodb-util.pl";
ib_discard_tablespaces("test", "t1");
ib_restore_tablespaces("test", "t1");
EOF
ALTER TABLE t1 IMPORT TABLESPACE;
SHOW INDEXES FROM t1;
SET STATEMENT use_stat_tables=never FOR
ANALYZE TABLE t1;
SHOW INDEXES FROM t1;
DROP TABLE t1;
SET GLOBAL innodb_file_per_table = @old_innodb_file_per_table;
--remove_files_wildcard $MYSQLTEST_VARDIR/tmp t1*.ibd
--remove_files_wildcard $MYSQLTEST_VARDIR/tmp t1*.cfg

View file

@ -0,0 +1,23 @@
--source include/have_innodb.inc
--connect (stop_purge,localhost,root)
# Prevent the purge of history from acquiring a table handle.
START TRANSACTION WITH CONSISTENT SNAPSHOT;
--connection default
CREATE TABLE t1(a INT PRIMARY KEY, b VARCHAR(1024))
ENGINE=InnoDB STATS_PERSISTENT=1;
INSERT INTO t1 VALUES (1,REPEAT('b',1024));
SELECT index_length FROM information_schema.tables
WHERE table_schema = 'test' AND table_name = 't1';
ALTER TABLE t1 ADD INDEX b (b(800));
SELECT FLOOR(index_length/@@innodb_page_size) FROM information_schema.tables
WHERE table_schema = 'test' AND table_name = 't1';
ALTER TABLE t1 ADD INDEX ba (b(800),a);
SELECT FLOOR(index_length/@@innodb_page_size) FROM information_schema.tables
WHERE table_schema = 'test' AND table_name = 't1';
disconnect stop_purge;
DROP TABLE t1;
--echo # End of 10.4 tests

View file

@ -7,6 +7,19 @@ call mtr.add_suppression("Innodb: Cannot add field.*row size is");
let $MYSQLD_DATADIR= `select @@datadir`;
SET SESSION innodb_strict_mode=ON;
--error ER_CANT_CREATE_TABLE
CREATE TABLE t1(a int PRIMARY KEY) ENGINE=InnoDB ROW_FORMAT=COMPRESSED;
--error ER_CANT_CREATE_TABLE
CREATE TABLE t1(a int PRIMARY KEY) ENGINE=InnoDB KEY_BLOCK_SIZE=4;
SET SESSION innodb_strict_mode=OFF;
CREATE TABLE t1(a int PRIMARY KEY) ENGINE=InnoDB ROW_FORMAT=COMPRESSED;
SHOW WARNINGS;
DROP TABLE t1;
CREATE TABLE t1(a int PRIMARY KEY) ENGINE=InnoDB KEY_BLOCK_SIZE=4;
SHOW WARNINGS;
DROP TABLE t1;
--echo # Test 1) Show the page size from Information Schema
SELECT variable_value FROM information_schema.global_status
WHERE LOWER(variable_name) = 'innodb_page_size';

View file

@ -8,6 +8,19 @@ call mtr.add_suppression('InnoDB: Cannot add field.*because after adding it, the
let $MYSQLD_DATADIR= `select @@datadir`;
SET SESSION innodb_strict_mode=ON;
--error ER_CANT_CREATE_TABLE
CREATE TABLE t1(a int PRIMARY KEY) ENGINE=InnoDB ROW_FORMAT=COMPRESSED;
--error ER_CANT_CREATE_TABLE
CREATE TABLE t1(a int PRIMARY KEY) ENGINE=InnoDB KEY_BLOCK_SIZE=4;
SET SESSION innodb_strict_mode=OFF;
CREATE TABLE t1(a int PRIMARY KEY) ENGINE=InnoDB ROW_FORMAT=COMPRESSED;
SHOW WARNINGS;
DROP TABLE t1;
CREATE TABLE t1(a int PRIMARY KEY) ENGINE=InnoDB KEY_BLOCK_SIZE=4;
SHOW WARNINGS;
DROP TABLE t1;
--echo # Test 1) Show the page size from Information Schema
SELECT variable_value FROM information_schema.global_status
WHERE LOWER(variable_name) = 'innodb_page_size';

View file

@ -0,0 +1,117 @@
# DEBUG_SYNC must be compiled in.
--source include/have_debug_sync.inc
--source include/have_debug.inc
--source include/have_innodb.inc
CREATE TABLE t1 (c1 INT , c2 CHAR(10), PRIMARY KEY (c1)) ENGINE = InnoDB;
INSERT INTO t1 VALUES(0, "0");
INSERT INTO t1 VALUES(1, "1");
INSERT INTO t1 VALUES(2, "2");
INSERT INTO t1 VALUES(3, "3");
--connect (con1,localhost,root,,)
--connect (con2,localhost,root,,)
--connect (con3,localhost,root,,)
--connect (con4,localhost,root,,)
--connect (con5,localhost,root,,)
--connect (con6,localhost,root,,)
connection default;
# Disable query log to avoid non-deterministic output conflicts
SET AUTOCOMMIT=0;
BEGIN;
# Lock all the records
SELECT * FROM t1 FOR UPDATE;
--disable_query_log
connection con1;
SET AUTOCOMMIT=1;
# Test if locking autocommit selects end up in the trx_sys_t::trx_list.
# We check this via the INFORMATION_SCHEMA.INNODB_TRX.
# This should block and show up in the I_S.
SET DEBUG_SYNC='lock_wait_suspend_thread_enter SIGNAL waiting1';
--send
SELECT COUNT(*) FROM t1 LOCK IN SHARE MODE;
connection con2;
SET AUTOCOMMIT=1;
# Test if non-locking autocommit selects end up in the trx_sys_t::trx_list.
# We check this via the INFORMATION_SCHEMA.INNODB_TRX.
# This should not block and should not show up in the I_S.
--send
SELECT COUNT(*) FROM t1;
connection con3;
SET AUTOCOMMIT=1;
# Note: autocommit non-locking selects are not converted to locking selects
# Therefore this should not block;
SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;
--send
SELECT COUNT(*) FROM t1;
connection con4;
SET AUTOCOMMIT=0;
# Note: Non-locking selects are converted to locking selects
# therefore this should block;
SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;
SET DEBUG_SYNC='now WAIT_FOR waiting1';
SET DEBUG_SYNC='lock_wait_suspend_thread_enter SIGNAL waiting4';
--send
SELECT COUNT(*) FROM t1 WHERE c1 >= 0;
connection con5;
SET AUTOCOMMIT=1;
# This should not block
BEGIN;
--send
SELECT COUNT(*) FROM t1;
connection con6;
SET AUTOCOMMIT=1;
# This will ignore the auto-commit setting but wont block because it is
# a non-locking select.
XA START '1';
--enable_query_log
SELECT * FROM t1 WHERE c1 <= 3;
connection default;
# Wait for SELECTs to get into the lock wait queue
SET DEBUG_SYNC='now WAIT_FOR waiting4';
SET DEBUG_SYNC= 'RESET';
# Check the number of non-locking transactions
let $wait_condition =
SELECT COUNT(*) = 5
FROM INFORMATION_SCHEMA.INNODB_TRX
WHERE trx_autocommit_non_locking = 0;
--source include/wait_condition.inc
# Check the waiting transactions
SELECT trx_state, trx_query, trx_autocommit_non_locking
FROM INFORMATION_SCHEMA.INNODB_TRX
WHERE trx_state = 'LOCK WAIT'
ORDER BY trx_query;
INSERT INTO t1 VALUES(4, '4');
COMMIT;
connection con6;
SELECT * FROM t1 WHERE c1 <= 4;
XA END '1';
XA PREPARE '1';
XA ROLLBACK '1';
disconnect con6;
disconnect con2;
disconnect con3;
disconnect con5;
connection con1;
reap;
disconnect con1;
connection con4;
reap;
disconnect con4;
connection default;
DROP TABLE t1;

View file

@ -690,6 +690,32 @@ ALTER TABLE t1 ADD COLUMN b DATETIME NOT NULL, LOCK=NONE;
SET @@SQL_MODE= @OLD_SQL_MODE;
DROP TABLE t1;
--echo #
--echo # Bug#20977779 CANNOT IMPORT TABLES CONTAINING PREFIX INDEXES
--echo #
CREATE TABLE t1 (c1 VARCHAR(32), c2 VARCHAR(32), c3 VARCHAR(32),
PRIMARY KEY (c1, c2, c3))
ENGINE=InnoDB;
ALTER TABLE t1 ADD INDEX ind1(c1(5), c2, c3);
ALTER TABLE t1 ADD INDEX ind2(c3, c1(10), c2);
ALTER TABLE t1 ADD INDEX ind3(c2, c3, c1(20));
INSERT INTO t1 VALUES ('Test Data -1', 'Test Data -2', 'Test Data -3');
let $source_db = test;
let $dest_db = test;
--echo # Test with 2ndary index having prefix
--source suite/innodb/include/import.inc
--echo # Test with PK & 2ndary index with prefix
ALTER TABLE t1 DROP PRIMARY KEY, ADD PRIMARY KEY(c1(5), c2(10), c3(20));
--source suite/innodb/include/import.inc
DROP TABLE t1;
#
# End of 10.2 tests
#

View file

@ -482,3 +482,32 @@ SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS;
DROP TABLE t2;
DROP TABLE t3;
--echo # Bug #17449901 TABLE DISAPPEARS WHEN ALTERING
--echo # WITH FOREIGN KEY CHECKS OFF
# Drop index via inplace algorithm
create table t1(f1 int,primary key(f1))engine=innodb;
create table t2(f2 int,f3 int,key t(f2,f3),foreign key(f2) references t1(f1))engine=innodb;
SET foreign_key_checks=0;
drop index t on t2;
drop table t2;
drop table t1;
# Drop index using alter statement via inplace
create table t1(f1 int ,primary key(f1))engine=innodb;
create table t2(f2 int,f3 int, key t(f2),foreign key(f2) references t1(f1))engine=innodb;
SET foreign_key_checks = 0;
alter table t2 drop key t,algorithm=inplace;
show create table t2;
drop table t2;
drop table t1;
create table t1(f1 int ,primary key(f1))engine=innodb;
create table t2(f2 int,f3 int, key t(f2),key t1(f2,f3),
foreign key(f2) references t1(f1))engine=innodb;
SET foreign_key_checks = 0;
alter table t2 drop key t,algorithm=inplace;
show create table t2;
drop table t2;
drop table t1;

View file

@ -0,0 +1,115 @@
--echo #
--echo # Bug #21025880 DUPLICATE UK VALUES IN READ-COMMITTED(AGAIN)
--echo #
--source include/have_innodb.inc
--source include/have_debug.inc
--source include/have_debug_sync.inc
SET @save_frequency = @@GLOBAL.innodb_purge_rseg_truncate_frequency;
SET GLOBAL innodb_purge_rseg_truncate_frequency=1;
let $i=0;
while ($i <=1 )
{
CREATE TABLE t1 (
a INT NOT NULL,
b INT NOT NULL,
PRIMARY KEY(b),
UNIQUE KEY(a))
ENGINE=INNODB;
SET @old_innodb_stats_auto_recalc = @@innodb_stats_auto_recalc;
SET GLOBAL innodb_stats_auto_recalc = OFF;
# Block purge
connect purge_control,localhost,root;
START TRANSACTION WITH CONSISTENT SNAPSHOT;
connection default;
SET @old_tx_isolation = @@tx_isolation;
SET GLOBAL tx_isolation = 'READ-COMMITTED';
SET @old_innodb_lock_wait_timeout = @@innodb_lock_wait_timeout;
SET GLOBAL innodb_lock_wait_timeout = 1;
--connect(con1,localhost,root,,)
# Create and delete-mark an index record
INSERT INTO t1 VALUES (1,1),(2,2);
DELETE FROM t1;
SET debug_sync = 'row_ins_sec_index_entry_dup_locks_created SIGNAL
con1_locks_done WAIT_FOR con1_go';
SET debug_sync = 'ha_commit_trans_after_acquire_commit_lock SIGNAL
con1_insert_done WAIT_FOR con1_finish';
--send
if ($i == 0)
{
REPLACE INTO t1 VALUES (1,2);
}
if ( $i == 1)
{
INSERT INTO t1 values (1,2) ON DUPLICATE KEY UPDATE a=2;
}
--connect(con2,localhost,root,,)
SET debug_sync = 'now WAIT_FOR con1_locks_done';
SET debug_sync = 'lock_wait_suspend_thread_enter SIGNAL con2_blocked
WAIT_FOR con2_go';
SET debug_sync = 'ha_commit_trans_after_acquire_commit_lock
WAIT_FOR con2_finish';
SET debug_sync = 'ib_after_row_insert SIGNAL con2_insert_done';
--send
REPLACE INTO t1 VALUES (1,3);
--connection default
SET debug_sync = 'now WAIT_FOR con2_blocked';
connection purge_control;
COMMIT;
disconnect purge_control;
connection default;
# Wait for purge to delete the delete-marked record
--source ../../innodb/include/wait_all_purged.inc
SET debug_sync = 'now SIGNAL con2_go WAIT_FOR con2_insert_done';
SET debug_sync = 'now SIGNAL con1_go WAIT_FOR con1_insert_done';
SET debug_sync = 'now SIGNAL con1_finish';
--connection con1
--reap
--disconnect con1
--connection default
SET debug_sync = 'now SIGNAL con2_finish';
--connection con2
--error 0,ER_LOCK_WAIT_TIMEOUT
--reap
--disconnect con2
--connection default
SET DEBUG_SYNC= 'RESET';
SELECT * FROM t1;
CHECK TABLE t1;
DROP TABLE t1;
SET GLOBAL innodb_stats_auto_recalc = @old_innodb_stats_auto_recalc;
SET GLOBAL tx_isolation = @old_tx_isolation;
SET GLOBAL innodb_lock_wait_timeout = @old_innodb_lock_wait_timeout;
--inc $i
}
SET GLOBAL innodb_purge_rseg_truncate_frequency=@save_frequency;

View file

@ -1,7 +1,6 @@
# DEBUG_SYNC must be compiled in.
--source include/have_debug_sync.inc
--source include/have_debug.inc
# We need to test the use case:
# a. Create a transaction T1 that will be promoted to RW.
# b. Create a transaction T2 that will be promoted to RW.
@ -27,22 +26,16 @@ INSERT INTO t2 VALUES(2, "c");
INSERT INTO t2 VALUES(3, "d");
--connect (con1,localhost,root,,)
--connect (con2,localhost,root,,)
connection con1;
--echo 'T1'
SET AUTOCOMMIT=0;
BEGIN;
SELECT * FROM t2;
connection default;
--echo 'T2'
SET AUTOCOMMIT=0;
BEGIN;
SELECT * FROM t1;
connection con2;
--echo 'T3'
--connect (con2,localhost,root,,)
SET AUTOCOMMIT=0;
SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;
BEGIN;
@ -50,48 +43,36 @@ SELECT * FROM t1;
SELECT * FROM t2;
connection con1;
--echo 'T1'
UPDATE t2 SET c1 = c1 + 100;
SELECT * FROM t2;
COMMIT;
connection default;
--echo 'T2'
UPDATE t1 SET c1 = c1 + 100;
SELECT * FROM t1;
COMMIT;
connection con2;
--echo 'T3'
SET DEBUG_SYNC='row_search_for_mysql_before_return WAIT_FOR waiting1';
--send SELECT * FROM t1;
connection default;
--echo 'T2'
SET DEBUG_SYNC='now SIGNAL waiting1';
--echo 'Signalled T3'
connection con2;
--echo 'T3'
reap;
connection con2;
--echo 'T3'
SET DEBUG_SYNC='row_search_for_mysql_before_return WAIT_FOR waiting1';
--send SELECT * FROM t2;
connection default;
--echo 'T2'
SET DEBUG_SYNC='now SIGNAL waiting1';
--echo 'Signalled T3'
connection con2;
--echo 'T3'
reap;
connection default;
disconnect con1;
disconnect con2;
# We need to test the use case:
# a. Create a transaction T1 that will be promoted to RW.
@ -105,17 +86,12 @@ disconnect con2;
# i. T3 Does a select - it should not see the changes made by T1 but should
# see the changes by T2
--connect (con1,localhost,root,,)
--connect (con2,localhost,root,,)
connection con1;
--echo 'T1'
SET AUTOCOMMIT=0;
BEGIN;
SELECT * FROM t1;
connection default;
--echo 'T2'
SET AUTOCOMMIT=0;
BEGIN;
SELECT * FROM t2;
@ -124,7 +100,6 @@ SELECT * FROM t2;
COMMIT;
connection con2;
--echo 'T3'
SET AUTOCOMMIT=0;
SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;
BEGIN;
@ -132,42 +107,30 @@ SELECT * FROM t1;
SELECT * FROM t2;
connection con1;
--echo 'T1'
UPDATE t1 SET c1 = c1 + 100;
SELECT * FROM t1;
COMMIT;
connection con2;
--echo 'T3'
SET DEBUG_SYNC='row_select_wait WAIT_FOR waiting1';
--send SELECT * FROM t1;
connection con1;
--echo 'T2'
SET DEBUG_SYNC='now SIGNAL waiting1';
--echo 'Signalled T3'
connection con2;
--echo 'T3'
reap;
connection con2;
--echo 'T3'
SET DEBUG_SYNC='row_select_wait WAIT_FOR waiting1';
--send SELECT * FROM t2;
connection default;
--echo 'T2'
SET DEBUG_SYNC='now SIGNAL waiting1';
--echo 'Signalled T3'
connection con2;
--echo 'T3'
reap;
disconnect con2;
connection default;
disconnect con1;
disconnect con2;
DROP TABLE t1;
DROP TABLE t2;
@ -176,8 +139,7 @@ DROP TABLE t2;
--echo # Bug 21433768: NON-REPEATABLE READ WITH REPEATABLE READ ISOLATION
--echo #
--connect (con1,localhost,root,,)
connection con1;
CREATE TABLE t1(col1 INT PRIMARY KEY, col2 INT) ENGINE = InnoDB;
INSERT INTO t1 values (1, 0), (2, 0);
SELECT * FROM t1 ORDER BY col1;
@ -200,9 +162,7 @@ reap;
disconnect con1;
connection default;
SET DEBUG_SYNC= 'RESET';
DROP TABLE t1;
# Clean up resources used in this test case.
SET DEBUG_SYNC= 'RESET';
--source include/wait_until_count_sessions.inc

View file

@ -0,0 +1,169 @@
#
# Test that user data is correctly "visualized" in
# INFORMATION_SCHEMA.innodb_locks.lock_data
#
-- source include/have_innodb.inc
SET @save_timeout=@@GLOBAL.innodb_lock_wait_timeout;
SET GLOBAL innodb_lock_wait_timeout=100000000;
let $table_def =
(
c01 TINYINT,
c02 TINYINT UNSIGNED,
c03 SMALLINT,
c04 SMALLINT UNSIGNED,
c05 MEDIUMINT,
c06 MEDIUMINT UNSIGNED,
c07 INT,
c08 INT UNSIGNED,
c09 BIGINT,
c10 BIGINT UNSIGNED,
PRIMARY KEY(c01, c02, c03, c04, c05, c06, c07, c08, c09, c10)
) ENGINE=INNODB;
-- eval CREATE TABLE t_min $table_def;
INSERT INTO t_min VALUES
(-128, 0,
-32768, 0,
-8388608, 0,
-2147483648, 0,
-9223372036854775808, 0);
-- eval CREATE TABLE t_max $table_def;
INSERT INTO t_max VALUES
(127, 255,
32767, 65535,
8388607, 16777215,
2147483647, 4294967295,
9223372036854775807, 18446744073709551615);
CREATE TABLE ```t'\"_str` (
c1 VARCHAR(32),
c2 VARCHAR(32),
c3 VARCHAR(32),
c4 VARCHAR(32),
c5 VARCHAR(32),
c6 VARCHAR(32),
c7 VARCHAR(32),
PRIMARY KEY(c1, c2, c3, c4, c5, c6, c7)
) ENGINE=INNODB;
INSERT INTO ```t'\"_str` VALUES
('1', 'abc', '''abc', 'abc''', 'a''bc', 'a''bc''', '''abc''''');
INSERT INTO ```t'\"_str` VALUES
('2', 'abc', '"abc', 'abc"', 'a"bc', 'a"bc"', '"abc""');
INSERT INTO ```t'\"_str` VALUES
('3', 'abc', '\\abc', 'abc\\', 'a\\bc', 'a\\bc\\', '\\abc\\\\');
INSERT INTO ```t'\"_str` VALUES
('4', 'abc', 0x00616263, 0x61626300, 0x61006263, 0x6100626300, 0x610062630000);
-- source include/count_sessions.inc
-- connect (con_lock,localhost,root,,)
-- connect (con_min_trylock,localhost,root,,)
-- connect (con_max_trylock,localhost,root,,)
-- connect (con_str_insert_supremum,localhost,root,,)
-- connect (con_str_lock_row1,localhost,root,,)
-- connect (con_str_lock_row2,localhost,root,,)
-- connect (con_str_lock_row3,localhost,root,,)
-- connect (con_str_lock_row4,localhost,root,,)
-- connect (con_verify_innodb_locks,localhost,root,,)
-- connection con_lock
SET autocommit=0;
SELECT * FROM t_min FOR UPDATE;
SELECT * FROM t_max FOR UPDATE;
SELECT * FROM ```t'\"_str` FOR UPDATE;
-- connection con_min_trylock
-- send
SELECT * FROM t_min FOR UPDATE;
-- connection con_max_trylock
-- send
SELECT * FROM t_max FOR UPDATE;
-- connection con_str_insert_supremum
-- send
INSERT INTO ```t'\"_str` VALUES
('z', 'z', 'z', 'z', 'z', 'z', 'z');
-- connection con_str_lock_row1
-- send
SELECT * FROM ```t'\"_str` WHERE c1 = '1' FOR UPDATE;
-- connection con_str_lock_row2
-- send
SELECT * FROM ```t'\"_str` WHERE c1 = '2' FOR UPDATE;
-- connection con_str_lock_row3
-- send
SELECT * FROM ```t'\"_str` WHERE c1 = '3' FOR UPDATE;
-- connection con_str_lock_row4
-- send
SELECT * FROM ```t'\"_str` WHERE c1 = '4' FOR UPDATE;
-- connection con_verify_innodb_locks
# Wait for the above queries to execute before continuing.
# Without this, it sometimes happens that the SELECT from innodb_locks
# executes before some of them, resulting in less than expected number
# of rows being selected from innodb_locks. If there is a bug and there
# are no 14 rows in innodb_locks then this test will fail with timeout.
# Notice that if we query INNODB_LOCKS more often than once per 0.1 sec
# then its contents will never change because the cache from which it is
# filled is updated only if it has not been read for 0.1 seconds. See
# CACHE_MIN_IDLE_TIME_US in trx/trx0i_s.c.
let $cnt=10;
while ($cnt)
{
let $success=`SELECT COUNT(*) = 14 FROM INFORMATION_SCHEMA.INNODB_LOCKS`;
if ($success)
{
let $cnt=0;
}
if (!$success)
{
real_sleep 0.2;
dec $cnt;
}
}
if (!$success)
{
-- echo Timeout waiting for rows in INNODB_LOCKS to appear
}
SELECT lock_mode, lock_type, lock_table, lock_index, lock_rec, lock_data
FROM INFORMATION_SCHEMA.INNODB_LOCKS ORDER BY lock_data;
SELECT lock_table, COUNT(*) FROM INFORMATION_SCHEMA.INNODB_LOCKS
GROUP BY lock_table;
set @save_sql_mode = @@sql_mode;
SET SQL_MODE='ANSI_QUOTES';
SELECT lock_table, COUNT(*) FROM INFORMATION_SCHEMA.INNODB_LOCKS
GROUP BY lock_table;
SET @@sql_mode=@save_sql_mode;
# Release all the locks;
-- connection con_lock
COMMIT;
-- connection default
-- disconnect con_lock
-- disconnect con_min_trylock
-- disconnect con_max_trylock
-- disconnect con_str_insert_supremum
-- disconnect con_str_lock_row1
-- disconnect con_str_lock_row2
-- disconnect con_str_lock_row3
-- disconnect con_str_lock_row4
-- disconnect con_verify_innodb_locks
DROP TABLE t_min, t_max, ```t'\"_str`;
-- source include/wait_until_count_sessions.inc
SET GLOBAL innodb_lock_wait_timeout=@save_timeout;

View file

@ -0,0 +1,95 @@
--source include/have_innodb.inc
#
# Test that transaction data is correctly "visualized" in
# INFORMATION_SCHEMA.INNODB_TRX
#
SET @save_timeout=@@GLOBAL.innodb_lock_wait_timeout;
SET GLOBAL innodb_lock_wait_timeout=100000000;
DESCRIBE INFORMATION_SCHEMA.INNODB_TRX;
CREATE TABLE t1 (
c01 INT,
c02 INT,
PRIMARY KEY (c01)
) ENGINE=INNODB STATS_AUTO_RECALC=0;
INSERT INTO t1 VALUES
(1,2),(2,4),(3,6),(4,8);
CREATE TABLE t2 (
c01 INT,
c02 INT,
PRIMARY KEY (c01),
FOREIGN KEY fk1 (c02) REFERENCES t1 (c01)
) ENGINE=INNODB STATS_AUTO_RECALC=0;
INSERT INTO t2 VALUES
(1,1),(2,2),(3,3);
-- source include/count_sessions.inc
-- connect (con_trx,localhost,root,,)
-- connect (con_verify_innodb_trx,localhost,root,,)
-- connection con_trx
SET autocommit=0;
INSERT INTO t1 VALUES (5,10);
SELECT * FROM t1 FOR UPDATE;
let $wait_timeout= 300;
let $wait_condition=
SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.INNODB_TRX;
-- source include/wait_condition.inc
-- connection con_verify_innodb_trx
SELECT trx_state, trx_weight, trx_tables_in_use, trx_tables_locked,
trx_rows_locked, trx_rows_modified, trx_concurrency_tickets,
trx_isolation_level, trx_unique_checks, trx_foreign_key_checks
FROM INFORMATION_SCHEMA.INNODB_TRX;
-- connection con_trx
ROLLBACK;
SET FOREIGN_KEY_CHECKS = 0;
SET UNIQUE_CHECKS = 0;
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
BEGIN;
INSERT INTO t1 VALUES (6,12);
let $wait_timeout= 300;
let $wait_condition=
SELECT trx_unique_checks = 0 FROM INFORMATION_SCHEMA.INNODB_TRX;
-- source include/wait_condition.inc
-- connection con_verify_innodb_trx
SELECT trx_isolation_level, trx_unique_checks, trx_foreign_key_checks
FROM INFORMATION_SCHEMA.INNODB_TRX;
-- connection con_trx
ROLLBACK;
SET FOREIGN_KEY_CHECKS = 1;
SET UNIQUE_CHECKS = 1;
BEGIN;
--error ER_NO_REFERENCED_ROW_2
INSERT INTO t2 VALUES (4,10);
let $wait_timeout= 300;
let $wait_condition=
SELECT trx_unique_checks = 1 FROM INFORMATION_SCHEMA.INNODB_TRX;
-- source include/wait_condition.inc
-- disconnect con_trx
-- connection con_verify_innodb_trx
SELECT trx_state, trx_isolation_level, trx_last_foreign_key_error
FROM INFORMATION_SCHEMA.INNODB_TRX;
-- disconnect con_verify_innodb_trx
-- connection default
DROP TABLE t2;
DROP TABLE t1;
-- source include/wait_until_count_sessions.inc
SET GLOBAL innodb_lock_wait_timeout=@save_timeout;

View file

@ -27,3 +27,4 @@
--loose-innodb_buffer_pool_pages
--loose-innodb_buffer_pool_pages_index
--loose-innodb_buffer_pool_pages_blob
--innodb-open-files=1000000

View file

@ -1,6 +1,10 @@
-- source include/have_innodb.inc
-- source include/not_embedded.inc
let SEARCH_FILE= $MYSQLTEST_VARDIR/log/mysqld.1.err;
let SEARCH_PATTERN= \[Warning\] InnoDB: innodb_open_files 1000000 should not be greater than the open_files_limit [0-9]+;
--source include/search_pattern_in_file.inc
#
# MDEV-7762 InnoDB: Failing assertion: block->page.buf_fix_count > 0 in buf0buf.ic line 730
#

View file

@ -0,0 +1 @@
--innodb-stats-persistent

View file

@ -0,0 +1,48 @@
#
# Test the persistent stats auto recalc
#
-- source include/have_innodb.inc
# Page numbers printed by this test depend on the page size
-- source include/have_innodb_16k.inc
-- vertical_results
-- let $check_stats1 = SELECT n_rows, clustered_index_size FROM mysql.innodb_table_stats WHERE table_name = 'autorecalc'
-- let $check_stats2 = SELECT index_name, stat_name, stat_value FROM mysql.innodb_index_stats WHERE table_name = 'autorecalc'
CREATE TABLE autorecalc (a INT, PRIMARY KEY (a)) ENGINE=INNODB;
# the CREATE should have inserted zeroed stats
-- eval $check_stats1
-- eval $check_stats2
INSERT INTO autorecalc VALUES (1);
INSERT INTO autorecalc VALUES (2);
# wait for the bg stats thread to update the stats, notice we wait on
# innodb_index_stats because innodb_table_stats gets updated first and
# it is possible that (if we wait on innodb_table_stats) the wait cond
# gets satisfied before innodb_index_stats is updated
let $wait_condition = SELECT stat_value = 2 FROM mysql.innodb_index_stats WHERE table_name = 'autorecalc' AND index_name = 'PRIMARY' AND stat_name = 'n_diff_pfx01';
-- source include/wait_condition.inc
# the second INSERT from above should have triggered an auto-recalc
-- eval $check_stats1
-- eval $check_stats2
# now DELETE the rows and trigger a second auto-recalc, InnoDB may wait a
# few seconds before triggering an auto-recalc again (it tries not to be too
# aggressive)
DELETE FROM autorecalc;
let $wait_timeout = 25;
let $wait_condition = SELECT stat_value = 0 FROM mysql.innodb_index_stats WHERE table_name = 'autorecalc' AND index_name = 'PRIMARY' AND stat_name = 'n_diff_pfx01';
-- source include/wait_condition.inc
# the DELETE from above should have triggered an auto-recalc
-- eval $check_stats1
-- eval $check_stats2
DROP TABLE autorecalc;

View file

@ -0,0 +1 @@
--innodb-stats-persistent

View file

@ -0,0 +1,49 @@
#
# Test the persistent stats auto recalc during DDL
#
-- source include/have_innodb.inc
-- vertical_results
-- let $check_stats1 = SELECT n_rows FROM mysql.innodb_table_stats WHERE table_name = 'arddl' ORDER BY 1
-- let $check_stats2 = SELECT index_name, stat_name, stat_value FROM mysql.innodb_index_stats WHERE table_name = 'arddl' AND index_name = 'PRIMARY' ORDER BY 1, 2, 3
# Test ADD INDEX during background stats gathering
CREATE TABLE arddl (a INT, b INT, PRIMARY KEY (a)) ENGINE=INNODB;
INSERT INTO arddl VALUES (1, 10);
INSERT INTO arddl VALUES (2, 10);
ALTER TABLE arddl ADD INDEX (b);
# wait for the bg stats thread to update the stats, notice we wait on
# innodb_index_stats because innodb_table_stats gets updated first and
# it is possible that (if we wait on innodb_table_stats) the wait cond
# gets satisfied before innodb_index_stats is updated
let $wait_condition = SELECT stat_value = 2 FROM mysql.innodb_index_stats WHERE table_name = 'arddl' AND index_name = 'PRIMARY' AND stat_name = 'n_diff_pfx01';
-- source include/wait_condition.inc
# the second INSERT from above should have triggered an auto-recalc
-- eval $check_stats1
-- eval $check_stats2
DROP TABLE arddl;
# Test DROP INDEX during background stats gathering
CREATE TABLE arddl (a INT, b INT, PRIMARY KEY (a), KEY (b)) ENGINE=INNODB;
INSERT INTO arddl VALUES (3, 10);
INSERT INTO arddl VALUES (4, 10);
ALTER TABLE arddl DROP INDEX b;
let $wait_condition = SELECT stat_value = 2 FROM mysql.innodb_index_stats WHERE table_name = 'arddl' AND index_name = 'PRIMARY' AND stat_name = 'n_diff_pfx01';
-- source include/wait_condition.inc
-- eval $check_stats1
-- eval $check_stats2
DROP TABLE arddl;

View file

@ -0,0 +1 @@
--innodb-stats-persistent

View file

@ -0,0 +1,45 @@
#
# Test the persistent stats auto recalc on lots of tables
#
--source include/no_valgrind_without_big.inc
-- source include/have_innodb.inc
let $check_stats = SELECT table_name, n_rows FROM mysql.innodb_table_stats WHERE table_name LIKE 'ar_%' ORDER BY table_name;
-- disable_query_log
let $i = 1200;
while ($i > 1000) {
eval CREATE TABLE ar_$i (a INT, PRIMARY KEY (a)) ENGINE=INNODB;
dec $i;
}
-- enable_query_log
# the CREATEs above should have inserted zeroed stats
-- eval $check_stats
-- disable_query_log
let $i = 1200;
while ($i > 1000) {
eval INSERT INTO ar_$i VALUES (1), (2);
dec $i;
}
-- enable_query_log
-- disable_query_log
let $i = 1200;
while ($i > 1000) {
eval INSERT INTO ar_$i VALUES (3), (4);
dec $i;
}
-- enable_query_log
# would be too long to wait for stats to become up to date here
-- disable_query_log
let $i = 1200;
while ($i > 1000) {
eval DROP TABLE ar_$i;
dec $i;
}
-- enable_query_log

View file

@ -0,0 +1 @@
--innodb-stats-persistent

View file

@ -0,0 +1,85 @@
#
# Test the persistent stats auto recalc when persistent stats do not exist
#
-- source include/have_innodb.inc
-- vertical_results
-- let $check_stats1 = SELECT COUNT(*) FROM mysql.innodb_table_stats WHERE table_name = 't'
-- let $check_stats2 = SELECT COUNT(*) FROM mysql.innodb_index_stats WHERE table_name = 't'
-- echo Test with default setting
CREATE TABLE t (a INT, PRIMARY KEY (a)) ENGINE=INNODB;
# the CREATE should have inserted zeroed stats
-- eval $check_stats1
-- eval $check_stats2
# close the table
FLUSH TABLE t;
DELETE FROM mysql.innodb_index_stats WHERE table_name = 't';
DELETE FROM mysql.innodb_table_stats WHERE table_name = 't';
-- eval $check_stats1
-- eval $check_stats2
# open the table, causing stats recalc/save
SELECT * FROM t;
-- eval $check_stats1
-- eval $check_stats2
DROP TABLE t;
-- echo Test with explicit enable
CREATE TABLE t (a INT, PRIMARY KEY (a)) ENGINE=INNODB STATS_AUTO_RECALC=1;
# the CREATE should have inserted zeroed stats
-- eval $check_stats1
-- eval $check_stats2
# close the table
FLUSH TABLE t;
DELETE FROM mysql.innodb_index_stats WHERE table_name = 't';
DELETE FROM mysql.innodb_table_stats WHERE table_name = 't';
-- eval $check_stats1
-- eval $check_stats2
# open the table, causing stats recalc/save
SELECT * FROM t;
-- eval $check_stats1
-- eval $check_stats2
DROP TABLE t;
-- echo Test with explicit disable
CREATE TABLE t (a INT, PRIMARY KEY (a)) ENGINE=INNODB STATS_AUTO_RECALC=0;
# the CREATE should have inserted zeroed stats
-- eval $check_stats1
-- eval $check_stats2
# close the table
FLUSH TABLE t;
DELETE FROM mysql.innodb_index_stats WHERE table_name = 't';
DELETE FROM mysql.innodb_table_stats WHERE table_name = 't';
-- eval $check_stats1
-- eval $check_stats2
# open the table, stats should not be present, since autorecalc is disabled
SELECT * FROM t;
-- eval $check_stats1
-- eval $check_stats2
DROP TABLE t;

View file

@ -0,0 +1,79 @@
#
# Bug#18384390 WRONG STATISTICS WITH BIG ROW LENGTH AND PERSISTENT STATS
#
--source include/have_innodb.inc
--source include/have_innodb_max_16k.inc
--source include/have_sequence.inc
CREATE TABLE bug18384390 (
id INT AUTO_INCREMENT PRIMARY KEY,
txt VARCHAR(10000)
) ENGINE=INNODB STATS_PERSISTENT=1 STATS_AUTO_RECALC=0;
let $count=1024;
eval
INSERT INTO bug18384390 (txt) SELECT REPEAT('0', 10000) FROM seq_1_to_$count;
set use_stat_tables=never;
ANALYZE TABLE bug18384390;
-- let $n_rows = `SELECT n_rows FROM mysql.innodb_table_stats WHERE table_name = 'bug18384390'`
-- let $table_rows = `SELECT table_rows FROM information_schema.tables WHERE table_name = 'bug18384390'`
-- let $n_diff = `SELECT stat_value FROM mysql.innodb_index_stats WHERE table_name = 'bug18384390' AND stat_name = 'n_diff_pfx01'`
-- let $cardinality = `SELECT cardinality FROM information_schema.statistics WHERE table_name = 'bug18384390'`
-- let $margin_of_err_pct = 30
-- let $margin_of_err_rows = `SELECT ROUND($count * $margin_of_err_pct / 100)`
-- let $min_allowed = `SELECT $count - $margin_of_err_rows`
-- let $max_allowed = `SELECT $count + $margin_of_err_rows`
-- let $dump_sql = SELECT COUNT(*) FROM bug18384390; SELECT * FROM mysql.innodb_table_stats; SELECT * FROM mysql.innodb_index_stats; SELECT * FROM information_schema.tables WHERE table_name = 'bug18384390'; SELECT * FROM information_schema.statistics WHERE table_name = 'bug18384390';
-- vertical_results
if ($n_rows < $min_allowed) {
-- echo mysql.innodb_table_stats.n_rows is too small ($n_rows < $min_allowed)
-- eval $dump_sql
}
if ($n_rows > $max_allowed) {
-- echo mysql.innodb_table_stats.n_rows is too big ($n_rows > $max_allowed)
-- eval $dump_sql
}
if ($table_rows < $min_allowed) {
-- echo information_schema.tables.table_rows is too small ($table_rows < $min_allowed)
-- eval $dump_sql
}
if ($table_rows > $max_allowed) {
-- echo information_schema.tables.table_rows is too big ($table_rows > $max_allowed)
-- eval $dump_sql
}
if ($n_diff < $min_allowed) {
-- echo mysql.innodb_index_stats.stat_value is too small ($n_diff < $min_allowed)
-- eval $dump_sql
}
if ($n_diff > $max_allowed) {
-- echo mysql.innodb_index_stats.stat_value is too big ($n_diff > $max_allowed)
-- eval $dump_sql
}
if ($cardinality < $min_allowed) {
-- echo information_schema.statistics.cardinality is too small ($cardinality < $min_allowed)
-- eval $dump_sql
}
if ($cardinality > $max_allowed) {
-- echo information_schema.statistics.cardinality is too big ($cardinality > $max_allowed)
-- eval $dump_sql
}
DROP TABLE bug18384390;

View file

@ -0,0 +1,4 @@
[on]
--innodb-stats-persistent=1
[off]
--innodb-stats-persistent=0

View file

@ -0,0 +1,91 @@
-- source include/have_innodb.inc
-- source include/not_embedded.inc
#
-- echo =====
-- echo === Test ANALYZE behavior after default creation
-- echo =====
CREATE TABLE test_ps_flag (a INT) ENGINE=INNODB;
-- source innodb_stats_flag_global_analyze.inc
DROP TABLE test_ps_flag;
CREATE TABLE test_ps_flag (a INT) ENGINE=INNODB STATS_PERSISTENT=default;
-- source innodb_stats_flag_global_analyze.inc
DROP TABLE test_ps_flag;
#
-- echo =====
-- echo === Test ANALYZE behavior after creation with explicit PS=OFF
-- echo =====
CREATE TABLE test_ps_flag (a INT) ENGINE=INNODB STATS_PERSISTENT=0;
-- source innodb_stats_flag_global_analyze.inc
DROP TABLE test_ps_flag;
#
-- echo =====
-- echo === Test ANALYZE behavior after creation with explicit PS=ON
-- echo =====
CREATE TABLE test_ps_flag (a INT) ENGINE=INNODB STATS_PERSISTENT=1;
-- source innodb_stats_flag_global_analyze.inc
DROP TABLE test_ps_flag;
#
-- echo =====
-- echo === Test ANALYZE behavior after creation with explicit PS=OFF,
-- echo === then ALTER to ON, then ALTER to OFF, then ALTER to default
-- echo =====
CREATE TABLE test_ps_flag (a INT) ENGINE=INNODB STATS_PERSISTENT=0;
ALTER TABLE test_ps_flag STATS_PERSISTENT=1;
# also check that the change from the ALTER TABLE survives server restart
-- source include/restart_mysqld.inc
-- source innodb_stats_flag_global_analyze.inc
ALTER TABLE test_ps_flag STATS_PERSISTENT=0;
-- source innodb_stats_flag_global_analyze.inc
ALTER TABLE test_ps_flag STATS_PERSISTENT=default;
-- source innodb_stats_flag_global_analyze.inc
DROP TABLE test_ps_flag;
#
-- echo =====
-- echo === Test ANALYZE behavior after creation with explicit PS=ON,
-- echo === then ALTER to OFF, then ALTER to ON, then ALTER to default
-- echo =====
CREATE TABLE test_ps_flag (a INT) ENGINE=INNODB STATS_PERSISTENT=1;
ALTER TABLE test_ps_flag STATS_PERSISTENT=0;
# also check that the change from the ALTER TABLE survives server restart
-- source include/restart_mysqld.inc
-- source innodb_stats_flag_global_analyze.inc
ALTER TABLE test_ps_flag STATS_PERSISTENT=1;
-- source innodb_stats_flag_global_analyze.inc
ALTER TABLE test_ps_flag STATS_PERSISTENT=default;
-- source innodb_stats_flag_global_analyze.inc
DROP TABLE test_ps_flag;

View file

@ -0,0 +1,13 @@
SHOW CREATE TABLE test_ps_flag;
DELETE FROM mysql.innodb_index_stats WHERE table_name = 'test_ps_flag';
DELETE FROM mysql.innodb_table_stats WHERE table_name = 'test_ps_flag';
# must be 0, we have just deleted the rows
SELECT COUNT(*) AS cnt_before FROM mysql.innodb_table_stats WHERE table_name = 'test_ps_flag';
SET STATEMENT use_stat_tables=never FOR
ANALYZE TABLE test_ps_flag;
# if the table is PS enabled, then this should be 1 and 0 otherwise
SELECT COUNT(*) AS cnt_after FROM mysql.innodb_table_stats WHERE table_name = 'test_ps_flag';

View file

@ -15,6 +15,7 @@ ENGINE=INNODB STATS_PERSISTENT=1,STATS_AUTO_RECALC=1;
CREATE TABLE t2 LIKE t1;
INSERT INTO t1 (val) SELECT 4 FROM seq_1_to_16;
SET STATEMENT use_stat_tables=never FOR
ANALYZE TABLE t1;
connect(con1, localhost, root,,);
@ -85,3 +86,41 @@ SET GLOBAL innodb_stats_include_delete_marked = @saved_include_delete_marked;
SET GLOBAL innodb_stats_traditional = @saved_traditional;
SET GLOBAL innodb_stats_modified_counter = @saved_modified_counter;
SET GLOBAL innodb_purge_rseg_truncate_frequency = @saved_frequency;
#
# Bug#12429573 TIMESTAMP COLUMN OF INNODB.INDEX_STATS ARE NOT UPDATED
# WHEN RE-RUNNING ANALYZE
#
CREATE TABLE bug12429573 (i INTEGER PRIMARY KEY, j INTEGER, KEY(j))
ENGINE=INNODB STATS_PERSISTENT=1;
SET STATEMENT use_stat_tables=never FOR
ANALYZE TABLE bug12429573;
# Cannot check the exact timestamp here because it is always different
# but at least check that both timestamps in innodb_table_stats and in
# innodb_index_stats have been updated to the same value. If the bug is
# present this check will fail.
SELECT last_update INTO @last FROM mysql.innodb_table_stats
WHERE table_name = 'bug12429573';
SELECT * FROM mysql.innodb_index_stats
WHERE table_name = 'bug12429573' AND last_update!=@last;
# The first ANALYZE would insert timestamp e.g. 17:23:39 in both
# innodb_table_stats and innodb_index_stats. The bug is that the second
# ANALYZE only updates the timestamp in innodb_table_stats. In order to
# check if the timestamp in innodb_index_stats has really been updated we
# need it to be different from the previous one (17:23:39) with at least
# one second.
-- sleep 1
SET STATEMENT use_stat_tables=never FOR
ANALYZE TABLE bug12429573;
SELECT * FROM mysql.innodb_table_stats
WHERE table_name = 'bug12429573' AND last_update=@last;
SELECT * FROM mysql.innodb_index_stats
WHERE table_name = 'bug12429573' AND last_update=@last;
DROP TABLE bug12429573;

View file

@ -0,0 +1 @@
--innodb-stats-persistent

View file

@ -0,0 +1,53 @@
#
# Test that the table option STATS_SAMPLE_PAGES=N|default is indeed
# used by InnoDB
#
-- source include/have_innodb.inc
# Page numbers printed by this test depend on the page size
-- source include/have_innodb_16k.inc
SET GLOBAL innodb_stats_persistent_sample_pages=17;
CREATE TABLE test_ps_sample_pages_used (
a VARCHAR(512), PRIMARY KEY (a)
) ENGINE=INNODB STATS_SAMPLE_PAGES=default;
# Insert enough records into the table so that it has more than 2*17+1 pages
# If we ask to scan more than the half of the leaf pages, then the sampling
# will do full scan and we cannot check whether the sample_pages variable was
# honored.
BEGIN;
-- disable_query_log
let $i=999;
while ($i) {
eval INSERT INTO test_ps_sample_pages_used VALUES (REPEAT(1000+$i, 128));
dec $i;
}
-- enable_query_log
COMMIT;
ANALYZE TABLE test_ps_sample_pages_used;
# confirm the big number of leaf pages in the index
SELECT stat_name, stat_value FROM mysql.innodb_index_stats
WHERE table_name='test_ps_sample_pages_used' AND stat_name='n_leaf_pages';
# confirm that 17 pages were sampled, that is - the global
# innodb_stats_persistent_sample_pages is used when the table option
# STATS_SAMPLE_PAGES is set to 'default'.
SELECT sample_size FROM mysql.innodb_index_stats
WHERE table_name='test_ps_sample_pages_used' AND stat_name='n_diff_pfx01';
ALTER TABLE test_ps_sample_pages_used STATS_SAMPLE_PAGES=14;
ANALYZE TABLE test_ps_sample_pages_used;
# confirm that 14 pages were sampled, that is - the table option
# STATS_SAMPLE_PAGES is used when it is set.
SELECT sample_size FROM mysql.innodb_index_stats
WHERE table_name='test_ps_sample_pages_used' AND stat_name='n_diff_pfx01';
DROP TABLE test_ps_sample_pages_used;
SET GLOBAL innodb_stats_persistent_sample_pages=default;

View file

@ -0,0 +1,83 @@
#
# Test CREATE TABLE ... STATS_AUTO_RECALC=0|1|default
#
-- source include/no_valgrind_without_big.inc
-- source include/have_innodb.inc
-- source include/not_embedded.inc
-- vertical_results
CREATE TABLE test_ps_auto_recalc (a INT, PRIMARY KEY (a)) ENGINE=INNODB;
SHOW CREATE TABLE test_ps_auto_recalc;
SELECT create_options FROM information_schema.tables
WHERE table_name='test_ps_auto_recalc';
ALTER TABLE test_ps_auto_recalc STATS_AUTO_RECALC=1;
# confirm that the flag survives server restart
-- source include/restart_mysqld.inc
SHOW CREATE TABLE test_ps_auto_recalc;
SELECT create_options FROM information_schema.tables
WHERE table_name='test_ps_auto_recalc';
DROP TABLE test_ps_auto_recalc;
##
CREATE TABLE test_ps_auto_recalc (a INT, PRIMARY KEY (a)) ENGINE=INNODB
STATS_AUTO_RECALC=default;
SHOW CREATE TABLE test_ps_auto_recalc;
SELECT create_options FROM information_schema.tables
WHERE table_name='test_ps_auto_recalc';
DROP TABLE test_ps_auto_recalc;
##
CREATE TABLE test_ps_auto_recalc (a INT, PRIMARY KEY (a)) ENGINE=INNODB
STATS_AUTO_RECALC=0;
# confirm that the flag survives server restart
-- source include/restart_mysqld.inc
SHOW CREATE TABLE test_ps_auto_recalc;
SELECT create_options FROM information_schema.tables
WHERE table_name='test_ps_auto_recalc';
ALTER TABLE test_ps_auto_recalc STATS_AUTO_RECALC=1;
# confirm that the flag survives server restart
-- source include/restart_mysqld.inc
SHOW CREATE TABLE test_ps_auto_recalc;
SELECT create_options FROM information_schema.tables
WHERE table_name='test_ps_auto_recalc';
DROP TABLE test_ps_auto_recalc;
##
CREATE TABLE test_ps_auto_recalc (a INT, PRIMARY KEY (a)) ENGINE=INNODB
STATS_AUTO_RECALC=1;
# confirm that the flag survives server restart
-- source include/restart_mysqld.inc
SHOW CREATE TABLE test_ps_auto_recalc;
SELECT create_options FROM information_schema.tables
WHERE table_name='test_ps_auto_recalc';
ALTER TABLE test_ps_auto_recalc STATS_AUTO_RECALC=0;
# confirm that the flag survives server restart
-- source include/restart_mysqld.inc
SHOW CREATE TABLE test_ps_auto_recalc;
SELECT create_options FROM information_schema.tables
WHERE table_name='test_ps_auto_recalc';
DROP TABLE test_ps_auto_recalc;

View file

@ -0,0 +1,103 @@
#
# Test CREATE TABLE ... STATS_SAMPLE_PAGES=N|default
#
-- source include/have_innodb.inc
# include/restart_mysqld.inc does not work in embedded mode
-- source include/not_embedded.inc
-- vertical_results
CREATE TABLE test_ps_sample_pages (a INT, PRIMARY KEY (a)) ENGINE=INNODB;
SHOW CREATE TABLE test_ps_sample_pages;
SELECT create_options FROM information_schema.tables
WHERE table_name='test_ps_sample_pages';
ALTER TABLE test_ps_sample_pages STATS_SAMPLE_PAGES=12345;
# confirm that the flag survives server restart
-- source include/restart_mysqld.inc
SHOW CREATE TABLE test_ps_sample_pages;
SELECT create_options FROM information_schema.tables
WHERE table_name='test_ps_sample_pages';
DROP TABLE test_ps_sample_pages;
##
CREATE TABLE test_ps_sample_pages (a INT, PRIMARY KEY (a)) ENGINE=INNODB
STATS_SAMPLE_PAGES=default;
SHOW CREATE TABLE test_ps_sample_pages;
SELECT create_options FROM information_schema.tables
WHERE table_name='test_ps_sample_pages';
DROP TABLE test_ps_sample_pages;
##
-- error ER_PARSE_ERROR
CREATE TABLE test_ps_sample_pages (a INT, PRIMARY KEY (a)) ENGINE=INNODB
STATS_SAMPLE_PAGES=-5;
-- error ER_PARSE_ERROR
CREATE TABLE test_ps_sample_pages (a INT, PRIMARY KEY (a)) ENGINE=INNODB
STATS_SAMPLE_PAGES=0;
-- error ER_PARSE_ERROR
CREATE TABLE test_ps_sample_pages (a INT, PRIMARY KEY (a)) ENGINE=INNODB
STATS_SAMPLE_PAGES=67000;
-- error ER_PARSE_ERROR
CREATE TABLE test_ps_sample_pages (a INT, PRIMARY KEY (a)) ENGINE=INNODB
STATS_SAMPLE_PAGES=670000;
-- error ER_PARSE_ERROR
CREATE TABLE test_ps_sample_pages (a INT, PRIMARY KEY (a)) ENGINE=INNODB
STATS_SAMPLE_PAGES=65536;
CREATE TABLE test_ps_sample_pages (a INT, PRIMARY KEY (a)) ENGINE=INNODB
STATS_SAMPLE_PAGES=65535;
SHOW CREATE TABLE test_ps_sample_pages;
DROP TABLE test_ps_sample_pages;
##
CREATE TABLE test_ps_sample_pages (a INT, PRIMARY KEY (a)) ENGINE=INNODB
STATS_SAMPLE_PAGES=1;
# confirm that the flag survives server restart
-- source include/restart_mysqld.inc
SHOW CREATE TABLE test_ps_sample_pages;
SELECT create_options FROM information_schema.tables
WHERE table_name='test_ps_sample_pages';
DROP TABLE test_ps_sample_pages;
##
CREATE TABLE test_ps_sample_pages (a INT, PRIMARY KEY (a)) ENGINE=INNODB
STATS_SAMPLE_PAGES=5678;
# confirm that the flag survives server restart
-- source include/restart_mysqld.inc
SHOW CREATE TABLE test_ps_sample_pages;
SELECT create_options FROM information_schema.tables
WHERE table_name='test_ps_sample_pages';
ALTER TABLE test_ps_sample_pages STATS_SAMPLE_PAGES=default;
# confirm that the flag survives server restart
-- source include/restart_mysqld.inc
SHOW CREATE TABLE test_ps_sample_pages;
SELECT create_options FROM information_schema.tables
WHERE table_name='test_ps_sample_pages';
DROP TABLE test_ps_sample_pages;

View file

@ -0,0 +1,17 @@
#
# Test ut_format_name()
#
-- source include/have_debug.inc
-- source include/have_innodb.inc
CREATE TABLE t (c INT) ENGINE=INNODB;
# This will invoke test_ut_format_name() in debug builds
SET @save_dbug = @@debug_dbug;
SET debug_dbug = '+d,test_ut_format_name';
DROP TABLE t;
SET debug_dbug = @save_dbug;

View file

@ -0,0 +1,432 @@
#
# Test btr_estimate_n_rows_in_range() which is used by
# ha_innobase::records_in_range()
#
-- source include/have_debug.inc
-- source include/have_innodb.inc
-- source include/innodb_page_size_small.inc
CREATE TABLE records_in_range_test (
c1 VARCHAR(16),
c2 VARCHAR(512),
PRIMARY KEY (c1)
) ENGINE=INNODB STATS_PERSISTENT=1;
# Insert some records so that they cannot fit in one page for some page sizes
# in order to exercise records_in_range() where 1, 2 or more pages are sampled
INSERT INTO records_in_range_test VALUES
('ccc', REPEAT('v', 512)),
('kkk01', REPEAT('v', 512)),
('kkk02', REPEAT('v', 512)),
('kkk03', REPEAT('v', 512)),
('kkk04', REPEAT('v', 512)),
('kkk05', REPEAT('v', 512)),
('kkk06', REPEAT('v', 512)),
('kkk07', REPEAT('v', 512)),
('kkk08', REPEAT('v', 512)),
('mmm', REPEAT('v', 512)),
('nnn', REPEAT('v', 512)),
('uuu01', REPEAT('v', 512)),
('uuu02', REPEAT('v', 512)),
('uuu03', REPEAT('v', 512)),
('uuu04', REPEAT('v', 512)),
('uuu05', REPEAT('v', 512)),
('uuu06', REPEAT('v', 512)),
('uuu07', REPEAT('v', 512)),
('uuu08', REPEAT('v', 512)),
('xxx', REPEAT('v', 512));
SET STATEMENT use_stat_tables=never FOR
ANALYZE TABLE records_in_range_test;
# 16k or bigger page size: 1 leaf page
# 8k page size: 2 leaf pages
# 4k page size: 4 leaf pages
SELECT index_name, stat_name, stat_value
FROM mysql.innodb_index_stats
WHERE
table_name='records_in_range_test' AND stat_name = 'n_leaf_pages';
# 16k or bigger page size: 1 page in total (leaf + nonleaf)
# 8k page size: 3 pages in total (leaf + nonleaf)
# 4k page size: 5 pages in total (leaf + nonleaf)
SELECT index_name, stat_name, stat_value
FROM mysql.innodb_index_stats
WHERE
table_name='records_in_range_test' AND stat_name = 'size';
# We exploit the warning mechanism here to display the return value from
# btr_estimate_n_rows_in_range()
SET @save_dbug = @@debug_dbug;
SET DEBUG_DBUG='+d,print_btr_estimate_n_rows_in_range_return_value';
-- echo
-- echo In all SELECTs below the number of the records in the range returned
-- echo by COUNT(*) must be the same as the number returned by
-- echo btr_estimate_n_rows_in_range() which can be seen inside the artificial
-- echo warning
-- echo
-- echo Test left-unbounded, right-open intervals
-- echo
SELECT COUNT(*) FROM records_in_range_test WHERE c1 < 'aaa';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 < 'ccc';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 < 'eee';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 < 'mmm';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 < 'nnn';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 < 'qqq';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 < 'xxx';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 < 'zzz';
-- echo
-- echo Test left-unbounded, right-closed intervals
-- echo
SELECT COUNT(*) FROM records_in_range_test WHERE c1 <= 'aaa';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 <= 'ccc';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 <= 'eee';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 <= 'mmm';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 <= 'nnn';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 <= 'qqq';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 <= 'xxx';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 <= 'zzz';
-- echo
-- echo Test left-open, right-unbounded intervals
-- echo
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'aaa';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'ccc';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'eee';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'mmm';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'nnn';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'qqq';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'xxx';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'zzz';
-- echo
-- echo Test left-closed, right-unbounded intervals
-- echo
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'aaa';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'ccc';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'eee';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'mmm';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'nnn';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'qqq';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'xxx';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'zzz';
-- echo
-- echo Test left-open, right-open intervals
-- echo In some cases here the optimizer is smart enough not to call
-- echo ha_innobase::records_in_range() at all, so we get no warning containing
-- echo the value returned from btr_estimate_n_rows_in_range()
-- echo
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'aaa' AND c1 < 'bbb';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'aaa' AND c1 < 'ccc';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'aaa' AND c1 < 'eee';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'aaa' AND c1 < 'mmm';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'aaa' AND c1 < 'nnn';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'aaa' AND c1 < 'qqq';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'aaa' AND c1 < 'xxx';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'aaa' AND c1 < 'zzz';
-- echo
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'ccc' AND c1 < 'bbb';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'ccc' AND c1 < 'ccc';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'ccc' AND c1 < 'eee';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'ccc' AND c1 < 'mmm';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'ccc' AND c1 < 'nnn';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'ccc' AND c1 < 'qqq';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'ccc' AND c1 < 'xxx';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'ccc' AND c1 < 'zzz';
-- echo
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'eee' AND c1 < 'bbb';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'eee' AND c1 < 'ccc';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'eee' AND c1 < 'eee';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'eee' AND c1 < 'mmm';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'eee' AND c1 < 'nnn';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'eee' AND c1 < 'qqq';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'eee' AND c1 < 'xxx';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'eee' AND c1 < 'zzz';
-- echo
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'mmm' AND c1 < 'bbb';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'mmm' AND c1 < 'ccc';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'mmm' AND c1 < 'eee';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'mmm' AND c1 < 'mmm';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'mmm' AND c1 < 'nnn';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'mmm' AND c1 < 'qqq';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'mmm' AND c1 < 'xxx';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'mmm' AND c1 < 'zzz';
-- echo
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'nnn' AND c1 < 'bbb';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'nnn' AND c1 < 'ccc';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'nnn' AND c1 < 'eee';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'nnn' AND c1 < 'mmm';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'nnn' AND c1 < 'nnn';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'nnn' AND c1 < 'qqq';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'nnn' AND c1 < 'xxx';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'nnn' AND c1 < 'zzz';
-- echo
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'qqq' AND c1 < 'bbb';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'qqq' AND c1 < 'ccc';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'qqq' AND c1 < 'eee';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'qqq' AND c1 < 'mmm';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'qqq' AND c1 < 'nnn';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'qqq' AND c1 < 'qqq';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'qqq' AND c1 < 'xxx';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'qqq' AND c1 < 'zzz';
-- echo
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'xxx' AND c1 < 'bbb';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'xxx' AND c1 < 'ccc';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'xxx' AND c1 < 'eee';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'xxx' AND c1 < 'mmm';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'xxx' AND c1 < 'nnn';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'xxx' AND c1 < 'qqq';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'xxx' AND c1 < 'xxx';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'xxx' AND c1 < 'zzz';
-- echo
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'zzz' AND c1 < 'bbb';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'zzz' AND c1 < 'ccc';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'zzz' AND c1 < 'eee';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'zzz' AND c1 < 'mmm';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'zzz' AND c1 < 'nnn';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'zzz' AND c1 < 'qqq';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'zzz' AND c1 < 'xxx';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'zzz' AND c1 < 'zzz';
-- echo
-- echo Test left-closed, right-open intervals
-- echo In some cases here the optimizer is smart enough not to call
-- echo ha_innobase::records_in_range() at all, so we get no warning containing
-- echo the value returned from btr_estimate_n_rows_in_range()
-- echo
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'aaa' AND c1 < 'bbb';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'aaa' AND c1 < 'ccc';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'aaa' AND c1 < 'eee';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'aaa' AND c1 < 'mmm';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'aaa' AND c1 < 'nnn';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'aaa' AND c1 < 'qqq';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'aaa' AND c1 < 'xxx';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'aaa' AND c1 < 'zzz';
-- echo
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'ccc' AND c1 < 'bbb';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'ccc' AND c1 < 'ccc';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'ccc' AND c1 < 'eee';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'ccc' AND c1 < 'mmm';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'ccc' AND c1 < 'nnn';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'ccc' AND c1 < 'qqq';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'ccc' AND c1 < 'xxx';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'ccc' AND c1 < 'zzz';
-- echo
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'eee' AND c1 < 'bbb';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'eee' AND c1 < 'ccc';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'eee' AND c1 < 'eee';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'eee' AND c1 < 'mmm';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'eee' AND c1 < 'nnn';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'eee' AND c1 < 'qqq';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'eee' AND c1 < 'xxx';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'eee' AND c1 < 'zzz';
-- echo
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'mmm' AND c1 < 'bbb';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'mmm' AND c1 < 'ccc';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'mmm' AND c1 < 'eee';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'mmm' AND c1 < 'mmm';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'mmm' AND c1 < 'nnn';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'mmm' AND c1 < 'qqq';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'mmm' AND c1 < 'xxx';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'mmm' AND c1 < 'zzz';
-- echo
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'nnn' AND c1 < 'bbb';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'nnn' AND c1 < 'ccc';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'nnn' AND c1 < 'eee';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'nnn' AND c1 < 'mmm';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'nnn' AND c1 < 'nnn';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'nnn' AND c1 < 'qqq';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'nnn' AND c1 < 'xxx';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'nnn' AND c1 < 'zzz';
-- echo
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'qqq' AND c1 < 'bbb';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'qqq' AND c1 < 'ccc';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'qqq' AND c1 < 'eee';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'qqq' AND c1 < 'mmm';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'qqq' AND c1 < 'nnn';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'qqq' AND c1 < 'qqq';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'qqq' AND c1 < 'xxx';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'qqq' AND c1 < 'zzz';
-- echo
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'xxx' AND c1 < 'bbb';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'xxx' AND c1 < 'ccc';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'xxx' AND c1 < 'eee';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'xxx' AND c1 < 'mmm';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'xxx' AND c1 < 'nnn';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'xxx' AND c1 < 'qqq';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'xxx' AND c1 < 'xxx';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'xxx' AND c1 < 'zzz';
-- echo
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'zzz' AND c1 < 'bbb';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'zzz' AND c1 < 'ccc';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'zzz' AND c1 < 'eee';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'zzz' AND c1 < 'mmm';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'zzz' AND c1 < 'nnn';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'zzz' AND c1 < 'qqq';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'zzz' AND c1 < 'xxx';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'zzz' AND c1 < 'zzz';
-- echo
-- echo Test left-open, right-closed intervals
-- echo In some cases here the optimizer is smart enough not to call
-- echo ha_innobase::records_in_range() at all, so we get no warning containing
-- echo the value returned from btr_estimate_n_rows_in_range()
-- echo
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'aaa' AND c1 <= 'bbb';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'aaa' AND c1 <= 'ccc';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'aaa' AND c1 <= 'eee';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'aaa' AND c1 <= 'mmm';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'aaa' AND c1 <= 'nnn';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'aaa' AND c1 <= 'qqq';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'aaa' AND c1 <= 'xxx';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'aaa' AND c1 <= 'zzz';
-- echo
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'ccc' AND c1 <= 'bbb';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'ccc' AND c1 <= 'ccc';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'ccc' AND c1 <= 'eee';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'ccc' AND c1 <= 'mmm';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'ccc' AND c1 <= 'nnn';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'ccc' AND c1 <= 'qqq';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'ccc' AND c1 <= 'xxx';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'ccc' AND c1 <= 'zzz';
-- echo
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'eee' AND c1 <= 'bbb';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'eee' AND c1 <= 'ccc';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'eee' AND c1 <= 'eee';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'eee' AND c1 <= 'mmm';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'eee' AND c1 <= 'nnn';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'eee' AND c1 <= 'qqq';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'eee' AND c1 <= 'xxx';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'eee' AND c1 <= 'zzz';
-- echo
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'mmm' AND c1 <= 'bbb';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'mmm' AND c1 <= 'ccc';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'mmm' AND c1 <= 'eee';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'mmm' AND c1 <= 'mmm';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'mmm' AND c1 <= 'nnn';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'mmm' AND c1 <= 'qqq';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'mmm' AND c1 <= 'xxx';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'mmm' AND c1 <= 'zzz';
-- echo
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'nnn' AND c1 <= 'bbb';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'nnn' AND c1 <= 'ccc';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'nnn' AND c1 <= 'eee';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'nnn' AND c1 <= 'mmm';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'nnn' AND c1 <= 'nnn';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'nnn' AND c1 <= 'qqq';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'nnn' AND c1 <= 'xxx';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'nnn' AND c1 <= 'zzz';
-- echo
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'qqq' AND c1 <= 'bbb';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'qqq' AND c1 <= 'ccc';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'qqq' AND c1 <= 'eee';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'qqq' AND c1 <= 'mmm';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'qqq' AND c1 <= 'nnn';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'qqq' AND c1 <= 'qqq';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'qqq' AND c1 <= 'xxx';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'qqq' AND c1 <= 'zzz';
-- echo
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'xxx' AND c1 <= 'bbb';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'xxx' AND c1 <= 'ccc';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'xxx' AND c1 <= 'eee';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'xxx' AND c1 <= 'mmm';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'xxx' AND c1 <= 'nnn';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'xxx' AND c1 <= 'qqq';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'xxx' AND c1 <= 'xxx';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'xxx' AND c1 <= 'zzz';
-- echo
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'zzz' AND c1 <= 'bbb';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'zzz' AND c1 <= 'ccc';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'zzz' AND c1 <= 'eee';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'zzz' AND c1 <= 'mmm';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'zzz' AND c1 <= 'nnn';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'zzz' AND c1 <= 'qqq';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'zzz' AND c1 <= 'xxx';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 > 'zzz' AND c1 <= 'zzz';
-- echo
-- echo Test left-closed, right-closed intervals
-- echo In some cases here the optimizer is smart enough not to call
-- echo ha_innobase::records_in_range() at all, so we get no warning containing
-- echo the value returned from btr_estimate_n_rows_in_range()
-- echo
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'aaa' AND c1 <= 'bbb';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'aaa' AND c1 <= 'ccc';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'aaa' AND c1 <= 'eee';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'aaa' AND c1 <= 'mmm';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'aaa' AND c1 <= 'nnn';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'aaa' AND c1 <= 'qqq';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'aaa' AND c1 <= 'xxx';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'aaa' AND c1 <= 'zzz';
-- echo
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'ccc' AND c1 <= 'bbb';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'ccc' AND c1 <= 'ccc';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'ccc' AND c1 <= 'eee';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'ccc' AND c1 <= 'mmm';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'ccc' AND c1 <= 'nnn';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'ccc' AND c1 <= 'qqq';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'ccc' AND c1 <= 'xxx';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'ccc' AND c1 <= 'zzz';
-- echo
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'eee' AND c1 <= 'bbb';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'eee' AND c1 <= 'ccc';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'eee' AND c1 <= 'eee';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'eee' AND c1 <= 'mmm';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'eee' AND c1 <= 'nnn';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'eee' AND c1 <= 'qqq';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'eee' AND c1 <= 'xxx';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'eee' AND c1 <= 'zzz';
-- echo
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'mmm' AND c1 <= 'bbb';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'mmm' AND c1 <= 'ccc';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'mmm' AND c1 <= 'eee';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'mmm' AND c1 <= 'mmm';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'mmm' AND c1 <= 'nnn';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'mmm' AND c1 <= 'qqq';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'mmm' AND c1 <= 'xxx';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'mmm' AND c1 <= 'zzz';
-- echo
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'nnn' AND c1 <= 'bbb';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'nnn' AND c1 <= 'ccc';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'nnn' AND c1 <= 'eee';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'nnn' AND c1 <= 'mmm';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'nnn' AND c1 <= 'nnn';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'nnn' AND c1 <= 'qqq';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'nnn' AND c1 <= 'xxx';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'nnn' AND c1 <= 'zzz';
-- echo
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'qqq' AND c1 <= 'bbb';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'qqq' AND c1 <= 'ccc';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'qqq' AND c1 <= 'eee';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'qqq' AND c1 <= 'mmm';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'qqq' AND c1 <= 'nnn';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'qqq' AND c1 <= 'qqq';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'qqq' AND c1 <= 'xxx';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'qqq' AND c1 <= 'zzz';
-- echo
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'xxx' AND c1 <= 'bbb';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'xxx' AND c1 <= 'ccc';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'xxx' AND c1 <= 'eee';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'xxx' AND c1 <= 'mmm';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'xxx' AND c1 <= 'nnn';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'xxx' AND c1 <= 'qqq';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'xxx' AND c1 <= 'xxx';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'xxx' AND c1 <= 'zzz';
-- echo
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'zzz' AND c1 <= 'bbb';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'zzz' AND c1 <= 'ccc';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'zzz' AND c1 <= 'eee';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'zzz' AND c1 <= 'mmm';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'zzz' AND c1 <= 'nnn';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'zzz' AND c1 <= 'qqq';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'zzz' AND c1 <= 'xxx';
SELECT COUNT(*) FROM records_in_range_test WHERE c1 >= 'zzz' AND c1 <= 'zzz';
SET DEBUG_DBUG = @save_dbug;
DROP TABLE records_in_range_test;

View file

@ -0,0 +1,2 @@
--innodb-sys-tablespaces
--innodb-sys-datafiles

View file

@ -0,0 +1,164 @@
--echo #
--echo # Test the limits of a file-per-table tablespace name. MySQL combines
--echo # the database name with the table name to make a unique table name.
--echo #
--source include/have_innodb.inc
--source include/not_windows.inc
# This will test the limit of a filename in MySQL at 512 bytes.
# We control that by making it a relative path starting with "./".
# The embedded server uses an absolute path as the datadir
# which has a non-deterministic length.
--source include/not_embedded.inc
SET default_storage_engine=InnoDB;
LET $MYSQLD_DATADIR = `select @@datadir`;
--echo #
--echo # MySQL limits each database and tablename identifier to 64 characters
--echo # of up to 3 bytes per character, corresponding to 192 bytes.
--echo #
LET $too_long_name = this_sixty_five_byte_name_is_too_long____________________________;
--error ER_WRONG_DB_NAME
--eval CREATE DATABASE `$too_long_name`
LET $long_name = this_sixty_four_byte_name_is_not_too_long_______________________;
--eval CREATE DATABASE `$long_name`
--eval USE `$long_name`
--echo #
--echo # A 64 character tablename can be created in a 64 character database name
--echo #
--eval CREATE TABLE `$long_name`.`$long_name` (a SERIAL)
--echo #
--echo # A 65 character tablename is too long.
--echo #
--error ER_WRONG_TABLE_NAME
--eval CREATE TABLE `test`.`$too_long_name` (a SERIAL)
--error ER_WRONG_TABLE_NAME
--eval CREATE TABLE `$long_name`.`$too_long_name` (a SERIAL)
--echo #
--echo # Non-non-filename-safe characters like '#' are expanded to '@0023'.
--echo # On many file systems, such as Linux extfs, you can create a database name
--echo # that expands to up to 255 bytes long.
--echo # `##################################################_long` is expanded to
--echo # (50 * 5) + 5 = 255.
--echo #
LET $long_db_name = ##################################################_long;
--eval CREATE DATABASE `$long_db_name`;
--eval USE `$long_db_name`
--echo #
--echo # This 256-byte name is only one byte longer but fails with an error code
--echo # from the stat operation.
--echo # `##################################################_long_` is expanded to
--echo # (50 * 5) + 6 = 256.
--echo #
--replace_regex /Errcode: [0-9]+/Errcode: ##/ /@0023/#/
--error 13
CREATE DATABASE `##################################################_long_`;
--echo #
--echo # This 300-byte name which is the longest name that gets an error code
--echo # from the stat operation.
--echo # `###########################################################_long` is expanded to
--echo # (59 * 5) + 5 = 300.
--echo #
--replace_regex /Errcode: [0-9]+/Errcode: ##/ /@0023/#/
--error 13
CREATE DATABASE `###########################################################_long`;
--echo #
--echo # This 301-byte name which is only one byte longer but fails with ER_TOO_LONG_IDENT.
--echo # `###########################################################_long_` is expanded to
--echo # (59 * 5) + 6 = 301.
--echo #
--replace_result @0023 #
--error ER_WRONG_DB_NAME
CREATE DATABASE `###########################################################_long_`;
USE test;
LET $long_249_byte_table_name = #################################################long;
LET $long_250_byte_table_name = #################################################_long;
LET $long_251_byte_table_name = #################################################_long_;
LET $long_252_byte_table_name = #################################################_long___;
--echo #
--echo # An expanded table name is limited to 251 bytes
--echo #
--eval CREATE TABLE `test`.`$long_251_byte_table_name` (a SERIAL)
--echo #
--echo # A 252-byte tablename is too long
--echo #
--replace_regex /errno: [0-9]+/errno: ##/ /@0023/#/
--error ER_CANT_CREATE_TABLE
--eval CREATE TABLE `test`.`$long_252_byte_table_name` (a SERIAL)
CREATE DATABASE twenty_byte_db_name_;
USE `twenty_byte_db_name_`;
--echo #
--echo # A 251 byte expanded table name will fit with a longer database name
--echo #
--eval CREATE TABLE `twenty_byte_db_name_`.`$long_251_byte_table_name` (a SERIAL)
--echo #
--echo # A 252 byte expanded table name is also too long in a longer database name
--echo #
--replace_regex /errno: [0-9]+/errno: ##/ /@0023/#/
--error ER_CANT_CREATE_TABLE
--eval CREATE TABLE `twenty_byte_db_name_`.`$long_252_byte_table_name` (a SERIAL)
--echo #
--echo # Another limitation is a 512 byte length to an expanded path that includes
--echo # the datadir which is './' in this test, the expanded database name,
--echo # the directory separator '/', the expanded table name, and the file extension.
--echo # './long_db_name.long_250_byte_table_name.frm'
--echo # 2+ 255 +1+ 250 +1+3 = 512
--echo #
--eval CREATE TABLE `$long_db_name`.`$long_250_byte_table_name` (a SERIAL)
--error ER_IDENT_CAUSES_TOO_LONG_PATH
--eval CREATE TABLE `$long_db_name`.`$long_251_byte_table_name` (a SERIAL)
SHOW WARNINGS;
--echo #
--echo # Show the successfully created databases and tables
--echo #
--echo ---- list_files MYSQLD_DATADIR/test
--replace_result @0023 #
--list_files $MYSQLD_DATADIR/test
--echo ---- list_files MYSQLD_DATADIR/$long_name
--replace_result @0023 #
--list_files $MYSQLD_DATADIR/$long_name
--echo ---- list_files MYSQLD_DATADIR/$long_db_name
--replace_result @0023 #
--list_files $MYSQLD_DATADIR/@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023_long
--replace_result @0023 #
SELECT name FROM information_schema.innodb_sys_tables WHERE name LIKE '%long%';
--replace_result @0023 #
SELECT name FROM information_schema.innodb_sys_tablespaces WHERE name LIKE '%long%';
--replace_result $MYSQLD_DATADIR MYSQLD_DATADIR @0023 #
SELECT path FROM information_schema.innodb_sys_datafiles WHERE path LIKE '%long%';
--vertical_results
--replace_regex /innodb_file_per_table_[0-9]*/innodb_file_per_table_##/
--replace_result $MYSQLD_DATADIR MYSQLD_DATADIR @0023 #
SELECT file_name, tablespace_name FROM information_schema.files WHERE file_name LIKE '%long%';
--horizontal_results
--echo #
--echo # Cleanup
--echo #
--eval DROP TABLE `$long_name`.`$long_name`
--eval DROP TABLE `test`.`$long_251_byte_table_name`
--eval DROP TABLE `twenty_byte_db_name_`.`$long_251_byte_table_name`
--eval DROP TABLE `$long_db_name`.`$long_250_byte_table_name`
--eval DROP DATABASE `$long_name`
--eval DROP DATABASE `$long_db_name`
DROP DATABASE `twenty_byte_db_name_`;

View file

@ -0,0 +1,2 @@
--innodb-sys-tablespaces
--innodb-sys-datafiles

View file

@ -0,0 +1,79 @@
--echo #
--echo # Test the limits of a file-per-table tablespace name. MySQL combines
--echo # the database name with the table name to make a unique table name.
--echo #
# There is no use in testing the maximum expanded filename using "#" or
# some other character that is expanded by MySQL to "@0023" because
# Windows imposes a maximum absolute path length of 260 bytes. So the
# results will depend upon what local directory this test is run in.
# See https://msdn.microsoft.com/en-us/library/aa365247.aspx
# "Maximum Path Length Limitation
# In the Windows API, the maximum length for a path is MAX_PATH, which is
# defined as 260 characters. A local path is structured in the following
# order: drive letter, colon, backslash, name components separated by
# backslashes, and a terminating null character. For example, the maximum
# path on drive D is "D:\some 256-character path string<NUL>" where
# "<NUL>" represents the invisible terminating null character for the
# current system codepage. (The characters < > are used here for visual
# clarity and cannot be part of a valid path string.)"
--source include/have_innodb.inc
--source include/windows.inc
# This will test the limit of a filename in MySQL at 512 bytes.
# We control that by making it a relative path starting with "./".
# The embedded server uses an absolute path as the datadir
# which has a non-deterministic length.
--source include/not_embedded.inc
SET default_storage_engine=InnoDB;
LET $MYSQLD_DATADIR = `select @@datadir`;
--echo #
--echo # MySQL limits each database and tablename identifier to 64 characters
--echo # of up to 3 bytes per character, corresponding to 192 bytes.
--echo #
LET $too_long_name = this_sixty_five_byte_name_is_too_long____________________________;
--error ER_WRONG_DB_NAME
--eval CREATE DATABASE `$too_long_name`
LET $long_name = this_sixty_four_byte_name_is_not_too_long_______________________;
--eval CREATE DATABASE `$long_name`
--eval USE `$long_name`
--echo #
--echo # A 64 character tablename can be created in a 64 character database name
--echo #
--eval CREATE TABLE `$long_name`.`$long_name` (a SERIAL)
--echo #
--echo # A 65 character tablename is too long.
--echo #
--error ER_WRONG_TABLE_NAME
--eval CREATE TABLE `test`.`$too_long_name` (a SERIAL)
--error ER_WRONG_TABLE_NAME
--eval CREATE TABLE `$long_name`.`$too_long_name` (a SERIAL)
--echo #
--echo # Show the successfully created database and table
--echo #
--eval SHOW CREATE TABLE `$long_name`.`$long_name`
--echo ---- list_files MYSQLD_DATADIR/$long_name
--list_files $MYSQLD_DATADIR/$long_name
SELECT name FROM information_schema.innodb_sys_tables WHERE name LIKE '%long%';
SELECT name FROM information_schema.innodb_sys_tablespaces WHERE name LIKE '%long%';
--replace_result $MYSQLD_DATADIR MYSQLD_DATADIR
SELECT path FROM information_schema.innodb_sys_datafiles WHERE path LIKE '%long%';
--vertical_results
--replace_regex /innodb_file_per_table_[0-9]*/innodb_file_per_table_##/
--replace_result $MYSQLD_DATADIR MYSQLD_DATADIR
SELECT file_name, tablespace_name FROM information_schema.files WHERE file_name LIKE '%long%';
--horizontal_results
--echo #
--echo # Cleanup
--echo #
--eval DROP DATABASE `$long_name`

View file

@ -0,0 +1,27 @@
CREATE TABLE t1 (
id INT NOT NULL,
title TEXT,
PRIMARY KEY (id),
FULLTEXT KEY (title),
FOREIGN KEY (id) REFERENCES t2 (id)
) ENGINE=InnoDB;
ERROR HY000: Can't create table `test`.`t1` (errno: 150 "Foreign key constraint is incorrectly formed")
CREATE TABLE t1 (
id INT NOT NULL,
title TEXT,
PRIMARY KEY (id)
) ENGINE=InnoDB;
ALTER TABLE t1 ADD FULLTEXT KEY (title), ADD FOREIGN KEY (id) REFERENCES t2 (id);
ERROR HY000: Can't create table `test`.`t1` (errno: 150 "Foreign key constraint is incorrectly formed")
SET FOREIGN_KEY_CHECKS = 0;
ALTER TABLE t1 ADD FULLTEXT KEY (title), ADD FOREIGN KEY (id) REFERENCES t2 (id);
DROP TABLE t1;
CREATE TABLE t1 (
id INT NOT NULL,
title TEXT,
PRIMARY KEY (id),
FULLTEXT KEY (title),
FOREIGN KEY (id) REFERENCES t2 (id)
) ENGINE=InnoDB;
DROP TABLE t1;
SET FOREIGN_KEY_CHECKS = 1;

View file

@ -0,0 +1,34 @@
CREATE TABLE t1 (
a varchar(40),
KEY a(a)
) ENGINE=InnoDB;
CREATE TABLE t1_fk (
a varchar(40),
KEY a(a),
FULLTEXT KEY (a),
CONSTRAINT fk FOREIGN KEY (a) REFERENCES t1 (a) ON UPDATE CASCADE
) ENGINE=InnoDB;
INSERT INTO t1 VALUES('mysql');
INSERT INTO t1_fk VALUES('mysql');
INSERT INTO t1_fk VALUES('mysql');
SELECT * FROM t1_fk;
a
mysql
mysql
SELECT * FROM t1_fk WHERE MATCH(a) AGAINST('mysql');
a
mysql
mysql
UPDATE t1 SET a = 'database' WHERE a = 'mysql';
SELECT * FROM t1_fk;
a
database
database
SELECT * FROM t1_fk WHERE MATCH(a) AGAINST('mysql');
a
SELECT * FROM t1_fk WHERE MATCH(a) AGAINST('database');
a
database
database
DROP TABLE t1_fk;
DROP TABLE t1;

View file

@ -0,0 +1,265 @@
SET @optimize=@@GLOBAL.INNODB_OPTIMIZE_FULLTEXT_ONLY;
SET GLOBAL INNODB_OPTIMIZE_FULLTEXT_ONLY=1;
CREATE TABLE articles (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
title VARCHAR(200),
content TEXT
) ENGINE= InnoDB;
CREATE FULLTEXT INDEX idx ON articles (title, content);
INSERT INTO articles (title, content) VALUES
('MySQL Tutorial','DBMS stands for MySQL DataBase ...'),
('How To Use MySQL Well','After you went through a ...'),
('Optimizing MySQL','In this tutorial we will show ...'),
('1001 MySQL Tricks','How to use full-text search engine'),
('Go MySQL Tricks','How to use full text search engine');
SET @aux=@@GLOBAL.innodb_ft_aux_table;
SET GLOBAL innodb_ft_aux_table='test/articles';
SELECT * FROM INFORMATION_SCHEMA.INNODB_FT_INDEX_CACHE;
WORD FIRST_DOC_ID LAST_DOC_ID DOC_COUNT DOC_ID POSITION
1001 4 4 1 4 0
after 2 2 1 2 22
database 1 1 1 1 37
dbms 1 1 1 1 15
engine 4 5 2 4 46
engine 4 5 2 5 44
full 4 5 2 4 29
full 4 5 2 5 27
mysql 1 5 5 1 0
mysql 1 5 5 1 31
mysql 1 5 5 2 11
mysql 1 5 5 3 11
mysql 1 5 5 4 5
mysql 1 5 5 5 3
optimizing 3 3 1 3 0
search 4 5 2 4 39
search 4 5 2 5 37
show 3 3 1 3 42
stands 1 1 1 1 20
text 4 5 2 4 34
text 4 5 2 5 32
through 2 2 1 2 37
tricks 4 5 2 4 11
tricks 4 5 2 5 9
tutorial 1 3 2 1 6
tutorial 1 3 2 3 25
use 2 5 3 2 7
use 2 5 3 4 25
use 2 5 3 5 23
well 2 2 1 2 17
went 2 2 1 2 32
you 2 2 1 2 28
OPTIMIZE TABLE articles;
Table Op Msg_type Msg_text
test.articles optimize status OK
SELECT * FROM INFORMATION_SCHEMA.INNODB_FT_INDEX_TABLE;
WORD FIRST_DOC_ID LAST_DOC_ID DOC_COUNT DOC_ID POSITION
1001 4 4 1 4 0
after 2 2 1 2 22
database 1 1 1 1 37
dbms 1 1 1 1 15
engine 4 5 2 4 46
engine 4 5 2 5 44
full 4 5 2 4 29
full 4 5 2 5 27
mysql 1 5 5 1 0
mysql 1 5 5 1 31
mysql 1 5 5 2 11
mysql 1 5 5 3 11
mysql 1 5 5 4 5
mysql 1 5 5 5 3
optimizing 3 3 1 3 0
search 4 5 2 4 39
search 4 5 2 5 37
show 3 3 1 3 42
stands 1 1 1 1 20
text 4 5 2 4 34
text 4 5 2 5 32
through 2 2 1 2 37
tricks 4 5 2 4 11
tricks 4 5 2 5 9
tutorial 1 3 2 1 6
tutorial 1 3 2 3 25
use 2 5 3 2 7
use 2 5 3 4 25
use 2 5 3 5 23
well 2 2 1 2 17
went 2 2 1 2 32
you 2 2 1 2 28
SET @save_dbug=@@debug_dbug;
SET debug_dbug='+d,fts_instrument_result_cache_limit';
SELECT * FROM INFORMATION_SCHEMA.INNODB_FT_INDEX_TABLE;
WORD FIRST_DOC_ID LAST_DOC_ID DOC_COUNT DOC_ID POSITION
1001 4 4 1 4 0
after 2 2 1 2 22
database 1 1 1 1 37
dbms 1 1 1 1 15
engine 4 5 2 4 46
engine 4 5 2 5 44
full 4 5 2 4 29
full 4 5 2 5 27
mysql 1 5 5 1 0
mysql 1 5 5 1 31
mysql 1 5 5 2 11
mysql 1 5 5 3 11
mysql 1 5 5 4 5
mysql 1 5 5 5 3
optimizing 3 3 1 3 0
search 4 5 2 4 39
search 4 5 2 5 37
show 3 3 1 3 42
stands 1 1 1 1 20
text 4 5 2 4 34
text 4 5 2 5 32
through 2 2 1 2 37
tricks 4 5 2 4 11
tricks 4 5 2 5 9
tutorial 1 3 2 1 6
tutorial 1 3 2 3 25
use 2 5 3 2 7
use 2 5 3 4 25
use 2 5 3 5 23
well 2 2 1 2 17
went 2 2 1 2 32
you 2 2 1 2 28
SET debug_dbug=@save_dbug;
DROP TABLE articles;
SET GLOBAL innodb_ft_result_cache_limit=default;
CREATE TABLE articles (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
title VARCHAR(200),
content TEXT
) ENGINE= InnoDB;
CREATE FULLTEXT INDEX idx_t ON articles (title);
CREATE FULLTEXT INDEX idx_c ON articles (content);
INSERT INTO articles (title, content) VALUES
('MySQL Tutorial','DBMS stands for MySQL DataBase ...'),
('How To Use MySQL Well','After you went through a ...'),
('Optimizing MySQL','In this tutorial we will show ...'),
('1001 MySQL Tricks','How to use full-text search engine'),
('Go MySQL Tricks','How to use full text search engine');
SELECT * FROM INFORMATION_SCHEMA.INNODB_FT_INDEX_CACHE;
WORD FIRST_DOC_ID LAST_DOC_ID DOC_COUNT DOC_ID POSITION
SET GLOBAL innodb_ft_aux_table='test/articles';
SELECT * FROM INFORMATION_SCHEMA.INNODB_FT_INDEX_CACHE;
WORD FIRST_DOC_ID LAST_DOC_ID DOC_COUNT DOC_ID POSITION
1001 4 4 1 4 0
mysql 1 5 5 1 0
mysql 1 5 5 2 11
mysql 1 5 5 3 11
mysql 1 5 5 4 5
mysql 1 5 5 5 3
optimizing 3 3 1 3 0
tricks 4 5 2 4 11
tricks 4 5 2 5 9
tutorial 1 1 1 1 6
use 2 2 1 2 7
well 2 2 1 2 17
after 2 2 1 2 0
database 1 1 1 1 22
dbms 1 1 1 1 0
engine 4 5 2 4 28
engine 4 5 2 5 28
full 4 5 2 4 11
full 4 5 2 5 11
mysql 1 1 1 1 16
search 4 5 2 4 21
search 4 5 2 5 21
show 3 3 1 3 25
stands 1 1 1 1 5
text 4 5 2 4 16
text 4 5 2 5 16
through 2 2 1 2 15
tutorial 3 3 1 3 8
use 4 5 2 4 7
use 4 5 2 5 7
went 2 2 1 2 10
you 2 2 1 2 6
OPTIMIZE TABLE articles;
Table Op Msg_type Msg_text
test.articles optimize status OK
SELECT * FROM INFORMATION_SCHEMA.INNODB_FT_INDEX_TABLE;
WORD FIRST_DOC_ID LAST_DOC_ID DOC_COUNT DOC_ID POSITION
1001 4 4 1 4 0
mysql 1 5 5 1 0
mysql 1 5 5 2 11
mysql 1 5 5 3 11
mysql 1 5 5 4 5
mysql 1 5 5 5 3
optimizing 3 3 1 3 0
tricks 4 5 2 4 11
tricks 4 5 2 5 9
tutorial 1 1 1 1 6
use 2 2 1 2 7
well 2 2 1 2 17
after 2 2 1 2 0
database 1 1 1 1 22
dbms 1 1 1 1 0
engine 4 5 2 4 28
engine 4 5 2 5 28
full 4 5 2 4 11
full 4 5 2 5 11
mysql 1 1 1 1 16
search 4 5 2 4 21
search 4 5 2 5 21
show 3 3 1 3 25
stands 1 1 1 1 5
text 4 5 2 4 16
text 4 5 2 5 16
through 2 2 1 2 15
tutorial 3 3 1 3 8
use 4 5 2 4 7
use 4 5 2 5 7
went 2 2 1 2 10
you 2 2 1 2 6
DROP TABLE articles;
SET NAMES utf8;
CREATE TABLE articles (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
title VARCHAR(200)
) ENGINE=InnoDB DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE FULLTEXT INDEX idx ON articles (title);
INSERT INTO articles (title) VALUES
('相亲相爱'),('怜香惜爱'),('充满可爱'),('爱恨交织');
SET GLOBAL innodb_ft_aux_table="test/articles";
SELECT * FROM INFORMATION_SCHEMA.INNODB_FT_INDEX_CACHE;
WORD FIRST_DOC_ID LAST_DOC_ID DOC_COUNT DOC_ID POSITION
充满可爱 3 3 1 3 0
怜香惜爱 2 2 1 2 0
爱恨交织 4 4 1 4 0
相亲相爱 1 1 1 1 0
OPTIMIZE TABLE articles;
Table Op Msg_type Msg_text
test.articles optimize status OK
SELECT * FROM INFORMATION_SCHEMA.INNODB_FT_INDEX_TABLE;
WORD FIRST_DOC_ID LAST_DOC_ID DOC_COUNT DOC_ID POSITION
充满可爱 3 3 1 3 0
怜香惜爱 2 2 1 2 0
爱恨交织 4 4 1 4 0
相亲相爱 1 1 1 1 0
DROP TABLE articles;
CREATE TABLE articles (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
title VARCHAR(200)
) ENGINE=InnoDB DEFAULT CHARACTER SET gb2312 COLLATE gb2312_chinese_ci;
CREATE FULLTEXT INDEX idx ON articles (title);
INSERT INTO articles (title) VALUES
('相亲相爱'),('怜香惜爱'),('充满可爱'),('爱恨交织');
SET GLOBAL innodb_ft_aux_table="test/articles";
SELECT * FROM INFORMATION_SCHEMA.INNODB_FT_INDEX_CACHE;
WORD FIRST_DOC_ID LAST_DOC_ID DOC_COUNT DOC_ID POSITION
爱恨交织 4 4 1 4 0
充满可爱 3 3 1 3 0
怜香惜爱 2 2 1 2 0
相亲相爱 1 1 1 1 0
OPTIMIZE TABLE articles;
Table Op Msg_type Msg_text
test.articles optimize status OK
SELECT * FROM INFORMATION_SCHEMA.INNODB_FT_INDEX_TABLE;
WORD FIRST_DOC_ID LAST_DOC_ID DOC_COUNT DOC_ID POSITION
怜香惜爱 2 2 1 2 0
充满可爱 3 3 1 3 0
相亲相爱 1 1 1 1 0
爱恨交织 4 4 1 4 0
DROP TABLE articles;
SET GLOBAL innodb_ft_aux_table=@aux;
SET GLOBAL INNODB_OPTIMIZE_FULLTEXT_ONLY=@optimize;

View file

@ -134,6 +134,7 @@ count(*)
2
DROP TABLE t1;
set global innodb_file_per_table=1;
set names utf8;
CREATE TABLE t1 (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
a TEXT,
@ -160,7 +161,7 @@ SELECT count(*) FROM t1
WHERE MATCH (a,b,c)
AGAINST ('"very blob"@4' IN BOOLEAN MODE);
count(*)
4
5
SELECT count(*) FROM t1
WHERE MATCH (a,b,c)
AGAINST ('"interesting blob"@9' IN BOOLEAN MODE);
@ -175,7 +176,7 @@ SELECT COUNT(*) FROM t1
WHERE MATCH (a,b,c)
AGAINST ('"very blob"@4 - "interesting blob"@9' IN BOOLEAN MODE);
COUNT(*)
3
4
DROP TABLE t1;
CREATE TABLE t1 (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,

View file

@ -0,0 +1,157 @@
# Bug #22709692 FTS QUERY EXCEEDS RESULT CACHE LIMIT
CREATE TABLE articles (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
title VARCHAR(200),
body TEXT,
FULLTEXT (title,body),
FULLTEXT (body))ENGINE=InnoDB;
INSERT INTO articles (title,body) VALUES
('MySQL Tutorial','DBMS stands for DataBase ...'),
('How To Use MySQL Well','After you went through a ...'),
('Optimizing MySQL','In this tutorial we will show ...'),
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL','In the following database comparison ...'),
('MySQL Security','When configured properly, MySQL ...');
SET @default_cache_size = @@GLOBAL.query_cache_size;
SET GLOBAL query_cache_size=0;
# Query involves Ranking
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('MySQL' IN NATURAL LANGUAGE MODE) LIMIT 1;
id title body
6 MySQL Security When configured properly, MySQL ...
# Without optimization
SET @save_dbug = @@debug_dbug;
SET debug_dbug = '+d,fts_union_limit_off';
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('MySQL' IN NATURAL LANGUAGE MODE) LIMIT 1;
id title body
6 MySQL Security When configured properly, MySQL ...
SET debug_dbug = @save_dbug;
# Query involves No Ranking and fts_union operations
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('MySQL' IN BOOLEAN MODE) limit 1;
id title body
6 MySQL Security When configured properly, MySQL ...
# Without optimization
SET debug_dbug = '+d,fts_union_limit_off';
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('MySQL' IN BOOLEAN MODE) limit 1;
id title body
6 MySQL Security When configured properly, MySQL ...
SET debug_dbug = @save_dbug;
# Query involves No ranking and fts_union, fts_ignore
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('MySQL -YourSQL' IN BOOLEAN MODE) limit 1;
id title body
6 MySQL Security When configured properly, MySQL ...
# Without optimization
SET debug_dbug = '+d,fts_union_limit_off';
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('MySQL -YourSQL' IN BOOLEAN MODE) limit 1;
id title body
6 MySQL Security When configured properly, MySQL ...
SET debug_dbug = @save_dbug;
# Query with fts_intersect
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('MySQL +YourSQL' IN BOOLEAN MODE) limit 1;
id title body
5 MySQL vs. YourSQL In the following database comparison ...
# Without optimization
SET debug_dbug = '+d,fts_union_limit_off';
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('MySQL +YourSQL' IN BOOLEAN MODE) limit 1;
id title body
5 MySQL vs. YourSQL In the following database comparison ...
SET debug_dbug = @save_dbug;
INSERT INTO articles (title,body) VALUES
('MySQL Tutorial','request doc@oraclehelp.com ...'),
('MySQL Tutorial','request support@oraclehelp.com ...'),
('Trial version','query performace @1255 minute on 2.1Hz
Memory 2GB...'),
('when To Use MySQL Well','for free faq mail@xyz.com ...');
# Query with @distance
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('"MySQL request"@3' IN BOOLEAN MODE) limit 1;
id title body
7 MySQL Tutorial request doc@oraclehelp.com ...
# Without optimization
SET debug_dbug = '+d,fts_union_limit_off';
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('"MySQL request"@3' IN BOOLEAN MODE) limit 1;
id title body
7 MySQL Tutorial request doc@oraclehelp.com ...
SET debug_dbug = @save_dbug;
# Query with subexpression
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('+MySQL +(-support +doc)' IN BOOLEAN MODE) limit 1;
id title body
7 MySQL Tutorial request doc@oraclehelp.com ...
# Without optimization
SET debug_dbug = '+d,fts_union_limit_off';
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('+MySQL +(-support +doc)' IN BOOLEAN MODE) limit 1;
id title body
7 MySQL Tutorial request doc@oraclehelp.com ...
SET debug_dbug = @save_dbug;
# limit num1 OFFSET num2
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('MySQL' in boolean mode) limit 4 offset 2;
id title body
2 How To Use MySQL Well After you went through a ...
3 Optimizing MySQL In this tutorial we will show ...
4 1001 MySQL Tricks 1. Never run mysqld as root. 2. ...
5 MySQL vs. YourSQL In the following database comparison ...
# Without optimization
SET debug_dbug = '+d,fts_union_limit_off';
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('MySQL' in boolean mode) limit 4 offset 2;
id title body
2 How To Use MySQL Well After you went through a ...
3 Optimizing MySQL In this tutorial we will show ...
4 1001 MySQL Tricks 1. Never run mysqld as root. 2. ...
5 MySQL vs. YourSQL In the following database comparison ...
SET debug_dbug = @save_dbug;
# wild card search
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('ru*' IN BOOLEAN MODE) limit 1;
id title body
4 1001 MySQL Tricks 1. Never run mysqld as root. 2. ...
# Without optimization
SET debug_dbug = '+d,fts_union_limit_off';
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('ru*' IN BOOLEAN MODE) limit 1;
id title body
4 1001 MySQL Tricks 1. Never run mysqld as root. 2. ...
SET debug_dbug = @save_dbug;
# phrase search
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('"request support"' IN BOOLEAN MODE) limit 1;
id title body
8 MySQL Tutorial request support@oraclehelp.com ...
# Without optimization
SET debug_dbug = '+d,fts_union_limit_off';
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('"request support"' IN BOOLEAN MODE) limit 1;
id title body
8 MySQL Tutorial request support@oraclehelp.com ...
SET debug_dbug = @save_dbug;
DROP TABLE articles;
SET GLOBAL query_cache_size = @default_cache_size;

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,922 @@
set names utf8;
call mtr.add_suppression("\\[Warning\\] InnoDB: A new Doc ID must be supplied while updating FTS indexed columns.");
call mtr.add_suppression("\\[Warning\\] InnoDB: FTS Doc ID must be larger than [0-9]+ for table `test`.`t1`");
CREATE TABLE t1 (
id1 INT ,
a1 VARCHAR(200) ,
b1 TEXT ,
FULLTEXT KEY (a1,b1), PRIMARY KEY (a1, id1)
) CHARACTER SET = utf8 , ENGINE = InnoDB;
CREATE TABLE t2 (
id2 INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
a2 VARCHAR(200),
b2 TEXT ,
FOREIGN KEY (a2) REFERENCES t1(a1) ON UPDATE CASCADE,
FULLTEXT KEY (b2,a2)
) CHARACTER SET = utf8 ,ENGINE = InnoDB;
INSERT INTO t1 (id1,a1,b1) VALUES
(1,'MySQL Tutorial','DBMS stands for DataBase VÐƷWİ...') ,
(2,'How To Use MySQL Well','After you went through a ...'),
(3,'Optimizing MySQL','In this tutorial we will show ...');
INSERT INTO t1 (id1,a1,b1) VALUES
(4,'1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
(5,'MySQL vs. YourSQL','In the following database comparison ...'),
(6,'MySQL Security','When configured properly, MySQL ...');
INSERT INTO t2 (a2,b2) VALUES
('MySQL Tutorial','DBMS stands for DataBase VÐƷWİ...') ,
('How To Use MySQL Well','After you went through a ...'),
('Optimizing MySQL','In this tutorial we will show ...');
INSERT INTO t2 (a2,b2) VALUES
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL','In the following database comparison ...'),
('MySQL Security','When configured properly, MySQL ...');
INSERT INTO t2 (a2,b2) VALUES
('MySQL Tricks','1. Never run mysqld as root. 2. ...');
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a2`) REFERENCES `t1` (`a1`) ON UPDATE CASCADE)
DELETE FROM t1;
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a2`) REFERENCES `t1` (`a1`) ON UPDATE CASCADE)
ANALYZE TABLE t1;
Table Op Msg_type Msg_text
test.t1 analyze status Engine-independent statistics collected
test.t1 analyze Warning Engine-independent statistics are not collected for column 'b1'
test.t1 analyze status OK
ANALYZE TABLE t2;
Table Op Msg_type Msg_text
test.t2 analyze status Engine-independent statistics collected
test.t2 analyze Warning Engine-independent statistics are not collected for column 'b2'
test.t2 analyze status OK
SELECT id1 FROM t1 WHERE MATCH (a1,b1) AGAINST ('tutorial') ORDER BY id1;
id1
1
3
SELECT id2 FROM t2 WHERE MATCH (a2,b2) AGAINST ('tutorial') ORDER BY id2;
id2
1
3
SELECT id1 FROM t1 WHERE MATCH (a1,b1) AGAINST ('tutorial (+mysql -VÐƷWİ)' IN BOOLEAN MODE) ORDER BY id1;
id1
1
2
3
4
5
6
SELECT id2 FROM t2 WHERE MATCH (a2,b2) AGAINST ('tutorial (+mysql -VÐƷWİ)' IN BOOLEAN MODE) ORDER BY id2;
id2
1
2
3
4
5
6
SELECT id1 FROM t1 WHERE MATCH (a1,b1) AGAINST ('tutorial' WITH QUERY EXPANSION) ORDER BY id1;
id1
1
2
3
4
5
6
SELECT id2 FROM t2 WHERE MATCH (a2,b2) AGAINST ('tutorial' WITH QUERY EXPANSION) ORDER BY id2;
id2
1
2
3
4
5
6
SELECT id1 FROM t1 WHERE MATCH (a1,b1) AGAINST ('"dbms database"@4' IN BOOLEAN MODE) ;
id1
1
SELECT id2 FROM t2 WHERE MATCH (a2,b2) AGAINST ('"dbms database"@4' IN BOOLEAN MODE) ;
id2
1
set global innodb_optimize_fulltext_only=1;
optimize table t1;
Table Op Msg_type Msg_text
test.t1 optimize status OK
set global innodb_optimize_fulltext_only=0;
UPDATE t1 SET a1 = "changing column - on update cascade" , b1 = "to check foreign constraint" WHERE
MATCH (a1,b1) AGAINST ('tutorial (+mysql -VÐƷWİ)' IN BOOLEAN MODE) ;
SELECT id1 FROM t1 WHERE MATCH (a1,b1) AGAINST ('tutorial (+mysql -VÐƷWİ)' IN BOOLEAN MODE) ;
id1
SELECT id2 FROM t2 WHERE MATCH (a2,b2) AGAINST ('tutorial (+mysql -VÐƷWİ)' IN BOOLEAN MODE) ;
id2
3
6
SELECT id1 FROM t1 WHERE MATCH (a1,b1) AGAINST ('+update +cascade' IN BOOLEAN MODE) ORDER BY id1;
id1
1
2
3
4
5
6
SELECT id2 FROM t2 WHERE MATCH (a2,b2) AGAINST ('+update +cascade' IN BOOLEAN MODE) ORDER BY id2;
id2
1
2
3
4
5
6
SELECT id2 FROM t2 WHERE a2 LIKE '%UPDATE CASCADE%' ORDER BY id2;
id2
1
2
3
4
5
6
DROP TABLE t2 , t1;
create table t1 (s1 int, s2 varchar(200), primary key (s1,s2)) ENGINE = InnoDB;
create table t2 (s1 int, s2 varchar(200),
fulltext key(s2),
foreign key (s1,s2) references t1 (s1,s2) on update cascade) ENGINE = InnoDB;
insert into t1 values (1,'Sunshine'),(2,'Lollipops');
insert into t2 values (1,'Sunshine'),(2,'Lollipops');
update t1 set s2 = 'Rainbows' where s2 <> 'Sunshine';
commit;
select * from t2 where match(s2) against ('Lollipops');
s1 s2
DROP TABLE t2 , t1;
create table t1 (s1 int, s2 varchar(200), primary key (s1,s2)) ENGINE = InnoDB;
create table t2 (s1 int, s2 varchar(200),
fulltext key(s2),
foreign key (s1,s2) references t1 (s1,s2) on delete cascade) ENGINE = InnoDB;
insert into t1 values (1,'Sunshine'),(2,'Lollipops');
insert into t2 values (1,'Sunshine'),(2,'Lollipops');
delete from t1 where s2 <> 'Sunshine';
select * from t2 where match(s2) against ('Lollipops');
s1 s2
DROP TABLE t2 , t1;
create table t1 (s1 int, s2 varchar(200), primary key (s1,s2)) ENGINE = InnoDB;
create table t2 (s1 int, s2 varchar(200),
fulltext key(s2),
foreign key (s1,s2) references t1 (s1,s2) on delete set null) ENGINE = InnoDB;
insert into t1 values (1,'Sunshine'),(2,'Lollipops');
insert into t2 values (1,'Sunshine'),(2,'Lollipops');
delete from t1 where s2 <> 'Sunshine';
select * from t2 where match(s2) against ('Lollipops');
s1 s2
DROP TABLE t2 , t1;
create table t1 (s1 int, s2 varchar(200), primary key (s1,s2)) ENGINE = InnoDB;
create table t2 (s1 int, s2 varchar(200),
fulltext key(s2),
foreign key (s1,s2) references t1 (s1,s2) on update set null) ENGINE = InnoDB;
insert into t1 values (1,'Sunshine'),(2,'Lollipops');
insert into t2 values (1,'Sunshine'),(2,'Lollipops');
update t1 set s2 = 'Rainbows' where s2 <> 'Sunshine';
commit;
select * from t2 where match(s2) against ('Lollipops');
s1 s2
DROP TABLE t2 , t1;
create table t1 (s1 bigint unsigned not null, s2 varchar(200),
primary key (s1,s2)) ENGINE = InnoDB;
create table t2 (FTS_DOC_ID BIGINT UNSIGNED NOT NULL, s2 varchar(200),
foreign key (FTS_DOC_ID) references t1 (s1)
on update cascade) ENGINE = InnoDB;
create fulltext index idx on t2(s2);
show create table t2;
Table Create Table
t2 CREATE TABLE `t2` (
`FTS_DOC_ID` bigint(20) unsigned NOT NULL,
`s2` varchar(200) DEFAULT NULL,
KEY `FTS_DOC_ID` (`FTS_DOC_ID`),
FULLTEXT KEY `idx` (`s2`),
CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`FTS_DOC_ID`) REFERENCES `t1` (`s1`) ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
insert into t1 values (1,'Sunshine'),(2,'Lollipops');
insert into t2 values (1,'Sunshine'),(2,'Lollipops');
update t1 set s1 = 3 where s1=1;
select * from t2 where match(s2) against ('sunshine');
FTS_DOC_ID s2
3 Sunshine
update t1 set s1 = 1 where s1=3;
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`FTS_DOC_ID`) REFERENCES `t1` (`s1`) ON UPDATE CASCADE)
DROP TABLE t2 , t1;
CREATE TABLE t1 (
id1 INT ,
a1 VARCHAR(200) PRIMARY KEY,
b1 TEXT character set utf8 ,
FULLTEXT KEY (a1,b1)
) CHARACTER SET = utf8 ,ENGINE = InnoDB;
CREATE TABLE t2 (
id2 INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
a2 VARCHAR(200),
b2 TEXT character set utf8 ,
FOREIGN KEY (a2) REFERENCES t1(a1) ON DELETE CASCADE,
FULLTEXT KEY (b2,a2)
) CHARACTER SET = utf8 ,ENGINE = InnoDB;
INSERT INTO t1 (id1,a1,b1) VALUES
(1,'MySQL Tutorial','DBMS stands for DataBase VÐƷWİ...') ,
(2,'How To Use MySQL Well','After you went through a ...'),
(3,'Optimizing MySQL','In this tutorial we will show ...'),
(4,'1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
(5,'MySQL vs. YourSQL','In the following database comparison ...'),
(6,'MySQL Security','When configured properly, MySQL ...');
INSERT INTO t2 (a2,b2) VALUES
('MySQL Tutorial','DBMS stands for DataBase VÐƷWİ...') ,
('How To Use MySQL Well','After you went through a ...'),
('Optimizing MySQL','In this tutorial we will show ...'),
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL','In the following database comparison ...'),
('MySQL Security','When configured properly, MySQL ...');
DELETE FROM t1 WHERE MATCH (a1,b1) AGAINST ('tutorial (+mysql -VÐƷWİ)' IN BOOLEAN MODE) ;
SELECT * FROM t1 WHERE MATCH (a1,b1) AGAINST ('tutorial (+mysql -VÐƷWİ)' IN BOOLEAN MODE) ;
id1 a1 b1
SELECT * FROM t2 WHERE MATCH (a2,b2) AGAINST ('tutorial (+mysql -VÐƷWİ)' IN BOOLEAN MODE) ;
id2 a2 b2
SELECT * FROM t1 WHERE a1 LIKE '%tutorial%';
id1 a1 b1
SELECT * FROM t2 WHERE a2 LIKE '%tutorial%';
id2 a2 b2
DROP TABLE t2 , t1;
call mtr.add_suppression("\\[ERROR\\] InnoDB: FTS Doc ID must be larger than 3 for table `test`.`t2`");
CREATE TABLE t1 (
id1 INT ,
a1 VARCHAR(200) ,
b1 TEXT ,
FULLTEXT KEY (a1,b1), PRIMARY KEY(a1, id1)
) CHARACTER SET = utf8 , ENGINE = InnoDB;
CREATE TABLE t2 (
id2 INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
a2 VARCHAR(200),
b2 TEXT ,
FOREIGN KEY (a2) REFERENCES t1(a1) ON UPDATE CASCADE,
FULLTEXT KEY (b2,a2)
) CHARACTER SET = utf8 ,ENGINE = InnoDB;
INSERT INTO t1 (id1,a1,b1) VALUES
(1,'MySQL Tutorial','DBMS stands for DataBase VÐƷWİ...') ,
(2,'How To Use MySQL Well','After you went through a ...'),
(3,'Optimizing MySQL','In this tutorial we will show ...');
INSERT INTO t2 (a2,b2) VALUES
('MySQL Tutorial','DBMS stands for DataBase VÐƷWİ...') ,
('How To Use MySQL Well','After you went through a ...'),
('Optimizing MySQL','In this tutorial we will show ...');
START TRANSACTION;
INSERT INTO t1 (id1,a1,b1) VALUES
(4,'1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
(5,'MySQL vs. YourSQL','In the following database comparison ...'),
(6,'MySQL Security','When configured properly, MySQL ...');
INSERT INTO t2 (a2,b2) VALUES
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL','In the following database comparison ...'),
('MySQL Security','When configured properly, MySQL ...');
INSERT INTO t2 (a2,b2) VALUES
('MySQL Tricks','1. Never run mysqld as root. 2. ...');
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a2`) REFERENCES `t1` (`a1`) ON UPDATE CASCADE)
DELETE FROM t1;
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a2`) REFERENCES `t1` (`a1`) ON UPDATE CASCADE)
SELECT * FROM t1 WHERE MATCH (a1,b1) AGAINST ('tutorial') ORDER BY id1;
id1 a1 b1
1 MySQL Tutorial DBMS stands for DataBase VÐƷWİ...
3 Optimizing MySQL In this tutorial we will show ...
SELECT * FROM t2 WHERE MATCH (a2,b2) AGAINST ('tutorial') ORDER BY id2;
id2 a2 b2
1 MySQL Tutorial DBMS stands for DataBase VÐƷWİ...
3 Optimizing MySQL In this tutorial we will show ...
SELECT * FROM t1 WHERE MATCH (a1,b1) AGAINST ('tutorial (+mysql -VÐƷWİ)' IN BOOLEAN MODE) ORDER BY id1;
id1 a1 b1
1 MySQL Tutorial DBMS stands for DataBase VÐƷWİ...
2 How To Use MySQL Well After you went through a ...
3 Optimizing MySQL In this tutorial we will show ...
SELECT * FROM t2 WHERE MATCH (a2,b2) AGAINST ('tutorial (+mysql -VÐƷWİ)' IN BOOLEAN MODE) ORDER BY id2;
id2 a2 b2
1 MySQL Tutorial DBMS stands for DataBase VÐƷWİ...
2 How To Use MySQL Well After you went through a ...
3 Optimizing MySQL In this tutorial we will show ...
SELECT * FROM t1 WHERE MATCH (a1,b1) AGAINST ('tutorial' WITH QUERY EXPANSION) ORDER BY id1;
id1 a1 b1
1 MySQL Tutorial DBMS stands for DataBase VÐƷWİ...
2 How To Use MySQL Well After you went through a ...
3 Optimizing MySQL In this tutorial we will show ...
SELECT * FROM t2 WHERE MATCH (a2,b2) AGAINST ('tutorial' WITH QUERY EXPANSION) ORDER BY id2;
id2 a2 b2
1 MySQL Tutorial DBMS stands for DataBase VÐƷWİ...
2 How To Use MySQL Well After you went through a ...
3 Optimizing MySQL In this tutorial we will show ...
SELECT * FROM t1 WHERE MATCH (a1,b1) AGAINST ('"dbms database"@4' IN BOOLEAN MODE) ;
id1 a1 b1
1 MySQL Tutorial DBMS stands for DataBase VÐƷWİ...
SELECT * FROM t2 WHERE MATCH (a2,b2) AGAINST ('"dbms database"@4' IN BOOLEAN MODE) ;
id2 a2 b2
1 MySQL Tutorial DBMS stands for DataBase VÐƷWİ...
SELECT * FROM t1 WHERE MATCH (a1,b1) AGAINST ('root') ;
id1 a1 b1
SELECT * FROM t2 WHERE MATCH (a2,b2) AGAINST ('root') ;
id2 a2 b2
SELECT * FROM t1 WHERE MATCH (a1,b1) AGAINST ('mysqld (+root)' IN BOOLEAN MODE) ;
id1 a1 b1
SELECT * FROM t2 WHERE MATCH (a2,b2) AGAINST ('mysqld (-root)' IN BOOLEAN MODE) ;
id2 a2 b2
SELECT * FROM t1 WHERE MATCH (a1,b1) AGAINST ('root' WITH QUERY EXPANSION) ;
id1 a1 b1
SELECT * FROM t2 WHERE MATCH (a2,b2) AGAINST ('root' WITH QUERY EXPANSION) ;
id2 a2 b2
SELECT * FROM t1 WHERE MATCH (a1,b1) AGAINST ('"database comparison"@02' IN BOOLEAN MODE) ;
id1 a1 b1
SELECT * FROM t2 WHERE MATCH (a2,b2) AGAINST ('"database comparison"@02' IN BOOLEAN MODE) ;
id2 a2 b2
SELECT * FROM t1 ORDER BY id1;
id1 a1 b1
1 MySQL Tutorial DBMS stands for DataBase VÐƷWİ...
2 How To Use MySQL Well After you went through a ...
3 Optimizing MySQL In this tutorial we will show ...
4 1001 MySQL Tricks 1. Never run mysqld as root. 2. ...
5 MySQL vs. YourSQL In the following database comparison ...
6 MySQL Security When configured properly, MySQL ...
SELECT * FROM t2 ORDER BY id2;
id2 a2 b2
1 MySQL Tutorial DBMS stands for DataBase VÐƷWİ...
2 How To Use MySQL Well After you went through a ...
3 Optimizing MySQL In this tutorial we will show ...
4 1001 MySQL Tricks 1. Never run mysqld as root. 2. ...
5 MySQL vs. YourSQL In the following database comparison ...
6 MySQL Security When configured properly, MySQL ...
COMMIT;
START TRANSACTION;
UPDATE t1 SET a1 = "changing column - on UPDATE cascade" , b1 = "to check foreign constraint" WHERE
MATCH (a1,b1) AGAINST ('tutorial (+mysql -VÐƷWİ)' IN BOOLEAN MODE) ;
COMMIT;
SELECT * FROM t1 WHERE MATCH (a1,b1) AGAINST ('tutorial (+mysql -VÐƷWİ)' IN BOOLEAN MODE) ;
id1 a1 b1
SELECT * FROM t2 WHERE MATCH (a2,b2) AGAINST ('tutorial (+mysql -VÐƷWİ)' IN BOOLEAN MODE) ;
id2 a2 b2
3 changing column - on UPDATE cascade In this tutorial we will show ...
6 changing column - on UPDATE cascade When configured properly, MySQL ...
SELECT * FROM t1 WHERE MATCH (a1,b1) AGAINST ('+UPDATE +cascade' IN BOOLEAN MODE) ORDER BY id1;
id1 a1 b1
1 changing column - on UPDATE cascade to check foreign constraint
2 changing column - on UPDATE cascade to check foreign constraint
3 changing column - on UPDATE cascade to check foreign constraint
4 changing column - on UPDATE cascade to check foreign constraint
5 changing column - on UPDATE cascade to check foreign constraint
6 changing column - on UPDATE cascade to check foreign constraint
SELECT * FROM t2 WHERE MATCH (a2,b2) AGAINST ('+UPDATE +cascade' IN BOOLEAN MODE) ORDER BY id2;
id2 a2 b2
1 changing column - on UPDATE cascade DBMS stands for DataBase VÐƷWİ...
2 changing column - on UPDATE cascade After you went through a ...
3 changing column - on UPDATE cascade In this tutorial we will show ...
4 changing column - on UPDATE cascade 1. Never run mysqld as root. 2. ...
5 changing column - on UPDATE cascade In the following database comparison ...
6 changing column - on UPDATE cascade When configured properly, MySQL ...
SELECT * FROM t2 WHERE a2 LIKE '%UPDATE CASCADE%' ORDER BY id2;
id2 a2 b2
1 changing column - on UPDATE cascade DBMS stands for DataBase VÐƷWİ...
2 changing column - on UPDATE cascade After you went through a ...
3 changing column - on UPDATE cascade In this tutorial we will show ...
4 changing column - on UPDATE cascade 1. Never run mysqld as root. 2. ...
5 changing column - on UPDATE cascade In the following database comparison ...
6 changing column - on UPDATE cascade When configured properly, MySQL ...
DROP TABLE t2 , t1;
CREATE TABLE t1 (s1 INT, s2 VARCHAR(200), PRIMARY KEY (s1,s2)) ENGINE = InnoDB;
CREATE TABLE t2 (s1 INT, s2 VARCHAR(200),
FULLTEXT KEY(s2),
FOREIGN KEY (s1,s2) REFERENCES t1 (s1,s2) on UPDATE cascade) ENGINE = InnoDB;
START TRANSACTION;
INSERT INTO t1 VALUES (1,'Sunshine'),(2,'Lollipops');
INSERT INTO t2 VALUES (1,'Sunshine'),(2,'Lollipops');
UPDATE t1 set s2 = 'Rainbows' WHERE s2 <> 'Sunshine';
COMMIT;
SELECT * FROM t2 WHERE MATCH(s2) AGAINST ('Lollipops');
s1 s2
DROP TABLE t2 , t1;
CREATE TABLE t1 (s1 INT, s2 VARCHAR(200), PRIMARY KEY (s1,s2)) ENGINE = InnoDB;
CREATE TABLE t2 (s1 INT, s2 VARCHAR(200),
FULLTEXT KEY(s2),
FOREIGN KEY (s1,s2) REFERENCES t1 (s1,s2) on DELETE cascade) ENGINE = InnoDB;
START TRANSACTION;
INSERT INTO t1 VALUES (1,'Sunshine'),(2,'Lollipops');
INSERT INTO t2 VALUES (1,'Sunshine'),(2,'Lollipops');
DELETE FROM t1 WHERE s2 <> 'Sunshine';
COMMIT;
SELECT * FROM t2 WHERE MATCH(s2) AGAINST ('Lollipops');
s1 s2
DROP TABLE t2 , t1;
CREATE TABLE t1 (s1 INT, s2 VARCHAR(200), PRIMARY KEY (s1,s2)) ENGINE = InnoDB;
CREATE TABLE t2 (s1 INT, s2 VARCHAR(200),
FULLTEXT KEY(s2),
FOREIGN KEY (s1,s2) REFERENCES t1 (s1,s2) on DELETE SET NULL) ENGINE = InnoDB;
START TRANSACTION;
INSERT INTO t1 VALUES (1,'Sunshine'),(2,'Lollipops');
INSERT INTO t2 VALUES (1,'Sunshine'),(2,'Lollipops');
DELETE FROM t1 WHERE s2 <> 'Sunshine';
COMMIT;
SELECT * FROM t2 WHERE MATCH(s2) AGAINST ('Lollipops');
s1 s2
DROP TABLE t2 , t1;
CREATE TABLE t1 (s1 INT, s2 VARCHAR(200), PRIMARY KEY (s1,s2)) ENGINE = InnoDB;
CREATE TABLE t2 (s1 INT, s2 VARCHAR(200),
FULLTEXT KEY(s2),
FOREIGN KEY (s1,s2) REFERENCES t1 (s1,s2) on UPDATE SET NULL) ENGINE = InnoDB;
START TRANSACTION;
INSERT INTO t1 VALUES (1,'Sunshine'),(2,'Lollipops');
INSERT INTO t2 VALUES (1,'Sunshine'),(2,'Lollipops');
UPDATE t1 set s2 = 'Rainbows' WHERE s2 <> 'Sunshine';
COMMIT;
SELECT * FROM t2 WHERE MATCH(s2) AGAINST ('Lollipops');
s1 s2
DROP TABLE t2 , t1;
CREATE TABLE t1 (s1 INT, s2 VARCHAR(200), PRIMARY KEY (s1,s2)) ENGINE = InnoDB;
CREATE TABLE t2 (s1 INT, s2 VARCHAR(200),
FULLTEXT KEY(s2),
FOREIGN KEY (s1,s2) REFERENCES t1 (s1,s2) on UPDATE cascade) ENGINE = InnoDB;
START TRANSACTION;
INSERT INTO t1 VALUES (1,'Sunshine'),(2,'Lollipops');
INSERT INTO t2 VALUES (1,'Sunshine'),(2,'Lollipops');
UPDATE t1 set s2 = 'Rainbows' WHERE s2 <> 'Sunshine';
ROLLBACK;
SELECT * FROM t2 WHERE MATCH(s2) AGAINST ('Lollipops');
s1 s2
DROP TABLE t2 , t1;
CREATE TABLE t1 (s1 INT, s2 VARCHAR(200), PRIMARY KEY (s1,s2)) ENGINE = InnoDB;
CREATE TABLE t2 (s1 INT, s2 VARCHAR(200),
FULLTEXT KEY(s2),
FOREIGN KEY (s1,s2) REFERENCES t1 (s1,s2) on DELETE cascade) ENGINE = InnoDB;
START TRANSACTION;
INSERT INTO t1 VALUES (1,'Sunshine'),(2,'Lollipops');
INSERT INTO t2 VALUES (1,'Sunshine'),(2,'Lollipops');
DELETE FROM t1 WHERE s2 <> 'Sunshine';
ROLLBACK;
SELECT * FROM t2 WHERE MATCH(s2) AGAINST ('Lollipops');
s1 s2
DROP TABLE t2 , t1;
CREATE TABLE t1 (s1 INT, s2 VARCHAR(200), PRIMARY KEY (s1,s2)) ENGINE = InnoDB;
CREATE TABLE t2 (s1 INT, s2 VARCHAR(200),
FULLTEXT KEY(s2),
FOREIGN KEY (s1,s2) REFERENCES t1 (s1,s2) on DELETE SET NULL) ENGINE = InnoDB;
START TRANSACTION;
INSERT INTO t1 VALUES (1,'Sunshine'),(2,'Lollipops');
INSERT INTO t2 VALUES (1,'Sunshine'),(2,'Lollipops');
DELETE FROM t1 WHERE s2 <> 'Sunshine';
ROLLBACK;
SELECT * FROM t2 WHERE MATCH(s2) AGAINST ('Lollipops');
s1 s2
DROP TABLE t2 , t1;
CREATE TABLE t1 (s1 INT, s2 VARCHAR(200), PRIMARY KEY (s1,s2)) ENGINE = InnoDB;
CREATE TABLE t2 (s1 INT, s2 VARCHAR(200),
FULLTEXT KEY(s2),
FOREIGN KEY (s1,s2) REFERENCES t1 (s1,s2) on UPDATE SET NULL) ENGINE = InnoDB;
START TRANSACTION;
INSERT INTO t1 VALUES (1,'Sunshine'),(2,'Lollipops');
INSERT INTO t2 VALUES (1,'Sunshine'),(2,'Lollipops');
UPDATE t1 set s2 = 'Rainbows' WHERE s2 <> 'Sunshine';
ROLLBACK;
SELECT * FROM t2 WHERE MATCH(s2) AGAINST ('Lollipops');
s1 s2
DROP TABLE t2 , t1;
set global innodb_file_per_table=1;
CREATE TABLE t1 (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
a VARCHAR(200),
b TEXT
) CHARACTER SET = utf8, ROW_FORMAT=COMPRESSED, ENGINE = InnoDB;
INSERT INTO t1 (a,b) VALUES
('MySQL Tutorial','DBMS stands for DataBase VÐƷWİ...') ,
('How To Use MySQL Well','After you went through a ...'),
('Optimizing MySQL','In this tutorial we will show ...');
ALTER TABLE t1 ADD FULLTEXT INDEX idx (a,b);
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`a` varchar(200) DEFAULT NULL,
`b` text DEFAULT NULL,
PRIMARY KEY (`id`),
FULLTEXT KEY `idx` (`a`,`b`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci ROW_FORMAT=COMPRESSED
SELECT count(*) FROM information_schema.innodb_sys_tables WHERE name LIKE "%FTS_%" AND space !=0;
count(*)
11
INSERT INTO t1 (a,b) VALUES
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL','In the following database comparison ...'),
('MySQL Security','When configured properly, MySQL ...');
ANALYZE TABLE t1;
SELECT * FROM t1 WHERE MATCH (a,b)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE) ORDER BY id;
id a b
1 MySQL Tutorial DBMS stands for DataBase VÐƷWİ...
3 Optimizing MySQL In this tutorial we will show ...
select * from t1 where MATCH(a,b) AGAINST("+tutorial +VÐƷWİ" IN BOOLEAN MODE);
id a b
1 MySQL Tutorial DBMS stands for DataBase VÐƷWİ...
select * from t1 where MATCH(a,b) AGAINST("+-VÐƷWİ" IN BOOLEAN MODE);
ERROR 42000: syntax error, unexpected '-'
select * from t1 where MATCH(a,b) AGAINST("+Mysql +(tricks never)" IN BOOLEAN MODE);
id a b
4 1001 MySQL Tricks 1. Never run mysqld as root. 2. ...
select * from t1 where MATCH(a,b) AGAINST("+mysql -(tricks never)" IN BOOLEAN MODE) ORDER BY id;
id a b
1 MySQL Tutorial DBMS stands for DataBase VÐƷWİ...
2 How To Use MySQL Well After you went through a ...
3 Optimizing MySQL In this tutorial we will show ...
5 MySQL vs. YourSQL In the following database comparison ...
6 MySQL Security When configured properly, MySQL ...
select *, MATCH(a,b) AGAINST("mysql stands" IN BOOLEAN MODE) as x from t1 ORDER BY id;
id a b x
1 MySQL Tutorial DBMS stands for DataBase VÐƷWİ... 0.6055193543434143
2 How To Use MySQL Well After you went through a ... 0.000000001885928302414186
3 Optimizing MySQL In this tutorial we will show ... 0.000000001885928302414186
4 1001 MySQL Tricks 1. Never run mysqld as root. 2. ... 0.000000001885928302414186
5 MySQL vs. YourSQL In the following database comparison ... 0.000000001885928302414186
6 MySQL Security When configured properly, MySQL ... 0.000000003771856604828372
select * from t1 where MATCH a,b AGAINST ("+database* +VÐƷW*" IN BOOLEAN MODE);
id a b
1 MySQL Tutorial DBMS stands for DataBase VÐƷWİ...
select * from t1 where MATCH a,b AGAINST ('"security mysql"' IN BOOLEAN MODE);
id a b
select * from t1 where MATCH(a,b) AGAINST ("VÐƷWİ" WITH QUERY EXPANSION) ORDER BY id;
id a b
1 MySQL Tutorial DBMS stands for DataBase VÐƷWİ...
2 How To Use MySQL Well After you went through a ...
3 Optimizing MySQL In this tutorial we will show ...
4 1001 MySQL Tricks 1. Never run mysqld as root. 2. ...
5 MySQL vs. YourSQL In the following database comparison ...
6 MySQL Security When configured properly, MySQL ...
ALTER TABLE t1 DROP INDEX idx;
CREATE FULLTEXT INDEX idx on t1 (a,b);
SELECT * FROM t1 WHERE MATCH (a,b)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE) ORDER BY id;
id a b
1 MySQL Tutorial DBMS stands for DataBase VÐƷWİ...
3 Optimizing MySQL In this tutorial we will show ...
select * from t1 where MATCH(a,b) AGAINST("+tutorial +VÐƷWİ" IN BOOLEAN MODE);
id a b
1 MySQL Tutorial DBMS stands for DataBase VÐƷWİ...
select * from t1 where MATCH(a,b) AGAINST("+dbms" IN BOOLEAN MODE);
id a b
1 MySQL Tutorial DBMS stands for DataBase VÐƷWİ...
select * from t1 where MATCH(a,b) AGAINST("+Mysql +(tricks never)" IN BOOLEAN MODE);
id a b
4 1001 MySQL Tricks 1. Never run mysqld as root. 2. ...
select * from t1 where MATCH(a,b) AGAINST("+mysql -(tricks never)" IN BOOLEAN MODE) ORDER BY id;
id a b
1 MySQL Tutorial DBMS stands for DataBase VÐƷWİ...
2 How To Use MySQL Well After you went through a ...
3 Optimizing MySQL In this tutorial we will show ...
5 MySQL vs. YourSQL In the following database comparison ...
6 MySQL Security When configured properly, MySQL ...
select *, MATCH(a,b) AGAINST("mysql VÐƷWİ" IN BOOLEAN MODE) as x from t1 ORDER BY id;
id a b x
1 MySQL Tutorial DBMS stands for DataBase VÐƷWİ... 0.6055193543434143
2 How To Use MySQL Well After you went through a ... 0.000000001885928302414186
3 Optimizing MySQL In this tutorial we will show ... 0.000000001885928302414186
4 1001 MySQL Tricks 1. Never run mysqld as root. 2. ... 0.000000001885928302414186
5 MySQL vs. YourSQL In the following database comparison ... 0.000000001885928302414186
6 MySQL Security When configured properly, MySQL ... 0.000000003771856604828372
select * from t1 where MATCH a,b AGAINST ('"security mysql"' IN BOOLEAN MODE);
id a b
select * from t1 where MATCH(a,b) AGAINST ("VÐƷWİ" WITH QUERY EXPANSION) ORDER BY id;
id a b
1 MySQL Tutorial DBMS stands for DataBase VÐƷWİ...
2 How To Use MySQL Well After you went through a ...
3 Optimizing MySQL In this tutorial we will show ...
4 1001 MySQL Tricks 1. Never run mysqld as root. 2. ...
5 MySQL vs. YourSQL In the following database comparison ...
6 MySQL Security When configured properly, MySQL ...
INSERT INTO t1 (a,b) VALUES ('test query expansion','for database ...');
INSERT INTO t1 (a,b) VALUES
('test proximity search, test, proximity and phrase',
'search, with proximity innodb');
INSERT INTO t1 (a,b) VALUES
('test proximity fts search, test, proximity and phrase',
'search, with proximity innodb');
INSERT INTO t1 (a,b) VALUES
('test more proximity fts search, test, more proximity and phrase',
'search, with proximity innodb');
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"proximity search"@2' IN BOOLEAN MODE);
id a b
8 test proximity search, test, proximity and phrase search, with proximity innodb
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"proximity search"@1' IN BOOLEAN MODE);
id a b
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"proximity search"@3' IN BOOLEAN MODE) ORDER BY id;
id a b
8 test proximity search, test, proximity and phrase search, with proximity innodb
9 test proximity fts search, test, proximity and phrase search, with proximity innodb
10 test more proximity fts search, test, more proximity and phrase search, with proximity innodb
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"test proximity"@5' IN BOOLEAN MODE) ORDER BY id;
id a b
8 test proximity search, test, proximity and phrase search, with proximity innodb
9 test proximity fts search, test, proximity and phrase search, with proximity innodb
10 test more proximity fts search, test, more proximity and phrase search, with proximity innodb
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"more test proximity"@2' IN BOOLEAN MODE);
id a b
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"more test proximity"@3' IN BOOLEAN MODE);
id a b
10 test more proximity fts search, test, more proximity and phrase search, with proximity innodb
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"more fts proximity"@03' IN BOOLEAN MODE);
id a b
10 test more proximity fts search, test, more proximity and phrase search, with proximity innodb
UPDATE t1 SET a = UPPER(a) , b = UPPER(b) ;
UPDATE t1 SET a = UPPER(a) , b = LOWER(b) ;
select * from t1 where MATCH(a,b) AGAINST("+tutorial +dbms" IN BOOLEAN MODE);
id a b
1 MYSQL TUTORIAL dbms stands for database vðʒwi...
select * from t1 where MATCH(a,b) AGAINST("+VÐƷWİ" IN BOOLEAN MODE);
id a b
1 MYSQL TUTORIAL dbms stands for database vðʒwi...
SELECT * FROM t1 WHERE MATCH (a,b)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE) ORDER BY id;
id a b
1 MYSQL TUTORIAL dbms stands for database vðʒwi...
3 OPTIMIZING MYSQL in this tutorial we will show ...
DELETE FROM t1 WHERE MATCH (a,b) AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
DELETE FROM t1 WHERE MATCH (a,b) AGAINST ('"proximity search"@14' IN BOOLEAN MODE);
SELECT * FROM t1 WHERE MATCH (a,b)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
id a b
SELECT * FROM t1 ORDER BY id;
id a b
2 HOW TO USE MYSQL WELL after you went through a ...
4 1001 MYSQL TRICKS 1. never run mysqld as root. 2. ...
5 MYSQL VS. YOURSQL in the following database comparison ...
6 MYSQL SECURITY when configured properly, mysql ...
7 TEST QUERY EXPANSION for database ...
DROP TABLE t1;
SET GLOBAL innodb_file_per_table=1;
CREATE TABLE t1 (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
a VARCHAR(200),
b TEXT
) CHARACTER SET = utf8, ENGINE=InnoDB;
INSERT INTO t1 (a,b) VALUES
('Я могу есть стекло', 'оно мне не вредит'),
('Мога да ям стъкло', 'то не ми вреди'),
('Μπορῶ νὰ φάω σπασμένα' ,'γυαλιὰ χωρὶς νὰ πάθω τίποτα'),
('Příliš žluťoučký kůň', 'úpěl ďábelské kódy'),
('Sævör grét', 'áðan því úlpan var ónýt'),
('うゐのおくやま','けふこえて'),
('いろはにほへど ちりぬる','あさきゆめみじ ゑひもせず');
INSERT INTO t1 (a,b) VALUES
('MySQL Tutorial','request docteam@oraclehelp.com ...') ,
('Trial version','query performace @1255 minute on 2.1Hz Memory 2GB...') ,
('when To Use MySQL Well','for free faq mail@xyz.com ...');
CREATE FULLTEXT INDEX idx on t1 (a,b);
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST ("вредит χωρὶς") ORDER BY id;
id a b
1 Я могу есть стекло оно мне не вредит
3 Μπορῶ νὰ φάω σπασμένα γυαλιὰ χωρὶς νὰ πάθω τίποτα
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST ("оно" WITH QUERY EXPANSION);
id a b
1 Я могу есть стекло оно мне не вредит
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST("вред*" IN BOOLEAN MODE) ORDER BY id;
id a b
1 Я могу есть стекло оно мне не вредит
2 Мога да ям стъкло то не ми вреди
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST("+γυαλιὰ +tutorial" IN BOOLEAN MODE);
id a b
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST("+tutorial +(Мога τίποτα)" IN BOOLEAN MODE);
id a b
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST ("あさきゆめみじ ゑひもせず");
id a b
7 いろはにほへど ちりぬる あさきゆめみじ ゑひもせず
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST ("ちりぬる" WITH QUERY EXPANSION);
id a b
7 いろはにほへど ちりぬる あさきゆめみじ ゑひもせず
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST ("+あさきゆめみじ +ゑひもせず" IN BOOLEAN MODE);
id a b
7 いろはにほへど ちりぬる あさきゆめみじ ゑひもせず
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST("うゐのおく*" IN BOOLEAN MODE);
id a b
6 うゐのおくやま けふこえて
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST("+Sævör +úlpan" IN BOOLEAN MODE);
id a b
5 Sævör grét áðan því úlpan var ónýt
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"γυαλιὰ χωρὶς"@2' IN BOOLEAN MODE);
id a b
3 Μπορῶ νὰ φάω σπασμένα γυαλιὰ χωρὶς νὰ πάθω τίποτα
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"query performace"@02' IN BOOLEAN MODE);
id a b
9 Trial version query performace @1255 minute on 2.1Hz Memory 2GB...
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"πάθω τίποτα"@2' IN BOOLEAN MODE);
id a b
3 Μπορῶ νὰ φάω σπασμένα γυαλιὰ χωρὶς νὰ πάθω τίποτα
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"あさきゆめみじ ゑひもせず"@1' IN BOOLEAN MODE);
id a b
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"あさきゆめみじ ゑひもせず"@2' IN BOOLEAN MODE);
id a b
7 いろはにほへど ちりぬる あさきゆめみじ ゑひもせず
ALTER TABLE t1 DROP INDEX idx;
CREATE FULLTEXT INDEX idx on t1 (a,b);
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST ("あさきゆめみじ ゑひもせず");
id a b
7 いろはにほへど ちりぬる あさきゆめみじ ゑひもせず
UPDATE t1 SET a = "Pchnąć w tę łódź jeża" , b = "lub osiem skrzyń fig" WHERE MATCH(a,b) AGAINST ("あさきゆめみじ ゑひもせず");
UPDATE t1 SET a = "В чащах юга жил-был цитрус? Да", b = "но фальшивый экземпляр! ёъ" WHERE MATCH(a,b) AGAINST ("вред*" IN BOOLEAN MODE);
DELETE FROM t1 WHERE MATCH(a,b) AGAINST("+Sævör +úlpan" IN BOOLEAN MODE);
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST ("あさきゆめみじ ゑひもせず");
id a b
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST ("łódź osiem");
id a b
7 Pchnąć w tę łódź jeża lub osiem skrzyń fig
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST("вред*" IN BOOLEAN MODE);
id a b
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST("фальшив*" IN BOOLEAN MODE) ORDER BY id;
id a b
1 В чащах юга жил-был цитрус? Да но фальшивый экземпляр! ёъ
2 В чащах юга жил-был цитрус? Да но фальшивый экземпляр! ёъ
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST("+Sævör +úlpan" IN BOOLEAN MODE);
id a b
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"łódź jeża"@2' IN BOOLEAN MODE);
id a b
7 Pchnąć w tę łódź jeża lub osiem skrzyń fig
SELECT * FROM t1 ORDER BY id;
id a b
1 В чащах юга жил-был цитрус? Да но фальшивый экземпляр! ёъ
2 В чащах юга жил-был цитрус? Да но фальшивый экземпляр! ёъ
3 Μπορῶ νὰ φάω σπασμένα γυαλιὰ χωρὶς νὰ πάθω τίποτα
4 Příliš žluťoučký kůň úpěl ďábelské kódy
6 うゐのおくやま けふこえて
7 Pchnąć w tę łódź jeża lub osiem skrzyń fig
8 MySQL Tutorial request docteam@oraclehelp.com ...
9 Trial version query performace @1255 minute on 2.1Hz Memory 2GB...
10 when To Use MySQL Well for free faq mail@xyz.com ...
DROP TABLE t1;
CREATE TABLE t1(ID INT PRIMARY KEY,
no_fts_field VARCHAR(10),
fts_field VARCHAR(10),
FULLTEXT INDEX f(fts_field)) ENGINE=INNODB;
INSERT INTO t1 VALUES (1, 'AAA', 'BBB');
SELECT * FROM t1 WHERE MATCH(fts_field) against("BBB");
ID no_fts_field fts_field
1 AAA BBB
UPDATE t1 SET fts_field='anychange' where id = 1;
SELECT * FROM t1 WHERE MATCH(fts_field) against("anychange");
ID no_fts_field fts_field
1 AAA anychange
UPDATE t1 SET no_fts_field='anychange' where id = 1;
SELECT * FROM t1 WHERE MATCH(fts_field) against("anychange");
ID no_fts_field fts_field
1 anychange anychange
UPDATE t1 SET no_fts_field='anychange', fts_field='other' where id = 1;
SELECT * FROM t1 WHERE MATCH(fts_field) against("other");
ID no_fts_field fts_field
1 anychange other
SELECT * FROM t1 WHERE MATCH(fts_field) against("BBB");
ID no_fts_field fts_field
DROP INDEX f on t1;
UPDATE t1 SET fts_field='anychange' where id = 1;
UPDATE t1 SET no_fts_field='anychange' where id = 1;
UPDATE t1 SET no_fts_field='anychange', fts_field='other' where id = 1;
CREATE FULLTEXT INDEX f ON t1(FTS_FIELD);
SELECT * FROM t1 WHERE MATCH(fts_field) against("other");
ID no_fts_field fts_field
1 anychange other
DROP TABLE t1;
CREATE TABLE t1(`FTS_DOC_ID` serial,
no_fts_field VARCHAR(10),
fts_field VARCHAR(10),
FULLTEXT INDEX f(fts_field)) ENGINE=INNODB;
INSERT INTO t1 VALUES (1, 'AAA', 'BBB');
UPDATE t1 SET fts_field='anychange' where FTS_DOC_ID = 1;
ERROR HY000: Invalid InnoDB FTS Doc ID
UPDATE t1 SET fts_field='anychange', FTS_DOC_ID = 2 where FTS_DOC_ID = 1;
SELECT * FROM t1 WHERE MATCH(fts_field) against("anychange");
FTS_DOC_ID no_fts_field fts_field
2 AAA anychange
SELECT * FROM t1 WHERE MATCH(fts_field) against("BBB");
FTS_DOC_ID no_fts_field fts_field
UPDATE t1 SET no_fts_field='anychange' where FTS_DOC_ID = 2;
SELECT * FROM t1 WHERE MATCH(fts_field) against("anychange");
FTS_DOC_ID no_fts_field fts_field
2 anychange anychange
UPDATE t1 SET no_fts_field='anychange', fts_field='other' where FTS_DOC_ID = 2;
ERROR HY000: Invalid InnoDB FTS Doc ID
SELECT * FROM t1 WHERE MATCH(fts_field) against("other");
FTS_DOC_ID no_fts_field fts_field
UPDATE t1 SET FTS_DOC_ID = 1 where FTS_DOC_ID = 2;
ERROR HY000: Invalid InnoDB FTS Doc ID
DROP INDEX f ON t1;
UPDATE t1 SET fts_field='newchange' where FTS_DOC_ID = 2;
UPDATE t1 SET no_fts_field='anychange' where FTS_DOC_ID = 2;
SELECT * FROM t1;
FTS_DOC_ID no_fts_field fts_field
2 anychange newchange
DROP TABLE t1;
CREATE TABLE t1(ID INT PRIMARY KEY,
no_fts_field VARCHAR(10),
fts_field VARCHAR(10),
FULLTEXT INDEX f(fts_field), index k(fts_field)) ENGINE=INNODB;
CREATE TABLE t2(ID INT PRIMARY KEY,
no_fts_field VARCHAR(10),
fts_field VARCHAR(10),
FULLTEXT INDEX f(fts_field),
INDEX k2(fts_field),
FOREIGN KEY(fts_field) REFERENCES
t1(fts_field) ON UPDATE CASCADE) ENGINE=INNODB;
INSERT INTO t1 VALUES (1, 'AAA', 'BBB');
INSERT INTO t2 VALUES (1, 'AAA', 'BBB');
update t1 set fts_field='newchange' where id =1;
SELECT * FROM t1 WHERE MATCH(fts_field) against("BBB");
ID no_fts_field fts_field
SELECT * FROM t2 WHERE MATCH(fts_field) against("BBB");
ID no_fts_field fts_field
SELECT * FROM t1 WHERE MATCH(fts_field) against("newchange");
ID no_fts_field fts_field
1 AAA newchange
SELECT * FROM t2 WHERE MATCH(fts_field) against("newchange");
ID no_fts_field fts_field
1 AAA newchange
DROP TABLE t2;
DROP TABLE t1;
CREATE TABLE t1(id INT PRIMARY KEY,
fts_field VARCHAR(10),
FULLTEXT INDEX f(fts_field)) ENGINE=INNODB;
CREATE TABLE t2(id INT PRIMARY KEY,
fts_field VARCHAR(10),
FULLTEXT INDEX f(fts_field)) ENGINE=INNODB;
INSERT INTO t1 values (1,'100'),(2,'200'),(3,'300'),(4,'400'),(5,'500'),(6,'600'), (7,'700'),(8,'800'),(9,'900'),(10,'1000'),(11,'1100'),(12,'1200');
INSERT INTO t2 values (1,'100'),(2,'200'),(3,'300'),(4,'400'),(5,'500'),(6,'600'), (7,'700'),(8,'800');
UPDATE t1, t2 set t1.fts_field = CONCAT(t1.fts_field, 'foo');
UPDATE t1, t2 set t1.fts_field = CONCAT(t1.fts_field, 'foo') WHERE t1.fts_field = "100foo";
UPDATE t1, t2 set t1.fts_field = CONCAT(t1.fts_field, 'xoo'), t2.fts_field = CONCAT(t1.fts_field, 'xoo') where t1.fts_field=CONCAT(t2.fts_field, 'foo');
SELECT * FROM t1 WHERE MATCH(fts_field) against("100foofoo");
id fts_field
1 100foofoo
SELECT * FROM t1 WHERE MATCH(fts_field) against("100foo");
id fts_field
SELECT * FROM t1 WHERE MATCH(fts_field) against("100");
id fts_field
SELECT * FROM t2 WHERE MATCH(fts_field) against("400fooxoo");
id fts_field
4 400fooxoo
SELECT * FROM t2 WHERE MATCH(fts_field) against("100");
id fts_field
1 100
SELECT * FROM t2 WHERE MATCH(fts_field) against("200");
id fts_field
SELECT * FROM t2 WHERE MATCH(fts_field) against("400");
id fts_field
DROP TABLE t1;
DROP TABLE t2;
BUG#13701973/64274: MYSQL THREAD WAS SUSPENDED WHEN EXECUTE UPDATE QUERY
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
CREATE TABLE t1 (
t1_id INT(10) UNSIGNED NOT NULL,
t2_id INT(10) UNSIGNED DEFAULT NULL,
PRIMARY KEY (t1_id),
FOREIGN KEY (t2_id) REFERENCES t2 (t2_id)
ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB;
CREATE TABLE t2 (
t1_id INT(10) UNSIGNED NOT NULL,
t2_id INT(10) UNSIGNED NOT NULL,
t3_id INT(10) UNSIGNED NOT NULL,
t4_id INT(10) UNSIGNED NOT NULL,
PRIMARY KEY (t2_id),
FOREIGN KEY (t1_id) REFERENCES t1 (t1_id),
FOREIGN KEY (t3_id) REFERENCES t3 (t3_id)
ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (t4_id) REFERENCES t4 (t4_id)
) ENGINE=InnoDB;
CREATE TABLE t3 (
t3_id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
payload char(3),
PRIMARY KEY (t3_id)
) ENGINE=InnoDB;
INSERT INTO t3 VALUES (1, '100');
CREATE TABLE t4 (
t2_id INT(10) UNSIGNED DEFAULT NULL,
t4_id INT(10) UNSIGNED NOT NULL,
PRIMARY KEY (t4_id),
FOREIGN KEY (t2_id) REFERENCES t2 (t2_id)
ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB;
SET FOREIGN_KEY_CHECKS=1;
UPDATE t3 SET payload='101' WHERE t3_id=1;
SET FOREIGN_KEY_CHECKS=0;
DROP TABLE t1;
DROP TABLE t2;
DROP TABLE t3;
DROP TABLE t4;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,84 @@
CREATE TABLE articles (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
title VARCHAR(200),
body TEXT,
FULLTEXT (title,body)
) ENGINE=InnoDB;
INSERT INTO articles (title,body) VALUES
(NULL, 'mysql good database'),
(NULL, ' mysql good database'),
('', 'mysql good database'),
('', ' mysql good database'),
(' ', 'mysql good database'),
('mysql', 'good database'),
('mysql ', 'good database'),
('mysql', ' good database'),
('mysql good database', ''),
('mysql good database', NULL);
SET GLOBAL innodb_ft_aux_table="test/articles";
SELECT * FROM INFORMATION_SCHEMA.INNODB_FT_INDEX_CACHE;
WORD FIRST_DOC_ID LAST_DOC_ID DOC_COUNT DOC_ID POSITION
database 1 10 10 1 11
database 1 10 10 2 12
database 1 10 10 3 11
database 1 10 10 4 12
database 1 10 10 5 13
database 1 10 10 6 11
database 1 10 10 7 12
database 1 10 10 8 12
database 1 10 10 9 11
database 1 10 10 10 11
good 1 10 10 1 6
good 1 10 10 2 7
good 1 10 10 3 6
good 1 10 10 4 7
good 1 10 10 5 8
good 1 10 10 6 6
good 1 10 10 7 7
good 1 10 10 8 7
good 1 10 10 9 6
good 1 10 10 10 6
mysql 1 10 10 1 0
mysql 1 10 10 2 1
mysql 1 10 10 3 0
mysql 1 10 10 4 1
mysql 1 10 10 5 2
mysql 1 10 10 6 0
mysql 1 10 10 7 0
mysql 1 10 10 8 0
mysql 1 10 10 9 0
mysql 1 10 10 10 0
SET GLOBAL innodb_ft_aux_table=default;
SELECT * FROM articles;
id title body
1 NULL mysql good database
2 NULL mysql good database
3 mysql good database
4 mysql good database
5 mysql good database
6 mysql good database
7 mysql good database
8 mysql good database
9 mysql good database
10 mysql good database NULL
SELECT * FROM articles WHERE MATCH(title, body)
AGAINST('"mysql good database"' IN BOOLEAN MODE);
id title body
1 NULL mysql good database
2 NULL mysql good database
3 mysql good database
4 mysql good database
5 mysql good database
9 mysql good database
10 mysql good database NULL
SELECT * FROM articles WHERE MATCH(title, body)
AGAINST('("mysql good database")' IN BOOLEAN MODE);
id title body
1 NULL mysql good database
2 NULL mysql good database
3 mysql good database
4 mysql good database
5 mysql good database
9 mysql good database
10 mysql good database NULL
DROP TABLE articles;

View file

@ -0,0 +1,31 @@
CREATE TABLE t1 (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
a VARCHAR(200),
b TEXT
) ENGINE= InnoDB;
CREATE FULLTEXT INDEX idx on t1 (a,b);
INSERT INTO t1 (a,b) VALUES
('MySQL from Tutorial','DBMS stands for DataBase ...') ,
('when To Use MySQL Well','After that you went through a ...'),
('where will Optimizing MySQL','what In this tutorial we will show ...'),
('MySQL from Tutorial','DBMS stands for DataBase ...') ,
('when To Use MySQL Well','After that you went through a ...'),
('where will Optimizing MySQL','what In this tutorial we will show ...'),
('MySQL from Tutorial','DBMS stands for DataBase ...') ,
('when To Use MySQL Well','After that you went through a ...'),
('where will Optimizing MySQL','what In this tutorial we will show ...');
SET @save_limit=@@GLOBAL.innodb_ft_result_cache_limit;
SET @save_dbug=@@debug_dbug;
SET debug_dbug="+d,fts_instrument_result_cache_limit";
SELECT COUNT(*) FROM t1 WHERE MATCH (a,b) AGAINST ('mysql' IN BOOLEAN MODE);
COUNT(*)
9
SELECT COUNT(*) FROM t1 WHERE MATCH (a,b) AGAINST ('mysql' WITH QUERY EXPANSION);
ERROR HY000: Table handler out of memory
SELECT COUNT(*) FROM t1 WHERE MATCH (a,b) AGAINST ('"mysql database"' IN BOOLEAN MODE);
ERROR HY000: Table handler out of memory
SELECT COUNT(*) FROM t1 WHERE MATCH (a,b) AGAINST ('"mysql database" @ 5' IN BOOLEAN MODE);
ERROR HY000: Table handler out of memory
SET debug_dbug=@save_dbug;
DROP TABLE t1;
SET GLOBAL innodb_ft_result_cache_limit=@save_limit;

View file

@ -0,0 +1,318 @@
CREATE TABLE articles (
id INT UNSIGNED NOT NULL PRIMARY KEY,
title VARCHAR(200),
FULLTEXT (title)
) ENGINE= InnoDB;
TRUNCATE TABLE articles;
INSERT INTO articles(id, title) VALUES(1, 'mysql');
BEGIN;
INSERT INTO articles(id, title) VALUES(2, 'mysql');
SAVEPOINT sp1;
INSERT INTO articles(id, title) VALUES(3, 'mysql');
ROLLBACK TO SAVEPOINT sp1;
INSERT INTO articles(id, title) VALUES(4, 'mysql');
COMMIT;
INSERT INTO articles(id, title) VALUES(5, 'mysql');
SELECT * FROM articles WHERE MATCH(title) AGAINST('mysql');
id title
1 mysql
2 mysql
4 mysql
5 mysql
TRUNCATE TABLE articles;
INSERT INTO articles(id, title) VALUES(1, 'mysql');
BEGIN;
INSERT INTO articles(id, title) VALUES(2, 'mysql');
SAVEPOINT sp1;
INSERT INTO articles(id, title) VALUES(3, 'mysql');
ROLLBACK TO SAVEPOINT sp1;
INSERT INTO articles(id, title) VALUES(4, 'mysql');
SAVEPOINT sp2;
INSERT INTO articles(id, title) VALUES(5, 'mysql');
ROLLBACK TO SAVEPOINT sp2;
INSERT INTO articles(id, title) VALUES(6, 'mysql');
COMMIT;
INSERT INTO articles(id, title) VALUES(7, 'mysql');
SELECT * FROM articles WHERE MATCH(title) AGAINST('mysql');
id title
1 mysql
2 mysql
4 mysql
6 mysql
7 mysql
TRUNCATE TABLE articles;
INSERT INTO articles(id, title) VALUES(1, 'mysql');
BEGIN;
INSERT INTO articles(id, title) VALUES(2, 'mysql');
SAVEPOINT sp1;
INSERT INTO articles(id, title) VALUES(3, 'mysql');
SAVEPOINT sp2;
INSERT INTO articles(id, title) VALUES(4, 'mysql');
ROLLBACK TO SAVEPOINT sp1;
INSERT INTO articles(id, title) VALUES(5, 'mysql');
COMMIT;
INSERT INTO articles(id, title) VALUES(6, 'mysql');
SELECT * FROM articles WHERE MATCH(title) AGAINST('mysql');
id title
1 mysql
2 mysql
5 mysql
6 mysql
TRUNCATE TABLE articles;
INSERT INTO articles(id, title) VALUES(1, 'mysql');
BEGIN;
INSERT INTO articles(id, title) VALUES(2, 'mysql');
SAVEPOINT sp1;
INSERT INTO articles(id, title) VALUES(3, 'mysql');
SAVEPOINT sp2;
INSERT INTO articles(id, title) VALUES(4, 'mysql');
ROLLBACK TO SAVEPOINT sp2;
INSERT INTO articles(id, title) VALUES(5, 'mysql');
ROLLBACK TO SAVEPOINT sp1;
INSERT INTO articles(id, title) VALUES(6, 'mysql');
COMMIT;
INSERT INTO articles(id, title) VALUES(7, 'mysql');
SELECT * FROM articles WHERE MATCH(title) AGAINST('mysql');
id title
1 mysql
2 mysql
6 mysql
7 mysql
TRUNCATE TABLE articles;
INSERT INTO articles(id, title) VALUES(1, 'mysql');
BEGIN;
INSERT INTO articles(id, title) VALUES(2, 'mysql');
SAVEPOINT sp1;
INSERT INTO articles(id, title) VALUES(3, 'mysql');
RELEASE SAVEPOINT sp1;
INSERT INTO articles(id, title) VALUES(4, 'mysql');
COMMIT;
INSERT INTO articles(id, title) VALUES(5, 'mysql');
SELECT * FROM articles WHERE MATCH(title) AGAINST('mysql');
id title
1 mysql
2 mysql
3 mysql
4 mysql
5 mysql
TRUNCATE TABLE articles;
INSERT INTO articles(id, title) VALUES(1, 'mysql');
BEGIN;
INSERT INTO articles(id, title) VALUES(2, 'mysql');
SAVEPOINT sp1;
INSERT INTO articles(id, title) VALUES(3, 'mysql');
RELEASE SAVEPOINT sp1;
INSERT INTO articles(id, title) VALUES(4, 'mysql');
SAVEPOINT sp2;
INSERT INTO articles(id, title) VALUES(5, 'mysql');
RELEASE SAVEPOINT sp2;
INSERT INTO articles(id, title) VALUES(6, 'mysql');
COMMIT;
INSERT INTO articles(id, title) VALUES(7, 'mysql');
SELECT * FROM articles WHERE MATCH(title) AGAINST('mysql');
id title
1 mysql
2 mysql
3 mysql
4 mysql
5 mysql
6 mysql
7 mysql
TRUNCATE TABLE articles;
INSERT INTO articles(id, title) VALUES(1, 'mysql');
BEGIN;
INSERT INTO articles(id, title) VALUES(2, 'mysql');
SAVEPOINT sp1;
INSERT INTO articles(id, title) VALUES(3, 'mysql');
SAVEPOINT sp2;
INSERT INTO articles(id, title) VALUES(4, 'mysql');
RELEASE SAVEPOINT sp1;
INSERT INTO articles(id, title) VALUES(5, 'mysql');
COMMIT;
INSERT INTO articles(id, title) VALUES(6, 'mysql');
SELECT * FROM articles WHERE MATCH(title) AGAINST('mysql');
id title
1 mysql
2 mysql
3 mysql
4 mysql
5 mysql
6 mysql
TRUNCATE TABLE articles;
INSERT INTO articles(id, title) VALUES(1, 'mysql');
BEGIN;
INSERT INTO articles(id, title) VALUES(2, 'mysql');
SAVEPOINT sp1;
INSERT INTO articles(id, title) VALUES(3, 'mysql');
SAVEPOINT sp2;
INSERT INTO articles(id, title) VALUES(4, 'mysql');
RELEASE SAVEPOINT sp2;
INSERT INTO articles(id, title) VALUES(5, 'mysql');
RELEASE SAVEPOINT sp1;
INSERT INTO articles(id, title) VALUES(6, 'mysql');
COMMIT;
INSERT INTO articles(id, title) VALUES(7, 'mysql');
SELECT * FROM articles WHERE MATCH(title) AGAINST('mysql');
id title
1 mysql
2 mysql
3 mysql
4 mysql
5 mysql
6 mysql
7 mysql
TRUNCATE TABLE articles;
INSERT INTO articles(id, title) VALUES(1, 'mysql');
BEGIN;
INSERT INTO articles(id, title) VALUES(2, 'mysql');
SAVEPOINT sp1;
INSERT INTO articles(id, title) VALUES(3, 'mysql');
ROLLBACK TO SAVEPOINT sp1;
INSERT INTO articles(id, title) VALUES(4, 'mysql');
SAVEPOINT sp2;
INSERT INTO articles(id, title) VALUES(5, 'mysql');
RELEASE SAVEPOINT sp2;
INSERT INTO articles(id, title) VALUES(6, 'mysql');
COMMIT;
INSERT INTO articles(id, title) VALUES(7, 'mysql');
SELECT * FROM articles WHERE MATCH(title) AGAINST('mysql');
id title
1 mysql
2 mysql
4 mysql
5 mysql
6 mysql
7 mysql
TRUNCATE TABLE articles;
INSERT INTO articles(id, title) VALUES(1, 'mysql');
BEGIN;
INSERT INTO articles(id, title) VALUES(2, 'mysql');
SAVEPOINT sp1;
INSERT INTO articles(id, title) VALUES(3, 'mysql');
RELEASE SAVEPOINT sp1;
INSERT INTO articles(id, title) VALUES(4, 'mysql');
SAVEPOINT sp2;
INSERT INTO articles(id, title) VALUES(5, 'mysql');
ROLLBACK TO SAVEPOINT sp2;
INSERT INTO articles(id, title) VALUES(6, 'mysql');
COMMIT;
INSERT INTO articles(id, title) VALUES(7, 'mysql');
SELECT * FROM articles WHERE MATCH(title) AGAINST('mysql');
id title
1 mysql
2 mysql
3 mysql
4 mysql
6 mysql
7 mysql
TRUNCATE TABLE articles;
INSERT INTO articles(id, title) VALUES(1, 'mysql');
BEGIN;
INSERT INTO articles(id, title) VALUES(2, 'mysql');
SAVEPOINT sp1;
INSERT INTO articles(id, title) VALUES(3, 'mysql');
SAVEPOINT sp2;
INSERT INTO articles(id, title) VALUES(4, 'mysql');
RELEASE SAVEPOINT sp2;
INSERT INTO articles(id, title) VALUES(5, 'mysql');
ROLLBACK TO SAVEPOINT sp1;
INSERT INTO articles(id, title) VALUES(6, 'mysql');
COMMIT;
INSERT INTO articles(id, title) VALUES(7, 'mysql');
SELECT * FROM articles WHERE MATCH(title) AGAINST('mysql');
id title
1 mysql
2 mysql
6 mysql
7 mysql
TRUNCATE TABLE articles;
INSERT INTO articles(id, title) VALUES(1, 'mysql');
BEGIN;
INSERT INTO articles(id, title) VALUES(2, 'mysql');
SAVEPOINT sp1;
INSERT INTO articles(id, title) VALUES(3, 'mysql');
SAVEPOINT sp2;
INSERT INTO articles(id, title) VALUES(4, 'mysql');
ROLLBACK TO SAVEPOINT sp2;
INSERT INTO articles(id, title) VALUES(5, 'mysql');
RELEASE SAVEPOINT sp1;
INSERT INTO articles(id, title) VALUES(6, 'mysql');
COMMIT;
INSERT INTO articles(id, title) VALUES(7, 'mysql');
SELECT * FROM articles WHERE MATCH(title) AGAINST('mysql');
id title
1 mysql
2 mysql
3 mysql
5 mysql
6 mysql
7 mysql
TRUNCATE TABLE articles;
INSERT INTO articles(id, title) VALUES(1, 'mysql');
BEGIN;
INSERT INTO articles(id, title) VALUES(2, 'mysql');
ROLLBACK;
INSERT INTO articles(id, title) VALUES(3, 'mysql');
SELECT * FROM articles WHERE MATCH(title) AGAINST('mysql');
id title
1 mysql
3 mysql
TRUNCATE TABLE articles;
INSERT INTO articles(id, title) VALUES(1, 'mysql');
BEGIN;
INSERT INTO articles(id, title) VALUES(2, 'mysql');
SAVEPOINT sp1;
INSERT INTO articles(id, title) VALUES(3, 'mysql');
ROLLBACK;
INSERT INTO articles(id, title) VALUES(4, 'mysql');
SELECT * FROM articles WHERE MATCH(title) AGAINST('mysql');
id title
1 mysql
4 mysql
TRUNCATE TABLE articles;
INSERT INTO articles(id, title) VALUES(1, 'mysql');
BEGIN;
INSERT INTO articles(id, title) VALUES(2, 'mysql');
SAVEPOINT sp1;
INSERT INTO articles(id, title) VALUES(3, 'mysql');
RELEASE SAVEPOINT sp1;
INSERT INTO articles(id, title) VALUES(4, 'mysql');
ROLLBACK;
INSERT INTO articles(id, title) VALUES(5, 'mysql');
SELECT * FROM articles WHERE MATCH(title) AGAINST('mysql');
id title
1 mysql
5 mysql
TRUNCATE TABLE articles;
INSERT INTO articles(id, title) VALUES(1, 'mysql');
BEGIN;
INSERT INTO articles(id, title) VALUES(2, 'mysql');
SAVEPOINT sp1;
INSERT INTO articles(id, title) VALUES(3, 'mysql');
ROLLBACK TO SAVEPOINT sp1;
INSERT INTO articles(id, title) VALUES(4, 'mysql');
ROLLBACK;
INSERT INTO articles(id, title) VALUES(5, 'mysql');
SELECT * FROM articles WHERE MATCH(title) AGAINST('mysql');
id title
1 mysql
5 mysql
TRUNCATE TABLE articles;
INSERT INTO articles(id, title) VALUES(1, 'mysql');
BEGIN;
INSERT INTO articles(id, title) VALUES(2, 'mysql');
SAVEPOINT sp1;
INSERT INTO articles(id, title) VALUES(3, 'mysql');
SAVEPOINT sp2;
INSERT INTO articles(id, title) VALUES(4, 'mysql');
ROLLBACK TO SAVEPOINT sp2;
INSERT INTO articles(id, title) VALUES(5, 'mysql');
RELEASE SAVEPOINT sp1;
INSERT INTO articles(id, title) VALUES(6, 'mysql');
ROLLBACK;
INSERT INTO articles(id, title) VALUES(7, 'mysql');
SELECT * FROM articles WHERE MATCH(title) AGAINST('mysql');
id title
1 mysql
7 mysql
DROP TABLE articles;

View file

@ -0,0 +1,105 @@
#
# Bug #20028323 INNODB FULLTEXT BOOLEAN SEARCH INCORRECTLY HANDLES
# PARENTHESES
#
CREATE TABLE t1 (
f1 INT NOT NULL AUTO_INCREMENT,
f2 TEXT NOT NULL,
PRIMARY KEY (f1),
FULLTEXT (f2)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO t1 (f2) VALUES
('Pumpkin soup with cheese bread'),
('Yellow chicken curry'),
('Fresh green vegetables with garlic');
SELECT * FROM t1 WHERE MATCH(f2) AGAINST('+pumpkin' IN BOOLEAN MODE);
f1 f2
1 Pumpkin soup with cheese bread
SELECT * FROM t1 WHERE MATCH(f2) AGAINST('+cheese' IN BOOLEAN MODE);
f1 f2
1 Pumpkin soup with cheese bread
SELECT * FROM t1 WHERE MATCH(f2) AGAINST('+(pumpkin cheese)' IN BOOLEAN MODE);
f1 f2
1 Pumpkin soup with cheese bread
SELECT * FROM t1 WHERE MATCH(f2)
AGAINST('+pumpkin +(souffle)' IN BOOLEAN MODE);
f1 f2
SELECT * FROM t1 WHERE MATCH(f2)
AGAINST('+pumpkin +(souffle tart)' IN BOOLEAN MODE);
f1 f2
SELECT * FROM t1 WHERE MATCH(f2)
AGAINST('+pumpkin +(>souffle <tart)' IN BOOLEAN MODE);
f1 f2
SELECT * FROM t1 WHERE MATCH(f2)
AGAINST('+pumpkin +(souffle tart)' IN BOOLEAN MODE);
f1 f2
INSERT INTO t1 (f2) VALUES
('This row contains only souffle'),
('This row contains only tart'),
('This row contains only pumpkin'),
('This row contains only cheese'),
('This row contains pumpkin and souffle'),
('This row contains pumpkin and tart'),
('This row contains pumpkin and cheese'),
('This row contains both souffle and tart'),
('This row contains both souffle and cheese'),
('This row contains both tart and cheese'),
('This row contains all three souffle, pumpkin and tart'),
('This row contains all four cheese, souffle, pumpkin and tart');
SELECT * FROM t1 WHERE MATCH(f2) AGAINST('+pumpkin' IN BOOLEAN MODE);
f1 f2
1 Pumpkin soup with cheese bread
6 This row contains only pumpkin
8 This row contains pumpkin and souffle
9 This row contains pumpkin and tart
10 This row contains pumpkin and cheese
14 This row contains all three souffle, pumpkin and tart
15 This row contains all four cheese, souffle, pumpkin and tart
SELECT * FROM t1 WHERE MATCH(f2) AGAINST('+cheese' IN BOOLEAN MODE);
f1 f2
1 Pumpkin soup with cheese bread
7 This row contains only cheese
10 This row contains pumpkin and cheese
12 This row contains both souffle and cheese
13 This row contains both tart and cheese
15 This row contains all four cheese, souffle, pumpkin and tart
SELECT * FROM t1 WHERE MATCH(f2) AGAINST('+(pumpkin cheese)' IN BOOLEAN MODE);
f1 f2
1 Pumpkin soup with cheese bread
10 This row contains pumpkin and cheese
15 This row contains all four cheese, souffle, pumpkin and tart
7 This row contains only cheese
12 This row contains both souffle and cheese
13 This row contains both tart and cheese
6 This row contains only pumpkin
8 This row contains pumpkin and souffle
9 This row contains pumpkin and tart
14 This row contains all three souffle, pumpkin and tart
SELECT * FROM t1 WHERE MATCH(f2)
AGAINST('+pumpkin +(souffle)' IN BOOLEAN MODE);
f1 f2
8 This row contains pumpkin and souffle
14 This row contains all three souffle, pumpkin and tart
15 This row contains all four cheese, souffle, pumpkin and tart
SELECT * FROM t1 WHERE MATCH(f2)
AGAINST('+pumpkin +(souffle tart)' IN BOOLEAN MODE);
f1 f2
14 This row contains all three souffle, pumpkin and tart
15 This row contains all four cheese, souffle, pumpkin and tart
8 This row contains pumpkin and souffle
9 This row contains pumpkin and tart
SELECT * FROM t1 WHERE MATCH(f2)
AGAINST('+pumpkin +(>souffle <tart)' IN BOOLEAN MODE);
f1 f2
8 This row contains pumpkin and souffle
14 This row contains all three souffle, pumpkin and tart
15 This row contains all four cheese, souffle, pumpkin and tart
9 This row contains pumpkin and tart
SELECT * FROM t1 WHERE MATCH(f2)
AGAINST('+pumpkin +(souffle tart)' IN BOOLEAN MODE);
f1 f2
14 This row contains all three souffle, pumpkin and tart
15 This row contains all four cheese, souffle, pumpkin and tart
8 This row contains pumpkin and souffle
9 This row contains pumpkin and tart
DROP TABLE t1;

View file

@ -0,0 +1,41 @@
#
# BUG#22094601 CREATE TABLE WITH FULLTEXT AND CONSTRAINT FAILS WHEN FOREIGN_KEY_CHECKS IS 0
#
--source include/have_innodb.inc
--error ER_CANT_CREATE_TABLE
CREATE TABLE t1 (
id INT NOT NULL,
title TEXT,
PRIMARY KEY (id),
FULLTEXT KEY (title),
FOREIGN KEY (id) REFERENCES t2 (id)
) ENGINE=InnoDB;
CREATE TABLE t1 (
id INT NOT NULL,
title TEXT,
PRIMARY KEY (id)
) ENGINE=InnoDB;
--error ER_CANT_CREATE_TABLE
ALTER TABLE t1 ADD FULLTEXT KEY (title), ADD FOREIGN KEY (id) REFERENCES t2 (id);
SET FOREIGN_KEY_CHECKS = 0;
ALTER TABLE t1 ADD FULLTEXT KEY (title), ADD FOREIGN KEY (id) REFERENCES t2 (id);
DROP TABLE t1;
CREATE TABLE t1 (
id INT NOT NULL,
title TEXT,
PRIMARY KEY (id),
FULLTEXT KEY (title),
FOREIGN KEY (id) REFERENCES t2 (id)
) ENGINE=InnoDB;
DROP TABLE t1;
SET FOREIGN_KEY_CHECKS = 1;

View file

@ -0,0 +1,34 @@
#
# BUG#21111301 INNODB FTS: ERROR DUPLICATE ENTRY IN FTS_DOC_ID_INDEX ON UPDATE CASCADE
#
-- source include/have_innodb.inc
CREATE TABLE t1 (
a varchar(40),
KEY a(a)
) ENGINE=InnoDB;
CREATE TABLE t1_fk (
a varchar(40),
KEY a(a),
FULLTEXT KEY (a),
CONSTRAINT fk FOREIGN KEY (a) REFERENCES t1 (a) ON UPDATE CASCADE
) ENGINE=InnoDB;
INSERT INTO t1 VALUES('mysql');
INSERT INTO t1_fk VALUES('mysql');
INSERT INTO t1_fk VALUES('mysql');
SELECT * FROM t1_fk;
SELECT * FROM t1_fk WHERE MATCH(a) AGAINST('mysql');
UPDATE t1 SET a = 'database' WHERE a = 'mysql';
SELECT * FROM t1_fk;
SELECT * FROM t1_fk WHERE MATCH(a) AGAINST('mysql');
SELECT * FROM t1_fk WHERE MATCH(a) AGAINST('database');
DROP TABLE t1_fk;
DROP TABLE t1;

View file

@ -0,0 +1,2 @@
--innodb-ft-index-cache
--innodb-ft-index-table

View file

@ -0,0 +1,121 @@
# This is the basic function tests for INNODB_FT_INDEX_TABLE
# and INNODB_FT_INDEX_TABLE in INFORMATION_SCHEMA.
-- source include/have_innodb.inc
-- source include/have_debug.inc
SET @optimize=@@GLOBAL.INNODB_OPTIMIZE_FULLTEXT_ONLY;
SET GLOBAL INNODB_OPTIMIZE_FULLTEXT_ONLY=1;
# Test Case 1: Test Result Cache Limit
CREATE TABLE articles (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
title VARCHAR(200),
content TEXT
) ENGINE= InnoDB;
CREATE FULLTEXT INDEX idx ON articles (title, content);
INSERT INTO articles (title, content) VALUES
('MySQL Tutorial','DBMS stands for MySQL DataBase ...'),
('How To Use MySQL Well','After you went through a ...'),
('Optimizing MySQL','In this tutorial we will show ...'),
('1001 MySQL Tricks','How to use full-text search engine'),
('Go MySQL Tricks','How to use full text search engine');
SET @aux=@@GLOBAL.innodb_ft_aux_table;
SET GLOBAL innodb_ft_aux_table='test/articles';
SELECT * FROM INFORMATION_SCHEMA.INNODB_FT_INDEX_CACHE;
OPTIMIZE TABLE articles;
SELECT * FROM INFORMATION_SCHEMA.INNODB_FT_INDEX_TABLE;
SET @save_dbug=@@debug_dbug;
SET debug_dbug='+d,fts_instrument_result_cache_limit';
SELECT * FROM INFORMATION_SCHEMA.INNODB_FT_INDEX_TABLE;
SET debug_dbug=@save_dbug;
DROP TABLE articles;
SET GLOBAL innodb_ft_result_cache_limit=default;
# Test Case 2: Test Multiple Indexes
CREATE TABLE articles (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
title VARCHAR(200),
content TEXT
) ENGINE= InnoDB;
CREATE FULLTEXT INDEX idx_t ON articles (title);
CREATE FULLTEXT INDEX idx_c ON articles (content);
INSERT INTO articles (title, content) VALUES
('MySQL Tutorial','DBMS stands for MySQL DataBase ...'),
('How To Use MySQL Well','After you went through a ...'),
('Optimizing MySQL','In this tutorial we will show ...'),
('1001 MySQL Tricks','How to use full-text search engine'),
('Go MySQL Tricks','How to use full text search engine');
# test.articles had been dropped, so this result will be empty
SELECT * FROM INFORMATION_SCHEMA.INNODB_FT_INDEX_CACHE;
SET GLOBAL innodb_ft_aux_table='test/articles';
SELECT * FROM INFORMATION_SCHEMA.INNODB_FT_INDEX_CACHE;
OPTIMIZE TABLE articles;
SELECT * FROM INFORMATION_SCHEMA.INNODB_FT_INDEX_TABLE;
DROP TABLE articles;
SET NAMES utf8;
# Test Case 3: Test UFT8 Charset
CREATE TABLE articles (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
title VARCHAR(200)
) ENGINE=InnoDB DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE FULLTEXT INDEX idx ON articles (title);
INSERT INTO articles (title) VALUES
('相亲相爱'),('怜香惜爱'),('充满可爱'),('爱恨交织');
SET GLOBAL innodb_ft_aux_table="test/articles";
SELECT * FROM INFORMATION_SCHEMA.INNODB_FT_INDEX_CACHE;
OPTIMIZE TABLE articles;
SELECT * FROM INFORMATION_SCHEMA.INNODB_FT_INDEX_TABLE;
DROP TABLE articles;
# Test Case 4: Test GB2312 Charset
CREATE TABLE articles (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
title VARCHAR(200)
) ENGINE=InnoDB DEFAULT CHARACTER SET gb2312 COLLATE gb2312_chinese_ci;
CREATE FULLTEXT INDEX idx ON articles (title);
INSERT INTO articles (title) VALUES
('相亲相爱'),('怜香惜爱'),('充满可爱'),('爱恨交织');
SET GLOBAL innodb_ft_aux_table="test/articles";
SELECT * FROM INFORMATION_SCHEMA.INNODB_FT_INDEX_CACHE;
OPTIMIZE TABLE articles;
SELECT * FROM INFORMATION_SCHEMA.INNODB_FT_INDEX_TABLE;
DROP TABLE articles;
# Restore global variables
SET GLOBAL innodb_ft_aux_table=@aux;
SET GLOBAL INNODB_OPTIMIZE_FULLTEXT_ONLY=@optimize;

View file

@ -163,6 +163,8 @@ DROP TABLE t1;
set global innodb_file_per_table=1;
set names utf8;
--character_set utf8
# Test fts with externally stored long column
CREATE TABLE t1 (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,

View file

@ -0,0 +1,143 @@
--source include/have_debug.inc
--source include/have_innodb.inc
--echo # Bug #22709692 FTS QUERY EXCEEDS RESULT CACHE LIMIT
CREATE TABLE articles (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
title VARCHAR(200),
body TEXT,
FULLTEXT (title,body),
FULLTEXT (body))ENGINE=InnoDB;
INSERT INTO articles (title,body) VALUES
('MySQL Tutorial','DBMS stands for DataBase ...'),
('How To Use MySQL Well','After you went through a ...'),
('Optimizing MySQL','In this tutorial we will show ...'),
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL','In the following database comparison ...'),
('MySQL Security','When configured properly, MySQL ...');
SET @default_cache_size = @@GLOBAL.query_cache_size;
SET GLOBAL query_cache_size=0;
--echo # Query involves Ranking
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('MySQL' IN NATURAL LANGUAGE MODE) LIMIT 1;
--echo # Without optimization
SET @save_dbug = @@debug_dbug;
SET debug_dbug = '+d,fts_union_limit_off';
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('MySQL' IN NATURAL LANGUAGE MODE) LIMIT 1;
SET debug_dbug = @save_dbug;
--echo # Query involves No Ranking and fts_union operations
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('MySQL' IN BOOLEAN MODE) limit 1;
--echo # Without optimization
SET debug_dbug = '+d,fts_union_limit_off';
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('MySQL' IN BOOLEAN MODE) limit 1;
SET debug_dbug = @save_dbug;
--echo # Query involves No ranking and fts_union, fts_ignore
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('MySQL -YourSQL' IN BOOLEAN MODE) limit 1;
--echo # Without optimization
SET debug_dbug = '+d,fts_union_limit_off';
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('MySQL -YourSQL' IN BOOLEAN MODE) limit 1;
SET debug_dbug = @save_dbug;
--echo # Query with fts_intersect
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('MySQL +YourSQL' IN BOOLEAN MODE) limit 1;
--echo # Without optimization
SET debug_dbug = '+d,fts_union_limit_off';
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('MySQL +YourSQL' IN BOOLEAN MODE) limit 1;
SET debug_dbug = @save_dbug;
# insert record with @ character which is used in proximity search
INSERT INTO articles (title,body) VALUES
('MySQL Tutorial','request doc@oraclehelp.com ...'),
('MySQL Tutorial','request support@oraclehelp.com ...'),
('Trial version','query performace @1255 minute on 2.1Hz
Memory 2GB...'),
('when To Use MySQL Well','for free faq mail@xyz.com ...');
--echo # Query with @distance
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('"MySQL request"@3' IN BOOLEAN MODE) limit 1;
--echo # Without optimization
SET debug_dbug = '+d,fts_union_limit_off';
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('"MySQL request"@3' IN BOOLEAN MODE) limit 1;
SET debug_dbug = @save_dbug;
--echo # Query with subexpression
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('+MySQL +(-support +doc)' IN BOOLEAN MODE) limit 1;
--echo # Without optimization
SET debug_dbug = '+d,fts_union_limit_off';
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('+MySQL +(-support +doc)' IN BOOLEAN MODE) limit 1;
SET debug_dbug = @save_dbug;
--echo # limit num1 OFFSET num2
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('MySQL' in boolean mode) limit 4 offset 2;
--echo # Without optimization
SET debug_dbug = '+d,fts_union_limit_off';
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('MySQL' in boolean mode) limit 4 offset 2;
SET debug_dbug = @save_dbug;
--echo # wild card search
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('ru*' IN BOOLEAN MODE) limit 1;
--echo # Without optimization
SET debug_dbug = '+d,fts_union_limit_off';
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('ru*' IN BOOLEAN MODE) limit 1;
SET debug_dbug = @save_dbug;
--echo # phrase search
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('"request support"' IN BOOLEAN MODE) limit 1;
--echo # Without optimization
SET debug_dbug = '+d,fts_union_limit_off';
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('"request support"' IN BOOLEAN MODE) limit 1;
SET debug_dbug = @save_dbug;
DROP TABLE articles;
SET GLOBAL query_cache_size = @default_cache_size;

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,894 @@
--source include/have_innodb.inc
--source include/innodb_page_size_small.inc
--source include/no_valgrind_without_big.inc
#------------------------------------------------------------------------------
# FTS with FK and update cascade
#-------------------------------------------------------------------------------
set names utf8;
call mtr.add_suppression("\\[Warning\\] InnoDB: A new Doc ID must be supplied while updating FTS indexed columns.");
call mtr.add_suppression("\\[Warning\\] InnoDB: FTS Doc ID must be larger than [0-9]+ for table `test`.`t1`");
# Create FTS table
CREATE TABLE t1 (
id1 INT ,
a1 VARCHAR(200) ,
b1 TEXT ,
FULLTEXT KEY (a1,b1), PRIMARY KEY (a1, id1)
) CHARACTER SET = utf8 , ENGINE = InnoDB;
CREATE TABLE t2 (
id2 INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
a2 VARCHAR(200),
b2 TEXT ,
FOREIGN KEY (a2) REFERENCES t1(a1) ON UPDATE CASCADE,
FULLTEXT KEY (b2,a2)
) CHARACTER SET = utf8 ,ENGINE = InnoDB;
# Insert rows
INSERT INTO t1 (id1,a1,b1) VALUES
(1,'MySQL Tutorial','DBMS stands for DataBase VÐƷWİ...') ,
(2,'How To Use MySQL Well','After you went through a ...'),
(3,'Optimizing MySQL','In this tutorial we will show ...');
# Insert rows
INSERT INTO t1 (id1,a1,b1) VALUES
(4,'1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
(5,'MySQL vs. YourSQL','In the following database comparison ...'),
(6,'MySQL Security','When configured properly, MySQL ...');
# Insert rows in t2 fk table
INSERT INTO t2 (a2,b2) VALUES
('MySQL Tutorial','DBMS stands for DataBase VÐƷWİ...') ,
('How To Use MySQL Well','After you went through a ...'),
('Optimizing MySQL','In this tutorial we will show ...');
# Insert rows t2 fk table
INSERT INTO t2 (a2,b2) VALUES
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL','In the following database comparison ...'),
('MySQL Security','When configured properly, MySQL ...');
# error on violating fk constraint
--error 1452
INSERT INTO t2 (a2,b2) VALUES
('MySQL Tricks','1. Never run mysqld as root. 2. ...');
# error on delete from parent table
--error 1451
DELETE FROM t1;
ANALYZE TABLE t1;
ANALYZE TABLE t2;
SELECT id1 FROM t1 WHERE MATCH (a1,b1) AGAINST ('tutorial') ORDER BY id1;
SELECT id2 FROM t2 WHERE MATCH (a2,b2) AGAINST ('tutorial') ORDER BY id2;
SELECT id1 FROM t1 WHERE MATCH (a1,b1) AGAINST ('tutorial (+mysql -VÐƷWİ)' IN BOOLEAN MODE) ORDER BY id1;
SELECT id2 FROM t2 WHERE MATCH (a2,b2) AGAINST ('tutorial (+mysql -VÐƷWİ)' IN BOOLEAN MODE) ORDER BY id2;
SELECT id1 FROM t1 WHERE MATCH (a1,b1) AGAINST ('tutorial' WITH QUERY EXPANSION) ORDER BY id1;
SELECT id2 FROM t2 WHERE MATCH (a2,b2) AGAINST ('tutorial' WITH QUERY EXPANSION) ORDER BY id2;
SELECT id1 FROM t1 WHERE MATCH (a1,b1) AGAINST ('"dbms database"@4' IN BOOLEAN MODE) ;
SELECT id2 FROM t2 WHERE MATCH (a2,b2) AGAINST ('"dbms database"@4' IN BOOLEAN MODE) ;
set global innodb_optimize_fulltext_only=1;
optimize table t1;
set global innodb_optimize_fulltext_only=0;
# Updating parent table hence child table should get updated due to 'update cascade' clause
UPDATE t1 SET a1 = "changing column - on update cascade" , b1 = "to check foreign constraint" WHERE
MATCH (a1,b1) AGAINST ('tutorial (+mysql -VÐƷWİ)' IN BOOLEAN MODE) ;
# no records expected
SELECT id1 FROM t1 WHERE MATCH (a1,b1) AGAINST ('tutorial (+mysql -VÐƷWİ)' IN BOOLEAN MODE) ;
# InnoDB:Error child table shows records which is incorrect - UPADTE on Fix
SELECT id2 FROM t2 WHERE MATCH (a2,b2) AGAINST ('tutorial (+mysql -VÐƷWİ)' IN BOOLEAN MODE) ;
# it shows updated record
SELECT id1 FROM t1 WHERE MATCH (a1,b1) AGAINST ('+update +cascade' IN BOOLEAN MODE) ORDER BY id1;
# InnoDB:Error child table does not show the expected record
SELECT id2 FROM t2 WHERE MATCH (a2,b2) AGAINST ('+update +cascade' IN BOOLEAN MODE) ORDER BY id2;
SELECT id2 FROM t2 WHERE a2 LIKE '%UPDATE CASCADE%' ORDER BY id2;
DROP TABLE t2 , t1;
# on update cascade
create table t1 (s1 int, s2 varchar(200), primary key (s1,s2)) ENGINE = InnoDB;
create table t2 (s1 int, s2 varchar(200),
fulltext key(s2),
foreign key (s1,s2) references t1 (s1,s2) on update cascade) ENGINE = InnoDB;
insert into t1 values (1,'Sunshine'),(2,'Lollipops');
insert into t2 values (1,'Sunshine'),(2,'Lollipops');
update t1 set s2 = 'Rainbows' where s2 <> 'Sunshine';
commit;
select * from t2 where match(s2) against ('Lollipops');
DROP TABLE t2 , t1;
# on delete cascade
create table t1 (s1 int, s2 varchar(200), primary key (s1,s2)) ENGINE = InnoDB;
create table t2 (s1 int, s2 varchar(200),
fulltext key(s2),
foreign key (s1,s2) references t1 (s1,s2) on delete cascade) ENGINE = InnoDB;
insert into t1 values (1,'Sunshine'),(2,'Lollipops');
insert into t2 values (1,'Sunshine'),(2,'Lollipops');
delete from t1 where s2 <> 'Sunshine';
select * from t2 where match(s2) against ('Lollipops');
DROP TABLE t2 , t1;
# on delete set NULL
create table t1 (s1 int, s2 varchar(200), primary key (s1,s2)) ENGINE = InnoDB;
create table t2 (s1 int, s2 varchar(200),
fulltext key(s2),
foreign key (s1,s2) references t1 (s1,s2) on delete set null) ENGINE = InnoDB;
insert into t1 values (1,'Sunshine'),(2,'Lollipops');
insert into t2 values (1,'Sunshine'),(2,'Lollipops');
delete from t1 where s2 <> 'Sunshine';
select * from t2 where match(s2) against ('Lollipops');
DROP TABLE t2 , t1;
# on update set NULL
create table t1 (s1 int, s2 varchar(200), primary key (s1,s2)) ENGINE = InnoDB;
create table t2 (s1 int, s2 varchar(200),
fulltext key(s2),
foreign key (s1,s2) references t1 (s1,s2) on update set null) ENGINE = InnoDB;
insert into t1 values (1,'Sunshine'),(2,'Lollipops');
insert into t2 values (1,'Sunshine'),(2,'Lollipops');
update t1 set s2 = 'Rainbows' where s2 <> 'Sunshine';
commit;
select * from t2 where match(s2) against ('Lollipops');
DROP TABLE t2 , t1;
# When Doc ID is involved
create table t1 (s1 bigint unsigned not null, s2 varchar(200),
primary key (s1,s2)) ENGINE = InnoDB;
create table t2 (FTS_DOC_ID BIGINT UNSIGNED NOT NULL, s2 varchar(200),
foreign key (FTS_DOC_ID) references t1 (s1)
on update cascade) ENGINE = InnoDB;
create fulltext index idx on t2(s2);
show create table t2;
insert into t1 values (1,'Sunshine'),(2,'Lollipops');
insert into t2 values (1,'Sunshine'),(2,'Lollipops');
update t1 set s1 = 3 where s1=1;
select * from t2 where match(s2) against ('sunshine');
# FTS Doc ID cannot be reused
--error 1451
update t1 set s1 = 1 where s1=3;
DROP TABLE t2 , t1;
#------------------------------------------------------------------------------
# FTS with FK and delete casecade
#------------------------------------------------------------------------------
# Create FTS table
CREATE TABLE t1 (
id1 INT ,
a1 VARCHAR(200) PRIMARY KEY,
b1 TEXT character set utf8 ,
FULLTEXT KEY (a1,b1)
) CHARACTER SET = utf8 ,ENGINE = InnoDB;
CREATE TABLE t2 (
id2 INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
a2 VARCHAR(200),
b2 TEXT character set utf8 ,
FOREIGN KEY (a2) REFERENCES t1(a1) ON DELETE CASCADE,
FULLTEXT KEY (b2,a2)
) CHARACTER SET = utf8 ,ENGINE = InnoDB;
# Insert rows
INSERT INTO t1 (id1,a1,b1) VALUES
(1,'MySQL Tutorial','DBMS stands for DataBase VÐƷWİ...') ,
(2,'How To Use MySQL Well','After you went through a ...'),
(3,'Optimizing MySQL','In this tutorial we will show ...'),
(4,'1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
(5,'MySQL vs. YourSQL','In the following database comparison ...'),
(6,'MySQL Security','When configured properly, MySQL ...');
# Insert rows in t2
INSERT INTO t2 (a2,b2) VALUES
('MySQL Tutorial','DBMS stands for DataBase VÐƷWİ...') ,
('How To Use MySQL Well','After you went through a ...'),
('Optimizing MySQL','In this tutorial we will show ...'),
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL','In the following database comparison ...'),
('MySQL Security','When configured properly, MySQL ...');
# delete records from parent
DELETE FROM t1 WHERE MATCH (a1,b1) AGAINST ('tutorial (+mysql -VÐƷWİ)' IN BOOLEAN MODE) ;
# no records expected
SELECT * FROM t1 WHERE MATCH (a1,b1) AGAINST ('tutorial (+mysql -VÐƷWİ)' IN BOOLEAN MODE) ;
SELECT * FROM t2 WHERE MATCH (a2,b2) AGAINST ('tutorial (+mysql -VÐƷWİ)' IN BOOLEAN MODE) ;
SELECT * FROM t1 WHERE a1 LIKE '%tutorial%';
SELECT * FROM t2 WHERE a2 LIKE '%tutorial%';
DROP TABLE t2 , t1;
#------------------------------------------------------------------------------
# FTS with FK+transactions and UPDATE casecade with transaction
#-------------------------------------------------------------------------------
call mtr.add_suppression("\\[ERROR\\] InnoDB: FTS Doc ID must be larger than 3 for table `test`.`t2`");
# Create FTS table
CREATE TABLE t1 (
id1 INT ,
a1 VARCHAR(200) ,
b1 TEXT ,
FULLTEXT KEY (a1,b1), PRIMARY KEY(a1, id1)
) CHARACTER SET = utf8 , ENGINE = InnoDB;
CREATE TABLE t2 (
id2 INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
a2 VARCHAR(200),
b2 TEXT ,
FOREIGN KEY (a2) REFERENCES t1(a1) ON UPDATE CASCADE,
FULLTEXT KEY (b2,a2)
) CHARACTER SET = utf8 ,ENGINE = InnoDB;
# Insert rows
INSERT INTO t1 (id1,a1,b1) VALUES
(1,'MySQL Tutorial','DBMS stands for DataBase VÐƷWİ...') ,
(2,'How To Use MySQL Well','After you went through a ...'),
(3,'Optimizing MySQL','In this tutorial we will show ...');
# Insert rows in t2 fk table
INSERT INTO t2 (a2,b2) VALUES
('MySQL Tutorial','DBMS stands for DataBase VÐƷWİ...') ,
('How To Use MySQL Well','After you went through a ...'),
('Optimizing MySQL','In this tutorial we will show ...');
START TRANSACTION;
# Insert rows
INSERT INTO t1 (id1,a1,b1) VALUES
(4,'1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
(5,'MySQL vs. YourSQL','In the following database comparison ...'),
(6,'MySQL Security','When configured properly, MySQL ...');
# Insert rows t2 fk table
INSERT INTO t2 (a2,b2) VALUES
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL','In the following database comparison ...'),
('MySQL Security','When configured properly, MySQL ...');
# error on violating fk constraint
--error 1452
INSERT INTO t2 (a2,b2) VALUES
('MySQL Tricks','1. Never run mysqld as root. 2. ...');
# error on DELETE FROM parent table
--error 1451
DELETE FROM t1;
# records expected
SELECT * FROM t1 WHERE MATCH (a1,b1) AGAINST ('tutorial') ORDER BY id1;
SELECT * FROM t2 WHERE MATCH (a2,b2) AGAINST ('tutorial') ORDER BY id2;
SELECT * FROM t1 WHERE MATCH (a1,b1) AGAINST ('tutorial (+mysql -VÐƷWİ)' IN BOOLEAN MODE) ORDER BY id1;
SELECT * FROM t2 WHERE MATCH (a2,b2) AGAINST ('tutorial (+mysql -VÐƷWİ)' IN BOOLEAN MODE) ORDER BY id2;
SELECT * FROM t1 WHERE MATCH (a1,b1) AGAINST ('tutorial' WITH QUERY EXPANSION) ORDER BY id1;
SELECT * FROM t2 WHERE MATCH (a2,b2) AGAINST ('tutorial' WITH QUERY EXPANSION) ORDER BY id2;
SELECT * FROM t1 WHERE MATCH (a1,b1) AGAINST ('"dbms database"@4' IN BOOLEAN MODE) ;
SELECT * FROM t2 WHERE MATCH (a2,b2) AGAINST ('"dbms database"@4' IN BOOLEAN MODE) ;
# no records as data not COMMITted.
SELECT * FROM t1 WHERE MATCH (a1,b1) AGAINST ('root') ;
SELECT * FROM t2 WHERE MATCH (a2,b2) AGAINST ('root') ;
SELECT * FROM t1 WHERE MATCH (a1,b1) AGAINST ('mysqld (+root)' IN BOOLEAN MODE) ;
SELECT * FROM t2 WHERE MATCH (a2,b2) AGAINST ('mysqld (-root)' IN BOOLEAN MODE) ;
SELECT * FROM t1 WHERE MATCH (a1,b1) AGAINST ('root' WITH QUERY EXPANSION) ;
SELECT * FROM t2 WHERE MATCH (a2,b2) AGAINST ('root' WITH QUERY EXPANSION) ;
SELECT * FROM t1 WHERE MATCH (a1,b1) AGAINST ('"database comparison"@02' IN BOOLEAN MODE) ;
SELECT * FROM t2 WHERE MATCH (a2,b2) AGAINST ('"database comparison"@02' IN BOOLEAN MODE) ;
SELECT * FROM t1 ORDER BY id1;
SELECT * FROM t2 ORDER BY id2;
COMMIT;
START TRANSACTION;
# Updating parent table hence child table should get updated due to 'UPDATE cascade' clause
UPDATE t1 SET a1 = "changing column - on UPDATE cascade" , b1 = "to check foreign constraint" WHERE
MATCH (a1,b1) AGAINST ('tutorial (+mysql -VÐƷWİ)' IN BOOLEAN MODE) ;
COMMIT;
# no records expected
SELECT * FROM t1 WHERE MATCH (a1,b1) AGAINST ('tutorial (+mysql -VÐƷWİ)' IN BOOLEAN MODE) ;
SELECT * FROM t2 WHERE MATCH (a2,b2) AGAINST ('tutorial (+mysql -VÐƷWİ)' IN BOOLEAN MODE) ;
# it shows updated record
SELECT * FROM t1 WHERE MATCH (a1,b1) AGAINST ('+UPDATE +cascade' IN BOOLEAN MODE) ORDER BY id1;
SELECT * FROM t2 WHERE MATCH (a2,b2) AGAINST ('+UPDATE +cascade' IN BOOLEAN MODE) ORDER BY id2;
SELECT * FROM t2 WHERE a2 LIKE '%UPDATE CASCADE%' ORDER BY id2;
DROP TABLE t2 , t1;
# FTS with FK+transactions - UPDATE cascade
CREATE TABLE t1 (s1 INT, s2 VARCHAR(200), PRIMARY KEY (s1,s2)) ENGINE = InnoDB;
CREATE TABLE t2 (s1 INT, s2 VARCHAR(200),
FULLTEXT KEY(s2),
FOREIGN KEY (s1,s2) REFERENCES t1 (s1,s2) on UPDATE cascade) ENGINE = InnoDB;
START TRANSACTION;
INSERT INTO t1 VALUES (1,'Sunshine'),(2,'Lollipops');
INSERT INTO t2 VALUES (1,'Sunshine'),(2,'Lollipops');
UPDATE t1 set s2 = 'Rainbows' WHERE s2 <> 'Sunshine';
COMMIT;
SELECT * FROM t2 WHERE MATCH(s2) AGAINST ('Lollipops');
DROP TABLE t2 , t1;
# FTS with FK+transactions - on DELETE cascade
CREATE TABLE t1 (s1 INT, s2 VARCHAR(200), PRIMARY KEY (s1,s2)) ENGINE = InnoDB;
CREATE TABLE t2 (s1 INT, s2 VARCHAR(200),
FULLTEXT KEY(s2),
FOREIGN KEY (s1,s2) REFERENCES t1 (s1,s2) on DELETE cascade) ENGINE = InnoDB;
START TRANSACTION;
INSERT INTO t1 VALUES (1,'Sunshine'),(2,'Lollipops');
INSERT INTO t2 VALUES (1,'Sunshine'),(2,'Lollipops');
DELETE FROM t1 WHERE s2 <> 'Sunshine';
COMMIT;
SELECT * FROM t2 WHERE MATCH(s2) AGAINST ('Lollipops');
DROP TABLE t2 , t1;
# FTS with FK+transactions - DELETE SET NULL
CREATE TABLE t1 (s1 INT, s2 VARCHAR(200), PRIMARY KEY (s1,s2)) ENGINE = InnoDB;
CREATE TABLE t2 (s1 INT, s2 VARCHAR(200),
FULLTEXT KEY(s2),
FOREIGN KEY (s1,s2) REFERENCES t1 (s1,s2) on DELETE SET NULL) ENGINE = InnoDB;
START TRANSACTION;
INSERT INTO t1 VALUES (1,'Sunshine'),(2,'Lollipops');
INSERT INTO t2 VALUES (1,'Sunshine'),(2,'Lollipops');
DELETE FROM t1 WHERE s2 <> 'Sunshine';
COMMIT;
SELECT * FROM t2 WHERE MATCH(s2) AGAINST ('Lollipops');
DROP TABLE t2 , t1;
# FTS with FK+transactions - UPDATE SET NULL
CREATE TABLE t1 (s1 INT, s2 VARCHAR(200), PRIMARY KEY (s1,s2)) ENGINE = InnoDB;
CREATE TABLE t2 (s1 INT, s2 VARCHAR(200),
FULLTEXT KEY(s2),
FOREIGN KEY (s1,s2) REFERENCES t1 (s1,s2) on UPDATE SET NULL) ENGINE = InnoDB;
START TRANSACTION;
INSERT INTO t1 VALUES (1,'Sunshine'),(2,'Lollipops');
INSERT INTO t2 VALUES (1,'Sunshine'),(2,'Lollipops');
UPDATE t1 set s2 = 'Rainbows' WHERE s2 <> 'Sunshine';
COMMIT;
SELECT * FROM t2 WHERE MATCH(s2) AGAINST ('Lollipops');
DROP TABLE t2 , t1;
#-----------------------------------------------------------------------------
# FTS with FK+transactions - UPDATE cascade
CREATE TABLE t1 (s1 INT, s2 VARCHAR(200), PRIMARY KEY (s1,s2)) ENGINE = InnoDB;
CREATE TABLE t2 (s1 INT, s2 VARCHAR(200),
FULLTEXT KEY(s2),
FOREIGN KEY (s1,s2) REFERENCES t1 (s1,s2) on UPDATE cascade) ENGINE = InnoDB;
START TRANSACTION;
INSERT INTO t1 VALUES (1,'Sunshine'),(2,'Lollipops');
INSERT INTO t2 VALUES (1,'Sunshine'),(2,'Lollipops');
UPDATE t1 set s2 = 'Rainbows' WHERE s2 <> 'Sunshine';
ROLLBACK;
SELECT * FROM t2 WHERE MATCH(s2) AGAINST ('Lollipops');
DROP TABLE t2 , t1;
# FTS with FK+transactions - DELETE cascade
CREATE TABLE t1 (s1 INT, s2 VARCHAR(200), PRIMARY KEY (s1,s2)) ENGINE = InnoDB;
CREATE TABLE t2 (s1 INT, s2 VARCHAR(200),
FULLTEXT KEY(s2),
FOREIGN KEY (s1,s2) REFERENCES t1 (s1,s2) on DELETE cascade) ENGINE = InnoDB;
START TRANSACTION;
INSERT INTO t1 VALUES (1,'Sunshine'),(2,'Lollipops');
INSERT INTO t2 VALUES (1,'Sunshine'),(2,'Lollipops');
DELETE FROM t1 WHERE s2 <> 'Sunshine';
ROLLBACK;
SELECT * FROM t2 WHERE MATCH(s2) AGAINST ('Lollipops');
DROP TABLE t2 , t1;
# FTS with FK+transactions - DELETE SET NULL
CREATE TABLE t1 (s1 INT, s2 VARCHAR(200), PRIMARY KEY (s1,s2)) ENGINE = InnoDB;
CREATE TABLE t2 (s1 INT, s2 VARCHAR(200),
FULLTEXT KEY(s2),
FOREIGN KEY (s1,s2) REFERENCES t1 (s1,s2) on DELETE SET NULL) ENGINE = InnoDB;
START TRANSACTION;
INSERT INTO t1 VALUES (1,'Sunshine'),(2,'Lollipops');
INSERT INTO t2 VALUES (1,'Sunshine'),(2,'Lollipops');
DELETE FROM t1 WHERE s2 <> 'Sunshine';
ROLLBACK;
SELECT * FROM t2 WHERE MATCH(s2) AGAINST ('Lollipops');
DROP TABLE t2 , t1;
# FTS with FK+transactions - UPDATE SET NULL
CREATE TABLE t1 (s1 INT, s2 VARCHAR(200), PRIMARY KEY (s1,s2)) ENGINE = InnoDB;
CREATE TABLE t2 (s1 INT, s2 VARCHAR(200),
FULLTEXT KEY(s2),
FOREIGN KEY (s1,s2) REFERENCES t1 (s1,s2) on UPDATE SET NULL) ENGINE = InnoDB;
START TRANSACTION;
INSERT INTO t1 VALUES (1,'Sunshine'),(2,'Lollipops');
INSERT INTO t2 VALUES (1,'Sunshine'),(2,'Lollipops');
UPDATE t1 set s2 = 'Rainbows' WHERE s2 <> 'Sunshine';
ROLLBACK;
SELECT * FROM t2 WHERE MATCH(s2) AGAINST ('Lollipops');
DROP TABLE t2 , t1;
#------------------------------------------------------------------------------
# FTS index with compressed row format
#------------------------------------------------------------------------------
# Save innodb variables
let $innodb_file_per_table_orig=`select @@innodb_file_per_table`;
set global innodb_file_per_table=1;
# Create FTS table
CREATE TABLE t1 (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
a VARCHAR(200),
b TEXT
) CHARACTER SET = utf8, ROW_FORMAT=COMPRESSED, ENGINE = InnoDB;
# Insert rows
INSERT INTO t1 (a,b) VALUES
('MySQL Tutorial','DBMS stands for DataBase VÐƷWİ...') ,
('How To Use MySQL Well','After you went through a ...'),
('Optimizing MySQL','In this tutorial we will show ...');
# Create the FTS index Using Alter Table
ALTER TABLE t1 ADD FULLTEXT INDEX idx (a,b);
EVAL SHOW CREATE TABLE t1;
# Check whether individual space id created for AUX tables
SELECT count(*) FROM information_schema.innodb_sys_tables WHERE name LIKE "%FTS_%" AND space !=0;
# Insert rows
INSERT INTO t1 (a,b) VALUES
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL','In the following database comparison ...'),
('MySQL Security','When configured properly, MySQL ...');
-- disable_result_log
ANALYZE TABLE t1;
-- enable_result_log
# Select word "tutorial" in the table
SELECT * FROM t1 WHERE MATCH (a,b)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE) ORDER BY id;
# boolean mode
select * from t1 where MATCH(a,b) AGAINST("+tutorial +VÐƷWİ" IN BOOLEAN MODE);
--error ER_PARSE_ERROR
select * from t1 where MATCH(a,b) AGAINST("+-VÐƷWİ" IN BOOLEAN MODE);
select * from t1 where MATCH(a,b) AGAINST("+Mysql +(tricks never)" IN BOOLEAN MODE);
select * from t1 where MATCH(a,b) AGAINST("+mysql -(tricks never)" IN BOOLEAN MODE) ORDER BY id;
select *, MATCH(a,b) AGAINST("mysql stands" IN BOOLEAN MODE) as x from t1 ORDER BY id;
select * from t1 where MATCH a,b AGAINST ("+database* +VÐƷW*" IN BOOLEAN MODE);
select * from t1 where MATCH a,b AGAINST ('"security mysql"' IN BOOLEAN MODE);
# query expansion
select * from t1 where MATCH(a,b) AGAINST ("VÐƷWİ" WITH QUERY EXPANSION) ORDER BY id;
# Drop index
ALTER TABLE t1 DROP INDEX idx;
# Create the FTS index again
CREATE FULLTEXT INDEX idx on t1 (a,b);
-- disable_query_log
-- disable_result_log
ANALYZE TABLE t1;
-- enable_result_log
-- enable_query_log
# Select word "tutorial" in the table
SELECT * FROM t1 WHERE MATCH (a,b)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE) ORDER BY id;
# boolean mode
select * from t1 where MATCH(a,b) AGAINST("+tutorial +VÐƷWİ" IN BOOLEAN MODE);
select * from t1 where MATCH(a,b) AGAINST("+dbms" IN BOOLEAN MODE);
select * from t1 where MATCH(a,b) AGAINST("+Mysql +(tricks never)" IN BOOLEAN MODE);
select * from t1 where MATCH(a,b) AGAINST("+mysql -(tricks never)" IN BOOLEAN MODE) ORDER BY id;
select *, MATCH(a,b) AGAINST("mysql VÐƷWİ" IN BOOLEAN MODE) as x from t1 ORDER BY id;
# Innodb:Assert eval0eval.c line 148
#select * from t1 where MATCH a,b AGAINST ("+database* +VÐƷWİ*" IN BOOLEAN MODE);
select * from t1 where MATCH a,b AGAINST ('"security mysql"' IN BOOLEAN MODE);
# query expansion
select * from t1 where MATCH(a,b) AGAINST ("VÐƷWİ" WITH QUERY EXPANSION) ORDER BY id;
# insert for proximity search
INSERT INTO t1 (a,b) VALUES ('test query expansion','for database ...');
# Insert into table with similar word of different distances
INSERT INTO t1 (a,b) VALUES
('test proximity search, test, proximity and phrase',
'search, with proximity innodb');
INSERT INTO t1 (a,b) VALUES
('test proximity fts search, test, proximity and phrase',
'search, with proximity innodb');
INSERT INTO t1 (a,b) VALUES
('test more proximity fts search, test, more proximity and phrase',
'search, with proximity innodb');
# This should only return the first document
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"proximity search"@2' IN BOOLEAN MODE);
# This would return no document
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"proximity search"@1' IN BOOLEAN MODE);
# This give you all three documents
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"proximity search"@3' IN BOOLEAN MODE) ORDER BY id;
# Similar boundary testing for the words
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"test proximity"@5' IN BOOLEAN MODE) ORDER BY id;
# Test with more word The last document will return, please notice there
# is no ordering requirement for proximity search.
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"more test proximity"@2' IN BOOLEAN MODE);
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"more test proximity"@3' IN BOOLEAN MODE);
# The phrase search will not require exact word ordering
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"more fts proximity"@03' IN BOOLEAN MODE);
UPDATE t1 SET a = UPPER(a) , b = UPPER(b) ;
UPDATE t1 SET a = UPPER(a) , b = LOWER(b) ;
select * from t1 where MATCH(a,b) AGAINST("+tutorial +dbms" IN BOOLEAN MODE);
select * from t1 where MATCH(a,b) AGAINST("+VÐƷWİ" IN BOOLEAN MODE);
SELECT * FROM t1 WHERE MATCH (a,b)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE) ORDER BY id;
DELETE FROM t1 WHERE MATCH (a,b) AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
DELETE FROM t1 WHERE MATCH (a,b) AGAINST ('"proximity search"@14' IN BOOLEAN MODE);
SELECT * FROM t1 WHERE MATCH (a,b)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
SELECT * FROM t1 ORDER BY id;
DROP TABLE t1;
eval SET GLOBAL innodb_file_per_table=$innodb_file_per_table_orig;
#------------------------------------------------------------------------------
# FTS index with utf8 character testcase
#------------------------------------------------------------------------------
# Create FTS table
EVAL CREATE TABLE t1 (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
a VARCHAR(200),
b TEXT
) CHARACTER SET = utf8, ENGINE=InnoDB;
# Insert rows from different languages
INSERT INTO t1 (a,b) VALUES
('Я могу есть стекло', 'оно мне не вредит'),
('Мога да ям стъкло', 'то не ми вреди'),
('Μπορῶ νὰ φάω σπασμένα' ,'γυαλιὰ χωρὶς νὰ πάθω τίποτα'),
('Příliš žluťoučký kůň', 'úpěl ďábelské kódy'),
('Sævör grét', 'áðan því úlpan var ónýt'),
('うゐのおくやま','けふこえて'),
('いろはにほへど ちりぬる','あさきゆめみじ ゑひもせず');
# insert english text
INSERT INTO t1 (a,b) VALUES
('MySQL Tutorial','request docteam@oraclehelp.com ...') ,
('Trial version','query performace @1255 minute on 2.1Hz Memory 2GB...') ,
('when To Use MySQL Well','for free faq mail@xyz.com ...');
# Create the FTS index again
CREATE FULLTEXT INDEX idx on t1 (a,b);
# FTS Queries
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST ("вредит χωρὶς") ORDER BY id;
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST ("оно" WITH QUERY EXPANSION);
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST("вред*" IN BOOLEAN MODE) ORDER BY id;
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST("+γυαλιὰ +tutorial" IN BOOLEAN MODE);
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST("+tutorial +(Мога τίποτα)" IN BOOLEAN MODE);
# Innodb:error - no result returned (update result of query once fixed) (innodb limit , does not understand character boundry for japanses like charcter set)
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST ("あさきゆめみじ ゑひもせず");
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST ("ちりぬる" WITH QUERY EXPANSION);
# Innodb:error - no result returned (update result of query once fixed) (innodb limit , does not understand character boundry for japanses like charcter set)
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST ("+あさきゆめみじ +ゑひもせず" IN BOOLEAN MODE);
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST("うゐのおく*" IN BOOLEAN MODE);
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST("+Sævör +úlpan" IN BOOLEAN MODE);
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"γυαλιὰ χωρὶς"@2' IN BOOLEAN MODE);
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"query performace"@02' IN BOOLEAN MODE);
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"πάθω τίποτα"@2' IN BOOLEAN MODE);
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"あさきゆめみじ ゑひもせず"@1' IN BOOLEAN MODE);
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"あさきゆめみじ ゑひもせず"@2' IN BOOLEAN MODE);
ALTER TABLE t1 DROP INDEX idx;
# Create the FTS index again
CREATE FULLTEXT INDEX idx on t1 (a,b);
# Innodb:error - no result returned (update result of query once fixed) (innodb limit , does not understand character boundry for japanses like charcter set)
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST ("あさきゆめみじ ゑひもせず");
# Update fails because where condition do not succeed which is incorrect (update result of query once fixed)
UPDATE t1 SET a = "Pchnąć w tę łódź jeża" , b = "lub osiem skrzyń fig" WHERE MATCH(a,b) AGAINST ("あさきゆめみじ ゑひもせず");
UPDATE t1 SET a = "В чащах юга жил-был цитрус? Да", b = "но фальшивый экземпляр! ёъ" WHERE MATCH(a,b) AGAINST ("вред*" IN BOOLEAN MODE);
DELETE FROM t1 WHERE MATCH(a,b) AGAINST("+Sævör +úlpan" IN BOOLEAN MODE);
# Innodb error - no result returned
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST ("あさきゆめみじ ゑひもせず");
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST ("łódź osiem");
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST("вред*" IN BOOLEAN MODE);
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST("фальшив*" IN BOOLEAN MODE) ORDER BY id;
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST("+Sævör +úlpan" IN BOOLEAN MODE);
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"łódź jeża"@2' IN BOOLEAN MODE);
SELECT * FROM t1 ORDER BY id;
DROP TABLE t1;
# This is to test the update operation on FTS indexed and non-indexed
# column
CREATE TABLE t1(ID INT PRIMARY KEY,
no_fts_field VARCHAR(10),
fts_field VARCHAR(10),
FULLTEXT INDEX f(fts_field)) ENGINE=INNODB;
INSERT INTO t1 VALUES (1, 'AAA', 'BBB');
SELECT * FROM t1 WHERE MATCH(fts_field) against("BBB");
# Update FULLTEXT indexed column, Doc ID will be updated
UPDATE t1 SET fts_field='anychange' where id = 1;
SELECT * FROM t1 WHERE MATCH(fts_field) against("anychange");
# Update non-FULLTEXT indexed column, Doc ID stay to be the same
UPDATE t1 SET no_fts_field='anychange' where id = 1;
SELECT * FROM t1 WHERE MATCH(fts_field) against("anychange");
# Update both FULLTEXT indexed and non-indexed column, Doc ID will be updated
UPDATE t1 SET no_fts_field='anychange', fts_field='other' where id = 1;
SELECT * FROM t1 WHERE MATCH(fts_field) against("other");
SELECT * FROM t1 WHERE MATCH(fts_field) against("BBB");
# FTS index dropped, the DOC_ID column is kept, however, the ID will not
# change
DROP INDEX f on t1;
UPDATE t1 SET fts_field='anychange' where id = 1;
UPDATE t1 SET no_fts_field='anychange' where id = 1;
UPDATE t1 SET no_fts_field='anychange', fts_field='other' where id = 1;
CREATE FULLTEXT INDEX f ON t1(FTS_FIELD);
SELECT * FROM t1 WHERE MATCH(fts_field) against("other");
DROP TABLE t1;
# Test on user supplied 'FTS_DOC_ID'
CREATE TABLE t1(`FTS_DOC_ID` serial,
no_fts_field VARCHAR(10),
fts_field VARCHAR(10),
FULLTEXT INDEX f(fts_field)) ENGINE=INNODB;
INSERT INTO t1 VALUES (1, 'AAA', 'BBB');
# Doc ID must be updated as well (HA_FTS_INVALID_DOCID).
--error 182
UPDATE t1 SET fts_field='anychange' where FTS_DOC_ID = 1;
UPDATE t1 SET fts_field='anychange', FTS_DOC_ID = 2 where FTS_DOC_ID = 1;
SELECT * FROM t1 WHERE MATCH(fts_field) against("anychange");
# "BBB" should be marked as deleted.
SELECT * FROM t1 WHERE MATCH(fts_field) against("BBB");
UPDATE t1 SET no_fts_field='anychange' where FTS_DOC_ID = 2;
SELECT * FROM t1 WHERE MATCH(fts_field) against("anychange");
# "HA_FTS_INVALID_DOCID"
--error 182
UPDATE t1 SET no_fts_field='anychange', fts_field='other' where FTS_DOC_ID = 2;
SELECT * FROM t1 WHERE MATCH(fts_field) against("other");
# Doc ID must be monotonically increase (HA_FTS_INVALID_DOCID)
--error 182
UPDATE t1 SET FTS_DOC_ID = 1 where FTS_DOC_ID = 2;
DROP INDEX f ON t1;
# After FULLTEXT index dropped, we can update the fields freely
UPDATE t1 SET fts_field='newchange' where FTS_DOC_ID = 2;
UPDATE t1 SET no_fts_field='anychange' where FTS_DOC_ID = 2;
SELECT * FROM t1;
DROP TABLE t1;
CREATE TABLE t1(ID INT PRIMARY KEY,
no_fts_field VARCHAR(10),
fts_field VARCHAR(10),
FULLTEXT INDEX f(fts_field), index k(fts_field)) ENGINE=INNODB;
CREATE TABLE t2(ID INT PRIMARY KEY,
no_fts_field VARCHAR(10),
fts_field VARCHAR(10),
FULLTEXT INDEX f(fts_field),
INDEX k2(fts_field),
FOREIGN KEY(fts_field) REFERENCES
t1(fts_field) ON UPDATE CASCADE) ENGINE=INNODB;
INSERT INTO t1 VALUES (1, 'AAA', 'BBB');
INSERT INTO t2 VALUES (1, 'AAA', 'BBB');
update t1 set fts_field='newchange' where id =1;
SELECT * FROM t1 WHERE MATCH(fts_field) against("BBB");
SELECT * FROM t2 WHERE MATCH(fts_field) against("BBB");
SELECT * FROM t1 WHERE MATCH(fts_field) against("newchange");
SELECT * FROM t2 WHERE MATCH(fts_field) against("newchange");
DROP TABLE t2;
DROP TABLE t1;
# Testcases adopted from innodb_multi_update.test
CREATE TABLE t1(id INT PRIMARY KEY,
fts_field VARCHAR(10),
FULLTEXT INDEX f(fts_field)) ENGINE=INNODB;
CREATE TABLE t2(id INT PRIMARY KEY,
fts_field VARCHAR(10),
FULLTEXT INDEX f(fts_field)) ENGINE=INNODB;
INSERT INTO t1 values (1,'100'),(2,'200'),(3,'300'),(4,'400'),(5,'500'),(6,'600'), (7,'700'),(8,'800'),(9,'900'),(10,'1000'),(11,'1100'),(12,'1200');
INSERT INTO t2 values (1,'100'),(2,'200'),(3,'300'),(4,'400'),(5,'500'),(6,'600'), (7,'700'),(8,'800');
UPDATE t1, t2 set t1.fts_field = CONCAT(t1.fts_field, 'foo');
UPDATE t1, t2 set t1.fts_field = CONCAT(t1.fts_field, 'foo') WHERE t1.fts_field = "100foo";
# Update two tables in the same statement
UPDATE t1, t2 set t1.fts_field = CONCAT(t1.fts_field, 'xoo'), t2.fts_field = CONCAT(t1.fts_field, 'xoo') where t1.fts_field=CONCAT(t2.fts_field, 'foo');
# Following selects shows whether the correct Doc ID are updated
# This row should present in table t1
SELECT * FROM t1 WHERE MATCH(fts_field) against("100foofoo");
# Following rows should be dropped
SELECT * FROM t1 WHERE MATCH(fts_field) against("100foo");
SELECT * FROM t1 WHERE MATCH(fts_field) against("100");
# This row should present in table t2
SELECT * FROM t2 WHERE MATCH(fts_field) against("400fooxoo");
SELECT * FROM t2 WHERE MATCH(fts_field) against("100");
# Follow rows should be marked as dropped
SELECT * FROM t2 WHERE MATCH(fts_field) against("200");
SELECT * FROM t2 WHERE MATCH(fts_field) against("400");
DROP TABLE t1;
DROP TABLE t2;
--echo
--echo BUG#13701973/64274: MYSQL THREAD WAS SUSPENDED WHEN EXECUTE UPDATE QUERY
--echo
# FTS setup did not track which tables it had already looked at to see whether
# they need initialization. Hilarity ensued when hitting circular dependencies.
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
CREATE TABLE t1 (
t1_id INT(10) UNSIGNED NOT NULL,
t2_id INT(10) UNSIGNED DEFAULT NULL,
PRIMARY KEY (t1_id),
FOREIGN KEY (t2_id) REFERENCES t2 (t2_id)
ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB;
CREATE TABLE t2 (
t1_id INT(10) UNSIGNED NOT NULL,
t2_id INT(10) UNSIGNED NOT NULL,
t3_id INT(10) UNSIGNED NOT NULL,
t4_id INT(10) UNSIGNED NOT NULL,
PRIMARY KEY (t2_id),
FOREIGN KEY (t1_id) REFERENCES t1 (t1_id),
FOREIGN KEY (t3_id) REFERENCES t3 (t3_id)
ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (t4_id) REFERENCES t4 (t4_id)
) ENGINE=InnoDB;
CREATE TABLE t3 (
t3_id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
payload char(3),
PRIMARY KEY (t3_id)
) ENGINE=InnoDB;
INSERT INTO t3 VALUES (1, '100');
CREATE TABLE t4 (
t2_id INT(10) UNSIGNED DEFAULT NULL,
t4_id INT(10) UNSIGNED NOT NULL,
PRIMARY KEY (t4_id),
FOREIGN KEY (t2_id) REFERENCES t2 (t2_id)
ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB;
SET FOREIGN_KEY_CHECKS=1;
UPDATE t3 SET payload='101' WHERE t3_id=1;
SET FOREIGN_KEY_CHECKS=0;
DROP TABLE t1;
DROP TABLE t2;
DROP TABLE t3;
DROP TABLE t4;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;

View file

@ -0,0 +1 @@
--query_cache_type=0

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,2 @@
--innodb-ft-index-cache
--innodb-ft-index-table

View file

@ -0,0 +1,39 @@
-- source include/have_innodb.inc
#
# BUG#20465273 - FULLTEXT SEARCH BEHAVIOUR WITH MYISAM VS. INNODB (WRONG RESULT WITH INNODB)
#
CREATE TABLE articles (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
title VARCHAR(200),
body TEXT,
FULLTEXT (title,body)
) ENGINE=InnoDB;
INSERT INTO articles (title,body) VALUES
(NULL, 'mysql good database'),
(NULL, ' mysql good database'),
('', 'mysql good database'),
('', ' mysql good database'),
(' ', 'mysql good database'),
('mysql', 'good database'),
('mysql ', 'good database'),
('mysql', ' good database'),
('mysql good database', ''),
('mysql good database', NULL);
SET GLOBAL innodb_ft_aux_table="test/articles";
SELECT * FROM INFORMATION_SCHEMA.INNODB_FT_INDEX_CACHE;
SET GLOBAL innodb_ft_aux_table=default;
SELECT * FROM articles;
SELECT * FROM articles WHERE MATCH(title, body)
AGAINST('"mysql good database"' IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH(title, body)
AGAINST('("mysql good database")' IN BOOLEAN MODE);
DROP TABLE articles;

View file

@ -0,0 +1,52 @@
# This is a basic test for innodb fts result cache limit.
-- source include/have_innodb.inc
# Must have debug code to use SET SESSION debug
--source include/have_debug.inc
# Create FTS table
CREATE TABLE t1 (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
a VARCHAR(200),
b TEXT
) ENGINE= InnoDB;
# Create the FTS index again
CREATE FULLTEXT INDEX idx on t1 (a,b);
# Insert rows
INSERT INTO t1 (a,b) VALUES
('MySQL from Tutorial','DBMS stands for DataBase ...') ,
('when To Use MySQL Well','After that you went through a ...'),
('where will Optimizing MySQL','what In this tutorial we will show ...'),
('MySQL from Tutorial','DBMS stands for DataBase ...') ,
('when To Use MySQL Well','After that you went through a ...'),
('where will Optimizing MySQL','what In this tutorial we will show ...'),
('MySQL from Tutorial','DBMS stands for DataBase ...') ,
('when To Use MySQL Well','After that you went through a ...'),
('where will Optimizing MySQL','what In this tutorial we will show ...');
SET @save_limit=@@GLOBAL.innodb_ft_result_cache_limit;
SET @save_dbug=@@debug_dbug;
SET debug_dbug="+d,fts_instrument_result_cache_limit";
# Simple term search
SELECT COUNT(*) FROM t1 WHERE MATCH (a,b) AGAINST ('mysql' IN BOOLEAN MODE);
# Query expansion
--error 128
SELECT COUNT(*) FROM t1 WHERE MATCH (a,b) AGAINST ('mysql' WITH QUERY EXPANSION);
# Simple phrase search
--error 128
SELECT COUNT(*) FROM t1 WHERE MATCH (a,b) AGAINST ('"mysql database"' IN BOOLEAN MODE);
# Simple proximity search
--error 128
SELECT COUNT(*) FROM t1 WHERE MATCH (a,b) AGAINST ('"mysql database" @ 5' IN BOOLEAN MODE);
SET debug_dbug=@save_dbug;
DROP TABLE t1;
SET GLOBAL innodb_ft_result_cache_limit=@save_limit;

View file

@ -0,0 +1,475 @@
# This is the basic function tests for innodb FTS savepoint
-- source include/have_innodb.inc
CREATE TABLE articles (
id INT UNSIGNED NOT NULL PRIMARY KEY,
title VARCHAR(200),
FULLTEXT (title)
) ENGINE= InnoDB;
# Test Part 1: ROLLBACK TO SAVEPOINT
# Test rollback to savepoint 1(S1,RB1)
TRUNCATE TABLE articles;
INSERT INTO articles(id, title) VALUES(1, 'mysql');
BEGIN;
INSERT INTO articles(id, title) VALUES(2, 'mysql');
SAVEPOINT sp1;
INSERT INTO articles(id, title) VALUES(3, 'mysql');
ROLLBACK TO SAVEPOINT sp1;
INSERT INTO articles(id, title) VALUES(4, 'mysql');
COMMIT;
INSERT INTO articles(id, title) VALUES(5, 'mysql');
SELECT * FROM articles WHERE MATCH(title) AGAINST('mysql');
# Test rollback to savepoint 2(S1,RB1,S2,RB2)
TRUNCATE TABLE articles;
INSERT INTO articles(id, title) VALUES(1, 'mysql');
BEGIN;
INSERT INTO articles(id, title) VALUES(2, 'mysql');
SAVEPOINT sp1;
INSERT INTO articles(id, title) VALUES(3, 'mysql');
ROLLBACK TO SAVEPOINT sp1;
INSERT INTO articles(id, title) VALUES(4, 'mysql');
SAVEPOINT sp2;
INSERT INTO articles(id, title) VALUES(5, 'mysql');
ROLLBACK TO SAVEPOINT sp2;
INSERT INTO articles(id, title) VALUES(6, 'mysql');
COMMIT;
INSERT INTO articles(id, title) VALUES(7, 'mysql');
SELECT * FROM articles WHERE MATCH(title) AGAINST('mysql');
# Test rollback to savepoint 3(S1,S2,RB1)
TRUNCATE TABLE articles;
INSERT INTO articles(id, title) VALUES(1, 'mysql');
BEGIN;
INSERT INTO articles(id, title) VALUES(2, 'mysql');
SAVEPOINT sp1;
INSERT INTO articles(id, title) VALUES(3, 'mysql');
SAVEPOINT sp2;
INSERT INTO articles(id, title) VALUES(4, 'mysql');
ROLLBACK TO SAVEPOINT sp1;
INSERT INTO articles(id, title) VALUES(5, 'mysql');
COMMIT;
INSERT INTO articles(id, title) VALUES(6, 'mysql');
SELECT * FROM articles WHERE MATCH(title) AGAINST('mysql');
# Test rollback to savepoint 4(S1,S2,RB2,RB1)
TRUNCATE TABLE articles;
INSERT INTO articles(id, title) VALUES(1, 'mysql');
BEGIN;
INSERT INTO articles(id, title) VALUES(2, 'mysql');
SAVEPOINT sp1;
INSERT INTO articles(id, title) VALUES(3, 'mysql');
SAVEPOINT sp2;
INSERT INTO articles(id, title) VALUES(4, 'mysql');
ROLLBACK TO SAVEPOINT sp2;
INSERT INTO articles(id, title) VALUES(5, 'mysql');
ROLLBACK TO SAVEPOINT sp1;
INSERT INTO articles(id, title) VALUES(6, 'mysql');
COMMIT;
INSERT INTO articles(id, title) VALUES(7, 'mysql');
SELECT * FROM articles WHERE MATCH(title) AGAINST('mysql');
# Test Part 2: RELEASE SAVEPOINT
# Test release savepoint 1(S1,RL1)
TRUNCATE TABLE articles;
INSERT INTO articles(id, title) VALUES(1, 'mysql');
BEGIN;
INSERT INTO articles(id, title) VALUES(2, 'mysql');
SAVEPOINT sp1;
INSERT INTO articles(id, title) VALUES(3, 'mysql');
RELEASE SAVEPOINT sp1;
INSERT INTO articles(id, title) VALUES(4, 'mysql');
COMMIT;
INSERT INTO articles(id, title) VALUES(5, 'mysql');
SELECT * FROM articles WHERE MATCH(title) AGAINST('mysql');
# Test release savepoint 2(S1,RL1,S2,RL2)
TRUNCATE TABLE articles;
INSERT INTO articles(id, title) VALUES(1, 'mysql');
BEGIN;
INSERT INTO articles(id, title) VALUES(2, 'mysql');
SAVEPOINT sp1;
INSERT INTO articles(id, title) VALUES(3, 'mysql');
RELEASE SAVEPOINT sp1;
INSERT INTO articles(id, title) VALUES(4, 'mysql');
SAVEPOINT sp2;
INSERT INTO articles(id, title) VALUES(5, 'mysql');
RELEASE SAVEPOINT sp2;
INSERT INTO articles(id, title) VALUES(6, 'mysql');
COMMIT;
INSERT INTO articles(id, title) VALUES(7, 'mysql');
SELECT * FROM articles WHERE MATCH(title) AGAINST('mysql');
# Test release savepoint 3(S1,S2,RL1)
TRUNCATE TABLE articles;
INSERT INTO articles(id, title) VALUES(1, 'mysql');
BEGIN;
INSERT INTO articles(id, title) VALUES(2, 'mysql');
SAVEPOINT sp1;
INSERT INTO articles(id, title) VALUES(3, 'mysql');
SAVEPOINT sp2;
INSERT INTO articles(id, title) VALUES(4, 'mysql');
RELEASE SAVEPOINT sp1;
INSERT INTO articles(id, title) VALUES(5, 'mysql');
COMMIT;
INSERT INTO articles(id, title) VALUES(6, 'mysql');
SELECT * FROM articles WHERE MATCH(title) AGAINST('mysql');
# Test release savepoint 4(S1,S2,RL2,RL1)
TRUNCATE TABLE articles;
INSERT INTO articles(id, title) VALUES(1, 'mysql');
BEGIN;
INSERT INTO articles(id, title) VALUES(2, 'mysql');
SAVEPOINT sp1;
INSERT INTO articles(id, title) VALUES(3, 'mysql');
SAVEPOINT sp2;
INSERT INTO articles(id, title) VALUES(4, 'mysql');
RELEASE SAVEPOINT sp2;
INSERT INTO articles(id, title) VALUES(5, 'mysql');
RELEASE SAVEPOINT sp1;
INSERT INTO articles(id, title) VALUES(6, 'mysql');
COMMIT;
INSERT INTO articles(id, title) VALUES(7, 'mysql');
SELECT * FROM articles WHERE MATCH(title) AGAINST('mysql');
# Test Part 3: RELEASE & ROLLBACK TO SAVEPOINT
# Test release & rollback to savepoint 1(S1,RB1,S2,RL2)
TRUNCATE TABLE articles;
INSERT INTO articles(id, title) VALUES(1, 'mysql');
BEGIN;
INSERT INTO articles(id, title) VALUES(2, 'mysql');
SAVEPOINT sp1;
INSERT INTO articles(id, title) VALUES(3, 'mysql');
ROLLBACK TO SAVEPOINT sp1;
INSERT INTO articles(id, title) VALUES(4, 'mysql');
SAVEPOINT sp2;
INSERT INTO articles(id, title) VALUES(5, 'mysql');
RELEASE SAVEPOINT sp2;
INSERT INTO articles(id, title) VALUES(6, 'mysql');
COMMIT;
INSERT INTO articles(id, title) VALUES(7, 'mysql');
SELECT * FROM articles WHERE MATCH(title) AGAINST('mysql');
# Test release & rollback to savepoint 2(S1,RL1,S2,RB2)
TRUNCATE TABLE articles;
INSERT INTO articles(id, title) VALUES(1, 'mysql');
BEGIN;
INSERT INTO articles(id, title) VALUES(2, 'mysql');
SAVEPOINT sp1;
INSERT INTO articles(id, title) VALUES(3, 'mysql');
RELEASE SAVEPOINT sp1;
INSERT INTO articles(id, title) VALUES(4, 'mysql');
SAVEPOINT sp2;
INSERT INTO articles(id, title) VALUES(5, 'mysql');
ROLLBACK TO SAVEPOINT sp2;
INSERT INTO articles(id, title) VALUES(6, 'mysql');
COMMIT;
INSERT INTO articles(id, title) VALUES(7, 'mysql');
SELECT * FROM articles WHERE MATCH(title) AGAINST('mysql');
# Test release & rollback to savepoint 3(S1,S2,RL2,RB1)
TRUNCATE TABLE articles;
INSERT INTO articles(id, title) VALUES(1, 'mysql');
BEGIN;
INSERT INTO articles(id, title) VALUES(2, 'mysql');
SAVEPOINT sp1;
INSERT INTO articles(id, title) VALUES(3, 'mysql');
SAVEPOINT sp2;
INSERT INTO articles(id, title) VALUES(4, 'mysql');
RELEASE SAVEPOINT sp2;
INSERT INTO articles(id, title) VALUES(5, 'mysql');
ROLLBACK TO SAVEPOINT sp1;
INSERT INTO articles(id, title) VALUES(6, 'mysql');
COMMIT;
INSERT INTO articles(id, title) VALUES(7, 'mysql');
SELECT * FROM articles WHERE MATCH(title) AGAINST('mysql');
# Test release & rollback to savepoint 4(S1,S2,RB2,RL1)
TRUNCATE TABLE articles;
INSERT INTO articles(id, title) VALUES(1, 'mysql');
BEGIN;
INSERT INTO articles(id, title) VALUES(2, 'mysql');
SAVEPOINT sp1;
INSERT INTO articles(id, title) VALUES(3, 'mysql');
SAVEPOINT sp2;
INSERT INTO articles(id, title) VALUES(4, 'mysql');
ROLLBACK TO SAVEPOINT sp2;
INSERT INTO articles(id, title) VALUES(5, 'mysql');
RELEASE SAVEPOINT sp1;
INSERT INTO articles(id, title) VALUES(6, 'mysql');
COMMIT;
INSERT INTO articles(id, title) VALUES(7, 'mysql');
SELECT * FROM articles WHERE MATCH(title) AGAINST('mysql');
# Test Part 4: ROLLBACK & SAVEPOINT
# Test rollback 1
TRUNCATE TABLE articles;
INSERT INTO articles(id, title) VALUES(1, 'mysql');
BEGIN;
INSERT INTO articles(id, title) VALUES(2, 'mysql');
ROLLBACK;
INSERT INTO articles(id, title) VALUES(3, 'mysql');
SELECT * FROM articles WHERE MATCH(title) AGAINST('mysql');
# Test rollback 2(S1)
TRUNCATE TABLE articles;
INSERT INTO articles(id, title) VALUES(1, 'mysql');
BEGIN;
INSERT INTO articles(id, title) VALUES(2, 'mysql');
SAVEPOINT sp1;
INSERT INTO articles(id, title) VALUES(3, 'mysql');
ROLLBACK;
INSERT INTO articles(id, title) VALUES(4, 'mysql');
SELECT * FROM articles WHERE MATCH(title) AGAINST('mysql');
# Test rollback 3(S1,RL1)
TRUNCATE TABLE articles;
INSERT INTO articles(id, title) VALUES(1, 'mysql');
BEGIN;
INSERT INTO articles(id, title) VALUES(2, 'mysql');
SAVEPOINT sp1;
INSERT INTO articles(id, title) VALUES(3, 'mysql');
RELEASE SAVEPOINT sp1;
INSERT INTO articles(id, title) VALUES(4, 'mysql');
ROLLBACK;
INSERT INTO articles(id, title) VALUES(5, 'mysql');
SELECT * FROM articles WHERE MATCH(title) AGAINST('mysql');
# Test rollback 4(S1,RB1)
TRUNCATE TABLE articles;
INSERT INTO articles(id, title) VALUES(1, 'mysql');
BEGIN;
INSERT INTO articles(id, title) VALUES(2, 'mysql');
SAVEPOINT sp1;
INSERT INTO articles(id, title) VALUES(3, 'mysql');
ROLLBACK TO SAVEPOINT sp1;
INSERT INTO articles(id, title) VALUES(4, 'mysql');
ROLLBACK;
INSERT INTO articles(id, title) VALUES(5, 'mysql');
SELECT * FROM articles WHERE MATCH(title) AGAINST('mysql');
# Test rollback 5(S1,S2,RB2,RL1)
TRUNCATE TABLE articles;
INSERT INTO articles(id, title) VALUES(1, 'mysql');
BEGIN;
INSERT INTO articles(id, title) VALUES(2, 'mysql');
SAVEPOINT sp1;
INSERT INTO articles(id, title) VALUES(3, 'mysql');
SAVEPOINT sp2;
INSERT INTO articles(id, title) VALUES(4, 'mysql');
ROLLBACK TO SAVEPOINT sp2;
INSERT INTO articles(id, title) VALUES(5, 'mysql');
RELEASE SAVEPOINT sp1;
INSERT INTO articles(id, title) VALUES(6, 'mysql');
ROLLBACK;
INSERT INTO articles(id, title) VALUES(7, 'mysql');
SELECT * FROM articles WHERE MATCH(title) AGAINST('mysql');
DROP TABLE articles;

View file

@ -0,0 +1,58 @@
--source include/have_innodb.inc
--echo #
--echo # Bug #20028323 INNODB FULLTEXT BOOLEAN SEARCH INCORRECTLY HANDLES
--echo # PARENTHESES
--echo #
CREATE TABLE t1 (
f1 INT NOT NULL AUTO_INCREMENT,
f2 TEXT NOT NULL,
PRIMARY KEY (f1),
FULLTEXT (f2)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO t1 (f2) VALUES
('Pumpkin soup with cheese bread'),
('Yellow chicken curry'),
('Fresh green vegetables with garlic');
SELECT * FROM t1 WHERE MATCH(f2) AGAINST('+pumpkin' IN BOOLEAN MODE);
SELECT * FROM t1 WHERE MATCH(f2) AGAINST('+cheese' IN BOOLEAN MODE);
SELECT * FROM t1 WHERE MATCH(f2) AGAINST('+(pumpkin cheese)' IN BOOLEAN MODE);
SELECT * FROM t1 WHERE MATCH(f2)
AGAINST('+pumpkin +(souffle)' IN BOOLEAN MODE);
SELECT * FROM t1 WHERE MATCH(f2)
AGAINST('+pumpkin +(souffle tart)' IN BOOLEAN MODE);
SELECT * FROM t1 WHERE MATCH(f2)
AGAINST('+pumpkin +(>souffle <tart)' IN BOOLEAN MODE);
SELECT * FROM t1 WHERE MATCH(f2)
AGAINST('+pumpkin +(souffle tart)' IN BOOLEAN MODE);
INSERT INTO t1 (f2) VALUES
('This row contains only souffle'),
('This row contains only tart'),
('This row contains only pumpkin'),
('This row contains only cheese'),
('This row contains pumpkin and souffle'),
('This row contains pumpkin and tart'),
('This row contains pumpkin and cheese'),
('This row contains both souffle and tart'),
('This row contains both souffle and cheese'),
('This row contains both tart and cheese'),
('This row contains all three souffle, pumpkin and tart'),
('This row contains all four cheese, souffle, pumpkin and tart');
SELECT * FROM t1 WHERE MATCH(f2) AGAINST('+pumpkin' IN BOOLEAN MODE);
SELECT * FROM t1 WHERE MATCH(f2) AGAINST('+cheese' IN BOOLEAN MODE);
SELECT * FROM t1 WHERE MATCH(f2) AGAINST('+(pumpkin cheese)' IN BOOLEAN MODE);
SELECT * FROM t1 WHERE MATCH(f2)
AGAINST('+pumpkin +(souffle)' IN BOOLEAN MODE);
SELECT * FROM t1 WHERE MATCH(f2)
AGAINST('+pumpkin +(souffle tart)' IN BOOLEAN MODE);
SELECT * FROM t1 WHERE MATCH(f2)
AGAINST('+pumpkin +(>souffle <tart)' IN BOOLEAN MODE);
SELECT * FROM t1 WHERE MATCH(f2)
AGAINST('+pumpkin +(souffle tart)' IN BOOLEAN MODE);
DROP TABLE t1;

View file

@ -1,22 +1,17 @@
CREATE TABLE t1 (c1 INT, c2 GEOMETRY NOT NULL, c3 GEOMETRY NOT NULL) ENGINE=INNODB;
INSERT INTO t1 VALUES(1, Point(1,1), ST_GeomFromText('POLYGON (( 0 -1, 0 1, 2 1, 2 -1, 0 -1))'));
INSERT INTO t1 VALUES(2, Point(2,2), ST_GeomFromText('POLYGON (( 0 -3, 0 -1, 2 -1, 2 -3, 0 -3))'));
INSERT INTO t1 VALUES(3, Point(3,3), ST_GeomFromText('POLYGON (( 1 0, 1 2, 3 2, 3 0, 1 0))'));
INSERT INTO t1 VALUES(4, Point(4,4), ST_GeomFromText('POLYGON (( -3 0, -3 2, -1 2, -1 0, -3 0))'));
INSERT INTO t1 VALUES(5, Point(5,5), ST_GeomFromText('POLYGON (( 0 0, 0 1, 1 1, 1 0, 0 0))'));
INSERT INTO t1 VALUES(6, Point(6,6), ST_GeomFromText('POLYGON (( 2 0, 2 2, 4 2, 4 0, 2 0))'));
INSERT INTO t1 VALUES(7, Point(7,7), ST_GeomFromText('POLYGON (( 0 3, 0 5, 2 5, 2 3, 0 3))'));
INSERT INTO t1 VALUES(8, Point(8,8), ST_GeomFromText('POLYGON (( 0 1, 0 3, 2 3, 2 1, 0 1))'));
INSERT INTO t1 VALUES(9, Point(9,9), ST_GeomFromText('POLYGON (( 0 0, 0 3, 3 3, 3 0, 0 0))'));
INSERT INTO t1 SELECT * FROM t1;
INSERT INTO t1 SELECT * FROM t1;
INSERT INTO t1 SELECT * FROM t1;
INSERT INTO t1 SELECT * FROM t1;
INSERT INTO t1 SELECT * FROM t1;
INSERT INTO t1 SELECT * FROM t1;
INSERT INTO t1 SELECT * FROM t1;
INSERT INTO t1 SELECT * FROM t1;
INSERT INTO t1 SELECT * FROM t1;
CREATE TEMPORARY TABLE t LIKE t1;
INSERT INTO t VALUES
(1, Point(1,1), ST_GeomFromText('POLYGON (( 0 -1, 0 1, 2 1, 2 -1, 0 -1))')),
(2, Point(2,2), ST_GeomFromText('POLYGON (( 0 -3, 0 -1, 2 -1, 2 -3, 0 -3))')),
(3, Point(3,3), ST_GeomFromText('POLYGON (( 1 0, 1 2, 3 2, 3 0, 1 0))')),
(4, Point(4,4), ST_GeomFromText('POLYGON (( -3 0, -3 2, -1 2, -1 0, -3 0))')),
(5, Point(5,5), ST_GeomFromText('POLYGON (( 0 0, 0 1, 1 1, 1 0, 0 0))')),
(6, Point(6,6), ST_GeomFromText('POLYGON (( 2 0, 2 2, 4 2, 4 0, 2 0))')),
(7, Point(7,7), ST_GeomFromText('POLYGON (( 0 3, 0 5, 2 5, 2 3, 0 3))')),
(8, Point(8,8), ST_GeomFromText('POLYGON (( 0 1, 0 3, 2 3, 2 1, 0 1))')),
(9, Point(9,9), ST_GeomFromText('POLYGON (( 0 0, 0 3, 3 3, 3 0, 0 0))'));
INSERT INTO t1 SELECT t.* FROM t, seq_1_to_512;
DROP TEMPORARY TABLE t;
CREATE SPATIAL INDEX idx ON t1(c2);
SELECT COUNT(*) FROM t1;
COUNT(*)
@ -30,8 +25,7 @@ SELECT COUNT(*) FROM t1 WHERE MBRWithin(t1.c2, @g1);
COUNT(*)
0
ALTER TABLE t1 DROP INDEX idx, ADD SPATIAL INDEX idx3(c2);
SET SESSION debug="+d,row_merge_instrument_log_check_flush";
Warnings:
Warning 1287 '@@debug' is deprecated and will be removed in a future release. Please use '@@debug_dbug' instead
SET debug_dbug='+d,row_merge_instrument_log_check_flush';
ALTER TABLE t1 DROP INDEX idx3, ADD SPATIAL INDEX idx4(c2), ADD SPATIAL INDEX idx5(c3);
ALTER TABLE t1 FORCE;
DROP TABLE t1;

View file

@ -0,0 +1 @@
--innodb_sort_buffer_size=64k

Some files were not shown because too many files have changed in this diff Show more