Home » RDBMS Server » Performance Tuning » Create Index ?
Create Index ? [message #333538] Sat, 12 July 2008 06:33 Go to next message
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 Go to previous messageGo to next message
rleishman
Messages: 3724
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 #333553 is a reply to message #333538] Sat, 12 July 2008 10:07 Go to previous messageGo to next message
Michel Cadot
Messages: 64133
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
You can create function-based index which can include CASE and so condition expressions.
Precise your needs we can give more accurate answers.

Regards
Michel
Re: Create Index ? [message #333608 is a reply to message #333538] Sun, 13 July 2008 10:09 Go to previous message
Kevin Meade
Messages: 2101
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

Previous Topic: GATHERING STATISTICS
Next Topic: how to force parallel to subquery of select statement ?
Goto Forum:
  


Current Time: Thu Dec 08 04:13:34 CST 2016

Total time taken to generate the page: 0.10459 seconds