
prompt
prompt 'create table eoda.t'
declare row_count number(5);
begin
	select count(1) into row_count from user_tables where table_name = upper('t');
	if row_count = 1 then
		execute immediate 'drop table eoda.t';
	end if;
	execute immediate '
		create table eoda.t (x int)
	';
end;
/

prompt
prompt 'insert data into eoda.t'
begin
	insert into eoda.t select rownum from dual connect by level < 1000000;
end;
/

prompt
prompt 'create index ti'
declare row_count number(5);
begin
	select count(1) into row_count from user_indexes where table_name = upper('t') and index_name = upper('ti');
	if row_count = 1 then
		execute immediate 'drop index eoda.ti';
	end if;
	execute immediate 'create index eoda.ti on eoda.t(x)';
end;
/

exec dbms_stats.gather_table_stats(user, 'T');

-- 当数据较少时，cbo会认为走索引好一点
select count(*) from eoda.t where x < 50;

-- 当超过一定
select count(*) from eoda.t where x < 1000000;
