Algorithm for processing R ⋈ S using an index