Chris,
I believe you can cut down the processing time by including the order by
and limit in each select:
(SELECT ... ORDER BY 2 DESC, 4 LIMIT 20)
union
(SELECT ... ORDER BY 2 DESC, 4 LIMIT 20)
ORDER BY 2 DESC, 4 LIMIT 20
Give it a try and let me know
JLL
P.S.
Question: Why not have a single table with a field log_type in ( 'A',
'B') ???
Chris Gamache wrote:
>
> Three tables...
> [...]
>
> I imagine the combination of UNION and ORDER BY causes the problem, since
> Postgres has to locate all the rows that match the search criteria, merge them,
> order them, then return the top 20...
>
> Any suggestions? Did I forget to provide any data that would make things
> clearer?