Indexes
Indexes are used to enforce unique constraints on one or multiple properties under the same entity. This ensures that the generated data is unique and can be used to identify each record uniquely. An index can be defined using the following properties:
- id: [required] It should be a non-negative integer. All properties with the same id value are regarded as one index. When its value is 0 and only a single
sequence
type property is included in the index, it generates a sequence starting with 1. This sequence serves a similar purpose as a primary key in a database table. - type: A predefined integer value with 0 as the default value. The allowed values are:
- 0: Regular index
- 1: Set index
- 2: Non-circular index
- 3: Ordered non-circular index
- 4: Distinct element index
- qualifier: An integer. It is only used when applying to a non-circular index or an ordered non-circular index. The allowed values for qualifiers are 1 and 2. When applying to a distinct element value index, the allowed value is 1.ly used when applying to non circular index or ordered non circular index, the allowed values are 1 and 2. When applying to distinct element value index, the allowed value is 1.
Properties with correlation constraints or alternation constraints are considered deferred properties. They should not be included in an index because their values are not available when the index is calculated.
Regular Index
A regular index is simply a unique combination of property values.
- Sample Regular Index
- Sample Output
properties:
- name: "product_id"
type: "sequence"
index:
id: 1
- name: "order_id"
type: "sequence"
index:
id: 1
[
{"product_id": 1, "order_id": 1},
{"product_id": 2, "order_id": 1},
{"product_id": 1, "order_id": 2},
{"product_id": 2, "order_id": 3},
{"product_id": 3, "order_id": 2}
]
Set Index
A set index is used to generate unique combinations of property values, regardless of the property order. For example, when the index values are [1, 2] and [2, 1], they are treated as duplicates.
- Sample Set Index
- Sample Output
properties:
- name: "product_id"
type: "sequence"
index:
id: 1
type: 1
- name: "order_id"
type: "sequence"
index:
id: 1
type: 1
[
{"product_id": 1, "order_id": 1},
{"product_id": 2, "order_id": 1},
{"product_id": 2, "order_id": 3}
]
Non-circular Index
A non-circular index treats each index entry as a branch of a graph. Each branch has a direction from parent to child, with a qualifier value of 1 identifying a parent and 2 identifying a child. A newly generated index is accepted only if the following two conditions are met:
- The new branch won’t create a cycle with existing values. For example, [1, 1] creates a cycle to itself, and [1, 2] or [2, 1] creates another cycle.
- The new branch won’t result in multiple parents for the same child. For instance, in the case of
[{“parent_id”: 1, “child_id”: 3}, {“parent_id”: 2, “child_id”: 3}]
, child_id 3 has two parent_ids: 1 and 2.
- Sample Non-circular Index
- Sample Output
properties:
- name: "parent_id"
type: "sequence"
index:
id: 1
type: 2
qualifier: 1
- name: "child_id"
type: "sequence"
index:
id: 1
type: 2
qualifier: 2
[
{"parent_id": 2, "child_id": 1},
{"parent_id": 2, "child_id": 3}
]
For a non-circular index, qualifier values 1 and 2 should be used in pairs and only once.
Ordered Non-circular Index
An ordered non-circular index is a non-circular index with an additional constraint that ensures the parent ID defined in the index entry is less than the value of the child ID. A sample usage could be to organize a list of comment records that were posted in sequence and replied to each other.
- Sample Ordered Non-circular Index
- Sample Output
properties:
- name: "parent_id"
type: "sequence"
index:
id: 1
type: 3
qualifier: 1
- name: "child_id"
type: "sequence"
index:
id: 1
type: 3
qualifier: 2
[
{"parent_id": 2, "child_id": 4},
{"parent_id": 2, "child_id": 3}
]
To use an ordered non-circular index, the data type of properties used as both parent and child should be same and comparable.
Distinct Element Index
The distinct element index does not allow duplicated values for any marked properties in the index. To mark a property, the qualifier is set to 1. If there are no properties with the qualifier set to 1, the distinct element index works the same as a regular index.
- Distinct Element Index
- Sample Output
properties:
- name: "from"
type: "sequence"
index:
id: 2
type: 4
qualifier: 1
- name: "to"
type: "sequence"
index:
id: 2
type: 4
qualifier: 1
[
{"from": 2, "to": 3},
{"from": 3, "to": 2}
]
Our generator assumes that properties marked by the qualifier have the same data type. To simplify the data type check, the string values of the desired properties are used to guarantee uniqueness.