SQL Distinct keyword bogs down performance?

前端 未结 4 579
长发绾君心
长发绾君心 2021-01-02 09:28

I have received a SQL query that makes use of the distinct keyword. When I tried running the query it took at least a minute to join two tables with hundreds of thousands of

4条回答
  •  攒了一身酷
    2021-01-02 09:56

    Yes, as using DISTINCT will (sometimes according to a comment) cause results to be ordered. Sorting hundreds of records takes time.

    Try GROUP BY all your columns, it can sometimes lead the query optimiser to choose a more efficient algorithm (at least with Oracle I noticed significant performance gain).

提交回复
热议问题