大网数据广告活动
服务器运维问答

Why did our AWS Aurora RDS spike and lock up?

· 52CE 我爱测

This morning our aurora mysql serverless 2 spiked and basically locked up. We have a writer/reader and a reader associated with the cluster. On the reader we had an intense select query. This is the query RDS shows (field names c…

问题原文

原帖链接 · Harpua · CC BY-SA 4.0

This morning our aurora mysql serverless 2 spiked and basically locked up. We have a writer/reader and a reader associated with the cluster.

On the reader we had an intense select query. This is the query RDS shows (field names changed), the point is it has multiple FIND_IN_SET functions and insights show it examined 109826.50 rows.

SELECT thisstuff ( thistime ) AS thestuff , COUNT ( * ) AS count FROM mytable WHERE todo = ? AND someID = ? AND ( ( FIND_IN_SET ( otherID , ? ) ) || ( FIND_IN_SET ( otherID , ? ) ) || ( FIND_IN_SET ( otherID , ? ) ) ) AND ( thistime BETWEEN ? AND ? ) AND some_status = ? GROUP BY months_todo ( thistime )

At the same time our writer had the following waits going on.

wait/io/redo_log_flush
synch/sxlock/innodb/hash_table_locks
wait/io/table/sql/handler

Can somebody please help me understand why this happened, as in did the writer lock the tables or did the FIND_IN_SET lock the writer? The writer was making updates to the same table at the time the query was going on. Is there a way to prevent this?

Thank You

已采纳解答

原帖链接 · Rick James · CC BY-SA 4.0

SELECT  thisstuff ( thistime ) AS thestuff , COUNT ( * ) AS count
    FROM  mytable
    WHERE  todo = ?
      AND  someID = ?
      AND  ( ( FIND_IN_SET ( otherID , ? ) ) ||
             ( FIND_IN_SET ( otherID , ? ) ) ||
             ( FIND_IN_SET ( otherID , ? ) ) 
           )
      AND  ( thistime BETWEEN ? AND ? )
      AND  some_status = ?
    GROUP BY  months_todo ( thistime )

Let's try to make the query run faster.

INDEX(someID, status, todo, thistime)

would help.

If the tests for otherID are single values, wouldn't this work as well (and faster)?

AND otherID IN ( ?, ?, ? )

If there are lists, then how about

AND otherID IN CONCAT_WS(',', ?, ?, ?)

What is months_todo? If it is a function, let's see it. It also looks like thissstuff(...) is a function; let's see it.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2024-02-22)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。