According to this German Wikipedia article, the time required to merge relations $R$ and $S$ is $\in \mathcal{O}(|R| + |S|)$ if both relations are already sorted. [Note: You don't really need to read the text and the link jumps right to where the time complexity is stated. But I added a translation of that section to this question for some clarity.]
Assume $R = S$ with $R$ having 2 columns. One is a random number and one is always 5 for every line. Join $R$ and $S$ on the column which is 5 for every line. The resulting output's space complexity is $\in \Theta(|R| \cdot |S|)$. Time complexity is always $\in \Omega(\text{spaceComplexity})$.
How can the time complexity stated by the Wikipedia article be true?
Here is the "Sort-Merge Join" section translated to English. Sorry, no markdown quote, just everything from here on is the quote. It's translated poorly (not how you would write it in English if you know what you're writing) in some parts to preserve the meaning as well as possible. I marked my own inline comments with ///
.
Quote of https://de.wikipedia.org/wiki/Joinalgorithmen#Sort-Merge_Join
Sort-Merge Join
Both relations get sorted by their join attributes. The result can be determined via a single scan through both sorted relations.
The algorithm is only suited for natural join and equi-join.
Pseudocode
Implementation of $R\bowtie_{R.a=S.a} S$ in pseudocode:
p_r := first tuple in R
p_s := first tuple in S
while(p_r != endof_r && p_s != endof_s)
// Collect all tuples in S with the same join attributes.
M_s := set with contents p_s /// Yes, it says "with", not "of".
foreach(t_s in S > p_s)
if(t_s.a = p_s.a)
M_s += set with contents t_s
elseif // I think they mean "else".
p_s := t_s
break foreach
endif
endforeach
// Seach suitable start tuple in R. /// "passend" can also be translated "fitting" or "matching", not just "suitable".
foreach(t_r in R > p_r)
p_r = t_r
if(t_r.a >= t_s.a)
break foreach
endif
endforeach
// Output tuples.
foreach(t_r in R > p_r)
if(t_r.a > t_s.a)
break foreach
endif
foreach(t_s in M_s)
Write output: (t_r, t_s)
endforeach
p_r = t_r
endforeach
endwhile
Evaluation
Sorting can be done with effort $\mathcal{O}(|R|\log|R|+|S|\log|S|)$. The number of block accesses to sort $S$ is $b_s\left(2\log\frac{b_s}{b_{free}}\right)+b_s$ in the worst case, analogous for $R$.
A merge of both relations after sorting them costs $\mathcal{O}(|R|+|S|)$. In the best case – i.e. the relations are already sorted –, the costs of merging are the only ones.
In the normal case, the total costs are $\mathcal{O}(n\log n)$.
Variants
[Not translated because it doesn't seem to be important for the question.]