yii2
yii2 copied to clipboard
Add support for index / query hints in query builder
Q | A |
---|---|
Is bugfix? | ❌ |
New feature? | ✔️ |
Breaks BC? | ❌ |
Fixed issues | #9119 |
PR Summary
-
Introduction of Force Index Property and Method The team has introduced a new attribute known as
$forceIndex
to theQuery
class and associated it with a new methodforceIndex()
. This method essentially allows setting the value of$forceIndex
. -
Query Builder Updates In order to accommodate the new
$forceIndex
attribute, modifications were made to thebuildFrom()
function in theQueryBuilder
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.
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()
.
@uaoleg Looks good. Please also add unit tests and a line in the changelog.md