Home      Mainframe Forum      Mainfarme Tutorials      IBM Manuals      Mainframe Interview Questions      Mainframe Books      IT News     SiteMap     Downloads


     
 
MAINFRAME - TIP OF THE DAY : programming pearls - The fastest algorithm can frequently be replaced by one that is almost as fast and much easier to understand.

Google
 
Web mainframegurukul.com

Welcome to the mainframegurukul forums.

You are currently viewing our mainframe forums as a guest which gives you limited access to view most discussions, articles. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support at admin@mainframegurukul.com


Using Index

 
Post new topic   Reply to topic    mainframegurukul.com Forum Index -> DB2 SQL - DB2 PROGRAMMING
  View previous topic :: View next topic  
Author Message
arrbee
Active Member


Joined: 24 Feb 2006
Posts: 147

PostPosted: Sun Jun 11, 2006 11:37 am    Post subject: Using Index Reply with quote

1). How do we know whether a SELECT query is using INDEX or not?
2). How can we say that a SELECT query is optimized or not? My guess is that before using that query in an embedded SQL we can run EXPLAIN on that. Can anybody explain the details?
3). How to use a TEST region program to run in DB2 PROD region using PROD tables, data?

TIA.
_________________
Arr Bee
-------------
?My joy in learning is partly that it enables me to teach? - Seneca(Roman philosopher, mid-1st century AD)
Back to top
View user's profile Send private message Send e-mail

Kalicharan
Moderator


Joined: 08 Feb 2006
Posts: 31

PostPosted: Thu Jul 06, 2006 12:07 pm    Post subject: Reply with quote

Hi,

1). How do we know whether a SELECT query is using INDEX or not?

EXPLAIN tells you if an index access or tablespace scan is used.
If indexes are used, EXPLAIN tells you how many indexes and
index columns are used and what I/O methods are used to read the pages.

Before you can use EXPLAIN, you must create a table called PLAN_TABLE to hold the results of EXPLAIN.

ACCESSTYPE keyword of PLAN_TABLE tells the method of accessing the table:
I ==> an index (identified in ACCESSCREATOR and ACCESSNAME)
I1 ==> a one-fetch index scan
N ==> By an index scan when the matching predicate contains the IN keyword
R ==> By a table space scan
M ==> By a multiple index scan (followed by MX, MI, or MU)
MX ==> By an index scan on the index named in ACCESSNAME
MI ==> By an intersection of multiple indexes
MU ==> By a union of multiple indexes
blank Not applicable to the current row

2). How can we say that a SELECT query is optimized or not? My guess is that before using that query in an embedded SQL we can run EXPLAIN on that. Can anybody explain the details?
Based on
a)Predicates
b)Predicate filter factor
c)Indexing
d)Usage of Subquery
e)Access path selection etc
we can determine whether the SELECT query is optimized or not.

EXPLAIN
As we know that DB2 optimizer chooses the access path for the query.
If we want to know what access path DB2 chooses during the plan preparation, then the request should be placed to DB2.
The request can be done in two ways.

Method 1: Use EXPLAIN(YES) parameter in the BIND card.

SELECT * from ownerid.PALN_TABLE order by APPLNAME,COLLID,VERSION,PROGRAME,TIMESTAMP DESC, QUERYNO,QBLOCKNO,PLANNO

Method 2: Use the following command directly in the program or in SPUFI or QMF.

Syntax: EXPLAIN ALL SET QUERYNO=integer FOR SQL-statement.

Before executing the request, there should be a PLAN_TABLE under the user-id, based on model SYSIBM.PLAN_TABLE is a standard table that must be defined with predetermined columns, data types and lengths. During bind process, DB2 optimizer briefs the access path chose by it in the PLAN_TABLE.

If you want to query the access path for single query then use the query below:
SELECT * from PLAN_TABLE where QUERYNO=integer ORDERBY QBLOCKNO, PLANNO.
Now the access path taken by the optimizer is loaded into PLAN_TABLE. Knowing the meaning of PLAN_TABLE columns and values
is very important to understand the access path.
DB2V7 has 49 columns in PLAN_TABLE.
Important Columns in the PLAN_TABLE are
QUERYNO
QBLOCKNO
APPLNAME
PROGRAME
PLANNO
METHOD
ACCESSTYPE
MATCHCOLS
INDEXONLY
PREFETCH
QBLOCK_TYPE
JOIN_TYPE
TIMESTAMP



3). How to use a TEST region program to run in DB2 PROD region using PROD tables, data?
Change the BIND CARD(Package, Plan, Owner, Qualifier) and other datasets accordingly.


Thanks,
Kalicharan
Back to top
View user's profile Send private message Send e-mail
arrbee
Active Member


Joined: 24 Feb 2006
Posts: 147

PostPosted: Mon Jul 10, 2006 10:52 am    Post subject: Reply with quote

Thanks Kali. The answers are very helpful.
_________________
Arr Bee
-------------
?My joy in learning is partly that it enables me to teach? - Seneca(Roman philosopher, mid-1st century AD)
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    mainframegurukul.com Forum Index -> DB2 SQL - DB2 PROGRAMMING All times are GMT + 5 Hours
Page 1 of 1



 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Related topics
 Topics   Replies   Author   Views   Last Post 
No new posts Practice/Mock Test - DB2 9 Family Fundamentals (000-730) 3 zh_lad 1013 Wed Jun 03, 2009 5:43 pm
dbzTHEdinosauer View latest post
No new posts How to test a empty file through JCL 2 kapil agarwal 2303 Sun Mar 22, 2009 11:20 pm
Frank Yaeger View latest post
No new posts Z/OS Mastery test 1 getu_mfsys 819 Tue Mar 17, 2009 3:52 pm
Anuj Dhawan View latest post
No new posts What is programming proficiency test .... 2 naresh.bangalore 1493 Fri Nov 02, 2007 10:30 am
naresh.bangalore View latest post
No new posts test datase empty 7 nick.mamone 5065 Wed Nov 22, 2006 6:42 pm
justaprogrammer View latest post
 



This widget requires Flash Player 9 or better








Go to top of the page
 

Online ABEND Reference ||  JCL References ||  COBOL References ||  VSAM References ||  Tutorials by Drona Series ||  SQL tutorial ||  BOOKS  ||  DB2 INTERVIEW QUESTIONS ||  COBOL INTERVIEW QUESTIONS  ||  JCL INTERVIEW QUESTIONS ||  JCL2 INTERVIEW QUESTIONS ||  VSAM INTERVIEW QUESTIONS ||  CICS INTERVIEW QUESTIONS  ||  Online tutorials ||  Online ABEND Reference ||  JCL References ||  COBOL References ||  VSAM References ||  Tutorials by Drona Series ||  SQL tutorial ||  BOOKS  ||  SiteMap  ||  Expeditor Tutorial  ||  FILE-AID Tutorial  ||  Changeman Tutorial  ||  COBOL   ||  DB2   ||  JCL  ||  CICS  ||  VSAM  ||  DB2 Interview Questions ( 110 )   || Simple JCL Tutorials  || JCL Tutorial from MainframeGurukul.com   || Simple JCL Tutorial - Chapter1 ;|| Mainframe Forum - Tutorials  || Mainframe Tutorials

Drona Educational Forums - Mainframe Cobol DB2 CICS Board
Powered by phpBB