SQL - improve NOT EXISTS query performance

前端 未结 7 1843
名媛妹妹
名媛妹妹 2021-02-07 09:08

Is there a way I can improve this kind of SQL query performance:

INSERT
INTO ...
WHERE NOT EXISTS(Validation...)

The problem is when I have ma

相关标签:
7条回答
  • Pay attention to the other answer regarding indexing. NOT EXISTS is typically quite fast if you have good indexes.

    But I have had performance issues with statements like you describe. One method I've used to get around that is to use a temp table for the candidate values, perform a DELETE FROM ... WHERE EXISTS (...), and then blindly INSERT the remainder. Inside a transaction, of course, to avoid race conditions. Splitting up the queries sometimes allows the optimizer to do its job without getting confused.

    0 讨论(0)
提交回复
热议问题