Jump to content

Optimize/Speed Up Query


a1amattyj

Recommended Posts

Hello,

 

I'm trying to speed up a search function. Here is an example query:

 

SELECT * FROM deals d JOIN tariffs h on(d.tarrif = h.tarrif_numericid)

WHERE h.anytime_mins <= '1500'

AND h.texts <= '1000'

AND ( h.network_numericid = '2' OR h.network_numericid = '3')

AND h.cost_month != 0.00

ORDER BY h.cost_month

LIMIT 30;

 

Showing rows 0 - 29 ( 30 total, Query took 8.8831 sec) [cost_month: 5.11 - 10.00]

 

Deals Table:

 

deal | tarrif 
text | int(15)

 

Tariffs Table:

 

tarrif_numericid  | network_numericid | contract_length | anytime_mins | texts | data | cost_month | someother coumns..
int(15) | int(15) | int(15) | int(15) | int(15) | int(15) | decimal(15,2)	 | ... 

 

Each of the coumns above depends on what the user searches for, please see query above for example.

 

Here are my current indexes:

 

1) h.tarrif_numericid

2) h.contract_length h.anytime_mins h.texts h.data h.cost_month

3) d.tarrif

 

Explain:

 

id select_type table type possible_keys key key_len ref rows Extra

1 SIMPLE d ALL tarrif NULL NULL NULL 1241496 Using temporary; Using filesort

1 SIMPLE h ref tarrif_numericid,network_numericid tarrif_numericid 4 latest_cms.d.tarrif 1 Using where

 

Any help would be greatly appreciated increasing the speed (from the current 8s)!

 

Link to comment
Share on other sites

Thanks for the response, here are the new outputs:

 

SELECT * FROM deals d STRAIGHT_JOIN tariffs h on(d.tarrif = h.tarrif_numericid) WHERE h.anytime_mins != '-1' AND h.texts <= '1500' AND ( h.network_numericid = '2' OR h.network_numericid = '3' OR h.network_numericid = '6' ) AND h.cost_month != 0.00 ORDER BY h.cost_month LIMIT 30

 

Showing rows 0 - 29 ( 30 total, Query took 9.2600 sec) [cost_month: 5.11 - 10.00]

 

id select_type table type possible_keys key key_len ref rows Extra

1 SIMPLE d ALL tarrif NULL NULL NULL 1241496 Using temporary; Using filesort

1 SIMPLE h ref tarrif_numericid,network_numericid tarrif_numericid 4 latest_cms.d.tarrif 1 Using where

 

Thanks

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.