-
Notifications
You must be signed in to change notification settings - Fork 4.1k
kv/sql: ability to query all versions of keys/rows #19749
Description
This is a two-part proposal, but each part is tied pretty closely to one another. The general idea is that we should make MVCC values more easily accessible from upper layers of Cockroach.
WARNING: It's not particularly well thought out. I got the idea from Murat's discussion on his recent work with HLC storage and retrieval.
KV scan for all versions of keys in range
We should consider adding an option on ScanRequest that returns all versions of a given range of keys instead of just the version whose timestamp is <= the batch timestamp. Another option to bound these timestamps might be useful as well, but for now, just picture a flag set on ScanRequest or BatchRequest that turns on this "all versions" mode. We already require lookups like these in certain place, so being able to fetch all versions of a key with a single request would be a win on its own.
SQL query with versioned-rows
We should also consider adding an option to query SQL tables and see all versions of each row. The idea would be similar to SELECT ... AS OF SYSTEM TIME, except the query (SELECT ... AS OF ALL TIMES?) would return the version of each selected row at all timestamps. It would also add a version_timestamp column to the SQL data source and result so that queries could manipulate or bound the timestamps that they want to see. This would be both cool and pretty useful when looking at how a row or set of rows has changed over time.
This may be starting to look too much like a time series database feature though...