Hi @Vineet S Since you did not post your query, here are several opportunities for enhancement:
Create indexes. Ensure that the columns referenced in the conditions are properly indexed. As with all indices, make them unique, if possible, which makes comparisons easier.
Separate filtering from matching. It is suggested that the condition only compares columns across the two tables (e.g., target.user_id=source.u_id
), not a column with a constant (e.g., source.account_status='ACTIVE'
).
Use query hints. For certain SQL engines, specify query hints may help.
Read the Query Plan. We may find out more ways to enhance the performance by reading the Query Plan. You may discover that the join order of tables or type of loop may not be ideal for your use case.
Refer to this blog for more details: 4 Ways to improve the performance of a SQL MERGE statement.
Best regards,
Cosmog Hong
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.