Will this solution works even if I had a lot of messages or subfolders?
Of course, if you know how to use the find(1) command. Test it carefully before you deploy it, though-- find | xargs rm is an extremely dangerous combination, since you'll probably need several iterations to get the find conditions right.
Will this index update take much time?
I can't say for sure. All I can say is that I've never noticed any significant delay. If you run the job daily, then index updates might be smaller and take less time. Even if Dovecot has to rebuild the whole index, you could probably arrange to make that happen right after you run your deletion job, at off hours. A search for "dovecot rebuild index" turns up some discussion of this problem.
Good luck, Andrew.