What is the syntax to force the use of an index for a join in MySQL

后端 未结 1 413
感情败类
感情败类 2021-02-12 04:02

The use of the \"FORCE/USE/IGNORE INDEX\" when doing a straightforward select is well-documented, but it\'s not clear from the documentation how to do it for a JOIN.

How

相关标签:
1条回答
  • 2021-02-12 04:42

    The FORCE/USE/IGNORE goes after the table name you are joining, and after the alias if you're using one.

    SELECT
      t1.`id` AS `id_1`,
      t2.`id` AS `id_2`
    FROM
      `table1` t1
    LEFT OUTER JOIN
      `table2` t2
      FORCE INDEX FOR JOIN (`table1_id`)
      ON (t2.`table1_id` = t1.`id`)
    
    0 讨论(0)
提交回复
热议问题