Opened 12 years ago

Last modified 12 years ago

#19441 closed Bug

No Postgres _like index when unique=True — at Version 1

Reported by: dylan@… Owned by: nobody
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords: postgresql
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Claude Paroz)

class Species(models.Model):
    scientific_name = models.CharField(max_length=200, db_index=True)

Generates 2 indexes:

BEGIN;
CREATE INDEX "species_species_scientific_name" ON "species_species" ("scientific_name");
CREATE INDEX "species_species_scientific_name_like" ON "species_species" ("scientific_name" varchar_pattern_ops);

COMMIT;
class Species(models.Model):
    scientific_name = models.CharField(max_length=200, unique=True, db_index=True)

...does not create any indexes, because it depends on UNIQUE, but it SHOULD generate the index:

CREATE INDEX "species_species_scientific_name_like" ON "species_species" ("scientific_name" varchar_pattern_ops);

to make sure Postgres is optimized for LIKE operator.

Change History (1)

comment:1 by Claude Paroz, 12 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top