伙计们我的表有一个列st_date,其中包含数据类型编号的日期,值类似于20101201即(01-DEC-2010).
如果我使用between子句为一个位于边界之间的日期编写一个select查询,我的问题是是否使用介于或小于或大于运算符,这是性能效率.
select id, sum(duration), sum(hit_count)
from A
where st_date between 20101101 AND 20101130
group by id
Run Code Online (Sandbox Code Playgroud)
该表有数百万条由st_date.Is分区的记录,高于或低于1.
select id, sum(duration), sum(hit_count)
from A
where st_date >= 20101101 AND st_date < 20101130
group by id
Run Code Online (Sandbox Code Playgroud)
请让我知道你的答案.
第二个是更高性能,因为它选择更少的数据:)
在内部,between被重写为> =和<=.您可以在执行计划的谓词信息部分中看到它.
explain plan for select * from t1 where n between 100 and 200;
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("N">=100 AND "N"<=200)
Run Code Online (Sandbox Code Playgroud)
而且,虽然我们在这里:
不要将日期存储为数字.
Oracle知道它们之间的区别date '2010-12-31' and date '2011-01-01'是1天.Oracle也知道20101231和20110101之间的区别是8870.
想想这对基数估计有什么影响.