#16013 done. Minor fixes to improve sql speed