Keine Ahnung, ob es schneller ist, aber es scheint viel weniger Tippen zu erfordern...
SELECT x.*
, IF(@prev = dept_id
, IF(salary <> @psalary,@i:[email protected]+1,@i:[email protected])
,@i:=1) rank
, @psalary := salary
, @prev := dept_id prev
FROM my_table x
, (SELECT @i:=1,@prev:='',@psalary:='') vars
ORDER
BY dept_id,salary;