/*
 * 位图联接索引
 *
 */
prompt
prompt 创建eoda.emp 和edoa.dept
declare
	row_count_emp number(5);
	row_count_dept number(5);
begin
	select count(1) into row_count_emp from user_tables where table_name = upper('emp');
	select count(1) into row_count_dept from user_tables where table_name = upper('dept');
	if row_count_emp = 1 then
		execute immediate 'drop table eoda.emp';
	end if;
	if row_count_dept = 1 then
		execute immediate 'drop table eoda.dept';
	end if;
	execute immediate '
		create table eoda.dept
		as
		select * from scott.dept
	';
	execute immediate '
		create table eoda.emp
		as
		select * from scott.emp
	';
end;
/

prompt
prompt 创建位图索引eoda.emp_bm_idx
declare
	row_count number(5);
begin
	select count(1) into row_count from user_indexes where index_name = upper('emp_bm_idx');
	if row_count = 1 then
		execute immediate 'drop index eoda.emp_bm_idx';
	end if;
	execute immediate '
		create bitmap index eoda.emp_bm_idx
		on eoda.emp (d.dname)
		from eoda.emp e,eoda.dept d
		where e.deptno = d.deptno
	';
end;
/

prompt
prompt 让cbo认为表很大eoda.emp、eoda.dept
begin
	dbms_stats.set_table_stats( user ,'EMP',numrows => 1000000,numblks => 300000);
	dbms_stats_set_table_stats( user,'DEPT' ,numrows => 1000000,numblks => 300000);
	dbms_stats.delete_index_stats( user,'EMP_BM_IDX' );
end;
/

select count(*) from eoda.emp a,eoda.dept b
where a.deptno = b.deptno
and b.dname = 'SALES';
