Repository navigation
di.qsp: merge partition constraints into one list before evaluating - #162
mkeenan-di wants to merge 3 commits into
Conversation
q prunes partitions only by the leading where constraint, and evaluates any later constraint on the virtual partition column row by row, which materialises the column. A user's date range followed by a policy embargo (date within a b, qsp.aged[date;2D]) read every partition in the range and built a date column over all of it. settle now folds the leading run of literal comparisons on the partition column into one (in;date;partitions) constraint, computed against .Q.pv, before partitionlimit and eval. explain shows the rewritten query before the merge, runx after it. Example: 63 -> 12 ms and 33 MB -> 5 KB. Also restore E in examples/equities/hdb.q, which -p needed.
| :tree.mapbase[fold[p;pv];rw]; | ||
| }; | ||
|
|
||
| / rewritten tree rw as it will run: partition constraints pinned and folded. Either step that |
There was a problem hiding this comment.
The while loop violates the project style guide, which forbids do/while/for and requires iterators instead. This loop scans cons linearly to count leading partfixed constraints; replace it with a vector/iterator form, e.g. k:sum(&\) ord.partfixed[ti] each cons (scan-and stops at first false, counting the leading run).
There was a problem hiding this comment.
Replaced with k:sum mins ord.partfixed[ti] each cons, plus a guard for fewer than two constraints, where each over an empty list returns () and sum mins () isn't 0.
DIReview Summary0 critical | 1 warning(s) | 0 suggestion(s)
|
DIReview Summary✅ No new findings at
|
| :first literal c 2; | ||
| }; | ||
|
|
||
| export:([normop;movable;place;prunes;prunesby;partfixed;guardvalues]); |
There was a problem hiding this comment.
Do we need all of these functions exported from the kdb-x module? We only need to export those which are used externally, these look like internal functions?
There was a problem hiding this comment.
I checked which exported functions other files actually call:
- place and guardvalues are called from core/walk.q.
- prunes, prunesby and partfixed are called from init.q.
- normop and movable are only used inside order.q, so I removed them.
| / slower than the range alone. fold[p;pv;x] is base query x with its leading run of constraints | ||
| / that compare the partition column with literal data - the user's, once pin has computed it, and | ||
| / an aged filter's cutoff, computed at rewrite - replaced by one: the partition column in the | ||
| / partitions of pv they select together. The same rows, from only the partitions that hold them |
There was a problem hiding this comment.
Can we trim down some of these verbose comments. I don't find this sort of thing particularly helpful as a comment, the language isn't easy or natural. It's using lots of words when a few would do. I think some of the team had success with the ponytail skill
There was a problem hiding this comment.
I trimmed the comments in the scripts
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| :first literal c 2; | ||
| }; | ||
|
|
||
| export:([place;prunes;prunesby;partfixed;guardvalues]); |
There was a problem hiding this comment.
The export list removes normop and movable from the exported symbols. If any other module uses ord.normop or ord.movable (the diff shows movable is called internally within order.q and referenced in init.q via ord.partfixed etc.), removing them from export will break any external caller that accesses them directly. Verify that no other module indexes the order module handle for normop or movable before merging.
DIReview Summary0 critical | 1 warning(s) | 0 suggestion(s)
|
q prunes partitions only by the leading where constraint, and evaluates any later constraint on the virtual partition column row by row, which materialises the column. A user's date range followed by a policy embargo (date within a b, qsp.aged[date;2D]) read every partition in the range and built a date column over all of it.
settle now folds the leading run of literal comparisons on the partition column into one (in;date;partitions) constraint, computed against .Q.pv, before partitionlimit and eval. explain shows the rewritten query before the merge, runx after it. Example: 63 -> 12 ms and 33 MB -> 5 KB.
Also restore E in examples/equities/hdb.q, which -p needed.