hi,

in certain cases, django-postgresql creates duplicate indexes...


imagine the following model:

 > class Item(Model):
 >    text = CharField(maxlength=200,unique=True, db_index = True)

when installing it, it generates the following sql: (manage.py sqlall)


 > BEGIN;
 > CREATE TABLE "y_item" (
 >     "id" serial NOT NULL PRIMARY KEY,
 >     "text" varchar(200) NOT NULL UNIQUE
 > );
 > CREATE UNIQUE INDEX y_item_text ON "y_item" ("text");
 > COMMIT;


and the result is the following db schema:

> boo=# \d y_item
>                                  Table "public.y_item"
>  Column |          Type          |                      Modifiers             
>          
> --------+------------------------+-----------------------------------------------------
>  id     | integer                | not null default 
> nextval('y_item_id_seq'::regclass)
>  text   | character varying(200) | not null
> Indexes:
>     "y_item_pkey" PRIMARY KEY, btree (id)
>     "y_item_text" UNIQUE, btree (text)
>     "y_item_text_key" UNIQUE, btree (text)

now, if you check the indexes, ithe "text" column is indexed twice...

the reason is that because it is UNIQUE, postgres automatically creates 
an index for it.

and then, because it has db_index = True, it gets a second index from 
django.

i'm no postgresql expert, but it seems to me that having 2 indexes on 
the same column is a bad thing (because when writing into this table, 
the index will have to be calculated twice).

(or are they "different" indexes?)

so, should i open a bugreport (ticket) about this?

or is this intentional?

also, in this case, the "workaround" is simple. simply remove the 
db_index=True.
but it's not that simple always.

for example imagine an unique SlugField. in that case the only possible 
fix is to manually delete the redundant index from the db.

gabor

--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to