Block indexes for MDC tables
This topic shows how records are organized in MDC tables using block indexes.
The MDC table shown in Figure 1 is
physically organized such that records having the same Region
and Year
values are grouped together into separate blocks,
or extents. An extent is a set of contiguous pages on disk, so these
groups of records are clustered on physically contiguous data pages.
Each table page belongs to exactly one block, and all blocks are of
equal size (that is, an equal number of pages). The size of a block
is equal to the extent size of the table space, so that block boundaries
line up with extent boundaries. In this case, two block indexes are
created, one for the Region
dimension, and another for the Year
dimension.
These block indexes contain pointers only to the blocks in the table.
A scan of the Region
block index for all records having Region
equal
to East
will find two blocks that qualify. All records, and
only those records, having Region
equal to East
will
be found in these two blocks, and will be clustered on those two
sets of contiguous pages or extents. At the same time, and completely
independently, a scan of the Year
index for records between
1999 and 2000 will find three blocks that qualify. A data scan
of each of these three blocks will return all records and only those
records that are between 1999 and 2000, and will find these records
clustered on the sequential pages within each of the blocks.

In addition to these clustering improvements, MDC tables provide the following benefits:
- Probes and scans of block indexes are much faster due to their incredibly small size in relation to record-based indexes
- Block indexes and the corresponding organization of data allows
for fine-grained
database partition elimination
, or selective table access - Queries that utilize the block indexes benefit from the reduced index size, optimized prefetching of blocks, and guaranteed clustering of the corresponding data
- Reduced locking and predicate evaluation is possible for some queries
- Block indexes have much less overhead associated with them for logging and maintenance because they only need to be updated when adding the first record to a block, or removing the last record from a block
- Data rolled in can reuse the contiguous space left by data previously rolled out.
When you create a table, you can specify one or more keys as dimensions along which to cluster the data. Each of these MDC dimensions can consist of one or more columns similar to regular index keys. A dimension block index will be automatically created for each of the dimensions specified, and it will be used by the optimizer to quickly and efficiently access data along each dimension. A composite block index will also automatically be created, containing all columns across all dimensions, and will be used to maintain the clustering of data over insert and update activity. A composite block index will only be created if a single dimension does not already contain all the dimension key columns. The composite block index may also be selected by the optimizer to efficiently access data that satisfies values from a subset, or from all, of the column dimensions.
Block indexes are structurally the same as regular indexes, except that they point to blocks instead of records. Block indexes are smaller than regular indexes by a factor of the block size multiplied by the average number of records on a page. The number of pages in a block is equal to the extent size of the table space, which can range from 2 to 256 pages. The page size can be 4 KB, 8 KB, 16 KB, or 32 KB.

As seen in Figure 2, in a block index there is a single index entry for each block compared to a single entry for each row. As a result, a block index provides a significant reduction in disk usage and significantly faster data access.
In an MDC table, every unique combination of dimension values form a logical cell, which may be physically made up of one or more blocks of pages. The logical cell will only have enough blocks associated with it to store the records having the dimension values of that logical cell. If there are no records in the table having the dimension values of a particular logical cell, no blocks will be allocated for that logical cell. The set of blocks that contain data having a particular dimension key value is called a slice.
- For a partitioned MDC table created with Db2® Version 9.7 Fix Pack 1 or later releases, the block indexes on the table are partitioned.
- For a partitioned MDC table created with Db2 V9.7 or earlier releases, the block indexes on the table are nonpartitioned.
Nonpartitioned block index are supported after upgrading the database to Db2 V9.7 Fix Pack 1 or later releases.