foreword
The data volume of a tpc-h database is used here to compare query plans. And analyze the execution plan with the help of 22 query statements in tpc-h.
MySQL uses a standard installation, and TiDB uses a stand-alone beta version. The performance results here cannot explain the difference in performance.
The main purpose of this article is to compare the differences between Mysql and TiDB when executing SQL queries.
mysql version 5.7 TiDB version v2.0.0-rc.4
Preparation Phase
After data is imported into TiDB, statistics are missing:
SHOW STATS_META
Statistics can be refreshed manually
ANALYZE TABLE nation,region,part,supplier,partsupp,customer,orders,lineitem
Check SHOW STATS_META again after refreshing
First select Q17 as an example to query
select sum(l_extendedprice) / 7.0 as avg_yearly from lineitem, part where p_partkey = l_partkey and p_brand = ' Brand#23 ' # Specify the brand. BRAND='Brand#MN', M and N are two letters, representing two values, independent of each other, the value is between 1 and 5, and p_container = ' MED BOX ' # Specify the packaging type. Randomly select within the range specified by the TPC - H standard and l_quantity < ( select 0.2 * avg (l_quantity) from lineitem where l_partkey = p_partkey );
The part table is 200,000 P_PARTKEY is the primary key, and the lineitem is 6 million
The query time of mysql is about 1 second, and the query time of TiDB is about 30 seconds. By comparison, it is found that mysql will automatically create an index when creating constraints.
mysql execution plan:
mysql first queries the part table, and the 200,000 data has been filtered to several hundred after processing where. Then associate with the lineitem, and finally process the subquery.
The primary key association is borrowed during the query, so
TiDB execution plan