The following query is 10x faster if I delete the "OR" clause.
WITH RECURSIVE toeng(lang1, english, syn, enid) AS
(SELECT lang1.word, english.word, english.synonym, english.id
FROM lang1 INNER JOIN english ON lang1.english_id=english.id
UNION
SELECT CAST('' as VARCHAR(255)), english.word, english.synonym, english.id
FROM english JOIN toeng ON toeng.syn=english.id OR toeng.enid=english.synonym)
....
The goal of the query is to retrieve all the parents/children of an initial set of nodes recursively. Is there a way to make it faster? I tried to split it into multiple joins but I can't find something that is totally equivalent to that. I'm using PostgreSQL.
Aucun commentaire:
Enregistrer un commentaire