Create Index ? [message #333538] |
Sat, 12 July 2008 06:33 |
ArvindBhope
Messages: 55 Registered: June 2008
|
Member |
|
|
Hello,
Can we create index with the conditions like "OR" and "AND" involved in it?
eg: the condition like ....
(("CCRYOID")OR "FNCT"='EG1192MR01') AND "VALIDITY"<>2)
Thanks
|
|
|
Re: Create Index ? [message #333540 is a reply to message #333538] |
Sat, 12 July 2008 06:46 |
rleishman
Messages: 3728 Registered: October 2005 Location: Melbourne, Australia
|
Senior Member |
|
|
Read up on Bitmap Indexes; they are unsuitable for many applications - especially OLTP - but may be applicable to you.
Ross Leishman
|
|
|
|
Re: Create Index ? [message #333608 is a reply to message #333538] |
Sun, 13 July 2008 10:09 |
|
Kevin Meade
Messages: 2103 Registered: December 1999 Location: Connecticut USA
|
Senior Member |
|
|
to tease your instincts, here is an example of what Michel means. We expect you will be doing your own research on this.
SQL> set autotrace off
SQL>
SQL> drop table a;
Table dropped.
SQL>
SQL> create table a (a number,b varchar2(30),c date);
Table created.
SQL>
SQL> create index ai1 on a (case when a > 0 or b like '%ABC%' or c < to_date('01-jan-2000','dd-mon-rrrr') then 'Y' end);
Index created.
SQL>
SQL> insert into a values (1,'ABC',SYSDATE);
1 row created.
SQL> insert into a values (0,'XYZ',sysdate);
1 row created.
SQL>
SQL> set autotrace on
SQL>
SQL> select *
2 from a
3 where case when a > 0 or b like '%ABC%' or c < to_date('01-jan-2000','dd-mon-rrrr') then 'Y' end = 'Y'
4 /
A B C
---------- ------------------------------ ---------
1 ABC 13-JUL-08
Execution Plan
----------------------------------------------------------
Plan hash value: 1327472245
------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 39 | 2 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| A | 1 | 39 | 2 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | AI1 | 1 | | 1 (0)| 00:00:01 |
------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access(CASE WHEN ("A">0 OR "B" LIKE '%ABC%' OR
"C"<TO_DATE('2000-01-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss')) THEN 'Y' END
='Y')
Note
-----
- dynamic sampling used for this statement
Statistics
----------------------------------------------------------
42 recursive calls
0 db block gets
16 consistent gets
0 physical reads
0 redo size
518 bytes sent via SQL*Net to client
381 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
SQL>
Good luck, Kevin
|
|
|