Fixed applyLimit for 'SELECT DISTINCT'
Merge origin/master into tests