Enforcing unique-index constraints

The UNIQUE or DISTINCT keyword in a CREATE INDEX or insert statement specifies that a secondary access method cannot insert multiple occurrences of a key value. The UNIQUE or DISTINCT keyword in a SELECT statement specifies that the access method must return only one occurrence of a key value.

To provide support for unique keys:

  1. Program the am_insert purpose function to scan an index before it inserts each new entry and raise an exception for a key value that the index already contains.
  2. Program the am_getnext purpose function to return only one occurrence of a key.
  3. Set the am_unique purpose flag.