我想优化以下查询。在我的开发服务器上使用LIMIT 10执行它需要150-200秒。我无法在生产服务器上运行它,因为执行时间有限。
SELECT
intensive.id AS intensive_id,
intensive.module_id AS intensive_module_id,
w.id AS w_id,
intensive.translation,
w.name_basic_lang,
w.image_name,
w.image_number,
w.image_ext
FROM mk_int_module_multiwordssentences intensive
INNER JOIN mk_words w ON intensive.translation= w.name_basic_lang
WHERE w.image_number <> '' AND w.image_number <> -1 AND intensive.img_name IS NULL
GROUP BY intensive.id
答案 0 :(得分:0)
试试这个:
SELECT
...
FROM mk_int_module_multiwordssentences intensive
INNER JOIN mk_words w ON intensive.translation = w.name_basic_lang
and w.image_number <> '' AND w.image_number <> -1 AND intensive.img_name IS NULL
Group by ...
答案 1 :(得分:0)
如果image_number没有除-1以外的任何其他负值,请检查是否可以使用
NVL(w.image_number,0)&gt; = 0
(取决于您的应用程序功能)。
请检查以下条件是否可以合并为单一条件
在哪里w.image_number&lt;&gt; ''和w.image_number&lt;&gt; -1 到
NVL(w.image_number,0)&lt;&gt; -1