Skip to content

Conversation

@dgarciabriseno
Copy link
Contributor

On Tuesday I noticed some XRT queries taking a very long time which slowed down database performance.

I found it was caused by mysql not selecting the optimal index when querying XRT.
The following query took 1 hour to complete:

SELECT id, sourceId, filepath, filename, date
                 FROM ( (SELECT id, sourceId, filepath, filename, date
                            FROM data
                            WHERE  groupThree = 10009 
                            AND date = (SELECT date
                                        FROM data
                                        WHERE  groupThree = 10009 
                                        AND date < '2020-11-29 12:50:41.000' ORDER BY date DESC LIMIT 1))
                        UNION ALL
                         (SELECT id, sourceId, filepath, filename, date
                          FROM data
                          WHERE  groupThree = 10009 
                          AND date = (SELECT date
                                      FROM data
                                      WHERE  groupThree = 10009 
                                      AND date >= '2020-11-29 12:50:41.000' ORDER BY date ASC LIMIT 1))
                        ) t
                 ORDER BY
                 ABS(TIMESTAMPDIFF(MICROSECOND, date, '2020-11-29 12:50:41.000'))
                 LIMIT 1;

By changing the sub queries to force the use of the "groupThree" index, the query completed in 0.27 seconds.

This patch is to manually select the index to use for XRT queries.

@dgarciabriseno dgarciabriseno merged commit 9c9c173 into Helioviewer-Project:master Jun 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant