mysql slow on first query, then fast for related queries

后端 未结 6 793
天涯浪人
天涯浪人 2020-12-29 07:12

I have been struggling with a problem that only happens when the database has been idle for a period of time for the data queried. The first query will be extremely slow, o

6条回答
  •  感动是毒
    2020-12-29 08:02

    I had an SSIS package that was timing out. The query was very simple, from a single MySQL table, but it sometimes returned a lot of records and would sometimes take a few minutes initially to execute, then only a few milliseconds afterwards if I wanted to query it again. We were stuck with the ADO connection, which meant it would time out after 30 seconds, so about half the databases we were trying to load were failing.

    After beating my head against the wall I tried performing an initial query first; very simple and only returning a few rows. Since it was so simple it executed fast and set the table in the cache for faster querying. In the next step of the package I would do the more complex query which returned the large data set that kept timing out. Problem solved - all tables loaded. I may start doing this on a regular basis, the complex queries execute much faster by doing a simple query first.

提交回复
热议问题