Document `index:quantile()`
Nobody has claimed this yet.
- Dominant language
- CSS
- Stars
- 15
- Forks
- 49
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 3
Description
Related dev. issue(s): https://github.com/tarantool/tarantool/issues/11111
Product: Tarantool
Since: 3.4
Root document: https://www.tarantool.io/en/doc/latest/reference/reference_lua/box_index/
SME: @ locker
Details
Scope:
- Add a new article on
quantile(same level ascount,min,max, etc.). - Add the record to the table in https://www.tarantool.io/en/doc/latest/reference/reference_lua/box_index/
The new index method finds a quantile point in an indexed data range.
It takes the quantile level (0 < L < 1) and optionally the target range
boundaries and returns such a key that the ratio of tuples less than
the key equals L.
Example:
local s = box.schema.space.create('test')
s:create_index('pk')
for i = 1, 100 do
s:insert({i * i, i})
end
-- Find the median in the whole index.
s.index.pk:quantile(0.5) -- returns {2601}
-- Find the 90th percentile among all keys < 1000
s.index.pk:quantile(0.9, {}, {1000}) -- returns {784}
The target range is defined as the intersection of the following read
requests:
s:select(begin_key, {iterator = 'ge'})
s:select(end_key, {iterator = 'lt'})
This means that using the empty key {} or nil for both begin_key
and end_key finds the quantile in the whole index. The function raises
an error if there can't possibly be any tuples in the target range, i.e.
if key_begin >= key_end.
The function returns nil if there are no tuples in the target
range or if it failed to find the quantile due to the limitations of
the storage engine, which are described below.
The function is implemented by memtx and vinyl tree indexes only.
In memtx the function returns the quantile point exactly. It has
the logarithmic complexity. It may return nil only if there are
no tuples in the target range. There's guaranteed to be a tuple
in the target range corresponding to the returned key.
The vinyl implementation returns the quantile point with a reasonable
degree of error for performance considerations. It has the logarithmic
complexity as well. There may or may not be a tuple in the target
range corresponding to the returned key. The function may return nil
even if the target range is not empty, in particular, if there are
no disk layers or if the range is smaller than the vinyl page size.
The function doesn't yield.
The function doesn't participate in transactions.
Like other index methods, index:quantile() can be used through
a space object as space:quantile(), in which case it works as
a shortcut for the primary index.
For more details, see the RFC document: https://github.com/orgs/tarantool/discussions/11194
Requested by @ locker in https://github.com/tarantool/tarantool/commit/a8df9b577c1355d40187722c7f727dfc87e105d1.
UPD: Since Tarantool 3.6, MemCS engine supports this method as well.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the box_index reference page and review the existing count, min, and max articles and their table entries. Add a quantile article covering the stated arguments, range behavior, engine differences, limitations, and examples, then add it to the index-method table. Done means the new method is listed and its documentation reflects the supplied behavior, including MemCS support since Tarantool 3.6.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 50/100