SAM Server DB performance improvements (backported from 5.4)