
So far most of the benchmarks posted about MySQL 5.6 use the sysbench OLTP workload. I wanted to test a set of queries which, unlike sysbench, utilize joins. I also wanted an easily reproducible set of data which is more rich than the simple sysbench table. The Star Schema Benchmark (SSB) seems ideal for this.
I wasn’t going to focus on the performance of individual queries in this post, but instead intended to focus only on the overall response time for answering all of the queries in the benchmark. I got some strange results, however, which showed MySQL 5.6.10 to be much slower than MySQL 5.5.30 even with only a single connection. I felt these results warranted deeper investigation, so I did some research and detailed my findings here.
Just a few notes:
I tested two scenarios: a buffer pool much smaller than the data set (default size of 128MB, which is 1/8th of the data) and I also testing a 4G buffer pool, which is larger than the data. Very little tuning was done. The goal was to see how MySQL 5.6 performs out-of-the-box as compared to 5.5.30 with default settings. The non-default settings were tried to dig deeper into performance differences and are documented in the post.
This blog post is not a definitive conclusion about innodb_old_blocks_pct or innodb_old_blocks_time. It does highlight how a data set much larger than the buffer pool may perform worse with innodb_old_blocks_time=1000, but as I said this needs further investigation. One particular point of investigation which needs to be followed up on, including testing innodb_old_blocks_time=1000 on MySQL 5.5.30 and testing multiple buffer pools on MySQL 5.5.30. Finally, MySQL 5.6.10 has many additional tuning options which must be investigated (MRR, BKA, ICP, etc) before coming to further conclusions. These will be the topic of further blog posts.
The SSB employs a data generator which produces data for a star schema. Star schema are commonly used for analytics because it is extremely easy to construct queries against. It is also very easy to define an OLAP cube over a star schema, so they are popular for use with tools like Mondrian and also for data mining. I wrote an earlier blog post which describes the differences between major schema types.
Star Schema Benchmark – Scale Factor 1 – Mysql 5.5 vs 5.6
response times are in seconds (lower is better)
| Version | Buffer | Cold | Run1 | Run2 | Run3 |
|---|---|---|---|---|---|
| 5.5.30 | 128M | 361.49 | 189.29 | 189.34 | 189.40 |
| 5.6.10 | 128M | 362.31 | 324.25 | 320.74 | 318.84 |
| 5.6.10 (innodb_old_blocks_time=0) | 128M | 349.24 | 178.80 | 178.55 | 179.07 |
| 5.5.30 | 4G | 200.87 | 20.53 | 20.36 | 20.35 |
| 5.6.10 | 4G | 195.33 | 14.41 | 14.45 | 14.61 |
I started by running the benchmark against MySQL 5.5.30. It took 361.49 seconds to complete all 13 queries. I then repeated the run three more times. The speed is very consistent, just a few tenths of a second off per run. I then rebooted the machine and fired up 5.6.10. I ran the test, and to my surprise MySQL 5.6.10 did not get much faster during the repeat runs, compared to the initial cold run. I stopped the MySQL 5.6 server, rebooted and verified again. Same issue. This was very different from MySQL 5.5.30, which performs significantly better on the repeat warm runs.
Just to be sure it wasn’t a disk problem, I pointed the MySQL 5.6.10 at the MySQL 5.5.30 data directory. Tthe speed was essentially the same. I did some further investigation and I determined that there was a lower buffer pool hit ratio during the MySQL 5.6 runs and MySQL 5.6.10 was doing more IO as a consequence. To confirm that this was indeed the problem I decided to compare performance with a buffer pool much larger than the data size, so I configured the server with a 4GB buffer pool. I tested both versions, and as you can see above, MySQL 5.6 outperformed MySQL 5.5.30 with the big buffer pool.
I thought about the differences in the defaults between MySQL 5.5 and MySQL 5.6 and innodb_old_blocks_time immediately came to mind. The InnoDB plugin introduced innodb_old_blocks_time to help control the behavior of the new split LRU mechanism which was implemented in the plugin. In the original InnoDB, the LRU was implemented as a classic LRU which is subject to “pollution” by full table scans. In the classic LRU, a full table scan pushes out important hot pages from the buffer pool often for an infrequent scan, like a backup or report. In an OLTP system this can have very negative performance consequences.
The plugin attempts to fix this problem by splitting the LRU into hot and cold sections. When a page is first read into the buffer pool it is first placed onto the head of the cold section of the LRU, where it begins to age of naturally. If the page is touched again while on the cold portion, it is moved to the head of the hot portion.
This sounds good in theory, but in practice it is problematic. What usually happens is that the full table scans access the table by primary key. This forces the storage engine to touch the same page numerous times in rapid succession. This invariably moves the page onto the hot area, defeating the split. In order to prevent this from happening, another variable innodb_old_blocks_time was introduced.
Innodb_old_blocks_time controls how long a page must be on the cold portion of the LRU before it is eligible to be moved to the hot portion. In MySQL 5.5 and earlier, innodb_old_blocks_time defaults to a value of 0(zero), which means that pages move rapidly from the cold portion to the hot portion because they must stay on the cold LRU for zero milliseconds before being able to move to the hot list. In MySQL 5.6 the default value of innodb_old_blocks_time is changed to 1000. The location at which a page is initially placed into the LRU is defined by innodb_old_blocks_pct. The default value on both versions is 38, which happens to be 3/8 of the buffer pool.
For this workload with a small buffer pool (the buffer pool is smaller than the working set) having innodb_old_blocks_time=1000 appears to cause a major performance regression. The new setting changes which pages end up staying in the buffer pool, and which are aged out.
|
1 |
mysql> select straight_join sum(lo_extendedprice*lo_discount) as revenue <br>from lineorder join dim_date on lo_orderdatekey = d_datekey <br>where d_year = 1993 and lo_discount between 1 and 3 and lo_quantity < 25;<br>+--------------+<br>| revenue |<br>+--------------+<br>| 446268068091 |<br>+--------------+<br>1 row in set (33.94 sec)<br><br>*************************** 1. row ***************************<br> id: 1<br> select_type: SIMPLE<br> table: lineorder<br> type: ALL<br>possible_keys: LO_OrderDateKey<br> key: NULL<br> key_len: NULL<br> ref: NULL<br> rows: 5996539<br> Extra: Using where<br>*************************** 2. row ***************************<br> id: 1<br> select_type: SIMPLE<br> table: dim_date<br> type: eq_ref<br>possible_keys: PRIMARY<br> key: PRIMARY<br> key_len: 4<br> ref: ssb.lineorder.LO_OrderDateKey<br> rows: 1<br> Extra: Using where<br>2 rows in set (0.00 sec) |
After running the query, see how many pages were read from disk versus how many page requests their were:
|
1 |
mysql> select * from information_schema.global_status where variable_name like '%innodb%read%';<br>+---------------------------------------+----------------+<br>| VARIABLE_NAME | VARIABLE_VALUE |<br>+---------------------------------------+----------------+<br>| INNODB_BUFFER_POOL_READ_AHEAD_RND | 0 |<br>| INNODB_BUFFER_POOL_READ_AHEAD | 38392 |<br>| INNODB_BUFFER_POOL_READ_AHEAD_EVICTED | 0 |<br>| INNODB_BUFFER_POOL_READ_REQUESTS | 6731100 |<br>| INNODB_BUFFER_POOL_READS | 570 |<br>| INNODB_DATA_PENDING_READS | 0 |<br>| INNODB_DATA_READ | 640536576 |<br>| INNODB_DATA_READS | 38972 |<br>| INNODB_PAGES_READ | 38961 |<br>| INNODB_ROWS_READ | 6611119 |<br>+---------------------------------------+----------------+<br>10 rows in set (0.00 sec)<br><br>Here are the contents of the buffer pool in pages afterwards:<br>mysql> select sq.*, pages / (@@innodb_buffer_pool_size / 16384) * 100 pct_buffer_pool <br>from (<br>select table_name, index_name, count(*) pages, sum(is_old='YES') old, <br>count(*) - sum(is_old='YES') hot, sum(number_records) records <br>from information_schema.innodb_buffer_page_lru <br>where table_name like '%ssb%' group by 1,2<br>) sq <br>order by pct_buffer_pool desc;<br>+-------------------+------------------+-------+------+------+---------+-----------------+<br>| table_name | index_name | pages | old | hot | records | pct_buffer_pool |<br>+-------------------+------------------+-------+------+------+---------+-----------------+<br>| `ssb`.`lineorder` | GEN_CLUST_INDEX | 6909 | 2559 | 4350 | 1083172 | 84.3384 |<br>| `ssb`.`lineorder` | LO_PartKey | 17 | 0 | 17 | 9979 | 0.2075 |<br>| `ssb`.`lineorder` | LO_CommitDateKey | 17 | 0 | 17 | 10776 | 0.2075 |<br>| `ssb`.`lineorder` | LO_OrderDateKey | 17 | 0 | 17 | 10376 | 0.2075 |<br>| `ssb`.`dim_date` | PRIMARY | 17 | 0 | 17 | 2481 | 0.2075 |<br>| `ssb`.`lineorder` | LO_CustKey | 16 | 0 | 16 | 8616 | 0.1953 |<br>| `ssb`.`lineorder` | LO_OrderKey | 16 | 0 | 16 | 10943 | 0.1953 |<br>| `ssb`.`lineorder` | LO_SuppKey | 15 | 0 | 15 | 11466 | 0.1831 |<br>+-------------------+------------------+-------+------+------+---------+-----------------+<br>8 rows in set (0.12 sec)<br><br>And the Innodb stats:<br>mysql> select * from information_schema.innodb_buffer_pool_statsG<br>*************************** 1. row ***************************<br> POOL_ID: 0<br> POOL_SIZE: 8191<br> FREE_BUFFERS: 1024<br> DATABASE_PAGES: 7162<br> OLD_DATABASE_PAGES: 2623<br> MODIFIED_DATABASE_PAGES: 0<br> PENDING_DECOMPRESS: 0<br> PENDING_READS: 0<br> PENDING_FLUSH_LRU: 0<br> PENDING_FLUSH_LIST: 0<br> PAGES_MADE_YOUNG: 3<br> PAGES_NOT_MADE_YOUNG: 4824154<br> PAGES_MADE_YOUNG_RATE: 0<br> PAGES_MADE_NOT_YOUNG_RATE: 0<br> NUMBER_PAGES_READ: 38960<br> NUMBER_PAGES_CREATED: 0<br> NUMBER_PAGES_WRITTEN: 1<br> PAGES_READ_RATE: 0<br> PAGES_CREATE_RATE: 0<br> PAGES_WRITTEN_RATE: 0<br> NUMBER_PAGES_GET: 6731253<br> HIT_RATE: 0<br> YOUNG_MAKE_PER_THOUSAND_GETS: 0<br>NOT_YOUNG_MAKE_PER_THOUSAND_GETS: 0<br> NUMBER_PAGES_READ_AHEAD: 38457<br> NUMBER_READ_AHEAD_EVICTED: 0<br> READ_AHEAD_RATE: 0<br> READ_AHEAD_EVICTED_RATE: 0<br> LRU_IO_TOTAL: 431<br> LRU_IO_CURRENT: 0<br> UNCOMPRESS_TOTAL: 0<br> UNCOMPRESS_CURRENT: 0<br>1 row in set (0.00 sec) |
|
1 |
mysql> set global innodb_old_blocks_time=0;<br>Query OK, 0 rows affected (0.00 sec)<br><br>mysql> select straight_join sum(lo_extendedprice*lo_discount) as revenue <br>from lineorder join dim_date on lo_orderdatekey = d_datekey <br>where d_year = 1993 and lo_discount between 1 and 3 and lo_quantity < 25G<br>*************************** 1. row ***************************<br>revenue: 446268068091<br>1 row in set (7.81 sec)<br><br>mysql> select * from information_schema.global_status where variable_name like '%innodb%read%';<br>+---------------------------------------+----------------+<br>| VARIABLE_NAME | VARIABLE_VALUE |<br>+---------------------------------------+----------------+<br>| INNODB_BUFFER_POOL_READ_AHEAD_RND | 0 |<br>| INNODB_BUFFER_POOL_READ_AHEAD | 38461 |<br>| INNODB_BUFFER_POOL_READ_AHEAD_EVICTED | 0 |<br>| INNODB_BUFFER_POOL_READ_REQUESTS | 6731687 |<br>| INNODB_BUFFER_POOL_READS | 550 |<br>| INNODB_DATA_PENDING_READS | 0 |<br>| INNODB_DATA_READ | 641339392 |<br>| INNODB_DATA_READS | 39021 |<br>| INNODB_PAGES_READ | 39010 |<br>| INNODB_ROWS_READ | 6611119 |<br>+---------------------------------------+----------------+<br>10 rows in set (0.00 sec)<br><br>mysql> select sq.*, pages / (@@innodb_buffer_pool_size / 16384) * 100 pct_buffer_pool <br>from (<br>select table_name, index_name, count(*) pages, sum(is_old='YES') old, <br>count(*) - sum(is_old='YES') hot, sum(number_records) records <br>from information_schema.innodb_buffer_page_lru <br>where table_name like '%ssb%' group by 1,2<br>) sq <br>order by pct_buffer_pool desc;<br>+-------------------+-----------------+-------+------+------+---------+-----------------+<br>| table_name | index_name | pages | old | hot | records | pct_buffer_pool |<br>+-------------------+-----------------+-------+------+------+---------+-----------------+<br>| `ssb`.`lineorder` | GEN_CLUST_INDEX | 7085 | 2547 | 4538 | 1104291 | 86.4868 |<br>| `ssb`.`dim_date` | PRIMARY | 17 | 17 | 0 | 2481 | 0.2075 |<br>+-------------------+-----------------+-------+------+------+---------+-----------------+<br>2 rows in set (0.11 sec)<br><br>So there is more of lineorder in the buffer pool and the other secondary indexes have been pushed out of the buffer pool.<br><br>mysql> select * from information_schema.innodb_buffer_pool_statsG<br>*************************** 1. row ***************************<br> POOL_ID: 0<br> POOL_SIZE: 8192<br> FREE_BUFFERS: 1024<br> DATABASE_PAGES: 7163<br> OLD_DATABASE_PAGES: 2624<br> MODIFIED_DATABASE_PAGES: 0<br> PENDING_DECOMPRESS: 0<br> PENDING_READS: 0<br> PENDING_FLUSH_LRU: 0<br> PENDING_FLUSH_LIST: 0<br> PAGES_MADE_YOUNG: 29501<br> PAGES_NOT_MADE_YOUNG: 0<br> PAGES_MADE_YOUNG_RATE: 951.6144640495468<br> PAGES_MADE_NOT_YOUNG_RATE: 0<br> NUMBER_PAGES_READ: 39009<br> NUMBER_PAGES_CREATED: 0<br> NUMBER_PAGES_WRITTEN: 1<br> PAGES_READ_RATE: 1249.8306506241734<br> PAGES_CREATE_RATE: 0<br> PAGES_WRITTEN_RATE: 0.032257023966968806<br> NUMBER_PAGES_GET: 6731790<br> HIT_RATE: 995<br> YOUNG_MAKE_PER_THOUSAND_GETS: 4<br>NOT_YOUNG_MAKE_PER_THOUSAND_GETS: 0<br> NUMBER_PAGES_READ_AHEAD: 38459<br> NUMBER_READ_AHEAD_EVICTED: 0<br> READ_AHEAD_RATE: 1240.5728847456533<br> READ_AHEAD_EVICTED_RATE: 0<br> LRU_IO_TOTAL: 531<br> LRU_IO_CURRENT: 0<br> UNCOMPRESS_TOTAL: 0<br> UNCOMPRESS_CURRENT: 0<br>1 row in set (0.01 sec) |
|
1 |
INNODB_OLD_BLOCKS_TIME=0 INNODB_OLD_BLOCKS_TIME=1000<br>*************************** 1. row ************************************************ 1. row *******<br> POOL_ID: 0 * POOL_ID: 0<br> POOL_SIZE: 8192 * POOL_SIZE: 8191<br> FREE_BUFFERS: 1024 * FREE_BUFFERS: 1024<br> DATABASE_PAGES: 7163 * DATABASE_PAGES: 7162<br> OLD_DATABASE_PAGES: 2624 * OLD_DATABASE_PAGES: 2623<br> MODIFIED_DATABASE_PAGES: 0 * MODIFIED_DATABASE_PAGES: 0<br> PENDING_DECOMPRESS: 0 * PENDING_DECOMPRESS: 0<br> PENDING_READS: 0 * PENDING_READS: 0<br> PENDING_FLUSH_LRU: 0 * PENDING_FLUSH_LRU: 0<br> PENDING_FLUSH_LIST: 0 * PENDING_FLUSH_LIST: 0<br> PAGES_MADE_YOUNG: 29501 * PAGES_MADE_YOUNG: 3<br> PAGES_NOT_MADE_YOUNG: 0 * PAGES_NOT_MADE_YOUNG: 4824154<br> PAGES_MADE_YOUNG_RATE: 951.6144640495468 * PAGES_MADE_YOUNG_RATE: 0<br> PAGES_MADE_NOT_YOUNG_RATE: 0 * PAGES_MADE_NOT_YOUNG_RATE: 0<br> NUMBER_PAGES_READ: 39009 * NUMBER_PAGES_READ: 38960<br> NUMBER_PAGES_CREATED: 0 * NUMBER_PAGES_CREATED: 0<br> NUMBER_PAGES_WRITTEN: 1 * NUMBER_PAGES_WRITTEN: 1<br> PAGES_READ_RATE: 1249.8306506241734 * PAGES_READ_RATE: 0<br> PAGES_CREATE_RATE: 0 * PAGES_CREATE_RATE: 0<br> PAGES_WRITTEN_RATE: 0.032257023966968806 * PAGES_WRITTEN_RATE: 0<br> NUMBER_PAGES_GET: 6731790 * NUMBER_PAGES_GET: 6731253<br> HIT_RATE: 995 * HIT_RATE: 0<br> YOUNG_MAKE_PER_THOUSAND_GETS: 4 * YOUNG_MAKE_PER_THOUSAND_GETS: 0<br>NOT_YOUNG_MAKE_PER_THOUSAND_GETS: 0 *NOT_YOUNG_MAKE_PER_THOUSAND_GETS: 0<br> NUMBER_PAGES_READ_AHEAD: 38459 * NUMBER_PAGES_READ_AHEAD: 38457<br> NUMBER_READ_AHEAD_EVICTED: 0 * NUMBER_READ_AHEAD_EVICTED: 0<br> READ_AHEAD_RATE: 1240.5728847456533 * READ_AHEAD_RATE: 0<br> READ_AHEAD_EVICTED_RATE: 0 * READ_AHEAD_EVICTED_RATE: 0<br> LRU_IO_TOTAL: 531 * LRU_IO_TOTAL: 431<br> LRU_IO_CURRENT: 0 * LRU_IO_CURRENT: 0<br> UNCOMPRESS_TOTAL: 0 * UNCOMPRESS_TOTAL: 0<br> UNCOMPRESS_CURRENT: 0 UNCOMPRESS_CURRENT: 0 |
|
1 |
mysql> select straight_join sum(lo_extendedprice*lo_discount) as revenue <br>from dim_date join lineorder on lo_orderdatekey = d_datekey <br>where d_year = 1993 and lo_discount between 1 and 3 <br>and lo_quantity < 25G<br>*************************** 1. row ***************************<br>revenue: 446268068091<br>1 row in set (22.54 sec)<br><br>mysql> explain select straight_join sum(lo_extendedprice*lo_discount) as revenue <br> -> from dim_date join lineorder on lo_orderdatekey = d_datekey <br> -> where d_year = 1993 and lo_discount between 1 and 3 <br> -> and lo_quantity < 25G<br>*************************** 1. row ***************************<br> id: 1<br> select_type: SIMPLE<br> table: dim_date<br> type: ALL<br>possible_keys: PRIMARY<br> key: NULL<br> key_len: NULL<br> ref: NULL<br> rows: 2704<br> Extra: Using where<br>*************************** 2. row ***************************<br> id: 1<br> select_type: SIMPLE<br> table: lineorder<br> type: ref<br>possible_keys: LO_OrderDateKey<br> key: LO_OrderDateKey<br> key_len: 4<br> ref: ssb.dim_date.D_DateKey<br> rows: 2837<br> Extra: Using where<br>2 rows in set (0.00 sec)<br><br>mysql> select * from information_schema.global_status where variable_name like '%innodb%read%';<br>+---------------------------------------+----------------+<br>| VARIABLE_NAME | VARIABLE_VALUE |<br>+---------------------------------------+----------------+<br>| INNODB_BUFFER_POOL_READ_AHEAD_RND | 0 |<br>| INNODB_BUFFER_POOL_READ_AHEAD | 0 |<br>| INNODB_BUFFER_POOL_READ_AHEAD_EVICTED | 0 |<br>| INNODB_BUFFER_POOL_READ_REQUESTS | 3776369 |<br>| INNODB_BUFFER_POOL_READS | 191571 |<br>| INNODB_DATA_PENDING_READS | 0 |<br>| INNODB_DATA_READ | 3140882432 |<br>| INNODB_DATA_READS | 191581 |<br>| INNODB_PAGES_READ | 191570 |<br>| INNODB_ROWS_READ | 910844 |<br>+---------------------------------------+----------------+<br>10 rows in set (0.01 sec)<br><br>mysql> select sq.*, pages / ((@@innodb_buffer_pool_size / 16384)) * 100 pct_buffer_pool from (select table_name, index_name, count(*) pages, sum(is_old='YES') old, count(*) - sum(is_old='YES') hot, sum(number_records) records from information_schema.innodb_buffer_page_lru where table_name like '%ssb%' group by 1,2) sq order by pct_buffer_pool desc;<br>+-------------------+------------------+-------+------+------+---------+-----------------+<br>| table_name | index_name | pages | old | hot | records | pct_buffer_pool |<br>+-------------------+------------------+-------+------+------+---------+-----------------+<br>| `ssb`.`lineorder` | GEN_CLUST_INDEX | 6001 | 2095 | 3906 | 964974 | 73.2544 |<br>| `ssb`.`lineorder` | LO_OrderDateKey | 31 | 28 | 3 | 18223 | 0.3784 |<br>| `ssb`.`dim_date` | PRIMARY | 17 | 11 | 6 | 2414 | 0.2075 |<br>| `ssb`.`lineorder` | LO_OrderKey | 17 | 17 | 0 | 11320 | 0.2075 |<br>| `ssb`.`lineorder` | LO_PartKey | 17 | 17 | 0 | 10095 | 0.2075 |<br>| `ssb`.`lineorder` | LO_CustKey | 17 | 17 | 0 | 9874 | 0.2075 |<br>| `ssb`.`lineorder` | LO_CommitDateKey | 16 | 16 | 0 | 10775 | 0.1953 |<br>| `ssb`.`lineorder` | LO_SuppKey | 16 | 16 | 0 | 11879 | 0.1953 |<br>+-------------------+------------------+-------+------+------+---------+-----------------+<br>8 rows in set (0.11 sec)<br><br>mysql> select * from information_schema.innodb_buffer_pool_statsG<br>*************************** 1. row ***************************<br> POOL_ID: 0<br> POOL_SIZE: 8192<br> FREE_BUFFERS: 1024<br> DATABASE_PAGES: 6175<br> OLD_DATABASE_PAGES: 2259<br> MODIFIED_DATABASE_PAGES: 0<br> PENDING_DECOMPRESS: 0<br> PENDING_READS: 0<br> PENDING_FLUSH_LRU: 0<br> PENDING_FLUSH_LIST: 0<br> PAGES_MADE_YOUNG: 62<br> PAGES_NOT_MADE_YOUNG: 2054952<br> PAGES_MADE_YOUNG_RATE: 1.0508296469551364<br> PAGES_MADE_NOT_YOUNG_RATE: 34829.104591447605<br> NUMBER_PAGES_READ: 191834<br> NUMBER_PAGES_CREATED: 0<br> NUMBER_PAGES_WRITTEN: 1<br> PAGES_READ_RATE: 3246.91106930391<br> PAGES_CREATE_RATE: 0<br> PAGES_WRITTEN_RATE: 0.01694886527346994<br> NUMBER_PAGES_GET: 3777151<br> HIT_RATE: 950<br> YOUNG_MAKE_PER_THOUSAND_GETS: 0<br>NOT_YOUNG_MAKE_PER_THOUSAND_GETS: 544<br> NUMBER_PAGES_READ_AHEAD: 0<br> NUMBER_READ_AHEAD_EVICTED: 0<br> READ_AHEAD_RATE: 0<br> READ_AHEAD_EVICTED_RATE: 0<br> LRU_IO_TOTAL: 186940<br> LRU_IO_CURRENT: 0<br> UNCOMPRESS_TOTAL: 0<br> UNCOMPRESS_CURRENT: 0<br>1 row in set (0.00 sec) |
|
1 |
mysql> select straight_join sum(lo_extendedprice*lo_discount) as revenue <br>from dim_date join lineorder on lo_orderdatekey = d_datekey <br>where d_year = 1993 and lo_discount between 1 and 3 and lo_quantity < 25G<br>*************************** 1. row ***************************<br>revenue: 446268068091<br>1 row in set (12.36 sec)<br><br>mysql> select * from information_schema.global_status where variable_name like '%innodb%read%';<br>+---------------------------------------+----------------+<br>| VARIABLE_NAME | VARIABLE_VALUE |<br>+---------------------------------------+----------------+<br>| INNODB_BUFFER_POOL_READ_AHEAD_RND | 0 |<br>| INNODB_BUFFER_POOL_READ_AHEAD | 0 |<br>| INNODB_BUFFER_POOL_READ_AHEAD_EVICTED | 0 |<br>| INNODB_BUFFER_POOL_READ_REQUESTS | 3811806 |<br>| INNODB_BUFFER_POOL_READS | 186407 |<br>| INNODB_DATA_PENDING_READS | 0 |<br>| INNODB_DATA_READ | 3056275456 |<br>| INNODB_DATA_READS | 186417 |<br>| INNODB_PAGES_READ | 186406 |<br>| INNODB_ROWS_READ | 910844 |<br>+---------------------------------------+----------------+<br>10 rows in set (0.00 sec)<br><br>mysql> select sq.*, pages / ((@@innodb_buffer_pool_size / 16384)) * 100 pct_buffer_pool <br>from (<br>select table_name, index_name, count(*) pages, <br>sum(is_old='YES') old, count(*) - sum(is_old='YES') hot, <br>sum(number_records) records <br>from information_schema.innodb_buffer_page_lru <br>where table_name like '%ssb%' <br>group by 1,2<br>) sq <br>order by pct_buffer_pool desc;<br>+-------------------+-----------------+-------+------+------+---------+-----------------+<br>| table_name | index_name | pages | old | hot | records | pct_buffer_pool |<br>+-------------------+-----------------+-------+------+------+---------+-----------------+<br>| `ssb`.`lineorder` | GEN_CLUST_INDEX | 6980 | 2563 | 4417 | 1119893 | 85.2051 |<br>| `ssb`.`lineorder` | LO_OrderDateKey | 47 | 17 | 30 | 30637 | 0.5737 |<br>| `ssb`.`dim_date` | PRIMARY | 12 | 0 | 12 | 1841 | 0.1465 |<br>+-------------------+-----------------+-------+------+------+---------+-----------------+<br>3 rows in set (0.12 sec)<br><br>mysql> select * from information_schema.innodb_buffer_pool_statsG<br>*************************** 1. row ***************************<br> POOL_ID: 0<br> POOL_SIZE: 8192<br> FREE_BUFFERS: 1024<br> DATABASE_PAGES: 7047<br> OLD_DATABASE_PAGES: 2581<br> MODIFIED_DATABASE_PAGES: 0<br> PENDING_DECOMPRESS: 0<br> PENDING_READS: 0<br> PENDING_FLUSH_LRU: 0<br> PENDING_FLUSH_LIST: 0<br> PAGES_MADE_YOUNG: 194023<br> PAGES_NOT_MADE_YOUNG: 0<br> PAGES_MADE_YOUNG_RATE: 4850.4537386565335<br> PAGES_MADE_NOT_YOUNG_RATE: 0<br> NUMBER_PAGES_READ: 186422<br> NUMBER_PAGES_CREATED: 0<br> NUMBER_PAGES_WRITTEN: 1<br> PAGES_READ_RATE: 4653.858653533662<br> PAGES_CREATE_RATE: 0<br> PAGES_WRITTEN_RATE: 0.02499937501562461<br> NUMBER_PAGES_GET: 3811961<br> HIT_RATE: 952<br> YOUNG_MAKE_PER_THOUSAND_GETS: 50<br>NOT_YOUNG_MAKE_PER_THOUSAND_GETS: 0<br> NUMBER_PAGES_READ_AHEAD: 0<br> NUMBER_READ_AHEAD_EVICTED: 0<br> READ_AHEAD_RATE: 0<br> READ_AHEAD_EVICTED_RATE: 0<br> LRU_IO_TOTAL: 186024<br> LRU_IO_CURRENT: 0<br> UNCOMPRESS_TOTAL: 0<br> UNCOMPRESS_CURRENT: 0<br>1 row in set (0.00 sec) |
|
1 |
select p1.seq, p1.state state, p1.duration, p2.duration, p1.cpu_user + p1.cpu_system p1_cpu, p2.cpu_user + p2.cpu_system p2_cpu, <br>p1.context_voluntary + p1.context_involuntary p1_cs, p2.context_voluntary + p2.context_involuntary p2_cs, <br>p1.block_ops_in + p1.block_ops_out p1_block_ops, p2.block_ops_in + p2.block_ops_out p2_block_ops,<br>p1.page_faults_major + p1.page_faults_minor p1_pf, p2.page_faults_major + p2.page_faults_minor p2_pf <br>from p1 join p2 using(seq) <br>where p1.state = p2.state <br>order by p1.duration desc;<br>+-----+----------------------+-----------+----------+-----------+-----------+-------+-------+--------------+--------------+-------+-------+<br>| seq | state | duration | duration | p1_cpu | p2_cpu | p1_cs | p2_cs | p1_block_ops | p2_block_ops | p1_pf | p2_pf |<br>+-----+----------------------+-----------+----------+-----------+-----------+-------+-------+--------------+--------------+-------+-------+<br>| 12 | Sending data | 33.764396 | 7.523023 | 40.173893 | 13.027019 | 4979 | 21399 | 0 | 0 | 90 | 90 |<br>| 5 | Opening tables | 0.270664 | 0.295955 | 0.025996 | 0.024996 | 34 | 35 | 2056 | 1488 | 48 | 48 |<br>| 2 | starting | 0.000230 | 0.000192 | 0.000000 | 0.000000 | 0 | 0 | 0 | 0 | 29 | 29 |<br>| 9 | statistics | 0.000130 | 0.000097 | 0.000000 | 0.000000 | 0 | 0 | 0 | 0 | 26 | 26 |<br>| 6 | init | 0.000105 | 0.000138 | 0.000000 | 0.000000 | 0 | 0 | 0 | 0 | 26 | 26 |<br>| 10 | preparing | 0.000068 | 0.000064 | 0.000000 | 0.000000 | 0 | 0 | 0 | 0 | 14 | 14 |<br>| 16 | freeing items | 0.000049 | 0.000117 | 0.000000 | 0.001000 | 0 | 0 | 0 | 0 | 3 | 3 |<br>| 8 | optimizing | 0.000048 | 0.000048 | 0.000000 | 0.000000 | 0 | 0 | 0 | 0 | 8 | 8 |<br>| 7 | System lock | 0.000031 | 0.000031 | 0.000000 | 0.000000 | 0 | 0 | 0 | 0 | 1 | 1 |<br>| 13 | end | 0.000027 | 0.000026 | 0.000000 | 0.000000 | 0 | 0 | 0 | 0 | 1 | 1 |<br>| 4 | checking permissions | 0.000015 | 0.000014 | 0.000000 | 0.000000 | 0 | 0 | 0 | 0 | 0 | 0 |<br>| 15 | closing tables | 0.000015 | 0.000016 | 0.000000 | 0.000000 | 0 | 0 | 0 | 0 | 0 | 0 |<br>| 3 | checking permissions | 0.000014 | 0.000014 | 0.000000 | 0.000000 | 0 | 0 | 0 | 0 | 0 | 0 |<br>| 11 | executing | 0.000013 | 0.000013 | 0.000000 | 0.000000 | 0 | 0 | 0 | 0 | 0 | 0 |<br>| 14 | query end | 0.000011 | 0.000012 | 0.000000 | 0.000000 | 0 | 0 | 0 | 0 | 0 | 0 |<br>+-----+----------------------+-----------+----------+-----------+-----------+-------+-------+--------------+--------------+-------+-------+<br>15 rows in set (0.00 sec) |
Here are my modified versions of the queries (just to use ANSI JOIN syntax):
|
1 |
-- Q1.1<br>select sum(lo_extendedprice*lo_discount) as<br>revenue<br>from lineorder join dim_date on lo_orderdatekey = d_datekey<br>where<br>d_year = 1993<br>and lo_discount between 1 and 3<br>and lo_quantity < 25; <br><br>-- Q1.2 <br>select sum(lo_extendedprice*lo_discount) as revenue <br>from lineorder <br>join dim_date on lo_orderdatekey = d_datekey <br>where d_yearmonth = 199401 and lo_discount <br>between 4 and 6 and lo_quantity between 26 and 35; <br><br>-- Q1.3 <br>select sum(lo_extendedprice*lo_discount) as revenue <br>from lineorder <br>join dim_date on lo_orderdatekey = d_datekey <br>where d_weeknuminyear = 6 <br>and d_year = 1994 <br>and lo_discount between 5 and 7 and lo_quantity between 26 and 35; <br><br>-- Q2.1 <br>select sum(lo_revenue), d_year, p_brand <br>from lineorder <br>join dim_date <br> on lo_orderdatekey = d_datekey <br>join part <br>on lo_partkey = p_partkey join supplier <br>on lo_suppkey = s_suppkey <br>where p_category = 'MFGR#12' <br>and s_region = 'AMERICA' <br>group by d_year, p_brand <br>order by d_year, p_brand; <br><br>-- Q2.2 <br>select sum(lo_revenue), d_year, p_brand <br>from lineorder <br>join dim_date <br>on lo_orderdatekey = d_datekey <br>join part <br>on lo_partkey = p_partkey <br>join supplier <br>on lo_suppkey = s_suppkey <br>where p_brand between 'MFGR#2221' and 'MFGR#2228' <br>and s_region = 'ASIA' <br>group by d_year, p_brand <br>order by d_year, p_brand; <br><br>-- Q2.3 <br>select sum(lo_revenue), d_year, p_brand <br>from lineorder <br>join dim_date <br>on lo_orderdatekey = d_datekey <br>join part <br>on lo_partkey = p_partkey <br>join supplier <br>on lo_suppkey = s_suppkey <br>where p_brand= 'MFGR#2239' <br>and s_region = 'EUROPE' <br>group by d_year, p_brand <br>order by d_year, p_brand; <br><br>-- Q3.1 <br>select c_nation, s_nation, d_year, sum(lo_revenue) as revenue <br>from customer <br>join lineorder <br>on lo_custkey = c_customerkey <br>join supplier <br>on lo_suppkey = s_suppkey <br>join dim_date on lo_orderdatekey = d_datekey <br>where c_region = 'ASIA' <br>and s_region = 'ASIA' <br>and d_year >= 1992 and d_year <= 1997 <br>group by c_nation, s_nation, d_year <br>order by d_year asc, revenue desc; <br><br>-- Q3.2 <br>select c_city, s_city, d_year, sum(lo_revenue) as revenue <br>from customer <br>join lineorder <br>on lo_custkey = c_customerkey <br>join supplier <br>on lo_suppkey = s_suppkey <br>join dim_date <br>on lo_orderdatekey = d_datekey <br>where c_nation = 'UNITED STATES' <br>and s_nation = 'UNITED STATES' <br>and d_year >= 1992 <br>and d_year <= 1997 <br>group by c_city, s_city, d_year <br>order by d_year asc, revenue desc; <br><br>-- Q3.3 <br>select c_city, s_city, d_year, sum(lo_revenue) as revenue <br>from customer <br>join lineorder <br>on lo_custkey = c_customerkey <br>join supplier on lo_suppkey = s_suppkey <br>join dim_date on lo_orderdatekey = d_datekey <br>where (c_city='UNITED KI1' or c_city='UNITED KI5') <br>and (s_city='UNITED KI1' or s_city='UNITED KI5') <br>and d_year >= 1992 <br>and d_year <= 1997<br>group by c_city, s_city, d_year<br>order by d_year asc, revenue desc;<br><br>-- Q3.4<br>select c_city, s_city, d_year, sum(lo_revenue)<br>as revenue<br>from customer<br>join lineorder<br> on lo_custkey = c_customerkey<br>join supplier<br> on lo_suppkey = s_suppkey<br>join dim_date<br> on lo_orderdatekey = d_datekey<br>where<br>(c_city='UNITED KI1' or c_city='UNITED KI5')<br>and (s_city='UNITED KI1' or s_city='UNITED KI5')<br>and d_yearmonth = 'Dec1997'<br>group by c_city, s_city, d_year<br>order by d_year asc, revenue desc;<br><br>-- Q4.1<br>select d_year, c_nation,<br>sum(lo_revenue - lo_supplycost) as profit<br>from lineorder<br>join dim_date <br> on lo_orderdatekey = d_datekey<br>join customer<br> on lo_custkey = c_customerkey<br>join supplier<br> on lo_suppkey = s_suppkey<br>join part<br> on lo_partkey = p_partkey<br>where<br>c_region = 'AMERICA'<br>and s_region = 'AMERICA'<br>and (p_mfgr = 'MFGR#1'<br>or p_mfgr = 'MFGR#2')<br>group by d_year, c_nation<br>order by d_year, c_nation;<br><br>-- Q4.2<br>select d_year, s_nation, p_category,<br>sum(lo_revenue - lo_supplycost) as profit<br>from lineorder<br>join dim_date <br> on lo_orderdatekey = d_datekey<br>join customer<br> on lo_custkey = c_customerkey<br>join supplier<br> on lo_suppkey = s_suppkey<br>join part<br> on lo_partkey = p_partkey<br>where<br>c_region = 'AMERICA'<br>and s_region = 'AMERICA'<br>and (d_year = 1997 or d_year = 1998)<br>and (p_mfgr = 'MFGR#1'<br>or p_mfgr = 'MFGR#2')<br>group by d_year, s_nation, p_category<br>order by d_year, s_nation, p_category;<br><br>-- Q4.3<br>select d_year, s_city, p_brand,<br>sum(lo_revenue - lo_supplycost) as profit<br>from lineorder<br>join dim_date <br> on lo_orderdatekey = d_datekey<br>join customer<br> on lo_custkey = c_customerkey<br>join supplier<br> on lo_suppkey = s_suppkey<br>join part<br> on lo_partkey = p_partkey<br>where<br>s_nation = 'UNITED STATES'<br>and (d_year = 1997 or d_year = 1998)<br>and p_category = 'MFGR#14'<br>group by d_year, s_city, p_brand<br>order by d_year, s_city, p_brand; |
|
1 |
DROP TABLE IF EXISTS customer;<br>CREATE TABLE IF NOT EXISTS customer<br>(<br> C_CustomerKey int primary key,<br> C_Name varchar(25),<br> C_Address varchar(25),<br> C_City varchar(10),<br> C_Nation varchar(15),<br> C_Region varchar(12),<br> C_Phone varchar(15),<br> C_MktSegment varchar(10),<br> KEY(C_Name),<br> KEY(C_City),<br> KEY(C_Region),<br> KEY(C_Phone),<br> KEY(C_MktSegment)<br>);<br><br>DROP TABLE IF EXISTS part;<br>CREATE TABLE IF NOT EXISTS part<br>(<br> P_PartKey int primary key,<br> P_Name varchar(25),<br> P_MFGR varchar(10),<br> P_Category varchar(10),<br> P_Brand varchar(15),<br> P_Colour varchar(15),<br> P_Type varchar(25),<br> P_Size tinyint,<br> P_Container char(10),<br> key(P_Name),<br> key(P_MFGR),<br> key(P_Category),<br> key(P_Brand)<br>);<br><br>DROP TABLE IF EXISTS supplier;<br>CREATE TABLE supplier<br>(<br> S_SuppKey int primary key,<br> S_Name char(25),<br> S_Address varchar(25),<br> S_City char(10),<br> S_Nation char(15),<br> S_Region char(12),<br> S_Phone char(15),<br> key(S_City), <br> key(S_Name),<br> key(S_Phone)<br>);<br><br>DROP TABLE IF EXISTS dim_date;<br>CREATE TABLE IF NOT EXISTS dim_date<br>(<br> D_DateKey int primary key,<br> D_Date char(18),<br> D_DayOfWeek char(9),<br> D_Month char(9),<br> D_Year smallint,<br> D_YearMonthNum int,<br> D_YearMonth char(7),<br> D_DayNumInWeek tinyint,<br> D_DayNumInMonth tinyint,<br> D_DayNumInYear smallint,<br> D_MonthNumInYear tinyint,<br> D_WeekNumInYear tinyint,<br> D_SellingSeason char(12),<br> D_LastDayInWeekFl tinyint,<br> D_LastDayInMonthFl tinyint,<br> D_HolidayFl tinyint,<br> D_WeekDayFl tinyint<br>);<br><br>DROP TABLE IF EXISTS lineorder;<br>CREATE TABLE IF NOT EXISTS lineorder<br>(<br> LO_OrderKey bigint not null,<br> LO_LineNumber tinyint not null,<br> LO_CustKey int not null,<br> LO_PartKey int not null,<br> LO_SuppKey int not null,<br> LO_OrderDateKey int not null,<br> LO_OrderPriority varchar(15),<br> LO_ShipPriority char(1),<br> LO_Quantity tinyint,<br> LO_ExtendedPrice decimal,<br> LO_OrdTotalPrice decimal,<br> LO_Discount decimal,<br> LO_Revenue decimal,<br> LO_SupplyCost decimal,<br> LO_Tax tinyint,<br> LO_CommitDateKey int not null,<br> LO_ShipMode varchar(10), <br> KEY(LO_OrderKey, LO_LineNumber),<br> KEY(LO_CustKey),<br> KEY(LO_SuppKey),<br> KEY(LO_PartKey),<br> KEY(LO_OrderDateKey),<br> KEY(LO_CommitDateKey) <br>); |
Resources
RELATED POSTS