Merge several identical LEFT/INNER joins into one LEFT
Fix db collation check