Hi, I'm writing a query which will grab translations from a table. The rules are that I select the keys with the specific locale first, then I select the keys with the language, finally select the rest in english.
I wrote the query below, but I'm not happy with the 12 step explain plan and cost of 486. It's already using the PK also. Is there a cleaner way to write this that I'm not seeing?
Thanks for looking!
I wrote the query below, but I'm not happy with the 12 step explain plan and cost of 486. It's already using the PK also. Is there a cleaner way to write this that I'm not seeing?
Code:
SELECT key_name, key_value, locale
FROM translation t1
WHERE set_id = 1
AND locale = 'fr-FR'
UNION ALL
SELECT key_name, key_value, locale
FROM translation t2
WHERE set_id = 1
AND locale = 'fr'
AND NOT EXISTS(SELECT 1
FROM translation t3
WHERE set_id = 1
AND locale = 'fr-FR'
AND t3.key_name = t2.key_name)
UNION ALL
SELECT key_name, key_value, locale
FROM translation t4
WHERE set_id = 1
AND locale = 'en'
AND NOT EXISTS(SELECT 1
FROM translation t5
WHERE set_id = 1
AND locale IN ('fr-FR', 'fr')
AND t5.key_name = t4.key_name);
Thanks for looking!