/*
 * 降序索引相关
 *
 */
prompt
prompt 创建表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
		as
		select *
		from all_objects
	';
end;
/

prompt
prompt 搜集相关信息表eoda.t
begin
	dbms_stats.gather_table_stats (user ,'T', method_opt=>'for all indexd columns');
end;
/

set autotrace traceonly explain
select owner, object_type
 from eoda.t
where owner between 'T' and 'z'
  and object_type is not null
order by owner desc, object_type desc;
/

select owner, object_type
 from eoda.t
where owner between 'T' and 'z'
  and object_type is not null
order by owner desc, object_type asc;
/

prompt
prompt 创建索引eoda.desc_t_idx
declare
	row_count number(5);
begin
	select count(1) into row_count from user_indexes where index_name = upper('desc_t_idx');
	if row_count = 1 then
		execute immediate 'drop index eoda.desc_t_idx';
	end if;
	execute immediate '
		create index eoda.desc_t_idx on eoda.t(owner desc, object_type asc )
	';
end;
/

select owner, object_type
 from eoda.t
where owner between 'T' and 'z'
  and object_type is not null
order by owner desc, object_type asc;
/
