Avoid unnecessary self-joins in TripleRelationJoiner

Also uses primary keys as unique keys for databases that don't
return primary keys in the former (eg. postgres)
Merge pull request #231 from arekinath/bugfix/selfjoins

Avoid unnecessary self-joins in TripleRelationJoiner