MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Creating Index Columns

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
NASCAR9
Intermediate


Joined: 08 Oct 2004
Posts: 274
Topics: 52
Location: California

PostPosted: Tue Apr 19, 2005 10:37 am    Post subject: Creating Index Columns Reply with quote

Is the Index on SSNO redundant?
Code:

CREATE UNIQUE INDEX HOURS.XPRMLT1
       ON HOURS.PREMLETTER       
      (SSNO,MONTH_CNT,MAILDATE)   
       USING STOGROUP FSGALLP     
       PRIQTY 12000               
       SECQTY 400                 
       CLUSTER                   
       BUFFERPOOL BP5             
       CLOSE NO;                 
                                 
                                 
CREATE INDEX HOURS.XPRMLT4       
       ON HOURS.PREMLETTER       
      (SSNO)                     
       USING STOGROUP FSGALLP     
       PRIQTY 12000               
       SECQTY 400                 
       BUFFERPOOL BP5             
       CLOSE NO;
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12376
Topics: 75
Location: San Jose

PostPosted: Tue Apr 19, 2005 12:49 pm    Post subject: Reply with quote

nascar9,

I don't think the index will reduntant. But change the definitions with ASC clause and type2 as shown below.

Code:

CREATE TYPE 2 UNIQUE INDEX HOURS.XPRMLT1
ON HOURS.PREMLETTER
(SSNO             ASC
 ,MONTH_CNT       ASC
 ,MAILDATE        ASC
)
USING STOGROUP FSGALLP
PRIQTY 12000
SECQTY 400
CLUSTER
BUFFERPOOL BP5
CLOSE NO;


Code:

CREATE TYPE 2 UNIQUE INDEX HOURS.XPRMLT4
ON HOURS.PREMLETTER
(SSNO             ASC   
)     
USING STOGROUP FSGALLP
PRIQTY 12000
SECQTY 400
BUFFERPOOL BP5
CLOSE NO;


Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
NASCAR9
Intermediate


Joined: 08 Oct 2004
Posts: 274
Topics: 52
Location: California

PostPosted: Tue Apr 19, 2005 2:04 pm    Post subject: Reply with quote

Koluso,
I'm not familiar with 'TYPE 2' so I checked the SQL Reference and it said,
"TYPE 2 specifies a type 2 index. The TYPE 2 clause is not required. A type 2 index is always created."

Also, you coded 'UNIQUE' on both indexes, index XPRMLT4 is a secondary index on PREMLETTER, and XPRMLT1 is the UNIQUE index. Am I missing something?

Thanks,
NASCAR9
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12376
Topics: 75
Location: San Jose

PostPosted: Tue Apr 19, 2005 2:36 pm    Post subject: Reply with quote

Quote:

I'm not familiar with 'TYPE 2' so I checked the SQL Reference and it said,
"TYPE 2 specifies a type 2 index. The TYPE 2 clause is not required. A type 2 index is always created."


Nascar9,

Prior to DB2 Version 6 IBM allowed 2 types of indexes TYPE 1 and TYPE 2. From version 6 onwards they made a default. So you really don't need the type 2 clause.

Quote:

Also, you coded 'UNIQUE' on both indexes, index XPRMLT4 is a secondary index on PREMLETTER, and XPRMLT1 is the UNIQUE index. Am I missing something?


I specified Unique phrase on both to ensure the UNIQUE SSNO. If you have UNIQUE only on the primary index then you will have Duplicate SSNO as the combination of SSNO,MONTH_CNT and MAILDATE can result in duplicate SSNO.

Also creating 2 indexes will let you access the table using SSNO or MONTH_CNT or MAILDATE.

Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
NASCAR9
Intermediate


Joined: 08 Oct 2004
Posts: 274
Topics: 52
Location: California

PostPosted: Tue Apr 19, 2005 2:54 pm    Post subject: Reply with quote

Kolusu, The combination of SSNO, MONTH_CNT, and MAILDATE make the key. A SSNO can be in this table more than once with MONTH_CNT or MAILDATE set to a different value.
SSNO is indexed for faster retrieval. That was the reason for my post. I
Back to top
View user's profile Send private message
bauer
Intermediate


Joined: 10 Oct 2003
Posts: 315
Topics: 49
Location: Germany

PostPosted: Wed Apr 20, 2005 6:32 am    Post subject: Reply with quote

Hi all,

index HOURS.XPRMLT4 doen't make sense for me.

If only SSNO is available in the where clause of your select DB2 uses index HOURS.XPRMLT1 with matchcols = 1. So HOURS.XPRMLT4 is not necessary.

BUT: The situation depends on the statistic data, cardinality, number of Rows matching SSNO only vs. number of Rows matching SSNO and the other fields.

So is can make sense for Db2 to uses index HOURS.XPRMLT4.

Check the getpagerate, statistic data, use explain command !

regards,
bauer
Back to top
View user's profile Send private message
NASCAR9
Intermediate


Joined: 08 Oct 2004
Posts: 274
Topics: 52
Location: California

PostPosted: Wed Apr 20, 2005 6:42 pm    Post subject: Reply with quote

Thanks bauer! I think what yourself and Kolusu have explained has helped. I'm not a DBA but seem to have many DBA responsibilities. We
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database 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


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group