Skip to content

di.qsp: merge partition constraints into one list before evaluating - #162

Open
mkeenan-di wants to merge 3 commits into
mainfrom
qsp-partition-fold
Open

mkeenan-di wants to merge 3 commits into
mainfrom
qsp-partition-fold

Conversation

@mkeenan-di

Copy link
Copy Markdown
Contributor

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.

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.
Comment thread di/qsp/init.q Outdated
:tree.mapbase[fold[p;pv];rw];
};

/ rewritten tree rw as it will run: partition constraints pinned and folded. Either step that

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@DI-Software-Engineering

Copy link
Copy Markdown

DIReview Summary

0 critical | 1 warning(s) | 0 suggestion(s)

⚠️ Spec check skipped — tracker lookup failed (NO_REF_FOUND). Standards axis only.

@DI-Software-Engineering

Copy link
Copy Markdown

DIReview Summary

✅ No new findings at db8ba87.

⚠️ Spec check skipped — tracker lookup failed (NO_REF_FOUND). Standards axis only.

Comment thread di/qsp/core/order.q Outdated
:first literal c 2;
};

export:([normop;movable;place;prunes;prunesby;partfixed;guardvalues]);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread di/qsp/init.q Outdated
/ 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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I trimmed the comments in the scripts

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread di/qsp/core/order.q
:first literal c 2;
};

export:([place;prunes;prunesby;partfixed;guardvalues]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@DI-Software-Engineering

Copy link
Copy Markdown

DIReview Summary

0 critical | 1 warning(s) | 0 suggestion(s)

⚠️ Spec check skipped — tracker lookup failed (NO_REF_FOUND). Standards axis only.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants