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

后端 未结 1 1993
走了就别回头了
走了就别回头了 2021-02-12 04:21

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:52

    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)
提交回复
热议问题