-
Notifications
You must be signed in to change notification settings - Fork 93
Composite index #1201
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
base: master
Are you sure you want to change the base?
Composite index #1201
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the API - using CompositeIndex
.
I agree that using strings is just much easier than actual column references.
class Album(Table):
name = Varchar()
released = Boolean(default=False)
name_released_idx = CompositeIndex(["name", "released"])
Is there a way to specify the index type?
It looks like B-tree, GiST, GIN, and BRIN can be used with multi-column indexes:
https://www.postgresql.org/docs/current/indexes-multicolumn.html
@dantownsend Great idea. I'll try to implement it. Thanks |
@engines_only("postgres", "cockroach") | ||
def test_add_table_with_composite_index(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a new commit with the index type in CompositeIndex
. I didn't write any test because for that we need to create an extension for each of those index types (except B-tree
) either in Github workflows or in PostgresEngine
. I tried it locally and it works. The test would be the same as this, except we add e.g. "index_type": IndexMethod.gin
instead of the default "index_type": IndexMethod.btree
and create the extension with
CREATE EXTENSION pg_trgm;
CREATE EXTENSION btree_gin;
for that index type.
Related to #1188. This is almost identical PR as for composite unique constraints, only it doesn't use custom ddl but modified Piccolo methods
create_index
anddrop_index
. Although it serves a different purpose, feel free to remove it if it represents too much code duplication and adds complexity, as adding and dropping a composite index can easily be done with manual migrations as described in the comment.Usage is: