Database query - slow the first couple of times.

Hi All,

we have field on the interface, when user enters a values and tabs out, we query a table to get information and load the rest of the page.

Issue is when a user logs in for the first time and enters the value, the query takes lot of time (7-8 seconds to load, soemtimes 10+seconds and the screen errors out).

But if he tries subsequently 2nd or 3rd time, the querying becomes very fast (100-200 ms).

The logs show that the execute times is what takes the maximum time.

Operation Type Operation Name Operation Detail Prepare Time (ms) Execute Time (ms) Transform Time (ms)
QUERY queryentity expression "[FAILED] Query[Selection[sl as sl (show), price as price (show), quantity as quantity (show), enter_date as enter_date (show), plant as plant (show), matnr as matnr (show), knumh as knumh (show)], criteria[(matnr = TypedValue[it=3,v=713-312126-002])], PagingInfo[startIndex=0, batchSize=-1, sort=[Sort[sl asc]]]]" 0 10013 0
QUERY queryentity expression "[FAILED] Query[Selection[sl as sl (show), price as price (show), quantity as quantity (show), enter_date as enter_date (show), plant as plant (show), matnr as matnr (show), knumh as knumh (show)], criteria[(matnr = TypedValue[it=3,v=713-335743-002])], PagingInfo[startIndex=0, batchSize=-1, sort=[Sort[sl asc]]]]" 0 10016 0

The table has 1.5 million rows and the column that we are searching on is properly indexed. So the table is properly optimized.

What could the possible reasons for it being really slow the first couple of times (1-2 times)

  Discussion posts and replies are publicly visible

Parents
  • Hi Siddharth

    Having an Index on a table of in itself is no guarantee that the Database engine is using it! Have you asked the DBA to perform an EXPLAIN on that table? If the Database internal statistics table doesn't reflect that actual data in the table (i.e. if the Database thinks there are only 100 rows rather than the 1.5 million rows) then the Database will perform a full table scan and ignore the index because it believes this is the most efficient way of retrieving the data. The DBA should be performing a RUNSTATS (this is the DB2 command) - or whatever the equivalent is for your Database platform - in order for the statistics tables to be updated. Even if this is up to date the EXPLAIN should still help you determine what the data retrieval plan is and whether other indexes need to be applied.

  • 0
    Certified Lead Developer
    in reply to Stewart Burchell

    This could be as simple as the sort you're applying... Are you actively applying a sort within the query entity?

Reply Children