That would be trivial with a join:
SELECT TRUE
FROM items AS i1
JOIN mapping AS m ON i1.id = m.id_a
JOIN items AS i2 ON m.id_b = i2.id
WHERE i1.name = '/foo/'
AND i2.name = '/foo/1' AND i2.group = 'app1';
If this returns a row, there is a match.
For good performance, create these tow indexes (if they don't already exist):
CREATE INDEX ON item (name, group);
CREATE INDEX ON mapping (id_b);
Then you should get an efficient nested loop join.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…