Thanks for the patch! On the branch I see 2 commits on top of the master. Did you send the first commit anywhere? This one - "sql: clear MEM only if necessary". I am not sure it is needed or even better than it was before, because it adds a branch.