I think that the issue on Trac is actually something different, it talks 
about the need (or not) of an index, when defining a unique constraint. 
Most databases (if not all) will create an index automatically when a 
unique constraint is defined, and correct me if I'm wrong, but PostgreSQL 
(I don't about Oracle) is the only one that actually has constraints 
(unique ones included here) and indexes as a separate thing, but for 
SQLServer and MySQL the unique constraint is just an additional option of 
the index.

What Dilyan is talking about, and correct me if I'm wrong again, is about 
the redundancy of defining an index on a foreing key, if you already have 
that column as the left-most part of an index (unique or not). Most of the 
time it will be redundant to have an index A, and another one (A,B), since 
the latter will be also used for A queries. However this is up to debate 
since using the (A,B) index can be potentially slower than using just the A 
index due to the index being bigger, but you save space and 
insert/update/delete performance for not having two different indexes.

In my case, most of the time I end up with a db_index=False on foreing keys 
that I know I have a index/unique defined somewhere else to avoid the 
overhead of the additional index.

El viernes, 16 de septiembre de 2016, 11:34:52 (UTC-3), Tim Graham escribió:
>
> Did you try to find anything related in Trac? Maybe 
> https://code.djangoproject.com/ticket/24082?
>
> I use this query in Google: postgresql unique index site:
> code.djangoproject.com
>
> On Friday, September 16, 2016 at 9:51:13 AM UTC-4, Dilyan Palauzov wrote:
>>
>> Hello, 
>>
>> according to the documentation models.ForeignKeys creates implicitly an 
>> index on the underlying database. 
>>
>> Wouldn't it be reasonable to change the default behaviour to only create 
>> implicit index, if there is no index_together or unique_together starting 
>> with the name of the foreign key?   In such cases the implicit index is 
>> redundant, at least with Postgresql, as the value can be found fast using 
>> the _together index. 
>>
>> Greetings 
>>    Dilian 
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/3200c618-5665-4c9e-8255-ef34da22aef1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to