You can use the indexes clause to define a primary index, primary AMP index, partitioning, and a set of secondary indexes for the join index.
You can use this clause with multitable and single-table join indexes.
PRIMARY INDEX
A primary index defined on the join index. The primary index for an aggregate join index must be from the columns specified in the GROUP BY clause of the join index definition. You cannot specify aggregated columns as part of the primary index. If the primary index is not compressed, you can define it as a single-level or multilevel row partitioned primary index by specifying one or more partitioning expressions. You cannot partition the primary index of a join index if the index is defined with compression.
- The partitioning columns for an aggregate join index must be drawn from the columns specified in the GROUP BY clause of the join index definition.
- You cannot specify an aggregated column as a partitioning column for the PPI.
- The partitioning level in a join index acts as a constraint on its underlying base tables. If an insert, delete, or update operation on a base table causes a partition violation in the join index by making one or more of the partitioning expressions evaluate to null, the request returns an error message, and neither the base table nor the join index is updated.
- If a join index definition includes an outer join, deleting base table rows may cause inserts into that join index for the unmatched rows.
- For your partitioned join indexes, you must define partitioning levels that do not prevent rows from being inserted into, updated, or deleted from the base tables when required.
- If you do not define an explicit NUPI, the first column defined for the join index is assigned to be the NUPI by default. You can define an uncompressed join index with a partitioned primary index. However, the primary index cannot be partitioned if the join index is compressed.
- Each NUSI counts toward the maximum number of 32 secondary indexes that you can define on a join index. Each multicolumn NUSI defined with an ORDER BY clause counts as two consecutive indexes against the limit of 32 per join index.
- XML
- Geospatial
- Derived Period
- Period
- UNIQUE
- You can define a unique primary index for an uncompressed single-table join index, but the primary index for any other join index must be nonunique even when it is defined on a unique column.
- index_name
- The optional name of the primary being defined. For information about naming database objects, see Object Names.
- (primary_index_column)
- Names of the primary index columns. For a composite primary index, primary_index_column indicates a comma-separated list of all the index columns in parenthesis. You cannot specify the begin or end columns of a derived period column in a primary index.
PRIMARY AMP
Add a primary AMP index.
Rows are hash-distributed to AMPs for a column-partitioned table or join index. Column partition values are ordered on each AMP by an internal partition number and a row hash for a column-partitioned table or join index.
If a PRIMARY AMP clause is specified, you must specify a PARTITION BY clause that includes a column-partitioning level, either in the PRIMARY AMP clause or by itself in the index list.
- INDEX
- Optionally, the INDEX keyword can be specified with AMP for readability.
- index_name
- Name of the primary AMP index. For information about naming database objects, see Object Names.
- (index_column_name)
- The primary AMP index columns. For a composite primary index, index_column_name indicates a comma-separated list of all the index columns in parenthesis. You cannot specify the begin or end columns of a derived period column in a primary index.
Example: Join Index with a Primary AMP Index and Column Partitioning
This example assumes the following table has been created:
CREATE TABLE t1 (a INT, b INT, c INT, d INT) PRIMARY INDEX (a);
The following CREATE JOIN INDEX statements are equivalent:
CREATE JOIN INDEX jt1_1 AS SELECT ROWID AS rw, a, b FROM t1 WHERE a<10 PRIMARY AMP (a) PARTITION BY COLUMN (rw NO AUTO COMPRESS, ROW(a,b));
CREATE JOIN INDEX jt1_1 AS SELECT ROWID AS rw, a, b FROM t1 WHERE a<10 PRIMARY AMP INDEX (a) PARTITION BY COLUMN (rw NO AUTO COMPRESS, ROW(a,b));
Example: Join Index with a Primary Index and Partitioning by Row and Column
This example assumes the following table has been created:
CREATE TABLE t1 (a INT, b INT, c INT, d INT) PRIMARY INDEX (a);
This example shows a CREATE JOIN INDEX statement with a primary index and partitioned by row and column:
CREATE JOIN INDEX jt1_4 AS SELECT ROWID rw, a, b, d FROM t1 PRIMARY INDEX (a) PARTITION BY (RANGE_N(b BETWEEN 1 AND 1000 EACH 1), COLUMN);
NO PRIMARY
The join index is defined with no primary index or primary AMP index.
You cannot specify NO PRIMARY if you specify UNIQUE PRIMARY INDEX or PRIMARY INDEX.
The NO PRIMARY specification is optional for column-partitioned join indexes. The default is no primary index.
If the preceding item in the index list is a partitioning clause that is not part of an index clause, you must specify a COMMA character preceding NO PRIMARY. Otherwise, the comma is optional.
You cannot specify a column name list following a NO PRIMARY specification.
If the preceding item in the index list is a partitioning clause that is not part of an index clause, you must specify a COMMA character preceding NO PRIMARY INDEX. Otherwise, the comma is optional.
See Primary Index Defaults for the complete set of rules that control primary index defaults.
PARTITION BY
The join index is partitioned by one or more partitioning levels. You can define either a single-level or multilevel partitioning for a join index, but only if the index is not row-compressed.
You cannot specify a PARTITION BY clause in the same join index definition as an ORDER BY CLAUSE.
You cannot collect statistics on the system-derived PARTITION#L n columns for a join index.
- partitioning expression
- Defines partitions for the level. You can also specify the ADD keyword for a partitioning level. For more information about partitioning tables and join indexes, see When Join Indexes Are Useful . If the preceding item in the index list is a partitioning clause that is not part of an index clause, you must specify a COMMA character following the PARTITION BY clause. Otherwise, the comma is optional. You can define multilevel partitioning for an uncompressed join index, with as many as 62 partitioning levels. Each level must be defined by a RANGE_N or CASE_N function or by the COLUMN keyword. You cannot specify character partitioning expressions for columns or constants that use the Kanji1 or KanjiSJIS server character sets. The result of a partitioning expression that is not a RANGE_N or CASE_N function is cast to an INTEGER, if it is not already an INTEGER. The value must be from 1 through 65,535. A RANGE_N or CASE_N function is only allowed for single-level partitioning. The maximum number of partitioning levels that you can specify for a join index with 2-byte partitioning is 15. The maximum number of partitioning levels that you can specify for a join index with 8-byte partitioning is 62. A partitioning expression for a join index must be a deterministic expression and cannot specify external or SQL UDFs or columns having any of the following data types:
- ARRAY
- VARRAY
- BLOB
- CLOB
- Geospatial
- COLUMN
- Keyword to indicate partitioning level.
- AUTO COMPRESS
- NO AUTO COMPRESS
- To enable or disable autocompression:
- If you specify AUTO COMPRESS for a column partitioning level in a PARTITION BY clause, the system applies autocompression for a column partition unless the you explicitly specify NO AUTO COMPRESS. This is the default.
- If you specify NO AUTO COMPRESS for a column partitioning level in a PARTITION BY clause, the system does not apply autocompression for a column partition unless you explicitly specify AUTO COMPRESS.
- ALL BUT (column_name_list)
- ALL BUT (column_group_list)
- A multicolumn partition with autocompression and system-determined COLUMN or ROW format that includes all of the columns in the join index definition that are not specified in column_name_list or column_group_list.
- COLUMN
- Specifies that the join index has a column-partitioned level.
- ROW
- Specifies that a column partition has ROW format. A ROW format means that only one column-partition value is stored in a physical row as a subrow.
- ADD constant
- The maximum number of partitions for a partitioning level is the number of partitions it defines plus the value of constant.
INDEX
A set of nonunique secondary indexes defined on the join index.
- index_name
- The optional name of the NUSI being defined. For information about naming database objects, see Object Names.
- ALL
- The defined NUSI is to maintain Row ID pointers for each logical row of the join index, instead of only the compressed physical rows.
- index_column_name
- A column set whose values are to be an index on this join index. If you specify more than one column, the new index is based on the combined values of each column.
- ORDER BY
- Row ordering on each AMP by a single NUSI column. The ordering of the NUSI column values can either value-ordered or hash-ordered. Each multicolumn NUSI defined with an ORDER BY clause counts as two consecutive indexes against the limit of 32 per join index. You cannot specify an ORDER BY clause in the same join index definition as a partitioned primary index.
- VALUES
- Value-ordering for the ORDER BY column. This is the default specification.
- HASH
- Hash-ordering for the ORDER BY column.
- order_column_name
- A column in the select list that specifies the sort order to be used for NUSI ordering.