Which provides better performance one big join or multiple queries?

后端 未结 5 1794

i have a table called orders. one column on order is customer_id
i have a table called customers with 10 fields

Given the two options if i want to build up an array

5条回答
  •  感动是毒
    2021-02-05 04:04

    If this customer_id is unique in your customer-table (and the other IDs are unique in the other tables), so your query only returns 1 row per Application, then doing a single SELECT is certainly more efficient.

    Joining all the required customers in one query will be optimized, while using lots of single SELECTs can't.

    EDIT
    I tried this with Oracle PL/SQL with 50.000 applications and 50.000 matching customers.

    Solution with selecting everything in one query took
    0.172 s

    Solution with selecting every customer in a single SELECT took
    1.984 s

    And this is most likely getting worse with other clients or when accessing over network.

提交回复
热议问题