1

So I have 2 tables, each of them is 25GB.

Table t1 has an index on a single column and t2 has a composite index.
All my queries are simple query making use of the index.

my t2 table

CREATE TABLE `t2` (
  `uid` bigint(20) DEFAULT NULL,
  `time` bigint(20) DEFAULT NULL,
  `content` mediumtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  KEY `composite` (`uid`,`time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 |

my query

explain select * from t2 where uid between 1 and 10000 and time between 11 and 10000000;

the explain result:

+----+-------------+-------+------------+-------+---------------+-----------+---------+------+------+----------+-----------------------+
| id | select_type | table | partitions | type  | possible_keys | key       | key_len | ref  | rows | filtered | Extra                 |
+----+-------------+-------+------------+-------+---------------+-----------+---------+------+------+----------+-----------------------+
|  1 | SIMPLE      | q3    | NULL       | range | composite     | composite | 18      | NULL | 2548 |    11.11 | Using index condition |
+----+-------------+-------+------------+-------+---------------+-----------+---------+------+------+----------+-----------------------+
1 row in set, 1 warning (0.19 sec)

The strange thing that I observed is that when I restore a database from the snapshot, the t2 would become super slow with 3000 latency but the t1 would become normal(with 100 latency) after around 5 minutes.

I understand the snapshot is stored in s3. But why t1 works fine but t2 is super slow?

UPDATE: I checked manually and found out the composite index is there. I suspect that my composite index for t2 doesn't even work.

And I don't think it's the issue of memory buffer, otherwise, the t2 should become normal after my 5 minutes intensive query test.

wwwwan
  • 407
  • 1
  • 4
  • 12
  • Short answer: well deleted tables data will be removed from the innodb db buffer.. new created/restored tables will not be in the innodb buffer (directly) meaning it's a disk i/o based not memory i/o based – Raymond Nijland Apr 26 '19 at 15:20
  • 2
    to manually warm up the innodb buffer i believe it was possible with `SELECT * FROM ORDER BY ` or it was `SELECT COUNT(*) FROM
    ORDER BY ` the select query might be better/faster as you dont't flood your MySQL client with data.
    – Raymond Nijland Apr 26 '19 at 15:21
  • And when you done that add `innodb_buffer_pool_dump_at_shutdown = ON, innodb_buffer_pool_load_at_startup = ON.` to the config for automatic warmup. – Raymond Nijland Apr 26 '19 at 15:25
  • @RaymondNijland hi, Raymond, why do you think it's the issue of memory buffer? Sorry if I didn't make it clear before, I would do a 5 minutes intensive query to warm up, the warmup only works for t1 but not for t2. – wwwwan Apr 26 '19 at 15:27
  • well to broad to explain buffer pool also has a [Buffer Pool LRU Algorithm](https://dev.mysql.com/doc/refman/5.5/en/innodb-buffer-pool.html) and also a size. – Raymond Nijland Apr 26 '19 at 15:30
  • yes i understand the buffer would be cleared time to time. But even without buffer, the latency shouldn't be that slow – wwwwan Apr 26 '19 at 15:37
  • Also the table structures might also impact the server performance.. ideally you should post the table structurs with `SHOW CREATE TABLE table` for every table involved in the question and the queries you are using and the `EXPLAIN query` output.. Otherwise we can't help you and you are on you own.. Also when in doubt contact amazon if you think the server is (heavy) underperforming. – Raymond Nijland Apr 26 '19 at 15:37
  • 1
    The most likely cause is that an EBS volume restored from a snapshot is lazily loaded. There are other questions about that on this site, or you can review the [EBS docs](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-restoring-volume.html). – guest Apr 26 '19 at 15:57
  • @RaymondNijland I just provided all information. thx! – wwwwan Apr 26 '19 at 16:29
  • yea just like i expected there is a text column, which requires extra disk i/o to be fetched as text is stored separated from the other table data.(other pages) – Raymond Nijland Apr 26 '19 at 16:32
  • @RaymondNijland i see... how would you suggest me to deal with it then? besides setting the automatic warmup. – wwwwan Apr 26 '19 at 16:50
  • Additional information request. Post on pastebin.com and share the links. RAM size of your MySQL Host server A) complete (not edited) my.cnf or my.ini Text results of: B) SHOW GLOBAL STATUS; after minimum 24 hours UPTIME C) SHOW GLOBAL VARIABLES; D) SHOW FULL PROCESSLIST; E) complete MySQLTuner report AND Optional very helpful information, if available includes - htop OR top OR mytop for most active apps, ulimit -a for a linux/unix list of limits, iostat -xm 5 3 for IOPS by device and core/cpu count, for server workload tuning analysis. – Wilson Hauck Apr 26 '19 at 20:46
  • 1
    What's the `PRIMARY KEY`? – Rick James Jan 15 '20 at 04:42
  • Ping ping @RickJames never got his answer :) – The Onin Sep 16 '20 at 20:30
  • @RaymondNijland 's suggested warm up query worked for me; after running it; query time for selects improved immediately! – Reece Mar 12 '21 at 20:36

0 Answers0