-
Notifications
You must be signed in to change notification settings - Fork 43
Closed
Labels
featureA new functionalityA new functionalityreference[location] Tarantool manual, Reference part[location] Tarantool manual, Reference partserver[area] Task relates to Tarantool's server (core) functionality[area] Task relates to Tarantool's server (core) functionalityuser_guide[location] Tarantool manual, User's Guide part[location] Tarantool manual, User's Guide part
Description
Any JSON index in which at least one partition contains "[*]" (array index placeholder) sign is called a "Multikey". Such indexes allow you to automatically index set of documents sharing the same document structure.
Multikey indexes design have a number of restrictions which must
be taken into account:
- Since multikey indexes allow a tuple to appear multiple times, it is prohibited for such an indexes to be a primary key.
- If a node in a JSON tree of all defined indexes contains an array index placeholder, no other JSON path can use an explicit JSON index on it's nested field.
- It support "unique" semantics, but it's uniqueness a little different from conventional indexes: you may insert a tuple in which the same key occurs multiple times into a unique multikey index, but you cannot insert a tuple when any of its keys appear in other tuple stored in a space.
- The unique multikey index "duplicate" conflict occurs when the sets of extracted keys have a non-empty logical intersection
- To identify different keys by which a given datum in a tuple is indexed, each key is assigned a logical sequence number in an array defined with array index placeholder in index. Such array is called multikey index root
- No index partition can contain more than one array index placeholder sign in it's JSON path,
- All parts containing JSON paths with array index placeholder must have the same (in terms of JSON tokens) prefix before this placeholder sign.
Example 1:
s = box.schema.space.create('clients')
s:format({{name='name', type='string'}, {name='phone', type='array'}})
name_idx = s:create_index('name_idx', {parts = {{'name', 'string'}}})
phone_idx = s:create_index('phone_idx', {parts = {{'phone[*]',
'string'}}})
s:insert({"Jorge", {"911", "89457609234"}})
s:insert({"Bob", {"81239876543"}})
phone_idx:get("911")
---
- ['Jorge', ['911', '89457609234']]
...
Example 2:
s = box.schema.space.create('withdata')
pk = s:create_index('pk')
parts = {
{2, 'str', path = 'data[*].name'},
{2, 'str', path = 'data[*].extra.phone'}
}
idx = s:create_index('idx', {parts = parts})
s:insert({1, {data = {{name="A", extra={phone="111"}},
{name="B", extra={phone="111"}}},
garbage = 1}}
idx:get({'A', '111'})
Requested by @kshcherbatov in tarantool/tarantool@f1d9f25.
Metadata
Metadata
Assignees
Labels
featureA new functionalityA new functionalityreference[location] Tarantool manual, Reference part[location] Tarantool manual, Reference partserver[area] Task relates to Tarantool's server (core) functionality[area] Task relates to Tarantool's server (core) functionalityuser_guide[location] Tarantool manual, User's Guide part[location] Tarantool manual, User's Guide part