Django

Code

Ticket #5680 (closed: fixed)

Opened 1 year ago

Last modified 5 months ago

DatabaseFeatures.autoindexes_primary_key is unnecessary

Reported by: Nis Jørgensen <nis@superlativ.dk> Assigned to: nobody
Milestone: Component: Database layer (models, ORM)
Version: SVN Keywords: db-be-api
Cc: ikelly Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

autoindex.diff (3.3 kB) - added by Nis Jørgensen <nis@superlativ.dk> on 10/04/07 04:07:17.
Fixes just this issue
autoindex_combined.diff (6.7 kB) - added by Nis Jørgensen <nis@superlativ.dk> on 10/04/07 04:11:01.
Combined with fix for 5671
autoindex.2.diff (3.8 kB) - added by ikelly on 03/27/08 17:36:41.
Updated patch after [7375]
models-mysql-duplicated-index-and-foreign-constraints.py (434 bytes) - added by Peter Melvyn <peter.melvyn@gmail.com> on 07/01/08 04:43:53.
example demonstrating duplicated index and foreign key constraints on MySQL
r7811-mysql-duplicated-index-and-foreign-constraints.py (0.6 kB) - added by Peter Melvyn <peter.melvyn@gmail.com> on 07/01/08 04:44:30.
Generated SQL showing duplicated index and foreign key constraints on MySQL

Change History

10/04/07 04:07:17 changed by Nis Jørgensen <nis@superlativ.dk>

  • attachment autoindex.diff added.

Fixes just this issue

10/04/07 04:11:01 changed by Nis Jørgensen <nis@superlativ.dk>

  • attachment autoindex_combined.diff added.

Combined with fix for 5671

10/04/07 04:19:58 changed by Nis Jørgensen <nis@superlativ.dk>

  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

I forgot to mention the discussion thread about the issue.

03/02/08 09:50:14 changed by jacob

  • stage changed from Unreviewed to Accepted.

03/27/08 17:36:41 changed by ikelly

  • attachment autoindex.2.diff added.

Updated patch after [7375]

03/27/08 17:39:38 changed by ikelly

  • cc set to ikelly.

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

06/24/08 10:47:03 changed by ramiro

See also #3030

06/25/08 11:37:22 changed by ramiro

  • keywords set to db-be-api.

06/29/08 23:47:00 changed by mtredinnick

  • status changed from new to closed.
  • resolution set to fixed.

(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.

07/01/08 03:30:04 changed by Peter Melvyn <peter.melvyn@gmail.com>

  • status changed from closed to reopened.
  • resolution deleted.

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.

07/01/08 03:51:54 changed 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.

07/01/08 04:43:53 changed by Peter Melvyn <peter.melvyn@gmail.com>

  • attachment models-mysql-duplicated-index-and-foreign-constraints.py added.

example demonstrating duplicated index and foreign key constraints on MySQL

07/01/08 04:44:30 changed by Peter Melvyn <peter.melvyn@gmail.com>

  • attachment r7811-mysql-duplicated-index-and-foreign-constraints.py added.

Generated SQL showing duplicated index and foreign key constraints on MySQL

07/01/08 05:30:26 changed by Peter Melvyn <peter.melvyn@gmail.com>

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...

07/01/08 05:36:18 changed by mtredinnick

  • status changed from reopened to closed.
  • resolution set to fixed.

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/Change #5680 (DatabaseFeatures.autoindexes_primary_key is unnecessary)




Change Properties
Action