日期:2014-05-16  浏览次数:20741 次

帮忙看一下下面这个语句如何建立索引?
SELECT g.id,g.city,g.end_time,g.small_img,g.market_price,g.shop_price,g.site_id,g.is_best,g.bought,g.name,g.sort,s.name as site_name,g.bussiess_id,(g.shop_price / g.market_price) as discount,g.click_count,g.url,s.code_position,s.cps_url
,(SELECT count(*) from goods where site_id=g.site_id and id>g.id and site_id>0 and end_time >= 1335983260 ) as group_id1 
FROM goods as g left join site as s on s.id = g.site_id where g.status = 1 and g.end_time >= 1335983260 and g.site_id>0 and (g.city = '' or g.city = '全国' or g.city like '北京%') group by g.id
order by group_id1 asc,s.sort, g.is_best desc,g.id desc limit 0,10



表 Goods , 表 Site 应该建立怎样的索引比较好 谢谢各位


------解决方案--------------------
create index xxx1 on goods on (site_id,end_time)
create index xxx2 on goods on (site_id,id)
create index xxx3 on site on (id)
create index xxx4 on goods on (status,end_time)

 先创建这几个。
------解决方案--------------------
我觉的在end_time上加索引是主要问题
------解决方案--------------------
create index aa on goods on(site_id,end_time);
create index bb on goods on(site_id,id);
create index cc on goods on(status,end_time);