Professional Documents
Culture Documents
Clusters
Index and Cluster Creation in SQL
Elisa Bertino
CS Department and CERIAS
Purdue University
1
Employees
Building
10 1100 D1 7977
Construction
3
Clustering
4
Clustering
6
Definition of clusters and indexes
in SQL
where
– IndexName is the name of the index being created
– The ON clause specifies the object on which the index is allocated
An index created on more than one column is called
composite index
7
Definition of clusters and indexes
in SQL
8
Definition of clusters and indexes in
SQL – Example
9
ASC and DESC Options
If the index is created on a single column, the two options do not make
any difference; the bidirectional-traversal capability of the index makes it
possible to use the index for queries that specify sorting of results in
either ascending or descending order of the sort column
If the index is composite, the ASC and DESC keywords might be
required
For example, if we want to optimize a SELECT statement whose
ORDER BY clause sorts on multiple columns and sorts each column in a
different order, and we want to use an index for this query, we need to
create a composite index that corresponds to the ORDER BY columns.
Example: SELECT salary, dept# FROM Employees ORDER BY salary
ASC, dept# DESC;
To use an index for this query we need to create an index that
corresponds to the order requirements of this query
CREATE INDEX sal_d_idx ON Employees (salary ASC, dept# DESC);
10
Definition of clusters and indexes
in SQL
11
Definition of clusters and indexes
in SQL
12
Definition of clusters and indexes
in SQL
13
Definition of clusters and indexes
in SQL – hash clusters
Index cluster:
CREATE CLUSTER Personnel(D# NUMBER);
16
Definition of clusters and indexes
in SQL – index clusters
18
Definition of clusters and indexes
in SQL - Example
19