perf(sql): allows removing DISTINCT from some MySQL queries

We add the "distinct" option to a few query functions to allow devs to
remove DISTINCT clauses from queries where they are unnecessary and worsen
performance. We also set the option in some core queries where it's unlikely
to cause trouble.

Fixes #4594
perf(db): Disabled SQL DISTINCT in more cases.
Merge branch 'Srokap-pr/7338' into 1.x