Note 1003 /* select#1 */ select `test`.`t1`.`class` AS `class`,`test`.`t1`.`id` AS `id`,`test`.`t1`.`title` AS `title` from `test`.`t1` where (`test`.`t1`.`id` = 10)
EXPLAIN SELECT * FROM t1 WHERE title = 'a10';
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
Note 1003 /* select#1 */ select `test`.`t1`.`class` AS `class`,`test`.`t1`.`id` AS `id`,`test`.`t1`.`title` AS `title` from `test`.`t1` where (`test`.`t1`.`title` = 'a10')
SELECT * FROM t1 WHERE id = 10;
class id title
10 10 a10
SELECT * FROM t1 WHERE title = 'a10';
class id title
10 10 a10
SELECT * FROM t1 WHERE id = 5000;
class id title
5000 5000 a5000
SELECT * FROM t1 WHERE title = 'a5000';
class id title
5000 5000 a5000
SELECT * FROM t1 WHERE id = 10000;
class id title
10000 10000 a10000
SELECT * FROM t1 WHERE title = 'a10000';
class id title
10000 10000 a10000
SELECT * FROM t1 WHERE id = 10010;
class id title
SELECT * FROM t1 WHERE title = 'a10010';
class id title
/*Insert/Update/Delete. */
DELETE FROM t1 WHERE id < 4010 AND id > 3990;
INSERT INTO t1 VALUES(4000, 4000, 'b4000');
UPDATE t1 SET title = CONCAT('b', id) WHERE id < 3010 AND id > 2990;
SELECT * FROM t1 WHERE id = 3000;
class id title
3000 3000 b3000
SELECT * FROM t1 WHERE title = 'a3000';
class id title
SELECT * FROM t1 WHERE title = 'b3000';
class id title
3000 3000 b3000
SELECT * FROM t1 WHERE id = 4000;
class id title
4000 4000 b4000
SELECT * FROM t1 WHERE title = 'a4000';
class id title
SELECT * FROM t1 WHERE title = 'b4000';
class id title
4000 4000 b4000
SELECT * FROM t1 WHERE id = 4001;
class id title
SELECT * FROM t1 WHERE title = 'a4001';
class id title
SELECT COUNT(*) FROM t1;
COUNT(*)
9992
/* Add column. */
ALTER TABLE t1 ADD COLUMN content TEXT;
CHECK TABLE t1;
Table Op Msg_type Msg_text
test.t1 check status OK
SELECT * FROM t1 WHERE id = 10;
class id title content
10 10 a10 NULL
SELECT * FROM t1 WHERE title = 'a10';
class id title content
10 10 a10 NULL
SELECT * FROM t1 WHERE id = 5000;
class id title content
5000 5000 a5000 NULL
SELECT * FROM t1 WHERE title = 'a5000';
class id title content
5000 5000 a5000 NULL
SELECT * FROM t1 WHERE id = 10000;
class id title content
10000 10000 a10000 NULL
SELECT * FROM t1 WHERE title = 'a10000';
class id title content
10000 10000 a10000 NULL
SELECT * FROM t1 WHERE id = 10010;
class id title content
SELECT * FROM t1 WHERE title = 'a10010';
class id title content
/* Drop column. */
ALTER TABLE t1 DROP COLUMN content;
CHECK TABLE t1;
Table Op Msg_type Msg_text
test.t1 check status OK
SELECT * FROM t1 WHERE id = 10;
class id title
10 10 a10
SELECT * FROM t1 WHERE title = 'a10';
class id title
10 10 a10
SELECT * FROM t1 WHERE id = 5000;
class id title
5000 5000 a5000
SELECT * FROM t1 WHERE title = 'a5000';
class id title
5000 5000 a5000
SELECT * FROM t1 WHERE id = 10000;
class id title
10000 10000 a10000
SELECT * FROM t1 WHERE title = 'a10000';
class id title
10000 10000 a10000
SELECT * FROM t1 WHERE id = 10010;
class id title
SELECT * FROM t1 WHERE title = 'a10010';
class id title
DROP TABLE t1;
CREATE TABLE t1(
a INT PRIMARY KEY,
b TEXT,
c TEXT) ENGINE=InnoDB ROW_FORMAT=REDUNDANT;
ALTER TABLE t1 ADD INDEX `idx` (a,b(5));
SELECT CHAR_LENGTH(b) FROM t1 WHERE a=4975;
CHAR_LENGTH(b)
10000
SELECT b=REPEAT(CONCAT('a',4975),2000) FROM t1 WHERE a=4975 AND b like 'a4975%';
b=REPEAT(CONCAT('a',4975),2000)
1
UPDATE t1 SET b = REPEAT(CONCAT('b',4975),2000) WHERE a=4975 AND b like 'a4975%';
SELECT b=REPEAT(CONCAT('a',4975),2000) FROM t1 WHERE a=4975 AND b like 'a4975%';
b=REPEAT(CONCAT('a',4975),2000)
SELECT b=REPEAT(CONCAT('b',4975),2000) FROM t1 WHERE a=4975 AND b like 'b4975%';
b=REPEAT(CONCAT('b',4975),2000)
1
DELETE FROM t1 WHERE a=4975 AND b like 'b4975%';
SELECT b=REPEAT(CONCAT('b',4975),2000) FROM t1 WHERE a=4975 AND b like 'b4975%';
b=REPEAT(CONCAT('b',4975),2000)
ALTER TABLE t1 DROP COLUMN c;
CHECK TABLE t1;
Table Op Msg_type Msg_text
test.t1 check status OK
SELECT CHAR_LENGTH(b) FROM t1 WHERE a=4975;
CHAR_LENGTH(b)
DROP TABLE t1;
DROP PROCEDURE populate_t1;
CREATE PROCEDURE populate_t1(load_even INT)
BEGIN
DECLARE i int DEFAULT 1;
START TRANSACTION;
WHILE (i <= 10000) DO
IF i%2 = 0 AND load_even = 1 THEN
INSERT INTO t1 VALUES (i, i, CONCAT('a', i));
END IF;
IF i%2 != 0 AND load_even != 1 THEN
INSERT INTO t1 VALUES (i, i, CONCAT('a', i));
END IF;
SET i = i + 1;
END WHILE;
COMMIT;
END|
SELECT @@innodb_fill_factor;
@@innodb_fill_factor
100
CREATE TABLE t1(
class INT,
id INT,
title VARCHAR(100)
) ENGINE=InnoDB ROW_FORMAT=COMPACT;
SELECT COUNT(*) FROM t1;
COUNT(*)
5000
/* Create index. */
CREATE INDEX idx_id ON t1(id);
CREATE INDEX idx_title ON t1(title);
/* Check table. */
CHECK TABLE t1;
Table Op Msg_type Msg_text
test.t1 check status OK
/* Select by index. */
EXPLAIN SELECT * FROM t1 WHERE id = 10;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
Note 1003 /* select#1 */ select `test`.`t1`.`class` AS `class`,`test`.`t1`.`id` AS `id`,`test`.`t1`.`title` AS `title` from `test`.`t1` where (`test`.`t1`.`id` = 10)
EXPLAIN SELECT * FROM t1 WHERE title = 'a10';
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
Note 1003 /* select#1 */ select `test`.`t1`.`class` AS `class`,`test`.`t1`.`id` AS `id`,`test`.`t1`.`title` AS `title` from `test`.`t1` where (`test`.`t1`.`title` = 'a10')
SELECT * FROM t1 WHERE id = 10;
class id title
10 10 a10
SELECT * FROM t1 WHERE title = 'a10';
class id title
10 10 a10
SELECT * FROM t1 WHERE id = 5000;
class id title
5000 5000 a5000
SELECT * FROM t1 WHERE title = 'a5000';
class id title
5000 5000 a5000
SELECT * FROM t1 WHERE id = 10000;
class id title
10000 10000 a10000
SELECT * FROM t1 WHERE title = 'a10000';
class id title
10000 10000 a10000
SELECT * FROM t1 WHERE id = 10010;
class id title
SELECT * FROM t1 WHERE title = 'a10010';
class id title
/*Insert/Update/Delete. */
DELETE FROM t1 WHERE id < 4010 AND id > 3990;
INSERT INTO t1 VALUES(4000, 4000, 'b4000');
UPDATE t1 SET title = CONCAT('b', id) WHERE id < 3010 AND id > 2990;
SELECT * FROM t1 WHERE id = 3000;
class id title
3000 3000 b3000
SELECT * FROM t1 WHERE title = 'a3000';
class id title
SELECT * FROM t1 WHERE title = 'b3000';
class id title
3000 3000 b3000
SELECT * FROM t1 WHERE id = 4000;
class id title
4000 4000 b4000
SELECT * FROM t1 WHERE title = 'a4000';
class id title
SELECT * FROM t1 WHERE title = 'b4000';
class id title
4000 4000 b4000
SELECT * FROM t1 WHERE id = 4001;
class id title
SELECT * FROM t1 WHERE title = 'a4001';
class id title
SELECT COUNT(*) FROM t1;
COUNT(*)
9992
/* Add column. */
ALTER TABLE t1 ADD COLUMN content TEXT;
CHECK TABLE t1;
Table Op Msg_type Msg_text
test.t1 check status OK
SELECT * FROM t1 WHERE id = 10;
class id title content
10 10 a10 NULL
SELECT * FROM t1 WHERE title = 'a10';
class id title content
10 10 a10 NULL
SELECT * FROM t1 WHERE id = 5000;
class id title content
5000 5000 a5000 NULL
SELECT * FROM t1 WHERE title = 'a5000';
class id title content
5000 5000 a5000 NULL
SELECT * FROM t1 WHERE id = 10000;
class id title content
10000 10000 a10000 NULL
SELECT * FROM t1 WHERE title = 'a10000';
class id title content
10000 10000 a10000 NULL
SELECT * FROM t1 WHERE id = 10010;
class id title content
SELECT * FROM t1 WHERE title = 'a10010';
class id title content
/* Drop column. */
ALTER TABLE t1 DROP COLUMN content;
CHECK TABLE t1;
Table Op Msg_type Msg_text
test.t1 check status OK
SELECT * FROM t1 WHERE id = 10;
class id title
10 10 a10
SELECT * FROM t1 WHERE title = 'a10';
class id title
10 10 a10
SELECT * FROM t1 WHERE id = 5000;
class id title
5000 5000 a5000
SELECT * FROM t1 WHERE title = 'a5000';
class id title
5000 5000 a5000
SELECT * FROM t1 WHERE id = 10000;
class id title
10000 10000 a10000
SELECT * FROM t1 WHERE title = 'a10000';
class id title
10000 10000 a10000
SELECT * FROM t1 WHERE id = 10010;
class id title
SELECT * FROM t1 WHERE title = 'a10010';
class id title
DROP TABLE t1;
CREATE TABLE t1(
a INT PRIMARY KEY,
b TEXT,
c TEXT) ENGINE=InnoDB ROW_FORMAT=COMPACT;
ALTER TABLE t1 ADD INDEX `idx` (a,b(5));
SELECT CHAR_LENGTH(b) FROM t1 WHERE a=4975;
CHAR_LENGTH(b)
10000
SELECT b=REPEAT(CONCAT('a',4975),2000) FROM t1 WHERE a=4975 AND b like 'a4975%';
b=REPEAT(CONCAT('a',4975),2000)
1
UPDATE t1 SET b = REPEAT(CONCAT('b',4975),2000) WHERE a=4975 AND b like 'a4975%';
SELECT b=REPEAT(CONCAT('a',4975),2000) FROM t1 WHERE a=4975 AND b like 'a4975%';
b=REPEAT(CONCAT('a',4975),2000)
SELECT b=REPEAT(CONCAT('b',4975),2000) FROM t1 WHERE a=4975 AND b like 'b4975%';
b=REPEAT(CONCAT('b',4975),2000)
1
DELETE FROM t1 WHERE a=4975 AND b like 'b4975%';
SELECT b=REPEAT(CONCAT('b',4975),2000) FROM t1 WHERE a=4975 AND b like 'b4975%';
b=REPEAT(CONCAT('b',4975),2000)
ALTER TABLE t1 DROP COLUMN c;
CHECK TABLE t1;
Table Op Msg_type Msg_text
test.t1 check status OK
SELECT CHAR_LENGTH(b) FROM t1 WHERE a=4975;
CHAR_LENGTH(b)
DROP TABLE t1;
DROP PROCEDURE populate_t1;
CREATE PROCEDURE populate_t1(load_even INT)
BEGIN
DECLARE i int DEFAULT 1;
START TRANSACTION;
WHILE (i <= 10000) DO
IF i%2 = 0 AND load_even = 1 THEN
INSERT INTO t1 VALUES (i, i, CONCAT('a', i));
END IF;
IF i%2 != 0 AND load_even != 1 THEN
INSERT INTO t1 VALUES (i, i, CONCAT('a', i));
END IF;
SET i = i + 1;
END WHILE;
COMMIT;
END|
SELECT @@innodb_fill_factor;
@@innodb_fill_factor
100
CREATE TABLE t1(
class INT,
id INT,
title VARCHAR(100)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC;
SELECT COUNT(*) FROM t1;
COUNT(*)
5000
/* Create index. */
CREATE INDEX idx_id ON t1(id);
CREATE INDEX idx_title ON t1(title);
/* Check table. */
CHECK TABLE t1;
Table Op Msg_type Msg_text
test.t1 check status OK
/* Select by index. */
EXPLAIN SELECT * FROM t1 WHERE id = 10;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
Note 1003 /* select#1 */ select `test`.`t1`.`class` AS `class`,`test`.`t1`.`id` AS `id`,`test`.`t1`.`title` AS `title` from `test`.`t1` where (`test`.`t1`.`id` = 10)
EXPLAIN SELECT * FROM t1 WHERE title = 'a10';
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
Note 1003 /* select#1 */ select `test`.`t1`.`class` AS `class`,`test`.`t1`.`id` AS `id`,`test`.`t1`.`title` AS `title` from `test`.`t1` where (`test`.`t1`.`title` = 'a10')
SELECT * FROM t1 WHERE id = 10;
class id title
10 10 a10
SELECT * FROM t1 WHERE title = 'a10';
class id title
10 10 a10
SELECT * FROM t1 WHERE id = 5000;
class id title
5000 5000 a5000
SELECT * FROM t1 WHERE title = 'a5000';
class id title
5000 5000 a5000
SELECT * FROM t1 WHERE id = 10000;
class id title
10000 10000 a10000
SELECT * FROM t1 WHERE title = 'a10000';
class id title
10000 10000 a10000
SELECT * FROM t1 WHERE id = 10010;
class id title
SELECT * FROM t1 WHERE title = 'a10010';
class id title
/*Insert/Update/Delete. */
DELETE FROM t1 WHERE id < 4010 AND id > 3990;
INSERT INTO t1 VALUES(4000, 4000, 'b4000');
UPDATE t1 SET title = CONCAT('b', id) WHERE id < 3010 AND id > 2990;
SELECT * FROM t1 WHERE id = 3000;
class id title
3000 3000 b3000
SELECT * FROM t1 WHERE title = 'a3000';
class id title
SELECT * FROM t1 WHERE title = 'b3000';
class id title
3000 3000 b3000
SELECT * FROM t1 WHERE id = 4000;
class id title
4000 4000 b4000
SELECT * FROM t1 WHERE title = 'a4000';
class id title
SELECT * FROM t1 WHERE title = 'b4000';
class id title
4000 4000 b4000
SELECT * FROM t1 WHERE id = 4001;
class id title
SELECT * FROM t1 WHERE title = 'a4001';
class id title
SELECT COUNT(*) FROM t1;
COUNT(*)
9992
/* Add column. */
ALTER TABLE t1 ADD COLUMN content TEXT;
CHECK TABLE t1;
Table Op Msg_type Msg_text
test.t1 check status OK
SELECT * FROM t1 WHERE id = 10;
class id title content
10 10 a10 NULL
SELECT * FROM t1 WHERE title = 'a10';
class id title content
10 10 a10 NULL
SELECT * FROM t1 WHERE id = 5000;
class id title content
5000 5000 a5000 NULL
SELECT * FROM t1 WHERE title = 'a5000';
class id title content
5000 5000 a5000 NULL
SELECT * FROM t1 WHERE id = 10000;
class id title content
10000 10000 a10000 NULL
SELECT * FROM t1 WHERE title = 'a10000';
class id title content
10000 10000 a10000 NULL
SELECT * FROM t1 WHERE id = 10010;
class id title content
SELECT * FROM t1 WHERE title = 'a10010';
class id title content
/* Drop column. */
ALTER TABLE t1 DROP COLUMN content;
CHECK TABLE t1;
Table Op Msg_type Msg_text
test.t1 check status OK
SELECT * FROM t1 WHERE id = 10;
class id title
10 10 a10
SELECT * FROM t1 WHERE title = 'a10';
class id title
10 10 a10
SELECT * FROM t1 WHERE id = 5000;
class id title
5000 5000 a5000
SELECT * FROM t1 WHERE title = 'a5000';
class id title
5000 5000 a5000
SELECT * FROM t1 WHERE id = 10000;
class id title
10000 10000 a10000
SELECT * FROM t1 WHERE title = 'a10000';
class id title
10000 10000 a10000
SELECT * FROM t1 WHERE id = 10010;
class id title
SELECT * FROM t1 WHERE title = 'a10010';
class id title
DROP TABLE t1;
CREATE TABLE t1(
a INT PRIMARY KEY,
b TEXT,
c TEXT) ENGINE=InnoDB ROW_FORMAT=DYNAMIC;
ALTER TABLE t1 ADD INDEX `idx` (a,b(5));
SELECT CHAR_LENGTH(b) FROM t1 WHERE a=4975;
CHAR_LENGTH(b)
10000
SELECT b=REPEAT(CONCAT('a',4975),2000) FROM t1 WHERE a=4975 AND b like 'a4975%';
b=REPEAT(CONCAT('a',4975),2000)
1
UPDATE t1 SET b = REPEAT(CONCAT('b',4975),2000) WHERE a=4975 AND b like 'a4975%';
SELECT b=REPEAT(CONCAT('a',4975),2000) FROM t1 WHERE a=4975 AND b like 'a4975%';
b=REPEAT(CONCAT('a',4975),2000)
SELECT b=REPEAT(CONCAT('b',4975),2000) FROM t1 WHERE a=4975 AND b like 'b4975%';
b=REPEAT(CONCAT('b',4975),2000)
1
DELETE FROM t1 WHERE a=4975 AND b like 'b4975%';
SELECT b=REPEAT(CONCAT('b',4975),2000) FROM t1 WHERE a=4975 AND b like 'b4975%';
Note 1003 /* select#1 */ select `test`.`t1`.`class` AS `class`,`test`.`t1`.`id` AS `id`,`test`.`t1`.`title` AS `title` from `test`.`t1` where (`test`.`t1`.`id` = 10)
EXPLAIN SELECT * FROM t1 WHERE title = 'a10';
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
Note 1003 /* select#1 */ select `test`.`t1`.`class` AS `class`,`test`.`t1`.`id` AS `id`,`test`.`t1`.`title` AS `title` from `test`.`t1` where (`test`.`t1`.`title` = 'a10')
SELECT * FROM t1 WHERE id = 10;
class id title
10 10 a10
SELECT * FROM t1 WHERE title = 'a10';
class id title
10 10 a10
SELECT * FROM t1 WHERE id = 5000;
class id title
5000 5000 a5000
SELECT * FROM t1 WHERE title = 'a5000';
class id title
5000 5000 a5000
SELECT * FROM t1 WHERE id = 10000;
class id title
10000 10000 a10000
SELECT * FROM t1 WHERE title = 'a10000';
class id title
10000 10000 a10000
SELECT * FROM t1 WHERE id = 10010;
class id title
SELECT * FROM t1 WHERE title = 'a10010';
class id title
/*Insert/Update/Delete. */
DELETE FROM t1 WHERE id < 4010 AND id > 3990;
INSERT INTO t1 VALUES(4000, 4000, 'b4000');
UPDATE t1 SET title = CONCAT('b', id) WHERE id < 3010 AND id > 2990;
SELECT * FROM t1 WHERE id = 3000;
class id title
3000 3000 b3000
SELECT * FROM t1 WHERE title = 'a3000';
class id title
SELECT * FROM t1 WHERE title = 'b3000';
class id title
3000 3000 b3000
SELECT * FROM t1 WHERE id = 4000;
class id title
4000 4000 b4000
SELECT * FROM t1 WHERE title = 'a4000';
class id title
SELECT * FROM t1 WHERE title = 'b4000';
class id title
4000 4000 b4000
SELECT * FROM t1 WHERE id = 4001;
class id title
SELECT * FROM t1 WHERE title = 'a4001';
class id title
SELECT COUNT(*) FROM t1;
COUNT(*)
9992
/* Add column. */
ALTER TABLE t1 ADD COLUMN content TEXT;
CHECK TABLE t1;
Table Op Msg_type Msg_text
test.t1 check status OK
SELECT * FROM t1 WHERE id = 10;
class id title content
10 10 a10 NULL
SELECT * FROM t1 WHERE title = 'a10';
class id title content
10 10 a10 NULL
SELECT * FROM t1 WHERE id = 5000;
class id title content
5000 5000 a5000 NULL
SELECT * FROM t1 WHERE title = 'a5000';
class id title content
5000 5000 a5000 NULL
SELECT * FROM t1 WHERE id = 10000;
class id title content
10000 10000 a10000 NULL
SELECT * FROM t1 WHERE title = 'a10000';
class id title content
10000 10000 a10000 NULL
SELECT * FROM t1 WHERE id = 10010;
class id title content
SELECT * FROM t1 WHERE title = 'a10010';
class id title content
/* Drop column. */
ALTER TABLE t1 DROP COLUMN content;
CHECK TABLE t1;
Table Op Msg_type Msg_text
test.t1 check status OK
SELECT * FROM t1 WHERE id = 10;
class id title
10 10 a10
SELECT * FROM t1 WHERE title = 'a10';
class id title
10 10 a10
SELECT * FROM t1 WHERE id = 5000;
class id title
5000 5000 a5000
SELECT * FROM t1 WHERE title = 'a5000';
class id title
5000 5000 a5000
SELECT * FROM t1 WHERE id = 10000;
class id title
10000 10000 a10000
SELECT * FROM t1 WHERE title = 'a10000';
class id title
10000 10000 a10000
SELECT * FROM t1 WHERE id = 10010;
class id title
SELECT * FROM t1 WHERE title = 'a10010';
class id title
DROP TABLE t1;
CREATE TABLE t1(
a INT PRIMARY KEY,
b BLOB,
c TEXT) ENGINE=InnoDB ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=4;
ALTER TABLE t1 ADD INDEX `idx` (a,b(5));
SELECT CHAR_LENGTH(b) FROM t1 WHERE a=4975;
CHAR_LENGTH(b)
10000
SELECT b=REPEAT(CONCAT('a',4975),2000) FROM t1 WHERE a=4975 AND b like 'a4975%';
b=REPEAT(CONCAT('a',4975),2000)
1
UPDATE t1 SET b = REPEAT(CONCAT('b',4975),2000) WHERE a=4975 AND b like 'a4975%';
SELECT b=REPEAT(CONCAT('a',4975),2000) FROM t1 WHERE a=4975 AND b like 'a4975%';
b=REPEAT(CONCAT('a',4975),2000)
SELECT b=REPEAT(CONCAT('b',4975),2000) FROM t1 WHERE a=4975 AND b like 'b4975%';
b=REPEAT(CONCAT('b',4975),2000)
1
DELETE FROM t1 WHERE a=4975 AND b like 'b4975%';
SELECT b=REPEAT(CONCAT('b',4975),2000) FROM t1 WHERE a=4975 AND b like 'b4975%';
b=REPEAT(CONCAT('b',4975),2000)
ALTER TABLE t1 DROP COLUMN c;
CHECK TABLE t1;
Table Op Msg_type Msg_text
test.t1 check status OK
SELECT CHAR_LENGTH(b) FROM t1 WHERE a=4975;
CHAR_LENGTH(b)
DROP TABLE t1;
SET GLOBAL innodb_file_per_table=default;
DROP PROCEDURE populate_t1;
SET GLOBAL innodb_fill_factor=10;
CREATE PROCEDURE populate_t1(load_even INT)
BEGIN
DECLARE i int DEFAULT 1;
START TRANSACTION;
WHILE (i <= 10000) DO
IF i%2 = 0 AND load_even = 1 THEN
INSERT INTO t1 VALUES (i, i, CONCAT('a', i));
END IF;
IF i%2 != 0 AND load_even != 1 THEN
INSERT INTO t1 VALUES (i, i, CONCAT('a', i));
END IF;
SET i = i + 1;
END WHILE;
COMMIT;
END|
SELECT @@innodb_fill_factor;
@@innodb_fill_factor
10
CREATE TABLE t1(
class INT,
id INT,
title VARCHAR(100)
) ENGINE=InnoDB ROW_FORMAT=COMPACT;
SELECT COUNT(*) FROM t1;
COUNT(*)
5000
/* Create index. */
CREATE INDEX idx_id ON t1(id);
CREATE INDEX idx_title ON t1(title);
/* Check table. */
CHECK TABLE t1;
Table Op Msg_type Msg_text
test.t1 check status OK
/* Select by index. */
EXPLAIN SELECT * FROM t1 WHERE id = 10;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
Note 1003 /* select#1 */ select `test`.`t1`.`class` AS `class`,`test`.`t1`.`id` AS `id`,`test`.`t1`.`title` AS `title` from `test`.`t1` where (`test`.`t1`.`id` = 10)
EXPLAIN SELECT * FROM t1 WHERE title = 'a10';
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
Note 1003 /* select#1 */ select `test`.`t1`.`class` AS `class`,`test`.`t1`.`id` AS `id`,`test`.`t1`.`title` AS `title` from `test`.`t1` where (`test`.`t1`.`title` = 'a10')
SELECT * FROM t1 WHERE id = 10;
class id title
10 10 a10
SELECT * FROM t1 WHERE title = 'a10';
class id title
10 10 a10
SELECT * FROM t1 WHERE id = 5000;
class id title
5000 5000 a5000
SELECT * FROM t1 WHERE title = 'a5000';
class id title
5000 5000 a5000
SELECT * FROM t1 WHERE id = 10000;
class id title
10000 10000 a10000
SELECT * FROM t1 WHERE title = 'a10000';
class id title
10000 10000 a10000
SELECT * FROM t1 WHERE id = 10010;
class id title
SELECT * FROM t1 WHERE title = 'a10010';
class id title
/*Insert/Update/Delete. */
DELETE FROM t1 WHERE id < 4010 AND id > 3990;
INSERT INTO t1 VALUES(4000, 4000, 'b4000');
UPDATE t1 SET title = CONCAT('b', id) WHERE id < 3010 AND id > 2990;
SELECT * FROM t1 WHERE id = 3000;
class id title
3000 3000 b3000
SELECT * FROM t1 WHERE title = 'a3000';
class id title
SELECT * FROM t1 WHERE title = 'b3000';
class id title
3000 3000 b3000
SELECT * FROM t1 WHERE id = 4000;
class id title
4000 4000 b4000
SELECT * FROM t1 WHERE title = 'a4000';
class id title
SELECT * FROM t1 WHERE title = 'b4000';
class id title
4000 4000 b4000
SELECT * FROM t1 WHERE id = 4001;
class id title
SELECT * FROM t1 WHERE title = 'a4001';
class id title
SELECT COUNT(*) FROM t1;
COUNT(*)
9992
/* Add column. */
ALTER TABLE t1 ADD COLUMN content TEXT;
CHECK TABLE t1;
Table Op Msg_type Msg_text
test.t1 check status OK
SELECT * FROM t1 WHERE id = 10;
class id title content
10 10 a10 NULL
SELECT * FROM t1 WHERE title = 'a10';
class id title content
10 10 a10 NULL
SELECT * FROM t1 WHERE id = 5000;
class id title content
5000 5000 a5000 NULL
SELECT * FROM t1 WHERE title = 'a5000';
class id title content
5000 5000 a5000 NULL
SELECT * FROM t1 WHERE id = 10000;
class id title content
10000 10000 a10000 NULL
SELECT * FROM t1 WHERE title = 'a10000';
class id title content
10000 10000 a10000 NULL
SELECT * FROM t1 WHERE id = 10010;
class id title content
SELECT * FROM t1 WHERE title = 'a10010';
class id title content
/* Drop column. */
ALTER TABLE t1 DROP COLUMN content;
CHECK TABLE t1;
Table Op Msg_type Msg_text
test.t1 check status OK
SELECT * FROM t1 WHERE id = 10;
class id title
10 10 a10
SELECT * FROM t1 WHERE title = 'a10';
class id title
10 10 a10
SELECT * FROM t1 WHERE id = 5000;
class id title
5000 5000 a5000
SELECT * FROM t1 WHERE title = 'a5000';
class id title
5000 5000 a5000
SELECT * FROM t1 WHERE id = 10000;
class id title
10000 10000 a10000
SELECT * FROM t1 WHERE title = 'a10000';
class id title
10000 10000 a10000
SELECT * FROM t1 WHERE id = 10010;
class id title
SELECT * FROM t1 WHERE title = 'a10010';
class id title
DROP TABLE t1;
CREATE TABLE t1(
a INT PRIMARY KEY,
b TEXT,
c TEXT) ENGINE=InnoDB ROW_FORMAT=COMPACT;
ALTER TABLE t1 ADD INDEX `idx` (a,b(5));
SELECT CHAR_LENGTH(b) FROM t1 WHERE a=4975;
CHAR_LENGTH(b)
10000
SELECT b=REPEAT(CONCAT('a',4975),2000) FROM t1 WHERE a=4975 AND b like 'a4975%';
b=REPEAT(CONCAT('a',4975),2000)
1
UPDATE t1 SET b = REPEAT(CONCAT('b',4975),2000) WHERE a=4975 AND b like 'a4975%';
SELECT b=REPEAT(CONCAT('a',4975),2000) FROM t1 WHERE a=4975 AND b like 'a4975%';
b=REPEAT(CONCAT('a',4975),2000)
SELECT b=REPEAT(CONCAT('b',4975),2000) FROM t1 WHERE a=4975 AND b like 'b4975%';
b=REPEAT(CONCAT('b',4975),2000)
1
DELETE FROM t1 WHERE a=4975 AND b like 'b4975%';
SELECT b=REPEAT(CONCAT('b',4975),2000) FROM t1 WHERE a=4975 AND b like 'b4975%';
b=REPEAT(CONCAT('b',4975),2000)
ALTER TABLE t1 DROP COLUMN c;
CHECK TABLE t1;
Table Op Msg_type Msg_text
test.t1 check status OK
SELECT CHAR_LENGTH(b) FROM t1 WHERE a=4975;
CHAR_LENGTH(b)
DROP TABLE t1;
DROP PROCEDURE populate_t1;
SET GLOBAL innodb_fill_factor=50;
CREATE PROCEDURE populate_t1(load_even INT)
BEGIN
DECLARE i int DEFAULT 1;
START TRANSACTION;
WHILE (i <= 10000) DO
IF i%2 = 0 AND load_even = 1 THEN
INSERT INTO t1 VALUES (i, i, CONCAT('a', i));
END IF;
IF i%2 != 0 AND load_even != 1 THEN
INSERT INTO t1 VALUES (i, i, CONCAT('a', i));
END IF;
SET i = i + 1;
END WHILE;
COMMIT;
END|
SELECT @@innodb_fill_factor;
@@innodb_fill_factor
50
CREATE TABLE t1(
class INT,
id INT,
title VARCHAR(100)
) ENGINE=InnoDB ROW_FORMAT=COMPACT;
SELECT COUNT(*) FROM t1;
COUNT(*)
5000
/* Create index. */
CREATE INDEX idx_id ON t1(id);
CREATE INDEX idx_title ON t1(title);
/* Check table. */
CHECK TABLE t1;
Table Op Msg_type Msg_text
test.t1 check status OK
/* Select by index. */
EXPLAIN SELECT * FROM t1 WHERE id = 10;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
Note 1003 /* select#1 */ select `test`.`t1`.`class` AS `class`,`test`.`t1`.`id` AS `id`,`test`.`t1`.`title` AS `title` from `test`.`t1` where (`test`.`t1`.`id` = 10)
EXPLAIN SELECT * FROM t1 WHERE title = 'a10';
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
Note 1003 /* select#1 */ select `test`.`t1`.`class` AS `class`,`test`.`t1`.`id` AS `id`,`test`.`t1`.`title` AS `title` from `test`.`t1` where (`test`.`t1`.`title` = 'a10')
SELECT * FROM t1 WHERE id = 10;
class id title
10 10 a10
SELECT * FROM t1 WHERE title = 'a10';
class id title
10 10 a10
SELECT * FROM t1 WHERE id = 5000;
class id title
5000 5000 a5000
SELECT * FROM t1 WHERE title = 'a5000';
class id title
5000 5000 a5000
SELECT * FROM t1 WHERE id = 10000;
class id title
10000 10000 a10000
SELECT * FROM t1 WHERE title = 'a10000';
class id title
10000 10000 a10000
SELECT * FROM t1 WHERE id = 10010;
class id title
SELECT * FROM t1 WHERE title = 'a10010';
class id title
/*Insert/Update/Delete. */
DELETE FROM t1 WHERE id < 4010 AND id > 3990;
INSERT INTO t1 VALUES(4000, 4000, 'b4000');
UPDATE t1 SET title = CONCAT('b', id) WHERE id < 3010 AND id > 2990;
SELECT * FROM t1 WHERE id = 3000;
class id title
3000 3000 b3000
SELECT * FROM t1 WHERE title = 'a3000';
class id title
SELECT * FROM t1 WHERE title = 'b3000';
class id title
3000 3000 b3000
SELECT * FROM t1 WHERE id = 4000;
class id title
4000 4000 b4000
SELECT * FROM t1 WHERE title = 'a4000';
class id title
SELECT * FROM t1 WHERE title = 'b4000';
class id title
4000 4000 b4000
SELECT * FROM t1 WHERE id = 4001;
class id title
SELECT * FROM t1 WHERE title = 'a4001';
class id title
SELECT COUNT(*) FROM t1;
COUNT(*)
9992
/* Add column. */
ALTER TABLE t1 ADD COLUMN content TEXT;
CHECK TABLE t1;
Table Op Msg_type Msg_text
test.t1 check status OK
SELECT * FROM t1 WHERE id = 10;
class id title content
10 10 a10 NULL
SELECT * FROM t1 WHERE title = 'a10';
class id title content
10 10 a10 NULL
SELECT * FROM t1 WHERE id = 5000;
class id title content
5000 5000 a5000 NULL
SELECT * FROM t1 WHERE title = 'a5000';
class id title content
5000 5000 a5000 NULL
SELECT * FROM t1 WHERE id = 10000;
class id title content
10000 10000 a10000 NULL
SELECT * FROM t1 WHERE title = 'a10000';
class id title content
10000 10000 a10000 NULL
SELECT * FROM t1 WHERE id = 10010;
class id title content
SELECT * FROM t1 WHERE title = 'a10010';
class id title content
/* Drop column. */
ALTER TABLE t1 DROP COLUMN content;
CHECK TABLE t1;
Table Op Msg_type Msg_text
test.t1 check status OK
SELECT * FROM t1 WHERE id = 10;
class id title
10 10 a10
SELECT * FROM t1 WHERE title = 'a10';
class id title
10 10 a10
SELECT * FROM t1 WHERE id = 5000;
class id title
5000 5000 a5000
SELECT * FROM t1 WHERE title = 'a5000';
class id title
5000 5000 a5000
SELECT * FROM t1 WHERE id = 10000;
class id title
10000 10000 a10000
SELECT * FROM t1 WHERE title = 'a10000';
class id title
10000 10000 a10000
SELECT * FROM t1 WHERE id = 10010;
class id title
SELECT * FROM t1 WHERE title = 'a10010';
class id title
DROP TABLE t1;
CREATE TABLE t1(
a INT PRIMARY KEY,
b TEXT,
c TEXT) ENGINE=InnoDB ROW_FORMAT=COMPACT;
ALTER TABLE t1 ADD INDEX `idx` (a,b(5));
SELECT CHAR_LENGTH(b) FROM t1 WHERE a=4975;
CHAR_LENGTH(b)
10000
SELECT b=REPEAT(CONCAT('a',4975),2000) FROM t1 WHERE a=4975 AND b like 'a4975%';
b=REPEAT(CONCAT('a',4975),2000)
1
UPDATE t1 SET b = REPEAT(CONCAT('b',4975),2000) WHERE a=4975 AND b like 'a4975%';
SELECT b=REPEAT(CONCAT('a',4975),2000) FROM t1 WHERE a=4975 AND b like 'a4975%';
b=REPEAT(CONCAT('a',4975),2000)
SELECT b=REPEAT(CONCAT('b',4975),2000) FROM t1 WHERE a=4975 AND b like 'b4975%';
b=REPEAT(CONCAT('b',4975),2000)
1
DELETE FROM t1 WHERE a=4975 AND b like 'b4975%';
SELECT b=REPEAT(CONCAT('b',4975),2000) FROM t1 WHERE a=4975 AND b like 'b4975%';
Note 1003 /* select#1 */ select `test`.`t1`.`class` AS `class`,`test`.`t1`.`id` AS `id`,`test`.`t1`.`title` AS `title` from `test`.`t1` where (`test`.`t1`.`title` = 'a10')
SELECT * FROM t1 WHERE title = 'a10';
class id title
10 10 a10
SELECT * FROM t1 WHERE title = 'a5000';
class id title
5000 5000 a5000
SELECT * FROM t1 WHERE title = 'a10000';
class id title
10000 10000 a10000
SELECT * FROM t1 WHERE title = 'a10010';
class id title
DROP TABLE t1;
# Test Blob
CREATE TABLE t1(
a INT PRIMARY KEY,
b TEXT,
c TEXT) ENGINE=InnoDB ROW_FORMAT=REDUNDANT;
INSERT INTO t1 VALUES
(1, REPEAT('a',10000), 'a'),
(2, REPEAT('b',20000), 'b'),
(3, REPEAT('c',40000), 'c'),
(4, REPEAT('d',60000), 'd');
SELECT CHAR_LENGTH(b) FROM t1;
CHAR_LENGTH(b)
10000
20000
40000
60000
SET SESSION debug="+d,crash_commit_before";
ALTER TABLE t1 DROP COLUMN c;
ERROR HY000: Lost connection to MySQL server during query
CHECK TABLE t1;
Table Op Msg_type Msg_text
test.t1 check status OK
SELECT CHAR_LENGTH(b) FROM t1;
CHAR_LENGTH(b)
10000
20000
40000
60000
DROP TABLE t1;
DROP PROCEDURE populate_t1;
CREATE PROCEDURE populate_t1()
BEGIN
DECLARE i int DEFAULT 1;
START TRANSACTION;
WHILE (i <= 10000) DO
INSERT INTO t1 VALUES (i, i, CONCAT('a', i));
SET i = i + 1;
END WHILE;
COMMIT;
END|
CREATE TABLE t1(
class INT,
id INT,
title VARCHAR(100)
) ENGINE=InnoDB ROW_FORMAT=COMPACT;
SELECT COUNT(*) FROM t1;
COUNT(*)
10000
CREATE INDEX idx_title ON t1(title);
# restart
CHECK TABLE t1;
Table Op Msg_type Msg_text
test.t1 check status OK
SELECT * FROM t1 WHERE title = 'a10';
class id title
10 10 a10
SELECT * FROM t1 WHERE title = 'a5000';
class id title
5000 5000 a5000
SELECT * FROM t1 WHERE title = 'a10000';
class id title
10000 10000 a10000
SELECT * FROM t1 WHERE title = 'a10010';
class id title
DROP TABLE t1;
# Test Blob
CREATE TABLE t1(
a INT PRIMARY KEY,
b TEXT,
c TEXT) ENGINE=InnoDB ROW_FORMAT=COMPACT;
INSERT INTO t1 VALUES
(1, REPEAT('a',10000), 'a'),
(2, REPEAT('b',20000), 'b'),
(3, REPEAT('c',40000), 'c'),
(4, REPEAT('d',60000), 'd');
SELECT CHAR_LENGTH(b) FROM t1;
CHAR_LENGTH(b)
10000
20000
40000
60000
ALTER TABLE t1 DROP COLUMN c;
# restart
CHECK TABLE t1;
Table Op Msg_type Msg_text
test.t1 check status OK
SELECT CHAR_LENGTH(b) FROM t1;
CHAR_LENGTH(b)
10000
20000
40000
60000
DROP TABLE t1;
CREATE TABLE t1(
class INT,
id INT,
title VARCHAR(100)
) ENGINE=InnoDB ROW_FORMAT=COMPACT;
SET SESSION debug="+d,crash_commit_before";
CREATE INDEX idx_title ON t1(title);
ERROR HY000: Lost connection to MySQL server during query
SELECT COUNT(*) FROM t1;
COUNT(*)
10000
CHECK TABLE t1;
Table Op Msg_type Msg_text
test.t1 check status OK
EXPLAIN SELECT * FROM t1 WHERE title = 'a10';
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
Note 1003 /* select#1 */ select `test`.`t1`.`class` AS `class`,`test`.`t1`.`id` AS `id`,`test`.`t1`.`title` AS `title` from `test`.`t1` where (`test`.`t1`.`title` = 'a10')
SELECT * FROM t1 WHERE title = 'a10';
class id title
10 10 a10
SELECT * FROM t1 WHERE title = 'a5000';
class id title
5000 5000 a5000
SELECT * FROM t1 WHERE title = 'a10000';
class id title
10000 10000 a10000
SELECT * FROM t1 WHERE title = 'a10010';
class id title
DROP TABLE t1;
# Test Blob
CREATE TABLE t1(
a INT PRIMARY KEY,
b TEXT,
c TEXT) ENGINE=InnoDB ROW_FORMAT=COMPACT;
INSERT INTO t1 VALUES
(1, REPEAT('a',10000), 'a'),
(2, REPEAT('b',20000), 'b'),
(3, REPEAT('c',40000), 'c'),
(4, REPEAT('d',60000), 'd');
SELECT CHAR_LENGTH(b) FROM t1;
CHAR_LENGTH(b)
10000
20000
40000
60000
SET SESSION debug="+d,crash_commit_before";
ALTER TABLE t1 DROP COLUMN c;
ERROR HY000: Lost connection to MySQL server during query
CHECK TABLE t1;
Table Op Msg_type Msg_text
test.t1 check status OK
SELECT CHAR_LENGTH(b) FROM t1;
CHAR_LENGTH(b)
10000
20000
40000
60000
DROP TABLE t1;
DROP PROCEDURE populate_t1;
CREATE PROCEDURE populate_t1()
BEGIN
DECLARE i int DEFAULT 1;
START TRANSACTION;
WHILE (i <= 10000) DO
INSERT INTO t1 VALUES (i, i, CONCAT('a', i));
SET i = i + 1;
END WHILE;
COMMIT;
END|
CREATE TABLE t1(
class INT,
id INT,
title VARCHAR(100)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC;
SELECT COUNT(*) FROM t1;
COUNT(*)
10000
CREATE INDEX idx_title ON t1(title);
# restart
CHECK TABLE t1;
Table Op Msg_type Msg_text
test.t1 check status OK
SELECT * FROM t1 WHERE title = 'a10';
class id title
10 10 a10
SELECT * FROM t1 WHERE title = 'a5000';
class id title
5000 5000 a5000
SELECT * FROM t1 WHERE title = 'a10000';
class id title
10000 10000 a10000
SELECT * FROM t1 WHERE title = 'a10010';
class id title
DROP TABLE t1;
# Test Blob
CREATE TABLE t1(
a INT PRIMARY KEY,
b TEXT,
c TEXT) ENGINE=InnoDB ROW_FORMAT=DYNAMIC;
INSERT INTO t1 VALUES
(1, REPEAT('a',10000), 'a'),
(2, REPEAT('b',20000), 'b'),
(3, REPEAT('c',40000), 'c'),
(4, REPEAT('d',60000), 'd');
SELECT CHAR_LENGTH(b) FROM t1;
CHAR_LENGTH(b)
10000
20000
40000
60000
ALTER TABLE t1 DROP COLUMN c;
# restart
CHECK TABLE t1;
Table Op Msg_type Msg_text
test.t1 check status OK
SELECT CHAR_LENGTH(b) FROM t1;
CHAR_LENGTH(b)
10000
20000
40000
60000
DROP TABLE t1;
CREATE TABLE t1(
class INT,
id INT,
title VARCHAR(100)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC;
SET SESSION debug="+d,crash_commit_before";
CREATE INDEX idx_title ON t1(title);
ERROR HY000: Lost connection to MySQL server during query
SELECT COUNT(*) FROM t1;
COUNT(*)
10000
CHECK TABLE t1;
Table Op Msg_type Msg_text
test.t1 check status OK
EXPLAIN SELECT * FROM t1 WHERE title = 'a10';
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
Note 1003 /* select#1 */ select `test`.`t1`.`class` AS `class`,`test`.`t1`.`id` AS `id`,`test`.`t1`.`title` AS `title` from `test`.`t1` where (`test`.`t1`.`title` = 'a10')
SELECT * FROM t1 WHERE title = 'a10';
class id title
10 10 a10
SELECT * FROM t1 WHERE title = 'a5000';
class id title
5000 5000 a5000
SELECT * FROM t1 WHERE title = 'a10000';
class id title
10000 10000 a10000
SELECT * FROM t1 WHERE title = 'a10010';
class id title
DROP TABLE t1;
# Test Blob
CREATE TABLE t1(
a INT PRIMARY KEY,
b TEXT,
c TEXT) ENGINE=InnoDB ROW_FORMAT=DYNAMIC;
INSERT INTO t1 VALUES
(1, REPEAT('a',10000), 'a'),
(2, REPEAT('b',20000), 'b'),
(3, REPEAT('c',40000), 'c'),
(4, REPEAT('d',60000), 'd');
SELECT CHAR_LENGTH(b) FROM t1;
CHAR_LENGTH(b)
10000
20000
40000
60000
SET SESSION debug="+d,crash_commit_before";
ALTER TABLE t1 DROP COLUMN c;
ERROR HY000: Lost connection to MySQL server during query
Note 1003 /* select#1 */ select `test`.`t1`.`class` AS `class`,`test`.`t1`.`id` AS `id`,`test`.`t1`.`title` AS `title` from `test`.`t1` where (`test`.`t1`.`title` = 'a10')
SELECT * FROM t1 WHERE title = 'a10';
class id title
10 10 a10
SELECT * FROM t1 WHERE title = 'a5000';
class id title
5000 5000 a5000
SELECT * FROM t1 WHERE title = 'a10000';
class id title
10000 10000 a10000
SELECT * FROM t1 WHERE title = 'a10010';
class id title
DROP TABLE t1;
# Test Blob
SET GLOBAL innodb_file_per_table=1;
CREATE TABLE t1(
a INT PRIMARY KEY,
b TEXT,
c TEXT) ENGINE=InnoDB ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=4;
INSERT INTO t1 VALUES
(1, REPEAT('a',10000), 'a'),
(2, REPEAT('b',20000), 'b'),
(3, REPEAT('c',40000), 'c'),
(4, REPEAT('d',60000), 'd');
SELECT CHAR_LENGTH(b) FROM t1;
CHAR_LENGTH(b)
10000
20000
40000
60000
SET SESSION debug="+d,crash_commit_before";
ALTER TABLE t1 DROP COLUMN c;
ERROR HY000: Lost connection to MySQL server during query
Note #### Sending passwords in plain text without SSL/TLS is extremely insecure.
Note #### Storing MySQL user name or password information in the master info repository is not secure and is therefore not recommended. Please consider using the USER and PASSWORD connection options for START SLAVE; see the 'START SLAVE Syntax' in the MySQL Manual for more information.
[connection master]
CREATE PROCEDURE populate_t1(load_even INT)
BEGIN
DECLARE i int DEFAULT 1;
START TRANSACTION;
WHILE (i <= 100) DO
IF i%2 = 0 AND load_even = 1 THEN
INSERT INTO t1 VALUES (i, i, CONCAT('a', i));
END IF;
IF i%2 != 0 AND load_even != 1 THEN
INSERT INTO t1 VALUES (i, i, CONCAT('a', i));
END IF;
SET i = i + 1;
END WHILE;
COMMIT;
END|
CREATE TABLE t1(
class INT,
id INT,
title VARCHAR(100)
) ENGINE=InnoDB ;
SELECT COUNT(*) FROM t1;
COUNT(*)
50
/* Create index. */
CREATE INDEX idx_id ON t1(id);
CREATE INDEX idx_title ON t1(title);
/* Select by index. */
EXPLAIN SELECT * FROM t1 WHERE id = 10;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
Note 1003 /* select#1 */ select `test`.`t1`.`class` AS `class`,`test`.`t1`.`id` AS `id`,`test`.`t1`.`title` AS `title` from `test`.`t1` where (`test`.`t1`.`id` = 10)
EXPLAIN SELECT * FROM t1 WHERE title = 'a10';
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
Note 1003 /* select#1 */ select `test`.`t1`.`class` AS `class`,`test`.`t1`.`id` AS `id`,`test`.`t1`.`title` AS `title` from `test`.`t1` where (`test`.`t1`.`title` = 'a10')
SELECT * FROM t1 WHERE id = 10;
class id title
10 10 a10
SELECT * FROM t1 WHERE title = 'a10';
class id title
10 10 a10
SELECT * FROM t1 WHERE id = 20;
class id title
20 20 a20
SELECT * FROM t1 WHERE title = 'a20';
class id title
20 20 a20
SELECT * FROM t1 WHERE id = 30;
class id title
30 30 a30
SELECT * FROM t1 WHERE title = 'a30';
class id title
30 30 a30
SELECT * FROM t1 WHERE id = 101;
class id title
SELECT * FROM t1 WHERE title = 'a101';
class id title
/*Insert/Update/Delete. */
DELETE FROM t1 WHERE id < 40 AND id > 30;
INSERT INTO t1 VALUES(38, 38, 'b38');
UPDATE t1 SET title = CONCAT('b', id) WHERE id < 30 AND id > 20;
SELECT * FROM t1 WHERE id = 28;
class id title
28 28 b28
SELECT * FROM t1 WHERE title = 'a28';
class id title
SELECT * FROM t1 WHERE title = 'b28';
class id title
28 28 b28
SELECT * FROM t1 WHERE id = 38;
class id title
38 38 b38
SELECT * FROM t1 WHERE title = 'a38';
class id title
SELECT * FROM t1 WHERE title = 'b38';
class id title
38 38 b38
SELECT * FROM t1 WHERE id = 101;
class id title
SELECT * FROM t1 WHERE title = 'a101';
class id title
SELECT COUNT(*) FROM t1;
COUNT(*)
97
SELECT * FROM t1 WHERE id = 10;
class id title
10 10 a10
SELECT * FROM t1 WHERE title = 'a10';
class id title
10 10 a10
SELECT * FROM t1 WHERE id = 20;
class id title
20 20 a20
SELECT * FROM t1 WHERE title = 'a20';
class id title
20 20 a20
SELECT * FROM t1 WHERE id = 30;
class id title
30 30 a30
SELECT * FROM t1 WHERE title = 'a30';
class id title
30 30 a30
SELECT * FROM t1 WHERE id = 101;
class id title
SELECT * FROM t1 WHERE title = 'a101';
class id title
CREATE TABLE t_part (
class INT ,
id INT ,
title VARCHAR(30)
) ENGINE=InnoDB
PARTITION BY RANGE(id)
SUBPARTITION BY KEY(id)
SUBPARTITIONS 4
(
PARTITION p0 VALUES LESS THAN (5000),
PARTITION p1 VALUES LESS THAN (MAXVALUE)
);
INSERT INTO t_part SELECT * FROM t1;
ALTER TABLE t_part ADD INDEX `idx` (class,id,title(10));
SELECT * FROM t_part WHERE id = 10;
class id title
10 10 a10
SELECT * FROM t_part WHERE title = 'a10';
class id title
10 10 a10
SELECT * FROM t_part WHERE id = 20;
class id title
20 20 a20
SELECT * FROM t_part WHERE title = 'a20';
class id title
20 20 a20
SELECT * FROM t_part WHERE id = 30;
class id title
30 30 a30
SELECT * FROM t_part WHERE title = 'a30';
class id title
30 30 a30
SELECT * FROM t_part WHERE id = 101;
class id title
SELECT * FROM t_part WHERE title = 'a101';
class id title
include/sync_slave_sql_with_master.inc
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`class` int(11) DEFAULT NULL,
`id` int(11) DEFAULT NULL,
`title` varchar(100) DEFAULT NULL,
KEY `idx_id` (`id`),
KEY `idx_title` (`title`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
SHOW CREATE TABLE t_part;
Table Create Table
t_part CREATE TABLE `t_part` (
`class` int(11) DEFAULT NULL,
`id` int(11) DEFAULT NULL,
`title` varchar(30) DEFAULT NULL,
KEY `idx` (`class`,`id`,`title`(10))
) ENGINE=InnoDB DEFAULT CHARSET=latin1
/*!50100 PARTITION BY RANGE (id)
SUBPARTITION BY KEY (id)
SUBPARTITIONS 4
(PARTITION p0 VALUES LESS THAN (5000) ENGINE = InnoDB,
PARTITION p1 VALUES LESS THAN MAXVALUE ENGINE = InnoDB) */
Note 1003 /* select#1 */ select `test`.`t1`.`class` AS `class`,`test`.`t1`.`id` AS `id`,`test`.`t1`.`title` AS `title` from `test`.`t1` where (`test`.`t1`.`id` = 10)
EXPLAIN SELECT * FROM t1 WHERE title = 'a10';
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
Note 1003 /* select#1 */ select `test`.`t1`.`class` AS `class`,`test`.`t1`.`id` AS `id`,`test`.`t1`.`title` AS `title` from `test`.`t1` where (`test`.`t1`.`title` = 'a10')
Note 1003 /* select#1 */ select `test`.`t1`.`class` AS `class`,`test`.`t1`.`id` AS `id`,`test`.`t1`.`title` AS `title` from `test`.`t1` where (`test`.`t1`.`id` = 10)
EXPLAIN SELECT * FROM t1 WHERE title = 'a10';
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
Note 1003 /* select#1 */ select `test`.`t1`.`class` AS `class`,`test`.`t1`.`id` AS `id`,`test`.`t1`.`title` AS `title` from `test`.`t1` where (`test`.`t1`.`title` = 'a10')
SELECT * FROM t1 WHERE id = 10;
class id title
10 10 a10
SELECT * FROM t1 WHERE title = 'a10';
class id title
10 10 a10
SELECT * FROM t1 WHERE id = 500;
class id title
500 500 a500
SELECT * FROM t1 WHERE title = 'a500';
class id title
500 500 a500
SELECT * FROM t1 WHERE id = 1000;
class id title
1000 1000 a1000
SELECT * FROM t1 WHERE title = 'a1000';
class id title
1000 1000 a1000
SELECT * FROM t1 WHERE id = 1010;
class id title
SELECT * FROM t1 WHERE title = 'a1010';
class id title
DROP TABLE t1;
CREATE TABLE t1(
a INT PRIMARY KEY,
b TEXT,
c TEXT) ENGINE=InnoDB ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=4;