Perf: Removed a useless distinct, add indexes.