我有MYSQL更新语句,有1500条记录,执行它需要很长时间。如何使表现更好?
UPDATE order_table A
INNER JOIN peoplex_table B
SET A.process_flag = 'D',
A.error_message = 'SUPPRESSED DUPLICATES'
WHERE A.process_flag in ('U', 'E')
AND B.order_type = A.order_type
AND B.order_id = A.order_id
AND B.trx_type = A.trx_type
AND B.trx_date = A.trx_date
AND B.trx_amount = A.trx_amount
AND IFNULL(B.ra_number, 'x') = IFNULL(A.ra_number, 'x')
AND IFNULL(B.transaction_id, 'x') = IFNULL(A.transaction_id, 'x')
AND IFNULL(B.tender_id, 'x') = IFNULL(A.tender_id, 'x')
AND IFNULL(B.refund_id, 'x') = IFNULL(A.refund_id, 'x')
AND B.id < A.id
更新:在数据库中未创建索引。
尚不清楚您目前拥有什么索引,或者根本没有索引,因为更新1500行的查询应该很快。如果尚未创建,我将创建以下索引:
create index ix1 on peoplex_table (order_id, trx_date, trx_amount,
order_type, trx_type, id);
此外,以下索引也可以加快查询的速度,但其效果尚不清楚。尝试使用带有和不带有第二个索引的查询,然后进行比较:
create index ix2 on order_table (process_flag);