-
Notifications
You must be signed in to change notification settings - Fork 48
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
Creating indexes on compressed columns #17
Comments
While looking around I actually just stumbled on your original blog post for this project which more or less describes this exact situation to a tee, you would think I was copying straight from the blog post. I see your suggested solution in the blog is to just break out the values you want to index into real columns, which I suppose works well enough, though proper indexing support would definitely be nice. I wonder if you ever manged to get anything else working with GENERATED columns? |
Sadly I don't think there's any solution for this right now except storing a copy of the extracted values separately. I'm not sure why SQLite doesn't use the existing index when querying the view even though the expression should be the same. It might be useful to ask this in the SQLite forum, it might be something that's easy to fix for the SQLite devs in an update. With I haven't tried this yet (should be easy to create an example manually even with the extension in it's current state), but I think there was some logical issue with it that I don't remember right now. |
Just tested it out, can confirm adding (virtual) generated columns to the _zstd table ( It's a little contrived, but it definitely works and allows me to use this more or less as is with a little housework on the schema. |
I tried using this on a database I'm using to store a lot of raw JSON objects, which I then have a view that uses SQLite's JSON support to extract the contents for querying. I originally had a few indexes on JSON expressions (something like
CREATE INDEX idx_data_uuid ON data(json_extract(body, '$.data.uuid'))
). SQLite's query planner uses this index even when querying from the view, but after compressing the data, there's no more obvious way to create indexes like this since you can't create indexes on views.I tried creating an index like
_data_zstd(json_extract(zstd_decompress_col(body, 1, _body_dict, true), '$.data.uuid'))
, but SQLite's query planner won't select this when querying from a view. I can make it use the index by replacing mydata_view.uuid
with the literaljson_extract(zstd_decompress_col(body, 1, _body_dict, true), '$.data.uuid')
in the SELECT statement, but that kind of defeats the purpose of the viewI see proper index support is on the "Future Work" section, so I assume there may not be any way to do this currently, but I wonder if you have any hints or experience with being able to coerce the query planner into using an index like the one above, since I believe it "should" be possible in theory.
In any case, I hope work on this extension continues, since the results I got were extremely promising. My database compressed to around 6% the original size, and for queries that didn't need those indexes, there was seemingly no loss in performance.
The text was updated successfully, but these errors were encountered: