Re: index for or relation

Поиск
Список
Период
Сортировка
От Chester Kustarz
Тема Re: index for or relation
Дата
Msg-id Pine.BSO.4.44.0409301614310.17616-100000@detroit.arbor.net
обсуждение исходный текст
Ответ на index for or relation  (Tsirkin Evgeny <tsurkin@mail.jct.ac.il>)
Список pgsql-admin
> select pj.populationtype,getPopulationName(pj.populationtype,pj.population) as
populationname,pj.population,pj.yaadid,
>                 pj.insert_trans_id,pj.invalidate_trans_id,
>                 j.time,w.login as worker_login,j.action,j.transaction_id as j_transaction_id
>              from journal j
>              INNER JOIN population2yaad_journal pj on (j.transaction_id=pj.insert_trans_id
>                     OR j.transaction_id=pj.invalidate_trans_id)
>              where j.action = 'add_yaad' or j.action = 'delete_yaad' or  j.action = 'change_yaad' order by j.time

Perhaps you can break apart the query by using UNION (ALL). Something
like:

SELECT ...
FROM journal j
JOIN population2yaad_journal pg
ON (j.transaction_id=pj.insert_trans_id)
WHERE j.action = 'add_yaad'
OR j.action = 'delete_yaad'
OR  j.action = 'change_yaad'
UNION ALL
SELECT ...
FROM journal j
JOIN population2yaad_journal pg
ON (j.transaction_id=pj.invalidate_trans_id)
WHERE (j.action = 'add_yaad'
OR j.action = 'delete_yaad'
OR  j.action = 'change_yaad')
/* Prevent duplicates from UNION *ALL*: */
AND j.transaction_id <> pj.insert_trans_id

> However this does not use the indexes because of the OR in the INNER JOIN.
> How should i create indexes to make this work right?

If this still doesn't work, then perhaps your indexes are not selective
enough or perhaps you need to ANALYZE your table.



В списке pgsql-admin по дате отправления:

Предыдущее
От: RWilke@Connectria.com
Дата:
Сообщение: Clustering PostgreSQL
Следующее
От: "Cao Van Khanh"
Дата:
Сообщение: Re: Compilation error with --with-java option