Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for index / query hints in query builder #19946

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

uaoleg
Copy link
Contributor

@uaoleg uaoleg commented Sep 2, 2023

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

@what-the-diff
Copy link

what-the-diff bot commented Sep 2, 2023

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.

@rob006
Copy link
Contributor

rob006 commented Sep 3, 2023

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().

@rhertogh
Copy link
Contributor

rhertogh commented Sep 3, 2023

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

Copy link
Contributor

@rob006 rob006 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is definitely not finished:

  1. There are no tests that would verify that generated queries actually work.
  2. Implementation uses MySQL specific syntax, so it would fail for the rest of DBMS.
  3. This MySQL syntax is planned to be removed, so the only part of this PR that works, is already soft-deprecated.

IMO instead of providing API for FORCE INDEX clause, we should just provide API for adding something after table name (including table name for JOIN) - it should be easier to maintain and more flexible for users (even index hints for MySQL are more complicated than just FORCE INDEX). If you need index hints, you're probably targeting very specific DBMS with specific version, so having abstraction at framework level does not bring much benefit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants