DB2 Index

DB2 Index Storage Structure DB2 Precompilation Process

Advertisements


INDEX is the link to access the data from the database very quickly.

This index will decide the rows storing place based on the index type so that the data can be easily accessed without any delay.

CREATE INDEX used to create the INDEX.

SYSADM or SYSCTRL authority is required to create the index.

INDEX is an ordered set of pointers to the rows of table data.

DB2 uses indexes to uniqueness and improve the performance.

An index is stored separately from the data in table.

Index’s are physically stored in its index space.

An Index can be partitioned or non-partitioned.

Advantages:

  • To improve performance.
  • TAccess to data is faster.
  • TTo make sure that particular row is unique.
  • TTo cluster the data.
  • <
  • TTo determine the data partition.
  • TTo provide index only access to data.

Disadvantages:

  • Once the index is created, needs additional processing for inserting, updating and deleting index keys.
  • Once the index is created, needs to perform the explicit maintenance like -reorganizing etc,.

Syntax:

	CREATE UNIQUE INDEX index-name 
	ON table-name column-name 
	key-expression ASC/DESC/RANDOM
	NOT CLUSTER/CLUSTER
	PARTITIONED
	NOT PADDED/PADDED
	DEFINE YES/NO
	COMPRESS NO/YES
	PARTITION BY partition
	BUFFERPOOL bpname
	CLOSE YES/NO
	DEFER NO/YES
	PIECESIZE integer K/M/G
	COPY NO/YES

Key-Expression:

Is an index which has a key combination.

A Key combination has one or more columns.

ASC:

Arranges key combination columns of index in ascending order.

DESC:

Arranges key combination columns of index in descending order.

RANDOM:

Arranges key combination columns of index randomly.

CLUSTER/NOT CLUSTER:

Specifies that the index of a table is a clustered or not clustered.

CLUSTER – Used to specify the index as clustered.

NOT CLUSTER – Used to specify the index used should not be clustered.

PARTITIONED:

Specifies that the index is data partitioned.

The types of partitioned indexes are partitioned and secondary.

Portioned index can be created on partitioned table space.

PADDED/NOT PADDED:

Specifies how the variable length records are added to the index key.

NOT PADDED – Specifies variable length columns are not padded with their maximum length to the index key.

The length of variable length columns stored along with the key.

PADDED - Specifies variable length columns are padded with their maximum length to the index key.

DEFINE:

Specifies about underlying datasets for the index physically created.

The valid values are YES and NO.

If YES, the datasets will be created when index created.

If NO, the datasets will not be created until the data inserted into the table.

COMPRESS:

Specifies that the index needs to be compressed or not after creation.

The valid values are YES and NO.

If YES, index will be compressed.

If NO, index will not be compressed.

NO is the default value, if not specified.

PARTITION BY:

Specifies the partition of index will be used for the table.

Specifies the range of the partition.

BUFFERPOOL:

Specifies the buffer pool used of index.

CLOSE:

Specifies the data set can be closed when the indexes are not used or maximum open datasets can be reached.

The valid values are YES and NO.

If YES, the dataset is eligible for closing.

If NO, the dataset is not eligible for closing.

DEFER:

Specifies whether the index is build during the CREATE INDEX execution.

The valid values are YES and NO.

If YES, the index is not built during the CREATE INDEX execution.

If NO, the index is built during CREATE INDEX execution.

The default value is NO.

PIECESIZE:

Specifies the maximum memory for the data set of non-partitioned index.

K - Specifies in Kilo bytes.

M - Specifies in Mega bytes.

G - Specifies in Giga bytes.

COPY:

Specifies whether the copy utility allows for the index.

The valid values are YES and NO.

Index Types:


There are two types of indexes in the current system.

	• Clustered index
	• Non-clustered index

Let’s discuss about each one of them in detail.

1. Clustered Index:

The clustered index is defined on the table, then the rows will group together which have the similar index key.

This will happen during the insertion. So the access will be a bit faster than other index.

2. Non-clustered index:

This index is default index.

The rows will be inserted where the space exists and in the order how it is inserted.


DB2 Index Storage Structure DB2 Precompilation Process

Advertisements