#24082: Unique=True on TextField or CharField should not create an index
-------------------------------------+-------------------------------------
Reporter: djbug | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.7
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by djbug):
Replying to [comment:6 marfire]:
> However, this is the
[https://docs.djangoproject.com/en/1.7/ref/models/fields/#unique currently
documented behavior] ("Note that when `unique` is `True` you don’t need to
specify `db_index`, because `unique` implies the creation of an index"),
so there would be a backwards-compatibility problem in changing it.
>
> The fact that you can't prevent the creation of the extra index with an
explicit `db_index=False` does feel like a bug, though, and something that
could be fixed without a deprecation cycle.
Agreed about backward compatibility & having `db_index=False` as a fix.
> As for the suggestion to use a single `text_pattern_ops` unique index to
serve double duty, the [http://www.postgresql.org/docs/9.3/static/indexes-
opclass.html PostgreSQL documentation] makes it clear that that will not
suffice to support all of Django's lookup types: "Note that you should
also create an index with the default operator class if you want queries
involving ordinary <, <=, >, or >= comparisons to use an index. Such
queries cannot use the xxx_pattern_ops operator classes."
A single `text_pattern_ops` index works for '''both''' `LIKE` & `=`
queries. But it won't work for other operators like `< <= etc.`. But, I
feel that, it would be an overkill to create 2 indexes by default. It
should be left to the user to decide if they want double index or a single
one with whichever operator class they want.
--
Ticket URL: <https://code.djangoproject.com/ticket/24082#comment:7>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/063.e8cda26860e29b24f0c3722d6e818c6f%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.