IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Limiting use of index in a SQL evenif there are 4-5 indexes


IBM Mainframe Forums -> Mainframe Interview Questions
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
shailesh_do

New User


Joined: 27 Jun 2006
Posts: 9

PostPosted: Sun Nov 01, 2009 10:14 am
Reply with quote

Dear All,

There was an question was in interview as;

Say there are 4-5 indexes on a table (say table A)& COBOL-DB2 pgm has sql query on the same table A. Can we limit the use of index when the query is performed in pgm as it should use only one index & not the all?

Hope I have tried to put question more clearly.
(P.S. -Aapologies if this is a repeat question but I couldn't find answer to this when used search facility)
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Mon Nov 02, 2009 3:04 am
Reply with quote

Hello,

What did you tell the interviewer? What was the interviewer's reaction?
Back to top
View user's profile Send private message
shailesh_do

New User


Joined: 27 Jun 2006
Posts: 9

PostPosted: Mon Nov 02, 2009 8:51 pm
Reply with quote

Hi,

Actually I couldn't think of any answer to this one & when at the end of interview asked to the interviewer for this question he didn't tell me the answer.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Mon Nov 02, 2009 9:25 pm
Reply with quote

Hello,

One way to "trick the optimizer" is to specify an ORDER BY. . .
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Mon Nov 02, 2009 9:38 pm
Reply with quote

Quote:
as it should use only one index & not the all?


does not deserve an answer.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Mon Nov 02, 2009 10:03 pm
Reply with quote

Hi Dick,

Quote:
does not deserve an answer.
It is surely amazing where/how some of these "interview" questions originate. . .

I suppose that when you're new and looking for work, you have to put up with such. . .
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Mon Nov 02, 2009 11:03 pm
Reply with quote

A legitimate question of how coded sql can exclude indexes deserves an answer:

Craig Mullins, in the Db2 Developer's Guide (5th) comments:

Quote:
DB2 might be able to use an index-only access path that is unavailable for SELECT *.

Quote:
Why would the optimizer determine that an index should not be used? Aren't indexes designed to make querying tables more efficient? The optimizer decides that an index should not be used for one of two reasons. The first reason is when the table being accessed has only a small number of rows. Using an index to query a small table can degrade performance because additional I/O is required. For example, consider a tablespace consisting of one page. Accessing this page without the index would require a single I/O. But if you use an index, at least one additional I/O is required to read the index page. Even more I/O may be required if index root pages, index non-leaf pages, and additional index leaf pages must be accessed.

The second reason for not using an index is that, for larger tables, the organization of the index could require additional I/O to satisfy the query. Factors affecting this are the full and first key cardinality of the index and the cluster ratio of the index.

Quote:
append OR 0 = 1 to the predicate.

Quote:
code redundant predicates

Quote:
modifying DB2 Catalog statistics

Quote:
Using Optimization Hints (OPTHINT) to Force an Access Path


there is more discussion on all topics,
but the TS wanted a list,
not information about each item.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> Mainframe Interview Questions

 


Similar Topics
Topic Forum Replies
No new posts Cobol file using index COBOL Programming 2
No new posts Limiting delay with GETMSG CLIST & REXX 11
No new posts DL/I status code AK for GU call using... IMS DB/DC 1
No new posts Add column to existing records using ... JCL & VSAM 2
No new posts choice of clustering index DB2 3
Search our Forums:

Back to Top