Code

Opened 7 years ago

Closed 6 years ago

#5680 closed (fixed)

DatabaseFeatures.autoindexes_primary_key is unnecessary

Reported by: Nis Jørgensen <nis@…> Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Keywords: db-be-api
Cc: ikelly Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

The db backend setting autoindexes_primary_key is unnecessary - since all backends do this.

Note that the changes necessary collide with my patch for #5671

2 patches attached:

  • one that fixes this issue, against trunk
  • one that combines this patch with the one for 5671.

Attachments (5)

autoindex.diff (3.3 KB) - added by Nis Jørgensen <nis@…> 7 years ago.
Fixes just this issue
autoindex_combined.diff (6.7 KB) - added by Nis Jørgensen <nis@…> 7 years ago.
Combined with fix for 5671
autoindex.2.diff (3.8 KB) - added by ikelly 6 years ago.
Updated patch after [7375]
models-mysql-duplicated-index-and-foreign-constraints.py (434 bytes) - added by Peter Melvyn <peter.melvyn@…> 6 years ago.
example demonstrating duplicated index and foreign key constraints on MySQL
r7811-mysql-duplicated-index-and-foreign-constraints.py (564 bytes) - added by Peter Melvyn <peter.melvyn@…> 6 years ago.
Generated SQL showing duplicated index and foreign key constraints on MySQL

Download all attachments as: .zip

Change History (15)

Changed 7 years ago by Nis Jørgensen <nis@…>

Fixes just this issue

Changed 7 years ago by Nis Jørgensen <nis@…>

Combined with fix for 5671

comment:1 Changed 7 years ago by Nis Jørgensen <nis@…>

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

I forgot to mention the discussion thread about the issue.

comment:2 Changed 6 years ago by jacob

  • Triage Stage changed from Unreviewed to Accepted

Changed 6 years ago by ikelly

Updated patch after [7375]

comment:3 Changed 6 years ago by ikelly

  • Cc ikelly added

I just added another reference to the autoindexes_primary_keys feature, so I've updated this patch to reflect that.

comment:4 Changed 6 years ago by ramiro

See also #3030

comment:5 Changed 6 years ago by ramiro

  • Keywords db-be-api added

comment:6 Changed 6 years ago by mtredinnick

  • Resolution set to fixed
  • Status changed from new to closed

(In [7790]) Make sure we only create the minimum number of table indexes for MySQL.

This patch simplifies a bunch of code for all backends and removes some
duplicate index creation for MySQL, in particular (versions 4.x and later).
Patch from Nis Jørgensen.

Fixed #5671, #5680, #7170, #7186.

comment:7 Changed 6 years ago by Peter Melvyn <peter.melvyn@…>

  • Resolution fixed deleted
  • Status changed from closed to reopened

This patch (with removed autoindexes_primary_keys feature) does not treat duplicated indexes and foreign key constraints on MySQL, whereas setting its value to True has solved it.

comment:8 Changed 6 years ago by mtredinnick

Please provide an example of how to duplicate the problem you are talking about. I tested the changes in [7790] fairly carefully with MySQL + InnoDB and couldn't create any duplicate indexes. So what case did I miss? Without more information I cannot hope to fix things.

Changed 6 years ago by Peter Melvyn <peter.melvyn@…>

example demonstrating duplicated index and foreign key constraints on MySQL

Changed 6 years ago by Peter Melvyn <peter.melvyn@…>

Generated SQL showing duplicated index and foreign key constraints on MySQL

comment:9 Changed 6 years ago by Peter Melvyn <peter.melvyn@…>

After uploading example, I reviewed MySQL tables again and I notice that there is now redundant index actually. Instead, if index is not supplied explicitly, MySQL creates inherent one.
Perhaps I confused it with foreign key duplications in ticket #7186 seeing CONSTRAINTS and CREATE INDEX commands together.
Sorry for the noice...

comment:10 Changed 6 years ago by mtredinnick

  • Resolution set to fixed
  • Status changed from reopened to closed

I had just finished typing in a bunch of output to show exactly that. In both MySQL 4 and MySQL 5 it doesn't create the index implicitly if one is specified. There's no bug here.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.