yii2 icon indicating copy to clipboard operation
yii2 copied to clipboard

Add support for index / query hints in query builder

Open uaoleg opened this issue 1 year ago • 3 comments

Q A
Is bugfix?
New feature? ✔️
Breaks BC?
Fixed issues #9119

uaoleg avatar Sep 02 '23 06:09 uaoleg

PR Summary

  • Introduction of Force Index Property and Method The team has introduced a new attribute known as $forceIndex to the Query class and associated it with a new method forceIndex(). This method essentially allows setting the value of $forceIndex.

  • Query Builder Updates In order to accommodate the new $forceIndex attribute, modifications were made to the buildFrom() function in the QueryBuilder file, thereby accepting $forceIndex as an additional parameter. This function was also updated to incorporate a new clause (FORCE INDEX) in our database queries whenever the $forceIndex parameter has a value. This encourages our system to apply specified index strategy while fetching data, helping in potential performance improvements.

what-the-diff[bot] avatar Sep 02 '23 06:09 what-the-diff[bot]

Note that this syntax is planned to be deprecated in MySQL:

As of MySQL 8.0.20, the server supports the index-level optimizer hints JOIN_INDEX, GROUP_INDEX, ORDER_INDEX, and INDEX, which are equivalent to and intended to supersede FORCE INDEX index hints, as well as the NO_JOIN_INDEX, NO_GROUP_INDEX, NO_ORDER_INDEX, and NO_INDEX optimizer hints, which are equivalent to and intended to supersede IGNORE INDEX index hints. Thus, you should expect USE INDEX, FORCE INDEX, and IGNORE INDEX to be deprecated in a future release of MySQL, and at some time thereafter to be removed altogether.

These index-level optimizer hints are supported with both single-table and multi-table DELETE statements.

For more information, see Index-Level Optimizer Hints.

https://dev.mysql.com/doc/refman/8.0/en/index-hints.html

And new syntax can already be handled by $option parameter in select().

rob006 avatar Sep 03 '23 09:09 rob006

@uaoleg Looks good. Please also add unit tests and a line in the changelog.md

rhertogh avatar Sep 03 '23 10:09 rhertogh