Index to speed up query I have this SQL query that I have to speed up:

SELECT DISTINCT A.attribute1, A.attribute2
FROM table1 A, table2 B
WHERE A.attribute1 = B.attribute3
AND B.attribute4 = 'String';


What I am currently doing is creating a hash index on B.attribute3 to speed up the JOIN and creating another hash index on B.attribute4 to speed up the equality with 'String'.

CREATE INDEX atr3_idx ON table2 USING HASH (attribute3);
CREATE INDEX atr4_idx ON table2 USING HASH (attribute4);


Is there a better way to optimise this 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.