I have the following MySql query
SELECT DISTINCT cats.name AS cat_name, cats.alias AS cat_alias, content.catid AS cat_id, content.title AS title, content.introtext AS text, content.created AS date, content.publish_up AS date_publish, content.id AS ID, content.alias AS alias, content.hits
AS hits, content.plugins AS plugins
FROM t0nbl_k2_items AS content LEFT JOIN t0nbl_k2_categories AS cats ON cats.id = content.catid
WHERE content.trash = 0
AND cats.access <=3
AND content.access <=3
AND content.published=1
AND cats.published=1
AND ( content.publish_up='0000-00-00 00:00:00' OR content.publish_up <='2014-10-31 00:00:00' )
AND ( content.publish_down='0000-00-00 00:00:00' OR content.publish_down>= '2014-10-31 00:00:00' )
ORDER BY content.created ASC
LIMIT 0,12;
It takes 4 second to get the result.
The explain statement shows the following
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE content range item,catid,item_categ,latest item 10 NULL 11858 Using index condition; Using where; Using temporary; Using filesort
1 SIMPLE cats eq_ref PRIMARY,category,published,access,item_categ PRIMARY 4 site2.content.catid 1 Using where
and here are the indexes.
INDEXNAME FIELDNAME
PRIMARY id
item published
publish_up
publish_down
trash
access
catid catid
created_by created_by
ordering ordering
featured featured
created created
language language
item_categ access
published
publish_up
publish_down
catid
created
latest publish_up
publish_down
created
I don't know how to optimize this query to speed it. the #_k2_items has 30.000 items. as you see it is not so big data. So which indexes i should define to let Mysql use them?
Sorry for my bad english and formating the codes. I am new here to use this editor.