The order of the where clause is not important. Including the leading (first) columns in the index is. If you remove the "a = ?" element from any of the queries then it may stop using the index. Oracle is smart enough to look at the entire where clause and work out what it can do to achieve the result quickest.
You may be thinking on the rule based optimisor where the ordering of where clauses is significant - for cost based optimisor the order is essentially irrelevant. Regards, Mark. "Novice DBA" <[EMAIL PROTECTED] To: Multiple recipients of list ORACLE-L <[EMAIL PROTECTED]> l.com> cc: Sent by: Subject: concatenated index [EMAIL PROTECTED] .com 08/07/2003 13:44 Please respond to ORACLE-L Dear all, 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). <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<---->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Privileged/Confidential information may be contained in this message. If you are not the addressee indicated in this message (or responsible for delivery of the message to such person), you may not copy or deliver this message to anyone. In such case, you should destroy this message and kindly notify the sender by reply e-mail or by telephone on (61 3) 9612-6999. Please advise immediately if you or your employer does not consent to Internet e-mail for messages of this kind. Opinions, conclusions and other information in this message that do not relate to the official business of Transurban City Link Ltd shall be understood as neither given nor endorsed by it. <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<---->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<---->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Privileged/Confidential information may be contained in this message. If you are not the addressee indicated in this message (or responsible for delivery of the message to such person), you may not copy or deliver this message to anyone. In such a case, you should destroy this message and kindly notify the sender by reply e-mail or by telephone on (03) 9612-6999 or (61) 3 9612-6999. Please advise immediately if you or your employer does not consent to Internet e-mail for messages of this kind. Opinions, conclusions and other information in this message that do not relate to the official business of Transurban Infrastructure Developments Limited and CityLink Melbourne Limited shall be understood as neither given nor endorsed by them. <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<---->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> -- Please see the official ORACLE-L FAQ: http://www.orafaq.net -- Author: Mark Richard 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).