Index Hints

indexHints can be used to optionally pass index hints when using mysql. The hint type must be a value from Sequelize.IndexHints and the values should reference existing indexes.

Index hints override the default behavior of the mysql query optimizer.

  1. Project.findAll({
  2. indexHints: [
  3. { type: IndexHints.USE, values: ['index_project_on_name'] }
  4. ],
  5. where: {
  6. id: {
  7. [Op.gt]: 623
  8. },
  9. name: {
  10. [Op.like]: 'Foo %'
  11. }
  12. }
  13. })

Will generate a mysql query that looks like this:

  1. SELECT * FROM Project USE INDEX (index_project_on_name) WHERE name LIKE 'FOO %' AND id > 623;

Sequelize.IndexHints includes USE, FORCE, and IGNORE.

See Issue #9421 for the original API proposal.