Changing database has slowed down query.

  • I am fairly new to SQL. I had a query that executed in about 20 seconds pulling from database 1. The only changes I made were to make it pull from database 2. It is currently running and has been for over an hour and a half. I am at a loss for why this happened. Any ideas are very much appreciated.

    Thank you

  • There are many possible reasons for this including:

    1. Much more data in the table(s) being accessed in database2

    2. Database2 being on a different server and not having as many resources

    3. Statistics not being accurate in database2 so the optimizer isn't choosing an optimal plan

    4. Index differences between databases

    5. A cached plan for the query in database2 that is not optimal for the parameters provided.

    There are probably others I've missed. The first thing I'd check the following:

    1. The row counts in each database

    2. The estimated execution plans for the query in each database to see what the optimizer is doing differently

  • It would help to know what query you are running. Is database2 on the same SQL Server or a linked server to another server.

    Have stats been updated on both tables/databases recently? How large of tables are both of these?

    Can you do a query plan for this query to see where it is performing most of its time? Are there any scans going on?

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply