简体   繁体   English

Mysql查询执行计划有缓存吗?

[英]Mysql query execution plan has caching?

I've looked everywhere for my issue but found no definite answer. 我到处寻找我的问题,但没有找到确切的答案。 Database: MySQL Given three numerical fields a, b, c and One datetime filed d, all indexed separately The involved table holds 10 mil. 数据库:MySQL给出三个数字字段a,b,c和一个日期时间字段d,所有索引单独索引表包含10密耳。 records. 记录。

Two numbers n,m 两个数字n,m

I have a basic query: 我有一个基本的查询:

select * where (a=n or b=n) and c IN(m) Order by d DESC

(n can be any number, m can be any number through 1-9) I also have a separate index on each one of them. (n可以是任意数字,m可以是1-9之间的任何数字)我也有一个单独的索引。 I've tried indexes on ac and bc but with no success. 我已尝试过ac和bc的索引,但没有成功。

On my development environment I always get an index merge which makes the query fast even though it makes a filesort for some reason that I dont' really care about. 在我的开发环境中,我总是得到一个索引合并,这使得查询速度很快,即使它出于某种原因而不是我真正关心的文件。

But on production(different sever-same schema/data) that doesn't happen no matter what I do. 但是在生产(不同的服务器 - 相同的模式/数据)上,无论我做什么都不会发生。

My workaround to this weird issue was turning the query into the following statement: 我对这个奇怪问题的解决方法是将查询转换为以下语句:

From: 从:

select * where (a=n or b=n) and c IN(m) ORDER BY d desc

To: 至:

select * where (a=n or b=n) and c IN(m,'m') ORDER BY d desc

And that resulted in an merge index query on the production environment as well which basically for me means that there's an execution plan cache somewhere and I can't figure out for the life of me where to clear that cache (if indeed there is one) 这导致了对生产环境的合并索引查询,这对我来说意味着在某处有一个执行计划缓存,我无法弄清楚我的生活在哪里清除缓存(如果确实有一个)

I need to know how can I tell the production environment to properly use that index in the first statement. 我需要知道如何告诉生产环境在第一个语句中正确使用该索引。

As a note ... for some reason Explain query tells me that d is the index used on production when explaining the query. 作为注释......出于某种原因,Explain查询告诉我d是解释查询时用于生产的索引。

I need to know how can I tell the production environment to properly use that index in the first statement. 我需要知道如何告诉生产环境在第一个语句中正确使用该索引。

Use the "force index" syntax. 使用“强制索引”语法。

If you paste CREATE TABLE & EXPLAIN output for the tables & queries involved (resp.) on dev & production we can narrow it down to a just a couple things. 如果您在开发和生产中粘贴表格和查询(相应)的CREATE TABLE&EXPLAIN输出,我们可以将其缩小到几个方面。 Might also help to know the RAM available on each machine. 可能还有助于了解每台机器上的RAM。

ps: PS:

On my development environment I always get an index merge which makes the query fast even though it makes a filesort for some reason that I dont' really care about. 在我的开发环境中,我总是得到一个索引合并,这使得查询速度很快,即使它出于某种原因而不是我真正关心的文件。

sorting by d which isn't in your index 按d排序,不在索引中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM