Avoid unnecessary self-joins in TripleRelationJoiner

The keys in nodeSets.toMap() are actually Var objects, not Strings -- previously this lookup was always returning null, resulting in lots of unnecessary self-joins. Spurious self-joins are not optimised very well in many RDBMs (including Postgres and MySQL, which I've tested this on)

This patch also introduces the ability to fall back to primary keys as unique keys for JDBC drivers that don't return primary keys in the former.