Make WordPress Core

Opened 10 years ago

Last modified 6 years ago

#39826 new enhancement

LIMIT clause not required in get_options function as there's already a UNIQUE KEY on option_name

Reported by: arjenlentz Owned by:
Priority: normal Milestone: Awaiting Review
Component: Database Version: 4.7.2
Severity: normal Keywords: 2nd-opinion has-patch
Cc: Focuses:

Description

The Core get_options (wp-includes/option.php) uses LIMIT 1 to retrieve only a single row for an option.
However, the option_name field already has a UNIQUE KEY in the table schema, so it's impossible for the db to contain or return more than one row for any option_name.

Barring history I'm unaware of (if there used to not be a UNIQUE KEY on this field in the past), it's safe to remove the LIMIT 1 clauses from these queries (there are a few instances in the function.

While LIMIT clauses can sometimes be harmful to performance, in this particular scenario that's not the case. However, it's just superfluous.

Attachments (1)

39826.patch​ (1.1 KB ) - added by esoj 6 years ago.

Download all attachments as: .zip

Change History (4)

This ticket was mentioned in ​Slack in #core by noisysocks. ​View the logs.


6 years ago

#2 @markparnell
6 years ago

  • Component General → Database
  • Keywords 2nd-opinion needs-patch added

@arjenlentz we discussed this in a bug scrub today, and it sounds reasonable. Tagging as 2nd-opinion in case there is some history we're not aware of though.

@esoj
6 years ago

#3 @esoj
6 years ago

  • Keywords has-patch added; needs-patch removed

Contributed a patch, builds nicely against trunk.
There is a good coverage of this by Unit tests in option/option.php.

N.B. However I do not have any knowledge regarding if there is any hstorical reasons for this, so 2nd-opinion still needed.

Note: See TracTickets for help on using tickets.