Skip to content
Advertisement

How to speed up BETWEEN operation on several million items?

I have table (very simplified) in MySQL:

Now I’m executing operation:

UPDATE my_table SET label = “xxx” WHERE datetime BETWEEN ‘2019-10-01 13:00:00’ AND ‘2019-10-01 13:30:00’

This is done correctly, but it takes a long, long time (over 30 seconds). How can I speed up my operation? Maybe something other instead of BETWEEN? Indexes? What indexes should I set up?

Advertisement

Answer

For this query:

You can add an index on datetime:

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement