You are on page 1of 2

SQL> create table muse (id number, muse_date date, name varchar2(10));

Table created.
SQL> declare
v_count number;
begin
v_count:=0;
for i in 1..1830
loop
for j in 1..1000 loop
v_count:= v_count+1;
insert into
muse values (v_count, sysdate-i, 'MUSE');
end loop;
end loop;
commit;
end;
/
SQL>
create index muse_i on muse(muse_date);
Index created.
SQL> exec dbms_stats.gather_table_stats(ownname=>'SCOTT', tabname=>'MUSE', casc
ade=>true, estimate_percent=>null, method_opt=>'FOR ALL COLUMNS SIZE 1');
PL/SQL procedure
successfully completed.
SQL> select * from muse where muse_date > sysdate - 365;
select * from muse where muse_date > (sysdate+365) - 365;
##############
Execution Plan
---------------------------------------------------------Plan hash value: 1710225340
-------------------------------------------------------------------------| Id | Operation
| Name | Rows | Bytes | Cost (%CPU)| Time
|
-------------------------------------------------------------------------| 0 | SELECT STATEMENT |
| 364K| 6401K| 1805 (12)| 00:00:22 |
|* 1 | TABLE ACCESS FULL| MUSE | 364K| 6401K| 1805 (12)| 00:00:22 |
-------------------------------------------------------------------------Predicate Information (identified by operation id):
--------------------------------------------------1 - filter("MUSE_DATE">SYSDATE@!-365)

##############################
declare
v_count number;

begin
v_count:=1830000;
for i in 1..365
loop
for j in 1..1000 loop
v_count:= v_count+1;
insert into
muse values (v_count, sysdate+i, 'MUSE');
end loop;
end loop;
commit;
end;
/
###################################
select * from muse where muse_date > (sysdate+365) - 365;
Execution Plan
---------------------------------------------------------Plan hash value: 3330108091
------------------------------------------------------------------------------------| Id | Operation
| Name | Rows | Bytes | Cost (%CPU)| Time
|
------------------------------------------------------------------------------------| 0 | SELECT STATEMENT
|
| 920 | 16560 |
9 (0)| 00:0
0:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| MUSE | 920 | 16560 |
9 (0)| 00:0
0:01 |
|* 2 | INDEX RANGE SCAN
| MUSE_I | 920 |
|
5 (0)| 00:0
0:01 |
------------------------------------------------------------------------------------Predicate Information (identified by operation id):
--------------------------------------------------2 - access("MUSE_DATE">SYSDATE@!+365-365)
exec dbms_stats.gather_table_stats(ownname=>'SYS', tabname=>'MUSE', cascade=
>true, estimate_percent=>null, method_opt=>'FOR ALL COLUMNS SIZE 1');

You might also like