-
-
Notifications
You must be signed in to change notification settings - Fork 114
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
Support creating descending order indexes #260
Comments
This reverts commit 9130ab1. Implementing this properly in simonw/sqlite-utils#260
The problem here is differentiating between a column with the name This won't work: db["ny_times_us_counties"].create_index(["date desc"], desc=True) Because we need to be able to create compound indexes with columns with different directions - for example: create index idx_age_desc_name on dogs (age desc, name) |
A few options: db["dogs"].create_index([("age", "desc"), "name"])
db["dogs"].create_index([desc("age"), "name"])
db["dogs"].create_index([db.desc("age"), "name"]) The first option uses an optional tuple. The second two use a
I don't like using the term |
Maybe: db["dogs"].create_index([db.descending_index("age"), "name"]) It's a little verbose but it's for a relatively rare activity and it does make it very clear what is going on. |
I could use |
Need to solve this for the CLI tool too. Currently that works like this: https://sqlite-utils.datasette.io/en/stable/cli.html#creating-indexes sqlite-utils create-index mydb.db mytable col1 [col2...] Even harder to decide how to add a descending option to this. Maybe like this? sqlite-utils create-index mydb.db mytable --direction col1 asc --direction col2 desc It's a bit gross though! We're saying here that if a single one of the columns you are creating an index for is in reverse direction you have to use |
For the CLI version I could say that you can use a sqlite-utils create-index mydb.db dogs -age name No, that doesn't work - it could get confused with a command-line flag. I guess you could do this:
This does mean that if any of your column names begin with a hyphen you can't use the CLI to add indexes to them. Is that an acceptable limitation? Users can always use |
Decisions: for the Python API I'm going with For the CLI I'm going to do the "-age" thing. |
Annoyingly the
|
See https://sqlite.org/pragma.html#pragma_index_xinfo Example output: https://covid-19.datasettes.com/covid?sql=select+*+from+pragma_index_xinfo%28%27idx_ny_times_us_counties_date%27%29 |
It's weird having to use |
This doesn't work:
But this does:
|
I confirmed and it's possible to have a SQLite column with a hyphen at the start, confirmed using:
|
SQLite lets you create indexes in reverse order, which can have a surprisingly big impact on performance, see simonw/covid-19-datasette#27
I tried doing this using
sqlite-utils
like so, but it's didn't work:The text was updated successfully, but these errors were encountered: