Index to speed up query
My first attempt would be to add btree indexes, not hash ones.


an index on B (attribute4, attribute3) and
an index on A (attribute1, attribute2)


The reasoning behind the suggestion is that the only a small part of the first index on B needs to be read, only the part that has attribute4 = 'String4' and then the values of attribute3 will be used for the join, against the other index on A.