dongluan7821 2016-07-24 20:31
浏览 79

Mysql查询执行时间减少

i have three tables in one database like this: company,categories,seo. i use this query :

SELECT seo.seo, company.diafhmish, comp_cat.cat, company.category, company.foto, comp_cat.diaf, company.comp_id, company.comp_name, company.perifereia, company.polh, company.thl, company.adress 
FROM company 
INNER JOIN comp_cat 
ON comp_cat.comp=company.comp_id 
INNER JOIN categories 
ON comp_cat.cat=categories.cat_id 
LEFT JOIN seo 
ON seo.comp=company.comp_id
WHERE categories.category = '$kathgoria' AND 
company.perifereia = '$polh' 
ORDER BY company.comp_name ASC

this take about 2,5 sec to execute, but if i try the same query without LEFT JOIN piece the time reduse at 0,5 sec!! Is there any way to replase the LEFT JOIN piece?

EXPLAIN:

id | select_type | table | type possible_keys | key | key_len | ref | rows | Extra

1 | SIMPLE | comp_cat | ALL | NULL | NULL | NULL | NULL | 15549 | Using temporary; Using filesort

1 | SIMPLE | company | eq_ref | PRIMARY | PRIMARY | 4 | tileodig_tileodigos.comp_cat.comp | 1 | Using where

1 | SIMPLE | seo | ALL | NULL | NULL | NULL | NULL | 1283

1 | SIMPLE | categories | eq_ref | PRIMARY | PRIMARY | 4 | tileodig_tileodigos.comp_cat.cat | 1 | Using where

I change the line LEFT JOIN seo ON seo.comp=company.comp_id with: LEFT JOIN seo ON seo.comp=comp_cat.comp both columns have the same value and i solved the problem.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 自适应 AR 模型 参数估计Matlab程序
    • ¥100 角动量包络面如何用MATLAB绘制
    • ¥15 merge函数占用内存过大
    • ¥15 Revit2020下载问题
    • ¥15 使用EMD去噪处理RML2016数据集时候的原理
    • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
    • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数
    • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
    • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
    • ¥15 如何在炒股软件中,爬到我想看的日k线