Repository navigation
Open
Labels
dialect: mariadbFor issues and PRs. Things that involve MariaDB (and do not involve all dialects).dialect: mssqlFor issues and PRs. Things that involve MSSQL (and do not involve all dialects).dialect: mysqlFor issues and PRs. Things that involve MySQL (and do not involve all dialects).dialect: sqliteFor issues and PRs. Things that involve SQLite (and do not involve all dialects).type: featureDEPRECATED: replace with the "feature" issue type
Description
Related support information
- MySQL https://dev.mysql.com/doc/refman/8.0/en/index-hints.html
- MariaDB
- MSSQL https://docs.microsoft.com/en-us/sql/t-sql/queries/hints-transact-sql-query?view=sql-server-2017
- SQLite https://www.sqlite.org/lang_indexedby.html
Reacted by Jesse Thomson, Faizan Hasan, Henry Arbolaez, monukanyal, aartemenko89, Osoian Marcel, Maxime CONY, Ronyeh3, Carsair, Mehmet and 2 more
Metadata
Metadata
Assignees
Labels
dialect: mariadbFor issues and PRs. Things that involve MariaDB (and do not involve all dialects).dialect: mssqlFor issues and PRs. Things that involve MSSQL (and do not involve all dialects).dialect: mysqlFor issues and PRs. Things that involve MySQL (and do not involve all dialects).dialect: sqliteFor issues and PRs. Things that involve SQLite (and do not involve all dialects).type: featureDEPRECATED: replace with the "feature" issue type
Activity
jessethomson commentedon May 17, 2018
Okay, I think a good starting point might be to go over SQL capabilities, and how/if we want to implement all of these.
Valid MySQL queries:
SELECT * FROM t1 USE INDEX ();Without using indicesSELECT * FROM t1 USE INDEX (i1);With single indexSELECT * FROM t1 USE INDEX (i1,i2);With multiple indicesSELECT * FROM t1 USE INDEX (i1) USE INDEX (i2);With multiple USE INDEXI think 1, 2, and 3 are all reasonable functionality. I don't see any reason why we would need to implement 4. As far as I know, 4 is simply a syntactically different way to represent 3, without adding any new functionality (I could be wrong).
Note: It is perfectly valid to use the same index more than once in an index hint.
For example:
SELECT * FROM t1 USE INDEX (i1) USE INDEX (i1);and
SELECT * FROM t1 USE INDEX (i1,i1);are both valid statement so we don't need to enforce index uniqueness.
jessethomson commentedon May 17, 2018
Also, it looks like all 3 Pull Requests referenced in the original post are for MySQL. I don't think there is any actual demand for this feature outside of the MySQL dialect; at least nothing that I have been able to find online.
harbolaez commentedon May 17, 2018
Agree with you @jwt1143 on my PR I was able to pass a collection of indexes. I like option
1,2and3aswellSELECT * FROM Order USE INDEX(idx_status_id) WHERE status_id = 1harbolaez commentedon May 17, 2018
Also, I like to support the ability to use
FORCE INDEXsometimes is useful but rare.ezequielzacca commentedon May 18, 2018
is not rare at all for very large databases
jessethomson commentedon May 18, 2018
Okay. I think it makes sense to support force (and probably ignore too in that case).
Here's an API proposal:
We add an
indexHintsproperty to the sequelize options.Examples:
SELECT * FROM t1 USE INDEX ();
SELECT * FROM t1 USE INDEX (i1);
SELECT * FROM t1 USE INDEX (i1,i2);
SELECT * FROM t1 FORCE INDEX (i1);
SELECT * FROM t1 IGNORE INDEX (i1);
SELECT * FROM t1 USE INDEX (i1,i2) IGNORE INDEX (i2);
Notes
I prefer using objects over arrays to represent each index hint because they are more explicit.
For example:
is not nearly as clear as
Being more verbose shouldn't be an issue as indexHints are only used in limited/rare circumstances.
sushantdhiman commentedon May 23, 2018
@jwt1143 Your proposal looks good, some comments
typeshould be an constant likequery hintsI also do perfer object based approach
As for implementation
MSSQL
We are only going to introduce this
Form of table hint expansion, we already support table hints for MSSQL, we just need to include index part when
indexHintsis also supplied, see this pull requestSQLite
Only need to add
For any given
indexHintsMySQL
Up to you, as that is your primary objective with this issue
monukanyal commentedon Oct 5, 2018
OsoianMarcel commentedon Nov 5, 2018
peteychuk commentedon Dec 12, 2018
danfarewell commentedon Dec 19, 2018
KevinTemes commentedon Mar 18, 2019
Diferno commentedon Apr 2, 2019
feat(query-generator): ability to use index hints in mysql (sequelize…
stale commentedon Jul 23, 2019
benjamin658 commentedon Oct 17, 2019
Will the indexHints option support
mariadbdialect?papb commentedon Oct 25, 2019
@benjamin658 Thanks for adding it on #11573 :)
feat(query-generator): ability to use indexHints on includes/joins fo…
timbowhite commentedon Jan 9, 2020
MySQL supports index hints on JOIN statements. It'd be nice to be able to do this:
and get something like this:
PR incoming.
theironcook commentedon Oct 13, 2020
Is it possible to get indexHints enabled with sql server / tedious?
QuanticPotatoes commentedon Mar 5, 2021
@timbowhite The index hints on JOIN statements features would be so life saving 🙏
arafat-al-mahmud commentedon Apr 24, 2021
Any workaround in v3?