Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
select * from table t where t.f_flag is not nullcol is not null стоимость фуллскана по таблице будет гораздо выше, чем стоимость фуллскана по индексу. А CBO ленив… Кейс:SQL> create table ttt( col int );
SQL> insert into ttt select null from dual connect by level <= 90;
SQL> insert into ttt select 1 from dual connect by level <= 5;
SQL> insert into ttt select 2 from dual connect by level <= 5;
SQL> commit;
SQL> select nvl(col, -1), count(*) from ttt group by nvl(col, -1);
NVL(COL,-1) COUNT(*)
----------- ----------
1 5
2 5
-1 90
SQL> create index ttt#ni#col on ttt(col);
SQL> exec dbms_stats.gather_table_stats( ownname => 'TEST', tabname => 'TTT', cascade => true );
select col from ttt where col is not null;
-------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 10 | 10 | 1 (0)| 00:00:01 |
|* 1 | INDEX FULL SCAN | TTT#NI#COL | 10 | 10 | 1 (0)| 00:00:01 |
-------------------------------------------------------------------------------
SQL> alter index ttt#ni#col unusable;
SQL> select col from ttt where col is not null;
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 10 | 10 | 3 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| TTT | 10 | 10 | 3 (0)| 00:00:01 |
--------------------------------------------------------------------------
create table t(
id int
, is_deleted varchar2(1) not null
, constraint t#ck#is_deleted check(is_deleted in 'Y', 'N')
);
create bitmap index t#bi#is_deleted on t(is_deleted);
Я просто не вижу альтернатив...length('') должен вернуть ноль, это же очевидно!Do not use the VARCHAR data type. Use the VARCHAR2 data type instead. Although the VARCHAR data type is currently synonymous with VARCHAR2, the VARCHAR data type is scheduled to be redefined as a separate data type used for variable-length character strings compared with different comparison semantics.
begin
IF NULL != NULL THEN
dbms_output.put_line('равно');
ELSE
dbms_output.put_line('не равно');
END IF;
end;
Заметка про NULL