Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql: add support to group all unique variants of a tuple in a range #7267

Closed
ddorian opened this issue Jun 16, 2016 · 14 comments
Closed

sql: add support to group all unique variants of a tuple in a range #7267

ddorian opened this issue Jun 16, 2016 · 14 comments
Labels
A-sql-encoding Relating to the SQL/KV encoding. C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) C-wishlist A wishlist feature. no-issue-activity O-community Originated from the community

Comments

@ddorian
Copy link

ddorian commented Jun 16, 2016

Like in bigtable, where all key-values with the same ROW-KEY are in the same range. Something specifiable, like an index, that should always keep (col1,col2, etc) unique values in 1 range. This can and will be misused (like ~every feature). This is done so the app-developer can make queries where all the data will be guaranteed in 1 range/node.

This will(?) help with the performance since it will be used in cases where I know the data won't grow alot to be bigger than a range.

Of course, this combination of columns can have only the columns of the primary-key and in the same order.

Makes sense ?

Jira issue: CRDB-6178

@ddorian
Copy link
Author

ddorian commented Jun 16, 2016

You probably already do this to keep a sql-row (which has many key-values on rocksdb) in 1 range (you should if not ?).

@knz knz added the C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) label Jun 16, 2016
@petermattis
Copy link
Collaborator

@ddorian All of the columns for a row are kept within a single range. Please reopen if there is something additional to do here.

@knz
Copy link
Contributor

knz commented Jun 16, 2016

@petermattis I think the request is that if a k/v table has a non-unique constraint on k, and there are multiple rows with the same value for k, the user should be able to request that all rows with the same k value reside on the same range.

@petermattis
Copy link
Collaborator

@ddorian Care to clarify?

@ddorian
Copy link
Author

ddorian commented Jun 16, 2016

@petermattis
I meant what knz explained.

Example: I'm storing the friends of a user. Primary-key = (user_id, friend_id), and I want all key-values where user_id is the same to reside on 1 range, so I can store/query as efficiently as possible all friends of a user.

Or I'm storing stuff as primary_key=(a,b,c,d,e) and I want all values of (a,b,c) to reside in 1 range since I will ~ALWAYS query for the same a,b,c rows.

Basically certain cases when:

  1. the row may be too big if I would store everything in 1 blob/json/array column
  2. the rows won't be too big for a range

@petermattis
Copy link
Collaborator

@ddorian Thanks for the clarification.

There is danger here in that a user might accidentally create very large ranges which are currently problematic. What should the system do if a range grows to multiple gigabytes because it can't be split? My instinct is that it would be better to figure out how to model the data as a single row and rely on rows being contained on a single range along with the (currently non-existent) row size limits.

And I'm curious how much of a benefit this feature would provide. If your rows are contiguous, they are very likely on the same range. Multi-range operations are certainly slower than single-range operations, but not that much slower and if they are rare for your data set then they'll be lost in the noise.

@petermattis petermattis reopened this Jun 16, 2016
@ddorian
Copy link
Author

ddorian commented Jun 16, 2016

@petermattis I remember hypertable returned an error when you tried to write to rows that grew too big.
This can maybe be an "advanced" feature.

I actually prefer the single-row option but there's no json/flatbuffers/blob column that can make modifications and checks. Since most cases are "get friendship, get all friendships, delete friendship, check friendship exists".

@petermattis
Copy link
Collaborator

@ddorian At some point we'd like to add support for CQL-style set/map types. Would that satisfy your use case?

@ddorian
Copy link
Author

ddorian commented Jun 16, 2016

@petermattis
Yes, but:
try to make them as blobs on the low-level (or some other fancy thing), since the current cql version has ~crazy overhead.

@petermattis
Copy link
Collaborator

@ddorian Thanks for the pointer. I'll have to read that article more closely and or dive into the CQL implementation. I was imagining each element of a {SET,MAP} would have similar storage overhead to a column. I can't imagine how there would be a 30x storage overhead.

@ddorian
Copy link
Author

ddorian commented Jun 17, 2016

@petermattis Cassandra goes to great length to increase overhead (ex: repeating full-column-names on every value until recently etc)

I assume in their case it was that much because they probably have a compound primary-key (which in this case all primary-key-columns are merged into 1 "string", while cassandra stores them differently in a sstable explained here: http://blog.librato.com/posts/cassandra-compact-storage and also short values.

I understand you want to implement them like the normal hbase/bigtable/hypertable way (they do column qualifier, you implement something similar on the key). This will be better for big/very-big sets/maps (you don't have to write big blobs on each update) and will suck for small sets/maps.

I think, in your case, why don't you use https://github.com/facebook/rocksdb/wiki/Merge-Operator . This is the same feature-request that I mention in this issue scylladb/scylladb#1321.

Assuming 1 value for a map/set:
The merge operator should allow you to only write to a map/set column for insert/update/delete and merge all the versions of it on read/compaction/merge etc.

Assuming you need to only replicate the "change" instead of the "final value" (slower since values can be big maps/sets/etc).

I think the way you want to implement it (each element as unique kv), can also be done by interleaved tables (even better, since you can also alter the interleaved table, while on a set you only have 1 value for each element) #2972

So if this has to be done, it should be on 1 column-value (for minimum overhead) and for 'normal' overhead you can use interleaved tables.

Makes sense ?

@petermattis petermattis changed the title Add support to group all unique variants of a tuple in a range sql: add support to group all unique variants of a tuple in a range Jun 29, 2016
@petermattis petermattis added this to the Later milestone Jun 29, 2016
@dianasaur323 dianasaur323 added O-community Originated from the community and removed community-questions labels Apr 23, 2017
@knz
Copy link
Contributor

knz commented May 9, 2018

@ddorian since you have filed this issue, CockroachDB has started supporting JSON columns. Would this be a suitable alternative?

@knz knz added the A-sql-encoding Relating to the SQL/KV encoding. label May 9, 2018
@ddorian
Copy link
Author

ddorian commented May 9, 2018

json may work in some cases but it's still limited to maximum row size, while this one offers more flexibility.

@petermattis petermattis removed this from the Later milestone Oct 5, 2018
@jordanlewis jordanlewis added the C-wishlist A wishlist feature. label Apr 21, 2020
@github-actions
Copy link

We have marked this issue as stale because it has been inactive for
18 months. If this issue is still relevant, removing the stale label
or adding a comment will keep it active. Otherwise, we'll close it in
10 days to keep the issue queue tidy. Thank you for your contribution
to CockroachDB!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-sql-encoding Relating to the SQL/KV encoding. C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) C-wishlist A wishlist feature. no-issue-activity O-community Originated from the community
Projects
None yet
Development

No branches or pull requests

5 participants