Hi I have this postgresql code that I want to optimize to use less temporary disk space:
SELECT l1.name, l2.name
FROM label l1 INNER JOIN label l2 ON l1.id > l2.id INNER JOIN
label l3 ON l1.id <> l3.id AND l2.id <> l3.id
WHERE NOT EXISTS (SELECT * FROM release_label rl1 INNER JOIN release_label rl2 ON rl1.release = rl2.release WHERE rl1.label = l1.id AND rl2.label = l2.id) AND
EXISTS (SELECT * FROM release_label rl1 INNER JOIN release_label rl3 ON rl1.release = rl3.release WHERE rl1.label = l1.id AND rl3.label = l3.id) AND
EXISTS (SELECT * FROM release_label rl2 INNER JOIN release_label rl3 ON rl2.release = rl3.release WHERE rl2.label = l2.id AND rl3.label = l3.id)`
The database that im using is musicbrainz but it gives me this error:
"could not write block 1973434 of temporary file: No space left on device"
I have a simplified version of the musicbrainz database which has less rows and it works perfectly, please help me find a way to optimize this code, cheers