tarantool / tarantool/doc

Covering secondary indexes support in memcs.

Open
#4,999 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

memcs
Dominant language
CSS
Stars
15
Forks
49
Avg merge
1d 13h
Merged PRs (30d)
3

Description

Memcs engine now supports secondary indexes.

We support next options for secondary indexes:

  • unique for index
  • is_nullable for index parts
  • exclude_null for index parts

Secondary index creation is possible for both empty and non-empty space.
So is secondary index altering. All modifying space and primary index
operations are supported when there are secondary indexes. The secondary
index itself supports same set operations as primary index with a few
exceptions. We do not support index:delete and index:update for
secondary indexes yet.

Secondary index is covering, that is it keeps only a subset of columns
of the primary index (see new covers option below). Yet all reading
index operations, that return full tuple for primary index, return full
tuple for secondary index too. It is possible because index always
covers columns of primary index key. This has impact on performance.
index:get requires additional search in primary index and
index:pairs and index:select require same search on every returned
tuple. Thus iteration over secondary index is much slower than over
primary index. Yet as secondary index scanning is possible only over
covered columns, it has same performance as primary index scan.

New index covers options specifies the subset of columns for the
secondary index. Example:

space:create_index('pk', {parts = {1})
space:create_index('sk', {parts = {2}, covers = {10, 15}})

The columns in covers can be specified as 1-based field number or
field name. The order of fields is not significant. The columns of
index key and the primary index key are implicitly covered, howevery it
is not an error to specify them explicitly.

Covered columns are visible in index info:

---
- unique: true
  parts:
  - fieldno: 2
    sort_order: asc
    type: unsigned
    exclude_null: false
    is_nullable: false
  covers: [1, 2, 10, 15]
  id: 1
  space_id: 512
  type: TREE
  name: sk
...

Requested by @nshy in https://github.com/tarantool/tarantool-ee/commit/efaf5ff38cde4a0e015b95f6fd4962493d68523f.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the existing documentation for space:create_index and the index:get, index:pairs, and index:select entry points. Compare the documented index options and operations with the secondary-index behavior described here, including covers, unique, is_nullable, and exclude_null. Done means the supported operations, limitations, covering rules, and index-info example are clearly documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua
Domain
databases, documentation
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.