Postgresql join

postgresql 中join的选项

  • Nested Loops(O(n2))

    1
    2
    3
    4
    5
    6
    for x in table1:
    for y in table2:
    if x.field == y.field
    issue row
    else
    keep doing
  • Hash joins

    1
    2
    3
    Hash join
    Sequentialscan table 1
    Sequentialscan table 2
  • Merge joins(O(n * log(n)))

    1
    2
    3
    4
    5
    6
    7
    8
    9
    Merge join
    Sort table 1
    Sequetial scan table 1
    Sort table 2
    Sequetial scan table 2
    ---
    Merge join
    Index scan table 1
    Index scan table 2