Speeding up inner joins between a large table and a small table

前端 未结 2 860
遥遥无期
遥遥无期 2021-02-05 01:29

This may be a silly question, but it may shed some light on how joins work internally.

Let\'s say I have a large table L and a small table S (1

2条回答
  •  一整个雨季
    2021-02-05 01:43

    I know Oracle's not on your list, but I think that most modern databases will behave that way.

    You can see in the following execution plan, that there is no difference between the two statements.

    It's a full access to each of the two tables (no index in my case), and then a HASH JOIN. Since you want everything from both tables, both tables need to be read and joined, the sequence does not have an impact.

    ---------------------------------------------------------------------------
    | Id  | Operation          | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    ---------------------------------------------------------------------------
    |   0 | SELECT STATEMENT   |      |   100 |   700 |    42  (12)| 00:00:01 |
    |*  1 |  HASH JOIN         |      |   100 |   700 |    42  (12)| 00:00:01 |
    |   2 |   TABLE ACCESS FULL| S    |   100 |   300 |     2   (0)| 00:00:01 |
    |   3 |   TABLE ACCESS FULL| L    |   100K|   390K|    38   (8)| 00:00:01 |
    ---------------------------------------------------------------------------
    

提交回复
热议问题