[英]MYSQL two tables query vs one of a time
I have this query:我有这个查询:
SELECT
cms_mod_lajmet_entry.LajmID,
page_id, date,
foto, eshte_video,
title, intro,
komente
FROM cms_mod_lajmet_entry, cms_mod_lajmet_entry_language
WHERE cms_mod_lajmet_entry.LajmID = cms_mod_lajmet_entry_language.LajmID
AND cms_mod_lajmet_entry.page_id = 2
AND cms_mod_lajmet_entry.publikimi = 1
AND cms_mod_lajmet_entry_language.language = 'sq'
AND cms_mod_lajmet_entry.renditja > 0
ORDER by renditja ASC, date DESC LIMIT 1
(loading time = 0.1219) (加载时间 = 0.1219)
when I split them:当我拆分它们时:
SELECT
LajmID,
page_id,
date,
foto,
eshte_video,
komente
FROM cms_mod_lajmet_entry
WHERE cms_mod_lajmet_entry.page_id = 2
AND cms_mod_lajmet_entry.publikimi = 1
AND cms_mod_lajmet_entry.renditja > 0 ORDER by renditja ASC, date DESC LIMIT 1
(loading time = 0.0801) (加载时间 = 0.0801)
and query this alone: ($t[LajmID] is a PrimaryID from the last table)并单独查询:($t[LajmID] 是最后一个表中的 PrimaryID)
SELECT
title,
intro
FROM cms_mod_lajmet_entry_language
WHERE LajmID = $t[LajmID]
AND language = 'sq'
(Loadin time = 0.0006) (加载时间 = 0.0006)
in total: 0.1219 > 0.0807 (0.0801 + 0.0006).总计:0.1219 > 0.0807 (0.0801 + 0.0006)。
Is this really faster as it looks and/or if there's any other faster ways.这看起来真的更快吗和/或是否还有其他更快的方法。
Indexes are as follows:指标如下:
First table:第一张表:
LajmID BTREE No No LajmID 36380 A LajmID BTREE 否 否 LajmID 36380 A
page_id 36380 A page_id 36380 A
publikimi 36380 A公众号 36380 A
klika 36380 A克里卡 36380 A
Second table:第二个表:
LajmID BTREE No No LajmID 38456 A LajmID BTREE 否 否 LajmID 38456 A
language 38456 A语言 38456 A
I wasn't originally planning on answering, but my comments on the question basically answered it.本来我不打算回答,但是我对这个问题的评论基本上回答了它。 My comments are summarized below:我的意见总结如下:
To get accurate query execution times, make sure you run the queries with SQL_NO_CACHE
.要获得准确的查询执行时间,请确保使用SQL_NO_CACHE
运行查询。 This will make sure that the query cache doesn't skew the results.这将确保查询缓存不会扭曲结果。 The index on the first table wasn't being used since LajmID
was on the top of it and it wasn't used in the query.第一个表上的索引没有被使用,因为LajmID
在它的顶部并且它没有在查询中使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.