Add test suite for checking parent_prefix

Part of #206.
True fix for parent_prefix

So, the old fix, which I really thought worked, did not work for all
scenarios. As soon as there were no matches at all inside a
parent_prefix, it broke.

This time around I've restructured the SQL query somewhat, moving
conditions from the WHERE clause into the join between p1 and p2. The
old structure was a bit of a mix between implicit and explicit join
syntax and this brings it together under a explicit join syntax. Easier
to read IMHO.

One thing I'm not too happy with is that we change from a JOIN to a LEFT
OUTER JOIN when in "parent_prefix mode". I don't like changing
"structural" parts of the SQL query, but I'm not sure what can be done
about it.

Perhaps we should rewrite this entire SQL query...

Part of #206.
Merge branch 'parent_prefix-fix'