I am not asking you to fix this. I am sharing here so you don't learn of this first when I share results in pubic.
Upgraded to TokuDB 5.7.15 from Percona Server, running the insert benchmark using
https://github.com/mdcallag/mytools/blob/master/bench/ibench/iq.sh. There are 3 phases in this test, insert only, inserts rate limited to 1000/second with concurrent queries, inserts rate limited to 100/second with concurrent queries. The query rates drop to 0 per second during the second and third phases.
This isn't bad query plans from bad index cardinality stats. I checked the results for SHOW INDEXES and SHOW TABLE STATUS and the numbers are good. The QPS rate drops because the queries do full (or long) index scans when they should be doing short index only scans on covering secondary indexes. InnoDB in MySQL 5.6.26 and 5.7.10 is OK on this. MyRocks from FB MySQL is OK on this. The problem is that TokuDB uses type:index when other engines use type:range for the index access. Is something ignoring the use of the LIMIT clause?
By accident the tests used values for tokudb_analyze_mode that are required to avoid bad query plans with sysbench. I might undo that for a few tests, but the index stats are good in this test. They don't drift to zero -- maybe that is a problem for update statements.
Slow query log output:
# Time: 2016-12-23T16:30:55.336869Z
# User@Host: root[root] @ localhost [127.0.0.1] Id: 2524
# Schema: ib Last_errno: 0 Killed: 0
# Query_time: 17.990052 Lock_time: 0.000068 Rows_sent: 10 Rows_examined: 41361128 Rows_affected: 0
# Bytes_sent: 540
SET timestamp=1482510655;
SELECT price,dateandtime,customerid FROM pi8 FORCE INDEX (pdc) WHERE (price>=319.30) ORDER BY price,dateandtime,customerid LIMIT 10;
# Time: 2016-12-23T16:30:56.928372Z
# User@Host: root[root] @ localhost [127.0.0.1] Id: 2544
# Schema: ib Last_errno: 0 Killed: 0
# Query_time: 29.310352 Lock_time: 0.000126 Rows_sent: 10 Rows_examined: 67533688 Rows_affected: 0
# Bytes_sent: 540
SET timestamp=1482510656;
SELECT price,dateandtime,customerid FROM pi9 FORCE INDEX (pdc) WHERE (price>=519.87) ORDER BY price,dateandtime,customerid LIMIT 10;
# Time: 2016-12-23T16:30:59.099488Z
# User@Host: root[root] @ localhost [127.0.0.1] Id: 2533
# Schema: ib Last_errno: 0 Killed: 0
# Query_time: 7.612549 Lock_time: 0.000059 Rows_sent: 10 Rows_examined: 18340078 Rows_affected: 0
# Bytes_sent: 546
SET timestamp=1482510659;
SELECT price,dateandtime,customerid FROM pi12 FORCE INDEX (pdc) WHERE (price>=143.04) ORDER BY price,dateandtime,customerid LIMIT 10;
# Time: 2016-12-23T16:31:01.702954Z
# User@Host: root[root] @ localhost [127.0.0.1] Id: 2555
# Schema: ib Last_errno: 0 Killed: 0
# Query_time: 17.916199 Lock_time: 0.000052 Rows_sent: 10 Rows_examined: 42871166 Rows_affected: 0
# Bytes_sent: 540
SET timestamp=1482510661;
SELECT price,dateandtime,customerid FROM pi2 FORCE INDEX (pdc) WHERE (price>=330.87) ORDER BY price,dateandtime,customerid LIMIT 10;
Explain of a problem query for TokuDB
mysql> explain SELECT price,dateandtime,customerid FROM pi5 FORCE INDEX (pdc) WHERE (price>=389.23) ORDER BY price,dateandtime,customerid LIMIT 10\G
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: pi5
partitions: NULL
type: index
possible_keys: pdc
key: pdc
key_len: 14
ref: NULL
rows: 10
filtered: 100.00
Extra: Using where; Using index
1 row in set, 1 warning (0.00 sec)
Explain of that problem query for InnoDB 5.7.10
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: pi5
partitions: NULL
type: range
possible_keys: pdc
key: pdc
key_len: 4
ref: NULL
rows: 64877752
filtered: 100.00
Extra: Using where; Using index
1 row in set, 1 warning (0.00 sec)
Table for problem query:
mysql> show create table pi5\G
*************************** 1. row ***************************
Table: pi5
Create Table: CREATE TABLE `pi5` (
`transactionid` int(11) NOT NULL AUTO_INCREMENT,
`dateandtime` datetime DEFAULT NULL,
`cashregisterid` int(11) NOT NULL,
`customerid` int(11) NOT NULL,
`productid` int(11) NOT NULL,
`price` float NOT NULL,
`data` varchar(4000) DEFAULT NULL,
PRIMARY KEY (`transactionid`),
KEY `marketsegment` (`price`,`customerid`),
KEY `registersegment` (`cashregisterid`,`price`,`customerid`),
KEY `pdc` (`price`,`dateandtime`,`customerid`)
) ENGINE=TokuDB AUTO_INCREMENT=130575101 DEFAULT CHARSET=latin1
1 row in set (0.00 sec)
Index stats:
mysql> show indexes from pi5;
+-------+------------+-----------------+--------------+----------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+-------+------------+-----------------+--------------+----------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| pi5 | 0 | PRIMARY | 1 | transactionid | A | 130577696 | NULL | NULL | | BTREE | | |
| pi5 | 1 | marketsegment | 1 | price | A | 132298 | NULL | NULL | | BTREE | | |
| pi5 | 1 | marketsegment | 2 | customerid | A | 65288848 | NULL | NULL | | BTREE | | |
| pi5 | 1 | registersegment | 1 | cashregisterid | A | 1086 | NULL | NULL | | BTREE | | |
| pi5 | 1 | registersegment | 2 | price | A | 130577696 | NULL | NULL | | BTREE | | |
| pi5 | 1 | registersegment | 3 | customerid | A | 130577696 | NULL | NULL | | BTREE | | |
| pi5 | 1 | pdc | 1 | price | A | 132971 | NULL | NULL | | BTREE | | |
| pi5 | 1 | pdc | 2 | dateandtime | A | 130577696 | NULL | NULL | YES | BTREE | | |
| pi5 | 1 | pdc | 3 | customerid | A | 130577696 | NULL | NULL | | BTREE | | |
+-------+------------+-----------------+--------------+----------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
mysql> show table status like "pi5"\G
*************************** 1. row ***************************
Name: pi5
Engine: TokuDB
Version: 10
Row_format: tokudb_zlib
Rows: 130580100
Avg_row_length: 43
Max_data_length: 9223372036854775807
Index_length: 14448534548
Data_free: 49168380
Auto_increment: 130580101
Create_time: 2016-12-22 20:30:16
Update_time: 2016-12-23 08:39:41
Check_time: NULL
Collation: latin1_swedish_ci
Checksum: NULL
Create_options:
Comment:
1 row in set (0.00 sec)
/etc/my.cnf
[mysqld]
sql_mode=no_engine_substitution,no_unsigned_subtraction
default_tmp_storage_engine=MyISAM
tmpdir=/data/mysql/toku
query_cache_size=0
query_cache_type=0
slow_query_log_file=/data/mysql/toku/slow.log
long_query_time=5
max_binlog_size=128M
sync_binlog=0
server_id=77
datadir=/data/mysql/toku/data
tokudb_cache_size = 10G