Motivation

Nest-Loop Join (NLJ)

For each r in R:
	For each s in S:
		if r.A = s.A: output(r,s)

Performance are bad when the table is large

Sort-Merge Join (SMJ)

if not sorted, sort R and S by A
i,j = 1,1
while i < len(R) and j < len(S):
	if R[i].A == S[j].A:
			output (R[i],S[j])
			i += 1
			j += 1
	else if R[i].A > S[j].A: j += 1
	else if R[i].A < S[j].A: i += 1

Index Join (IJ)

  1. Create an index for S.A if needed

For each r in R:
	let X = loopkup index on S.A with r.A value
	For each s in X:
			output (r,s)

Hash Join (HJ)

  1. Hashing stage (bucketizing): hash tuples into buckets
  2. Join stage: join tuples in matching buckets