Using .Q.pm to give us an in-memory index (attribute) on the live partition - #1
Open
picoDoc wants to merge 2 commits into
Open
Using .Q.pm to give us an in-memory index (attribute) on the live partition#1picoDoc wants to merge 2 commits into
.Q.pm to give us an in-memory index (attribute) on the live partition#1picoDoc wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The idea
Ok, so in the first two blog posts in what I'm now calling my "rdbs are shit" trilogy, I argued that rdbs are not so necessary in kdb+ architectures, but they do still win for anything that really benefits from attributes. And we can't have attributes on disk for live data because they are not appendable.
I've spent a while banging my head against this (for years really), and now talking to AI about it too. Fable recently pointed out
.Q.pmto me, and while not being mentioned in the docs at all, it basically unlocks the whole thing.So what is
.Q.pm?.Q.MAP[]leaves it behind, and it's basically a dictionary of the mapped tables and their columns. so if you have a normal looking hdb with one table.Q.pmmight look like:and something I really did not expect about this: you can just modify the entries!
so that just drops an in-memory column in place of the one it originally mapped from disk, with an attribute. So long as that column is the right length everything else just seems to work. The engine just sees a column with an attribute and does not care where it came from. So you get plain q-sql, by sym, aj, all that stuff. And it composes with history: p# serves the older partitions, and g# the live one. And it's appendable now.
So really this lets you build something like a "normal" database: an in-memory index over bulk data on disk.
This PR specifically
Adds an experimental, opt-in, per-process flag that gives the live partition an in-memory index. Default off, mapped mode only. With it off, everything is as it was
Two important notes:
n _ d, so it reads the new rows, not the whole column). So no messing around with needing an IPC feed/subscription etc., and it's pretty cheap as it's only ever tailing the files from diskPerformance
This is in the README now too, but worth putting here:
usememattrsym, ~5k rows)tradetime, ~5k rows)avg/sumbysym)So it basically goes to full rdb performance on everything. Even ajs (not shown here).
It does obviously mean, if you switch this on, that each db process is no longer "free". They each have whatever the attributed columns are in-memory. but that's a lot less than an rdb. And you can opt in or out of it on a process by process basis.
I've had claude batter as many queries as it could think of against this and it can't find anything where splicing data in like this causes any issues, but it is still basically an undocumented feature. We should maybe ask KX about it.
I've got a blog post sitting here that explains the same stuff in a more blog-posty way, but it's not quite done yet. Any and all thoughts and feedback appreciated here.