| View previous topic :: View next topic | 
	
	
		| Author | Message | 
	
		| NASCAR9 Intermediate
 
 
 Joined: 08 Oct 2004
 Posts: 274
 Topics: 52
 Location: California
 
 | 
			
				|  Posted: Tue Apr 19, 2005 10:37 am    Post subject: Creating Index Columns |   |  
				| 
 |  
				| 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 |  | 
	
		|  | 
	
		| kolusu Site Admin
 
  
 
 Joined: 26 Nov 2002
 Posts: 12394
 Topics: 75
 Location: San Jose
 
 | 
			
				|  Posted: Tue Apr 19, 2005 12:49 pm    Post subject: |   |  
				| 
 |  
				| 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 |  | 
	
		|  | 
	
		| NASCAR9 Intermediate
 
 
 Joined: 08 Oct 2004
 Posts: 274
 Topics: 52
 Location: California
 
 | 
			
				|  Posted: Tue Apr 19, 2005 2:04 pm    Post subject: |   |  
				| 
 |  
				| 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 |  | 
	
		|  | 
	
		| kolusu Site Admin
 
  
 
 Joined: 26 Nov 2002
 Posts: 12394
 Topics: 75
 Location: San Jose
 
 | 
			
				|  Posted: Tue Apr 19, 2005 2:36 pm    Post subject: |   |  
				| 
 |  
				|  	  | 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 |  | 
	
		|  | 
	
		| NASCAR9 Intermediate
 
 
 Joined: 08 Oct 2004
 Posts: 274
 Topics: 52
 Location: California
 
 | 
			
				|  Posted: Tue Apr 19, 2005 2:54 pm    Post subject: |   |  
				| 
 |  
				| 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 |  | 
	
		|  | 
	
		| bauer Intermediate
 
 
 Joined: 10 Oct 2003
 Posts: 317
 Topics: 50
 Location: Germany
 
 | 
			
				|  Posted: Wed Apr 20, 2005 6:32 am    Post subject: |   |  
				| 
 |  
				| 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 |  | 
	
		|  | 
	
		| NASCAR9 Intermediate
 
 
 Joined: 08 Oct 2004
 Posts: 274
 Topics: 52
 Location: California
 
 | 
			
				|  Posted: Wed Apr 20, 2005 6:42 pm    Post subject: |   |  
				| 
 |  
				| 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 |  | 
	
		|  | 
	
		|  | 
	
		|  |