Slow update query in mysql (mariadb)
Don't use IN ( SELECT ... ).  But it seems to be necessary due to the @row_num computation.

Don't use @row_num computation if you can do the equivalent with ORDER BY ... LIMIT ....

What are you trying to do?  Set delete_flag=true for all but the latest 5 rows?  "Latest" is defined by fileRevId?

"Million records"?  In which table?  Or do you mean that you need to call the proc a million times?

In checking for 5 rows, are there cases where you have thousands?  I ask because 5+ rows can possibly be optimized one way, but 1000+ rows may need a different optimization.

Please provide SHOW CREATE TABLE FileRevisions, I need to check what composite indexes you have.

Update

The schema, as you have it, does not allow for more than one revision per FileId -- because of PRIMARY KEY(FileId) on FileRevisions.  Also AUTO_INCREMENT demands to be the first column in some index.  So, I recommend

 PRIMARY KEY (FileID),
 KEY FileRev_FileID_FK_idx(FileId),


-->

 PRIMARY KEY (FileID, fileRevId),
 INDEX(fileRevId)