1

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

1 Answer 1

1
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.

4
  • Thank you, I was suspecting the query was the issue more so than the system. After researching the months_todo is a function MONTHNAME(). There are a lot of queries similar to this that will need revising. Would adding another reader specifically for these types of reports prevent aurora from locking up everything?
    – Harpua
    Commented Feb 23 at 16:55
  • So, are you taking a slice of all, say, Julys? That is lumping together last July and all previous Julys?
    – Rick James
    Commented Feb 23 at 18:40
  • @RickJames When your advice has been implemented, ask Harpua to visit www.mysqlservertuning.com for high performance tuning assistance, please. Thanks Commented Feb 23 at 20:26
  • We rewrote the query using IN statements. This can be multiple months, but yes grouped by all July's over the years. Thank you for the link I will definitely look into this.
    – Harpua
    Commented Mar 5 at 13:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .