Forum Moderators: open

Message Too Old, No Replies

What is wrong with this query? Running slow, but dont see reason

         

brandon0401

7:12 pm on Jan 25, 2008 (gmt 0)

10+ Year Member



Hey guys, I have a script that is executing a query a lot of times, and its running real slow for some reason. I dont see why, hoping someone can help shed some light.

Here is an example of query

EXPLAIN SELECT count( id )
FROM link_feeds
WHERE (
(
feed_url = 'http://www.domain.com/articles/2008/01/25/sports'
OR feed_title = 'KENTUCKY BASKETBALL: Some text here that we are looking for'
)
AND ( 13683 )
IN (

SELECT rssid
FROM category_rss
WHERE cat_id =340
)
)

explain:
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY link_feeds ALL titleindx NULL NULL NULL 946857 Using where
2 DEPENDENT SUBQUERY category_rss const PRIMARY,cat_id PRIMARY 2 1

thanks in advance..

there are index's on all pats of table, id is primary key in tables..

B

jtara

8:41 pm on Jan 25, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



there are index's on all pats of table

Butter comes in pats, at least in a restaurant. I didn't know that indices came in pats. Or are you from Bahston? :)

You need indices on feed_url, feed_title, and cat_id. Do you have them?

brandon0401

10:33 pm on Jan 25, 2008 (gmt 0)

10+ Year Member



Yes, with feed_title being text, its a index feed_title(255)

the others are indexes...

Indexes:

Keyname Type Cardinality Action Field
PRIMARY PRIMARY 953584 Edit Drop id
rss_id INDEX 4414 Edit Drop rss_id
pub_date INDEX 476792 Edit Drop pub_date
hits INDEX 312 Edit Drop hits
titleindx INDEX 953584 Edit Drop feed_title 255

other table is
cat_id INDEX 281 Edit Drop cat_id

this is super fast with just the feed_title and not url too..

Thanks for your help!

brandon0401

11:39 pm on Jan 25, 2008 (gmt 0)

10+ Year Member



was missing index on url...fixed by splitting them up though the or parts...why does it take so long together?

andyll

7:13 am on Jan 26, 2008 (gmt 0)

10+ Year Member



was missing index on url...fixed by splitting them up though the or parts...why does it take so long together?

Just a guess...

You are using an 'or' on two different fields. Even iff there are indexes on both fields it can't use both indexes at the same time.

Since you are 'And'ing the result to another clause I would guess it 1st has to find all results of the 'or' instead of quitting when it finds the 1st which means a table scan.

Andy