|
| 1 | +--[[ |
| 2 | +
|
| 3 | +Temporary notes |
| 4 | +--------------- |
| 5 | +
|
| 6 | +Task: got result using index lookup(s) that are superset of the needed result. |
| 7 | +
|
| 8 | +- pattern matchers (match only what that is suitable for index lookup) |
| 9 | +- support >, < and so on in find_index |
| 10 | +- unit tests for find_index, try to make it reusable |
| 11 | +- glue them all |
| 12 | +- ---- |
| 13 | +- each node: suitable index parts: {index,field_no,iterator(=,!=,>,<,>=,<=),key} |
| 14 | +- each node: suitable indexes: {index,iterator,key,full_match} |
| 15 | +- each node: suitable index-sets: {{suitable indexes},full_match} |
| 16 | +- construction: |
| 17 | + - index: // note: should be based on child index-sets, not indexes |
| 18 | + - and: |
| 19 | + - or: |
| 20 | + - index-set: |
| 21 | + - and: |
| 22 | + - or: |
| 23 | +- full_match can be superseded with |
| 24 | + - for index: weight = covered child nodes / child nodes |
| 25 | + - for index-set: weight = index weights sum / child nodes |
| 26 | + - the above is wrong weights: it should not be about which part of an |
| 27 | + expr are covered, but about which fraction of the result we covered |
| 28 | +- ---- |
| 29 | +- idea: doing all boolean arithmetic on parts, don't introduce |
| 30 | + index/index-set until end |
| 31 | +- idea: we can construct DNF of parts (corr. to CNF of expr ops) during |
| 32 | + tree traversal by expanding and of ors / or of ands and passing negation |
| 33 | + down |
| 34 | +- ---- |
| 35 | +- provide an iterator that merges several iterator results |
| 36 | +- ---- |
| 37 | +- idea: construct DNF structure, where some conjuncts can be just expr, but |
| 38 | + some are saturated with index parts info |
| 39 | +- it worth to support ranges: (x > V1 && x < V2) and so on; set index and stop |
| 40 | + key for it |
| 41 | +
|
| 42 | +]]-- |
| 43 | + |
| 44 | +--local expressions = require('graphql.expressions') |
| 45 | + |
| 46 | +local find_expr_index = {} |
| 47 | + |
| 48 | +--[[ |
| 49 | +local cmp_op_to_iterator_type = { |
| 50 | + ['=='] = 'EQ', |
| 51 | + ['!='] = 'NE', -- discarded after all NOT ops processing |
| 52 | + ['>'] = 'GT', |
| 53 | + ['>='] = 'GE', |
| 54 | + ['<'] = 'LT', |
| 55 | + ['<='] = 'LE', |
| 56 | +} |
| 57 | +
|
| 58 | +-- 42 > x => x < 42 |
| 59 | +local reverse_iterator_type = { |
| 60 | + ['EQ'] = 'EQ', |
| 61 | + ['NE'] = 'NE', |
| 62 | + ['GT'] = 'LT', |
| 63 | + ['GE'] = 'LE', |
| 64 | + ['LT'] = 'GT', |
| 65 | + ['LE'] = 'GE', |
| 66 | +} |
| 67 | +
|
| 68 | +-- !(x < 42) => x >= 42 |
| 69 | +local negate_iterator_type = { |
| 70 | + ['EQ'] = 'NE', |
| 71 | + ['NE'] = 'EQ', |
| 72 | + ['GT'] = 'LE', |
| 73 | + ['GE'] = 'LT', |
| 74 | + ['LT'] = 'GE', |
| 75 | + ['LE'] = 'GT', |
| 76 | +} |
| 77 | +
|
| 78 | +local function is_cmp_op(op) |
| 79 | + return cmp_op_to_iterator_type[op] ~= nil |
| 80 | +end |
| 81 | +]]-- |
| 82 | + |
| 83 | +return find_expr_index |
0 commit comments