我在同一个表上有很少的查询。但第一个是考2个MS,其他人几乎不考390个μ,我找不出原因。我使用的是MariaDb 10.2
耗时2微秒
select `ask_price` from `trades` where (`coin` = 'HLCN' and `market` = 'ETH') order by `time` desc limit 1其他低于390μ的学生
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个MS!
发布于 2018-09-02 03:29:10
问题是为什么第一个案例很快,但如果需要的话,这个查询通常是快速的,如果你还没有那些列的索引,你可以试试:
create index idx_name on `trades`(`coin`,`market`,`time`);然后运行您的查询。
发布于 2018-09-02 09:47:34
查询速度改变的原因可能有很多。在您的例子中,这很可能是由于磁盘页面缓存或查询缓存造成的。
但是,还有很多其他的选择。低级数据库技巧非常有用,因此除非您决定成为一名MySQL或MariaDB程序员,否则您无法真正了解正在发生的一切。
https://stackoverflow.com/questions/52131321
复制相似问题