Issue #2966523: MySQL 8 Support added support for MySQL 8, and one of the changes was that it escaped all MySQL reserved keywords.

Whenever the quoteIdentifier method is called, it performs an in_array() call.

in_array() calls are O(n) because it has to iterate through all the elements in the reserved keywords array. The reserved keywords array has 263 elements as of now. Because this function is called for each alias, field, and table the number of calls to this function can add up easily.

I would like to suggest that we convert this to an isset() call instead. We can flip the reserved keywords array to make the reserved keywords as array keys, so we can perform a (close to) an O(1) isset() lookup.

Here is a quick benchmark: https://3v4l.org/ctKEL

Comments

Ayesh created an issue. See original summary.

ayesh’s picture

Attaching the suggested patch.
I also introduced the static keyword because the reserved values do not change between connections.

ayesh’s picture

Status: Active » Needs review
ayesh’s picture

Issue summary: View changes

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

andypost’s picture

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

daffie’s picture

Status: Needs review » Closed (won't fix)

#2986452: Database reserved keywords need to be quoted as per the ANSI standard has landed. Making this issue moot.

Edit: Changed mute to moot. Sorry I am not a native English speaker.
Thank you @idebr.

idebr’s picture

moot*

(sorry)