Make WordPress Core

Opened 9 years ago

Closed 8 years ago

#34873 closed enhancement (fixed)

dbDelta PRIMARY KEY Single Space Recreates Index

Reported by: charlestonsw's profile charlestonsw Owned by: ocean90's profile ocean90
Milestone: 4.6 Priority: normal
Severity: normal Version: 3.5.1
Component: Database Keywords:
Focuses: performance Cc:


Reference ticket #10404.

This is to decompose the original ticket into components. May be fixed in 4.4. Needs testing.

If there is a double space after PRIMARY KEY the dbDelta method will create the primary key and future comparisons match, reducing overhead whenever dbDelta is called (on a plugin/theme update for example).

On a large table, hundreds of thousands of records, this can be a notable performance penalty when updating a plugin/theme.

This avoids performance penalties:

PRIMARY KEY  my_pkey ( id ),

This recreates the index:

PRIMARY KEY my_pkey ( id ),

Change History (2)

#1 @ocean90
8 years ago

  • Milestone changed from Awaiting Review to 4.6

#2 @ocean90
8 years ago

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

In 37583:

Database: Normalize index definitions in dbDelta().

dbDelta() compares the index definitions against the result of SHOW INDEX FROM $table_name. This requires a specific format so indices are not unnecessarily re-created. This format wasn't ensured, until now.

  • Parse the raw index definition to extract the type, name and columns so a normalized definition can be built (#20263, #34873).
  • Standardize on uppercase types (#34871) and on 'KEY'. 'INDEX' is only a synonym for 'KEY'.
  • Escape index names with backticks (#20263).
  • Normalize columns: Ignore ASC and DESC definitions (#34959), remove whitespaces (#34869) and escape column names with backticks (#20263).
  • Add backticks to all index change queries (#20263).

Props ocean90, pento, kurtpayne.
Fixes #20263, #34869, #34871, #34873, #34959.

Note: See TracTickets for help on using tickets.