views:

196

answers:

1

Hi all, I have 2 tables: 1. news (450k rows) 2. news_tags (3m rows)

There are some triggers on news table update which updating listings. This SQL executes too long...

UPDATE news
SET news_category = some_number
WHERE news_id IN (SELECT news_id
                  FROM news_tags
                  WHERE tag_id = some_number); #about 3k rows

How can I make it faster?

Thanks in advance, S.

A: 

If this is a one time update, you may find it better to disable your triggers, run the update, then run a statement that performs what your triggers do in bulk.

Robin Day
Hi Robin,Yes, this is one time update BUT I have to update production db. So it's impossible to disable triggers...
sergeik
If you disable triggers, run your update, then enable triggers all within a transaction then the table will be locked and no other queries will be allowed to run. This assumes it then runs fast enough for this to be possible.
Robin Day
We decided to update only 40 rows:) Thanks for your help.
sergeik