Skip to content

Commit 054590f

Browse files
author
Andrei Zavada
committed
add a diagram illustrating how query gets compiled & transformed
1 parent 8b34221 commit 054590f

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

open/inverse-distribution-functions.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,38 @@ Inverse distribution functions are parsed to produce a tagged lexeme by the same
3838

3939
The presence of `ORDER BY` will direct `riak_kv_qry_worker` to use query buffers for the query with inverse distribution functions. Note that the ORDER BY spec will have the resulting buffer sorted by the column argument.
4040

41+
By way of illustration:
42+
43+
```
44+
<---Network--->
45+
46+
+ FROM <-----------------------+ + FROM mytable on vnode X
47+
| | |
48+
| SELECT PERCENTILE(Temp, 0.1) | | SELECT Temp
49+
| | Chunk1 |
50+
| GROUP BY [] +--------+ GROUP BY []
51+
| | |
52+
| ORDER BY [] | | ORDER BY Temp ASC NULLS LAST
53+
| | |
54+
| LIMIT [] | | LIMIT 1
55+
| | |
56+
| OFFSET [] | | OFFSET $TotalRows * 0.1
57+
| | |
58+
+ WHERE [] | + WHERE + start_key = {myfamily, myseries, 1233}
59+
| | end_key = {myfamily, myseries, 4000}
60+
| + temp > 18
61+
|
62+
. Chunk 2
63+
. ------
64+
.
65+
```
66+
67+
Note that
68+
69+
1. Presence of inverse distribution functions does not affect the compilation of WHERE clause and the breakdown of the query into subqueries.
70+
71+
2. The substitution of `TotalRows` in OFFSET happens when the collection of selection rows is completed in the query buffers manager. At compile time, `#riak_select_v3.'OFFSET'` will be set up with a list of functional objects, each taking `TotalRows` as a single argument and returning the effective OFFSET value, for every inverse distribution function appearing in the query.
72+
4173
### Compute offsets at fetch time
4274

4375
On successful collection of all records, in `riak_kv_qry_buffers:fetch_limit`, we check whether the `Offset` parameter is a list of functions. If it is, each function is called with the total number of rows as an argument, yielding the effective offset. For each offset `N`, we extract the `N`th record from the buffer (either in-memory buffer or leveldb-backed one). The values fetched are then placed on a list, and that list becomes the single row returned by `fetch_limit`.

0 commit comments

Comments
 (0)