2006 Nov 06 8:57 AM
Hello,
I've several index's created on a specific table. Does the order of the fields in the "WHERE" statement important for the right index to be chosen ?
For example:
============
Index fields: MANDT, BANFN (in this order)
statement:
SELECT * FROM EBAN WHERE BANFN = ... AND MANDT = ...
will this statement choose the existing index ?
Please advice,
Dimitry Haritonov
2006 Nov 06 8:58 AM
Hello,
I've several index's created on a specific table. Does the order of the fields in the "WHERE" statement important for the right index to be chosen ?
For example:
============
Index fields: MANDT, BANFN (in this order)
statement:
SELECT * FROM EBAN WHERE BANFN = ... AND MANDT = ...
will this statement choose the existing index ?
Please advice,
Dimitry Haritonov
2006 Nov 06 8:58 AM
2006 Nov 06 9:05 AM
Yes, the order of the fields in the "WHERE" statement is important for the right index to be chosen.
How to Check if an Index is Used
Procedure
Open a second session and choose System ® Utilities ® Performance trace.
The Trace Requests screen appears.
Select Trace on.
The SQL trace is activated for your user, that is all the database operations under your user are recorded.
In the first window, perform the action in which the index should be used.
If your database system uses a cost-based optimizer, you should perform this action with as representative data as possible. A cost-based optimizer tries to determine the best index based on the statistics.
In the second session, choose Trace off and then Trace list.
Result
The format of the generated output depends on the database system used. You can determine the index that the database used for your action with the EXPLAIN function for the critical statements (PREPARE, OPEN, REPOPEN).
Best Regards,
Vibha
*Please mark all the helpful answers
2006 Nov 06 9:38 AM
2006 Nov 06 9:39 AM
2006 Nov 06 9:49 AM
One more question:
==================
If the index includes 4 fields, and I include 3 fields in the right order (the 1, 2, 4 fields without the third field). Will the optimizer use the index ?
Please advice,
Dimitry
2006 Nov 06 9:53 AM
An index is defined on fields FIELD1, FIELD2, FIELD3 and FIELD4 of table BSPTAB in this order. This table is accessed with the SELECT statement:
SELECT * FROM BSPTAB WHERE FIELD1 = X1 AND FIELD2 = X2 AND FIELD4= X4.
Since FIELD3 is not specified more exactly, only the index sorting up to FIELD2 is of any use. If the database system accesses the data using this index, it will quickly find all the records for which FIELD1 = X1 and FIELD2 = X2. You then have to select all the records for which FIELD4 = X4 from this set.
This is what is given by sap help. So i think in that case that index will not not be of much help.
I hope this answers ur question.
Best Regards,
Vibha
*Please mark all the helpful answers
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |