MySQL Hangs

Gps man 2 years ago
SELECT tc_positions.* FROM tc_positions WHERE id IN (SELECT positionId FROM tc_devices)

I am using AWS RDS and not sure, what api / function is calling above query, which hangs MYSQL.

The CPU utilization rises to 100% and AAS goes beyond 300

Anton Tananaev 2 years ago

Maybe AWS is using an ancient version of MySQL that didn't know how to handle this query?

Gps man 2 years ago

Any suggestions I should look into setting any parameters. I am using mysql 8.0.33

Anton Tananaev 2 years ago

You need to check the query execution plan to see why it takes so long. It's probably not using indexes for some reason.

Gps man 2 years ago
Anton Tananaev 2 years ago

It looks good to me. I don't understand why it would hang on it though. Either this is not the query that it hangs on or there's some serious problem with your database.

Richard Creer 2 years ago

How about

Select tc_positions.* from tc_positions
Join tc_devices on id = positionid
Gps man 2 years ago

This requires code level change ? As we are not doing this query

Richard Creer 2 years ago

Could you use a mysql utility to run and compare the two?

Also I've seen it suggested that max_allowed_packet may need increasing for large IN clauses.

Gps man 2 years ago

appreciate your response the result of this is faster compared to the original query

Select tc_positions.* from tc_positions Join tc_devices on tc_positions.id = positionid

i have increased the max_allowed_packet to 32 MB from default 16 MB. But in query execution level it didnt made any change

Gps man 2 years ago

additionally, if you can please guide which api is using this query, it may help to drill down the cause

Gps man 2 years ago

Can I do this query change in default.xml ?? Id yes how