我今天在执行查询时发现了一些奇怪的事情,我想知道这是如何发生的。
以下是我的查询:
select sum(price) as total from table_a where testing_date = '2020-06-10'
Run Code Online (Sandbox Code Playgroud)
此查询在搜索数据时需要 2-5 秒。现在我对查询做了一些小更改,如下所示:
select sum(price) as total from table_a where date(testing_date) = '2020-06-10'
Run Code Online (Sandbox Code Playgroud)
在这种情况下,查询需要 2-3 分钟。这里的testing_date列数据采用日期时间格式,例如:2020-06-01 00:00:00
这里的总记录大小超过 700 万条。