What is better? Subqueries or inner joining ten tables?

后端 未结 5 1955
青春惊慌失措
青春惊慌失措 2021-02-12 17:49

An old system have arrived on our office for some changes and fix, but it is also suffering from performance issues. We don\'t know exactly what is the source of this slowness.<

5条回答
  •  执笔经年
    2021-02-12 18:16

    As this answer argues, it should not affect the performance. However, some query optimizers might perform better on JOINs, so you should make some experiments on your system.

    And now for something completely different: JOINing each table to the next one might be more aesthetic than JOINing all with TABLE, and prevents errors whenever the id appears more than once in one of the tables:

    SELECT
        A.X, B.Y, C.Z
    FROM
        TABLE
        INNER JOIN A on A.ID = TABLE.ID
        INNER JOIN B on A.ID = B.ID
        INNER JOIN C on B.ID = C.ID
    WHERE
        TABLE.id = @param;
    

提交回复
热议问题