同一表中的同一类型查询需要不同的时间来执行MySQL
我在同一张桌子上有几个问题。但是第一个需要2ms,而其他的几乎不需要390μs。我找不出原因。我正在使用MariaDb 10.2 2微秒同一表中的同一类型查询需要不同的时间来执行MySQL,mysql,mariadb,Mysql,Mariadb,我在同一张桌子上有几个问题。但是第一个需要2ms,而其他的几乎不需要390μs。我找不出原因。我正在使用MariaDb 10.2 2微秒 select `ask_price` from `trades` where (`coin` = 'HLCN' and `market` = 'ETH') order by `time` desc limit 1 其他低于390μs的 select `ask_price` from `trades` where (`coin` = 'BTC' and `ma
select `ask_price` from `trades` where (`coin` = 'HLCN' and `market` = 'ETH') order by `time` desc limit 1
其他低于390μs的
select `ask_price` from `trades` where (`coin` = 'BTC' and `market` = 'ETH') order by `time` desc limit 1
select `ask_price` from `trades` where (`coin` = 'BCH' and `market` = 'ETH') order by `time` desc limit 1
为什么第一个需要2-3毫秒 问题是为什么第一个案例很快,但如果您需要,这个查询通常很快,如果您还没有这些列的索引,您可以尝试:
create index idx_name on `trades`(`coin`,`market`,`time`);
然后运行查询。查询速度变化的原因可能有很多。在您的情况下,这很可能是由于磁盘页面缓存,或查询缓存
但是,还有很多其他选择。低级数据库技巧非常有用,因此除非你决定成为MySQL或MariaDB程序员,否则你无法真正了解正在发生的一切。你能展示解释计划吗?2微秒不太可能;也许你的意思是2毫秒(2000微秒)?