I have a basic doubt. I grew up (in Oracle) believing that for the concatenated indexes to be used by a query the ordering of the columns in the where clause was very important. But now I have doubts
I have a table test and a composite index on it.
CREATE TABLE TEST ( A NUMBER, B NUMBER, C NUMBER, D VARCHAR2 (30) ) ;
CREATE INDEX TEST_COMPOSITE ON TEST(A, B, C) ;
I inserted some test data into it(376833 rows)
Then tried some queries with explain plan. There is only one row which matches this criteria.
SQL> explain plan for 2 select * from test 3 where a= 112 4 and b=113 5 and c=114;
Explained.
SQL> @plan
Plan Table
--------------------------------------------------------------------------------
| Operation | Name | Rows | Bytes| Cost | Pstart| Pstop |
--------------------------------------------------------------------------------
| SELECT STATEMENT | | 5K| 74K| 88 | | |
| TABLE ACCESS BY INDEX ROW|TEST | 5K| 74K| 88 | | |
| INDEX RANGE SCAN |TEST_COMP | 5K| | 39 | | |
--------------------------------------------------------------------------------
6 rows selected.
SQL> explain plan for 2 select * from test 3 where a= 112 4 and c=114 5 and b=113;
Explained.
SQL> @plan
Plan Table
--------------------------------------------------------------------------------
| Operation | Name | Rows | Bytes| Cost | Pstart| Pstop |
--------------------------------------------------------------------------------
| SELECT STATEMENT | | 5K| 74K| 88 | | |
| TABLE ACCESS BY INDEX ROW|TEST | 5K| 74K| 88 | | |
| INDEX RANGE SCAN |TEST_COMP | 5K| | 39 | | |
--------------------------------------------------------------------------------
6 rows selected.
SQL> explain plan for 2 select * from test 3 where b=113 4 and a= 112 5 and c=114;
Explained.
SQL> @plan
Plan Table
--------------------------------------------------------------------------------
| Operation | Name | Rows | Bytes| Cost | Pstart| Pstop |
--------------------------------------------------------------------------------
| SELECT STATEMENT | | 5K| 74K| 88 | | |
| TABLE ACCESS BY INDEX ROW|TEST | 5K| 74K| 88 | | |
| INDEX RANGE SCAN |TEST_COMP | 5K| | 39 | | |
--------------------------------------------------------------------------------
6 rows selected.
SQL> explain plan for 2 select * from test 3 where b=113 4 and c=114 5 and a= 112;
Explained.
SQL> @plan
Plan Table
--------------------------------------------------------------------------------
| Operation | Name | Rows | Bytes| Cost | Pstart| Pstop |
--------------------------------------------------------------------------------
| SELECT STATEMENT | | 5K| 74K| 88 | | |
| TABLE ACCESS BY INDEX ROW|TEST | 5K| 74K| 88 | | |
| INDEX RANGE SCAN |TEST_COMP | 5K| | 39 | | |
--------------------------------------------------------------------------------
6 rows selected.
SQL> explain plan for 2 select * from test 3 where b=113 4 and c=114;
Explained.
SQL> @plan
Plan Table
--------------------------------------------------------------------------------
| Operation | Name | Rows | Bytes| Cost | Pstart| Pstop |
--------------------------------------------------------------------------------
| SELECT STATEMENT | | 23K| 299K| 158 | | |
| TABLE ACCESS FULL |TEST | 23K| 299K| 158 | | |
--------------------------------------------------------------------------------
Now I am at loss. I know this is something very basic. But I am unable to understand why the index is being used even when the order of the columns in the where clause is changed.
Oracle version 8.1.7.2.
Please enlighten me
Thanks in advance
Novice No more Oracle Certifiable DBA
_________________________________________________________________
Mobile, masti, magic! Cool ringtones & logos. http://www.msn.co.in/mobile/ Get noticed.
-- Please see the official ORACLE-L FAQ: http://www.orafaq.net -- Author: Novice DBA INET: [EMAIL PROTECTED]
Fat City Network Services -- 858-538-5051 http://www.fatcity.com San Diego, California -- Mailing list and web hosting services --------------------------------------------------------------------- To REMOVE yourself from this mailing list, send an E-Mail message to: [EMAIL PROTECTED] (note EXACT spelling of 'ListGuru') and in the message BODY, include a line containing: UNSUB ORACLE-L (or the name of mailing list you want to be removed from). You may also send the HELP command for other information (like subscribing).