Pr/7338

Replaces  #7338

Fixes #4594

- [ ] I'm in the process of adding more cases in the core that are fine with disabling distinct.
- [ ] Change commit message to use perf(db)