Search code examples
mysqlsql-updateinnodbexplain

Reduce row scan of update query without using index


I am using MySQL InnoDB engine. The result of below explain update query is

EXPLAIN UPDATE H_M_SAMP SET NEW_M_ID=17 WHERE M_ID IN(363)

EXPLAIN QUERY RESULT

Primary key of H_M_SAMP table is H_M_ID. And there is no foreign key relation.

Is it possible to reduce number of rows scan by the update query without using index on M_ID because I have to update the table multiple times?

Thanks.


Solution

  • Yes. You want an index on H_M_SAMP(M_ID):

    create index idx_h_m_sampe_1 on h_m_sampe(m_id);