01-09-2013 11:06 AM
Hi
I have got the following error when i am running code inspector,
"Large table STPO: No first field of a table index in WHERE Condition"
My code is like below:
SELECT stlnr idnrk
FROM stpo
INTO TABLE git_stpo
FOR ALL ENTRIES IN git_mast
WHERE stlnr = git_mast-stlnr.
Please guid me how to remove this error and how to use index in where clause?
Thanks.
Vijay.
01-09-2013 11:17 AM
Hi Vijay,
STPO is large table, so you have to put 1st key field (STLTY) in where condition to remove code inspector error, please refer the code.
SELECT stlnr idnrk
FROM stpo
INTO TABLE git_stpo
FOR ALL ENTRIES IN git_mast
WHERE STLTY = 'E' and
stlnr = git_mast-stlnr.
Regards,
Deepak
01-09-2013 11:15 AM
Hi
select stlnr idnrk from stpo into table git_stpo %_hints ORACLE 'INDEX("STPO" "STPO~A")' WHERE FIELD = <cond>...
Regards
Sabyasachi
01-10-2013 9:40 AM
Hi,
Why should it help to tell the database to use index STPO~A (fields MANDT + AENNR) when the WHERE-clause contains the field STLNR?
Regards, Randolf
01-10-2013 10:27 AM
Hi Sabyasachi,
not only your advice is incorrect, the syntax is it as well.
Forcing the optimizer to use the index on MANDT and AENNR will
not influence the SCI message nor will it improve the run time. Most
likely run time will be worse!
Kind regards,
Hermann
01-09-2013 11:17 AM
Hi Vijay,
STPO is large table, so you have to put 1st key field (STLTY) in where condition to remove code inspector error, please refer the code.
SELECT stlnr idnrk
FROM stpo
INTO TABLE git_stpo
FOR ALL ENTRIES IN git_mast
WHERE STLTY = 'E' and
stlnr = git_mast-stlnr.
Regards,
Deepak
01-10-2013 9:52 AM
Hi,
Yes, that's correct, and this what also the check documentation says: "Check whether you can formulate the WHERE condition to suit a table index."
The first fields of the primary key of table STPO are: MANDT, STLTY, STLNR
Some database platforms might be able to add the missing (non-selective) field STLTY and do an index skip scan, but maybe not always. Therefore the left-justified fields of an index have to be in the WHERE-clause - that is at least the first field of an index.
If there is no information about the 'BOM category' STLTY, it would even be better to put all possible values into an IN-clause:
SELECT stlnr idnrk
FROM stpo
INTO TABLE git_stpo
FOR ALL ENTRIES IN git_mast
WHERE STLTY IN ('D', 'E', 'K', 'M') and
stlnr = git_mast-stlnr.
Best Regards,
Randolf
01-17-2013 6:41 AM
Thank you Deepak and Radolf.
My issue has been solved.
Thank you for everyone.