我在服务中有 UPDATE 查询,这导致了性能问题。
如果我们在 UPDATE 语句的 where 条件中使用的列上创建索引,将解决性能问题。
我的问题有多有效?
UPDATE TABLE table_name
set description='some text',
title='some title',
updated_ts=now()
where some_id_col=?;
对于此查询:
update table table_name
set description = 'some text',
title = 'some title',
updated_ts = now()
where some_id_col = ?;
您需要一个 some_id_col
上的索引,或者一个索引,其中 some_id_col
是索引中的第一个键。 在这些情况下,Update 语句将使用索引 - 只需确保传入的参数与列的类型相同即可。