简体   繁体   中英

AWS Aurora RDS MySQL Performance Issue on Simple Join no indexes

AWS RDS Aurora MySQL 5.7.12 Joining two tables with a simple join both with a 1M rows each a simple join hangs while a simple join on the a sub-query for each table returns 1M rows in 4 secs. What DB parameter(s) is most likely to be causing this optimizer issue.

Simple Join Explain

Subquery Explain

You pasted two visual explain diagrams from MySQL Workbench.

The explain for the join solution shows that you are joining two tables, and it causes a nested-loop join with no index. So it does a table-scan for the first table, and for every row in the first table, it repeats a table-scan on the second table. This is what happens when there's no index to support the join. The query costs O(n 2 ) relative to the number of rows. The visual explain reports that the total cost estimate is 196565556843.57

The visual explain for the subquery-based solution that generates a temporary index for the derived-table subquery. This is blogged about here: https://mysqlserverteam.com/mysql-5-7-improved-performance-of-queries-with-derived-tables/ This helps MySQL to eliminate a lot of repeated table-scans. The cost estimate of this query is 12134406.48, which is much lower.

But frankly, neither query is optimized. Even the "good one" is taking 4 seconds by your description, which is probably not fast enough for your task. You should create an index to support the join, which will save MySQL from doing the work of generating an autokey. I'm not sure why you aren't asking about that.

If you want help with query optimization, you should always include in your question minimally:

  • The query you want to optimize. It's impossible for us to guess what your query is, and the advice on how to optimize it depends on the query.
  • The output of SHOW CREATE TABLE <name>\G for each table involved in the query, so we know what columns, data types, and indexes you have defined.
  • The size of the tables. Use SHOW TABLE STATUS LIKE '<name>'\G for each table involved in the query. This will tell us how many rows, average row size, and the approximately size of data and indexes.
  • Some information about the server. In your case, you're using AWS Aurora, so you should know the instance size. AWS instance sizes are standardized , so we'd be able to get other specs from that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM