我在.my.cnf
中有以下内容# LOGGING #
slow_query_log = ON
slow_query_log_file = /var/log/mariadb/slow_query.log
log-queries-not-using-indexes = 1
当我运行tuning-primer.sh时,我得到了这个:
SLOW QUERIES
The slow query log is NOT enabled.
Current long_query_time = 10.000000 sec.
You have 0 out of 36 that take longer than 10.000000 sec. to complete
Your long_query_time seems to be fine
有人可以解释一下这是怎么回事吗?
答案 0 :(得分:0)
显然慢速 现在正在工作。你知道解决这个问题的原因吗?
与此同时,这已经变成了查询调优...
#1是什么?它为什么经常运行?它返回平均156K行检查(整个表?),但只返回665行。 665是很多行;你真的需要它们吗?可以在SQL中进行更多过滤吗?
听起来没有INDEX(autoload)
- 添加它;它应该大大加快查询速度。
#1
SELECT option_name, option_value
FROM wp_options
WHERE autoload = 'S'
您正在使用以下数千行进行操作?而且你正在进行数千次预演?
#2
SELECT st.value AS tra, s.value AS org, s.domain_name_context_md5 AS ctx
FROM wp_icl_strings s
LEFT JOIN wp_icl_string_translations st ON s.id=st.string_id
AND st.status=N
AND st.language='S'
AND s.language!='S'
#3
SELECT slug, taxonomy
FROM wp_posts
INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id)
INNER JOIN wp_term_taxonomy ON (wp_term_relationships.term_taxonomy_id =
wp_term_taxonomy.term_taxonomy_id )
INNER JOIN wp_terms ON (wp_term_taxonomy.term_id = wp_terms.term_id )
WHERE wp_posts.ID IN ("S","S","S","S","S","S","S","S","S",...)
ORDER BY wp_terms.name ASC
#4
SELECT t.element_id, tax.term_id, tax.taxonomy
FROM wp_icl_translations t
JOIN wp_term_taxonomy tax ON t.element_id = tax.term_taxonomy_id
AND t.element_type = CONCAT('S', tax.taxonomy)
JOIN wp_terms terms ON terms.term_id = tax.term_id
WHERE tax.term_id != tax.term_taxonomy_id
为什么#2中的LEFT
?这可能会阻止从st
开始,INDEX(language, status)
可能会更具选择性。
在#3中:wp_terms可能会受益于INDEX(name)
。
在#4中:架构设计导致了笨拙的CONCAT('S', tax.taxonomy)
;可以纠正吗?也就是说,t.element_type
和tax.taxonomy
看起来是一样的 - 要么都带有前缀,要么两者都没有?或者前缀可能是一个单独的列?
如果您想进一步讨论这些问题,请提供SHOW CREATE TABLE
和EXPLAIN SELECT ...
。