# How to tune tokuDB query with "sort by"

**URL:** <https://forums.percona.com/t/how-to-tune-tokudb-query-with-sort-by/5455>\
**Category:** General Questions\
**Created:** [March 2, 2017, 5:23am UTC](https://forums.percona.com/t/how-to-tune-tokudb-query-with-sort-by/5455 "2017-03-02T05:23:32Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![changmao.wang](https://avatars.discourse-cdn.com/v4/letter/c/b77776/32.png) [@changmao.wang](https://forums.percona.com/u/changmao.wang)\
**Post date:** [March 2, 2017, 5:23am UTC](https://forums.percona.com/t/how-to-tune-tokudb-query-with-sort-by/5455/1 "2017-03-02T05:23:32Z")

</div>

I have single table query with order by clause. The execution plan of this query is as below:  
mysql\> explain select barTime,dataDate,closePrice,shortnm from MarketDataTDB.equity\_pricemin where datadate \>= 20170103 and datadate \<= 20170227 and ticker=000001 and exchangecd=‘XSHG’ order by datadate,secOffset;  
±—±------------±----------------±------±------------------------------±--------±--------±-----±------±----------------------------+  
| id | select\_type | table | type | possible\_keys | key | key\_len | ref | rows | Extra |  
±—±------------±----------------±------±------------------------------±--------±--------±-----±------±----------------------------+  
| 1 | SIMPLE | equity\_pricemin | range | equity\_price\_dtticker,cvr\_idx | cvr\_idx | 9 | NULL | 14026 | Using where; Using filesort |  
±—±------------±----------------±------±------------------------------±--------±--------±-----±------±----------------------------+  
1 row in set (0.00 sec)

After I use mysqlslamp to concurrently run it with 20 sessions, it ran so slowly, with only 50% performance with same query of Innodb Engine. The table have same data structure and indexes on TokuDB and InnoDB engine.

I saw many "Creating sort index“ and “Queried about 10000 rows” from ‘show processlist’, when I did above query testing.  
So my question is how to tuning this ‘sort’?
