MySQL Hangs

Gps man8 months 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 Tananaev8 months ago

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

Gps man8 months ago

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

Anton Tananaev8 months 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 man8 months ago
Anton Tananaev8 months 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 Creer8 months ago

How about

Select tc_positions.* from tc_positions
Join tc_devices on id = positionid
Gps man8 months ago

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

Richard Creer8 months 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 man8 months 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 man8 months ago

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

Gps man4 months ago

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