This is good, because UNION ALL makes pagination of any sort utterly evilEdit: never mind, took a new approach,![]()
How so?This is good, because UNION ALL makes pagination of any sort utterly evil![]()
It is the amount of data that needs to be inserted into the temporary table to implement pagination when using unions.How so?
Considering that a temporary table is built as the result of any union, if where constraints are appropriate at each query of the union then using limit on the output of the temporary table is simple.
select *
from a
where a.foo != 'bar'
UNION ALL
select *
from b
where a.bar != 'foo'
select *
from (
select *
from a
where a.foo != 'bar'
UNION ALL
select *
from b
where a.bar != 'foo'
) c
limit 50
offset 10000
Push as many joins outside of the UNION if you can.Option One:
UNION ALL does work well and guarantees there will be members to display per level 1 forum if there are any. It's just noticeably slower to execute, and can become quite large if there are a number of level 1 nodes on forum home. I use INNER JOIN for the user data, and that appears to be a little faster than LEFT JOIN.
select *
from a
join d on d.id = a.id
where a.foo != 'bar'
UNION ALL
select *
from b
join d on d.id = b.id
where b.bar != 'foo'
select *
from
(select a.id
from a
where a.foo != 'bar'
UNION ALL
select b.id
from b
where b.bar != 'foo'
) c
join d on d.id = c.id
Not totally sure I understand what your objective/output is. But it does sounds like a few joins would be more optimised than a union. That said, I can't imagine you'd be pulling back more than a few thousand records in your union result set, so a union should be quite fast too.UNION ALL does work well and guarantees there will be members to display per level 1 forum if there are any. It's just noticeably slower to execute, and can become quite large if there are a number of level 1 nodes on forum home. I use INNER JOIN for the user data, and that appears to be a little faster than LEFT JOIN.
Instead of programmatically generating a UNION ALL and repeating the same query a lot, can you rewrite the WHERE clause on the node table to use IN rather than = ?
We use essential cookies to make this site work, and optional cookies to enhance your experience.