different time for same query

  • hello

    I've a query, the first time I execute it, it take 10s, the second times it take 1s

    there is no problem of locks, no problem of indexes, and my buffer cache hit ratio is more than 98%

    I've a machine with 24 cpus, 32 go of memory

    and about 500 query/second ( a big website)

    thanks

  • there could be a several issues. I would check this first.

    my first guess the first time you ran it...the pages were not in cache...

    you need to test this on dev machine...run

    DBCC DROPCLEANBUFFERS

    then run the qry...this will give you the time when the pages are not in cache

    then run it again without running DBCC DROPCLEANBUFFERS, this will tell you how long it took to run while in cahce

    also run this.before your qry .

    USE AdventureWorks2008R2;

    GO

    SET STATISTICS IO ON;

    GO

    this will tell you how many pages are IO(phyiscal) vs buffer(logical)

  • thanks for your answer but there is no physical reads

  • The first time you exec a query, it has to create an execution plan, pull the data, etc.

    The second time, unless it has been flushed, it will already have the execution plan saved, data cached, etc.

    The first time a query runs is always slower.

  • Derrick is correct..

    SET STATISTICS TIME ON

    1. run the query

    2. DBCC FREEPROCCACHE ...ONLY ON DEV!

    3. run the query again, this will more or less tell you how much time you are spending compiling the plan.

    4. now compare the two, before the qry complied and with no compile

    10 second compiling the plan is a while but depending on the qry this could be true!

    ----if the times are close then the next thing to ask are the qry that you are running the EXACT SAME..

    dont run a qry with a search on X and then a search on Y.

  • Thanks for your advice !

Viewing 6 posts - 1 through 5 (of 5 total)

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