Manually merge query improvements from main repository.