Opened 15 months ago

Closed 3 weeks ago

#28077 closed New feature (fixed)

Allow specifying custom operator classes for PostgreSQL indexes

Reported by: IzyJeepee Owned by: Ian Foote
Component: Database layer (models, ORM) Version: 1.11
Severity: Normal Keywords: postgres, gin, operator, class
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Hello,

I want use the GinIndex method to create a gin index with the django's migration. But while the migration, I have this errror :

django.db.utils.ProgrammingError : data type character varying has no default operator class for access method "gin"
HINT : You must specify an operator class ofr the index or define a default operator class for the data type.

This error may be resolved by enabling the btree_gin extension.

It is possible to pass the operator class during the index's creation ? For example :

class Meta:
    indexes = [
        GinIndex(fields=['my_field'], name='my_index_gin', operator_class='my_operator')
    ]

Thanks

Change History (8)

comment:2 Changed 15 months ago by Mads Jensen

#27437 looks like it's overlapping a little bit.

comment:3 Changed 15 months ago by Tim Graham

Summary: GinIndex() and operator classAllow specifying an operator class for GinIndex()
Triage Stage: UnreviewedAccepted

I don't have much expertise here about the use cases and how this might interact with #27437. Tentatively accepting for further investigation.

comment:5 Changed 9 months ago by vinay karanam

I've a use case where I am always doing __contains query on JSONField. So, I would prefer GIN index to be created using jsonb_path_ops operator class rather than the default jsonb_ops.

comment:6 Changed 7 months ago by Tim Graham

Component: contrib.postgresDatabase layer (models, ORM)
Has patch: set
Owner: set to nobody
Summary: Allow specifying an operator class for GinIndex()Allow specifying custom operator classes for PostgreSQL indexes

#28783 was a duplicate and provides a PR.

comment:7 Changed 8 weeks ago by Ian Foote

Owner: changed from nobody to Ian Foote
Status: newassigned
Last edited 3 weeks ago by Tim Graham (previous) (diff)

comment:8 Changed 8 weeks ago by Ian Foote

I've noticed that in the postgis schema editor, we have custom index creation code for single-field indexes for geodetic fields. For example, we set the GIST_GEOMETRY_OPS_ND operator class for fields with dimension higher than two.

It would probably be good to refactor to allow this custom code to integrate with the operator class support I've added, but I'm not familiar enough with postgis to be confident making a change without guidance.

comment:9 Changed 3 weeks ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In 38cada7:

Fixed #28077 -- Added support for PostgreSQL opclasses in Index.

Thanks Vinay Karanam for the initial patch.

Note: See TracTickets for help on using tickets.
Back to Top