Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mysql> select @@version,@@version_comment;
- +-----------+--------------------------------------------------------+
- | @@version | @@version_comment |
- +-----------+--------------------------------------------------------+
- | 5.7.22-22 | Percona Server (GPL), Release '22', Revision 'f62d93c' |
- +-----------+--------------------------------------------------------+
- 1 row in set (0.00 sec)
- mysql> show create table tok1\G
- *************************** 1. row ***************************
- Table: tok1
- Create Table: CREATE TABLE `tok1` (
- `id` int(11) NOT NULL AUTO_INCREMENT,
- `a` varchar(50) DEFAULT NULL,
- `d` datetime DEFAULT NULL,
- PRIMARY KEY (`id`),
- KEY `a` (`a`),
- KEY `d` (`d`)
- ) ENGINE=TokuDB AUTO_INCREMENT=11 DEFAULT CHARSET=latin1
- 1 row in set (0.00 sec)
- mysql> show variables like 'tokudb_%analyze%';
- +--------------------------------+-------------------------+
- | Variable_name | Value |
- +--------------------------------+-------------------------+
- | tokudb_analyze_delete_fraction | 1.000000 |
- | tokudb_analyze_in_background | ON |
- | tokudb_analyze_mode | TOKUDB_ANALYZE_STANDARD |
- | tokudb_analyze_throttle | 0 |
- | tokudb_analyze_time | 5 |
- | tokudb_auto_analyze | 30 |
- +--------------------------------+-------------------------+
- 6 rows in set (0.00 sec)
- # ./mysql_random_data_loader -h 10.129.7.190 -u root test tok1 10
- INFO[2018-07-20T08:22:55Z] Starting
- 0s [====================================================================] 100%
- INFO[2018-07-20T08:22:56Z] 10 rows inserted
- mysql> show indexes from tok1;
- +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
- | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
- +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
- | tok1 | 0 | PRIMARY | 1 | id | A | 10 | NULL | NULL | | BTREE | | |
- | tok1 | 1 | a | 1 | a | A | 10 | NULL | NULL | YES | BTREE | | |
- | tok1 | 1 | d | 1 | d | A | 10 | NULL | NULL | YES | BTREE | | |
- +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
- 3 rows in set (0.00 sec)
- # ./mysql_random_data_loader -h 10.129.7.190 -u root test tok1 100
- INFO[2018-07-20T08:24:46Z] Starting
- 0s [====================================================================] 100%
- INFO[2018-07-20T08:24:46Z] 100 rows inserted
- mysql> show indexes from tok1;
- +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
- | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
- +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
- | tok1 | 0 | PRIMARY | 1 | id | A | 110 | NULL | NULL | | BTREE | | |
- | tok1 | 1 | a | 1 | a | A | 110 | NULL | NULL | YES | BTREE | | |
- | tok1 | 1 | d | 1 | d | A | 110 | NULL | NULL | YES | BTREE | | |
- +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
- 3 rows in set (0.00 sec)
- mysql> EXPLAIN select * from tok1 where id>100;
- +----+-------------+-------+------------+-------+---------------+---------+---------+------+------+----------+-------------+
- | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
- +----+-------------+-------+------------+-------+---------------+---------+---------+------+------+----------+-------------+
- | 1 | SIMPLE | tok1 | NULL | range | PRIMARY | PRIMARY | 4 | NULL | 10 | 100.00 | Using where |
- +----+-------------+-------+------------+-------+---------------+---------+---------+------+------+----------+-------------+
- 1 row in set, 1 warning (0.00 sec)
- mysql> set global tokudb_auto_analyze=0;
- Query OK, 0 rows affected (0.00 sec)
- # ./mysql_random_data_loader -h 10.129.7.190 -u root test tok1 100
- INFO[2018-07-20T08:27:50Z] Starting
- 0s [====================================================================] 100%
- INFO[2018-07-20T08:27:50Z] 100 rows inserted
- mysql> show indexes from tok1;
- +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
- | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
- +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
- | tok1 | 0 | PRIMARY | 1 | id | A | 210 | NULL | NULL | | BTREE | | |
- | tok1 | 1 | a | 1 | a | A | 210 | NULL | NULL | YES | BTREE | | |
- | tok1 | 1 | d | 1 | d | A | 210 | NULL | NULL | YES | BTREE | | |
- +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
- 3 rows in set (0.00 sec)
- mysql> show table status like 'tok1'\G
- *************************** 1. row ***************************
- Name: tok1
- Engine: TokuDB
- Version: 10
- Row_format: tokudb_zlib
- Rows: 210
- Avg_row_length: 49
- Data_length: 10439
- Max_data_length: 9223372036854775807
- Index_length: 11909
- Data_free: 75746
- Auto_increment: 211
- Create_time: 2018-07-20 08:07:34
- Update_time: 2018-07-20 08:24:50
- Check_time: NULL
- Collation: latin1_swedish_ci
- Checksum: NULL
- Create_options:
- Comment:
- 1 row in set (0.00 sec)
- mysql> EXPLAIN select * from tok1 where id>100;
- +----+-------------+-------+------------+-------+---------------+---------+---------+------+------+----------+-------------+
- | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
- +----+-------------+-------+------------+-------+---------------+---------+---------+------+------+----------+-------------+
- | 1 | SIMPLE | tok1 | NULL | range | PRIMARY | PRIMARY | 4 | NULL | 110 | 100.00 | Using where |
- +----+-------------+-------+------------+-------+---------------+---------+---------+------+------+----------+-------------+
- 1 row in set, 1 warning (0.00 sec)
- -- restarted with options in my.cnf:
- tokudb_auto_analyze = 0
- tokudb_analyze_in_background = 0
- mysql> show variables like 'tokudb_%analyze%';
- +--------------------------------+-------------------------+
- | Variable_name | Value |
- +--------------------------------+-------------------------+
- | tokudb_analyze_delete_fraction | 1.000000 |
- | tokudb_analyze_in_background | OFF |
- | tokudb_analyze_mode | TOKUDB_ANALYZE_STANDARD |
- | tokudb_analyze_throttle | 0 |
- | tokudb_analyze_time | 5 |
- | tokudb_auto_analyze | 0 |
- +--------------------------------+-------------------------+
- 6 rows in set (0.00 sec)
- -- every next insertion by 100 rows updates cardinality and rows count in table status exactly.
- mysql> select count(*) from tok1;
- +----------+
- | count(*) |
- +----------+
- | 710 |
- +----------+
- 1 row in set (0.00 sec)
- mysql> show indexes from tok1;
- +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
- | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
- +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
- | tok1 | 0 | PRIMARY | 1 | id | A | 710 | NULL | NULL | | BTREE | | |
- | tok1 | 1 | a | 1 | a | A | 710 | NULL | NULL | YES | BTREE | | |
- | tok1 | 1 | d | 1 | d | A | 710 | NULL | NULL | YES | BTREE | | |
- +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
- 3 rows in set (0.00 sec)
- -- even one row insert updates statistics:
- mysql> show indexes from tok1;
- +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
- | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
- +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
- | tok1 | 0 | PRIMARY | 1 | id | A | 711 | NULL | NULL | | BTREE | | |
- | tok1 | 1 | a | 1 | a | A | 711 | NULL | NULL | YES | BTREE | | |
- | tok1 | 1 | d | 1 | d | A | 711 | NULL | NULL | YES | BTREE | | |
- +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
- 3 rows in set (0.00 sec)
- mysql> EXPLAIN select * from tok1 where id>100;
- +----+-------------+-------+------------+-------+---------------+---------+---------+------+------+----------+-------------+
- | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
- +----+-------------+-------+------------+-------+---------------+---------+---------+------+------+----------+-------------+
- | 1 | SIMPLE | tok1 | NULL | range | PRIMARY | PRIMARY | 4 | NULL | 611 | 100.00 | Using where |
- +----+-------------+-------+------------+-------+---------------+---------+---------+------+------+----------+-------------+
- 1 row in set, 1 warning (0.00 sec)
- -- changed global to tokudb_analyze_mode='TOKUDB_ANALYZE_CANCEL'
- mysql> show variables like 'tokudb_%analyze%';
- +--------------------------------+-----------------------+
- | Variable_name | Value |
- +--------------------------------+-----------------------+
- | tokudb_analyze_delete_fraction | 1.000000 |
- | tokudb_analyze_in_background | OFF |
- | tokudb_analyze_mode | TOKUDB_ANALYZE_CANCEL |
- | tokudb_analyze_throttle | 0 |
- | tokudb_analyze_time | 5 |
- | tokudb_auto_analyze | 0 |
- +--------------------------------+-----------------------+
- 6 rows in set (0.00 sec)
- -- add 100 more rows:
- mysql> select count(*) from tok1;
- +----------+
- | count(*) |
- +----------+
- | 811 |
- +----------+
- 1 row in set (0.00 sec)
- mysql> show indexes from tok1;
- +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
- | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
- +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
- | tok1 | 0 | PRIMARY | 1 | id | A | 811 | NULL | NULL | | BTREE | | |
- | tok1 | 1 | a | 1 | a | A | 811 | NULL | NULL | YES | BTREE | | |
- | tok1 | 1 | d | 1 | d | A | 811 | NULL | NULL | YES | BTREE | | |
- +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
- 3 rows in set (0.00 sec)
- mysql> EXPLAIN select * from tok1 where id>100;
- +----+-------------+-------+------------+-------+---------------+---------+---------+------+------+----------+-------------+
- | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
- +----+-------------+-------+------------+-------+---------------+---------+---------+------+------+----------+-------------+
- | 1 | SIMPLE | tok1 | NULL | range | PRIMARY | PRIMARY | 4 | NULL | 711 | 100.00 | Using where |
- +----+-------------+-------+------------+-------+---------------+---------+---------+------+------+----------+-------------+
- 1 row in set, 1 warning (0.00 sec)
- mysql> delete from tok1 where id>400;
- Query OK, 411 rows affected (0.03 sec)
- mysql> EXPLAIN select * from tok1 where id>100;
- +----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+-------------+
- | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
- +----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+-------------+
- | 1 | SIMPLE | tok1 | NULL | ALL | PRIMARY | NULL | NULL | NULL | 400 | 100.00 | Using where |
- +----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+-------------+
- 1 row in set, 1 warning (0.00 sec)
- mysql> select * from INFORMATION_SCHEMA.TOKUDB_BACKGROUND_JOB_STATUS;
- Empty set (0.00 sec)
- -- Cardinality for this TokuDB table is 100% accurate at this point, where for similar InnoDB table is not:
- mysql> select count(*) from inno1;
- +----------+
- | count(*) |
- +----------+
- | 800 |
- +----------+
- 1 row in set (0.01 sec)
- mysql> show indexes from inno1;
- +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
- | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
- +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
- | inno1 | 0 | PRIMARY | 1 | id | A | 559 | NULL | NULL | | BTREE | | |
- | inno1 | 1 | a | 1 | a | A | 559 | NULL | NULL | YES | BTREE | | |
- | inno1 | 1 | d | 1 | d | A | 559 | NULL | NULL | YES | BTREE | | |
- +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
- 3 rows in set (0.00 sec)
Add Comment
Please, Sign In to add comment