If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Informix > Initial SQL query taking very long to execute

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-15-07, 09:07
peterhjr peterhjr is offline
Registered User
 
Join Date: Feb 2007
Posts: 1
Question Initial SQL query taking very long to execute

I have a SQL query going to an Informix DB, which initially takes up to three minutes to complete, regardless of the size of the data returned.

If I call the query again, even with completely different parameters, within the next 10 minutes, it completes within seconds.

It feels like the SQL is being compiled and cached, but I don't understand how one relatively simple query should take three minutes to compile and then only a few seconds to execute:

SELECT *
FROM internet:ref_referrals inner join internet:crvet_application on internet:ref_referrals.ref_reference=internet:crve t_application.referral_no
WHERE date(ref_enter_date) between '2007/01/01' and '2007/01/30'

The problem does not seem to appear on any other queries. ANY ideas would be greatly appreciated.
Reply With Quote
  #2 (permalink)  
Old 03-09-07, 05:39
stanislav.ondac stanislav.ondac is offline
Registered User
 
Join Date: Aug 2005
Posts: 140
Yes, you'r right. First time Informix reads the data from disk, other times
mostly from buffers.
And why it takes three minutes to compile depends on many factors: fi: how the optimizer process the query(look at the explain of the query), how the table looks like on the disk(how many extents, fragmented or not...), how much data the query returns...and so on.
Reply With Quote
  #3 (permalink)  
Old 03-13-07, 13:52
ifx ifx is offline
Registered User
 
Join Date: Feb 2005
Posts: 33
I don't know your table layout but here are a few common suggestions:

You could speed up your initial query by setting suitable indices on the referencing columns (ref_reference, referral_no) and on the conditional columns (ref_enter_date) helping the database not to go through the whole tables for your results.

Try to avoid the use of functions where it is not neccessary. Maybe you could use the following clause to speed up:
"where ref_enter_date between '2007-01-01 00:00:00' and '2007-01-30 23:59:59'"
(depending on your column definition you have to add milliseconds or leave out the seconds or whatever)
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On