[OpenStreetMap] #4494: Relation members won't download
Tom Hughes
tom at compton.nu
Fri Jul 27 11:03:26 BST 2012
On 27/07/12 10:53, Andy Allan wrote:
> When you look at the queries they aren't doing much that's
> complicated, and would be much simpler as e.g. node_id in (123, 234,
> 345) rather than ((node_id = 123) or (node_id = 234) or ...)
>
> Tom, would you say this is a bug in rails (arel making stupid queries)
> or in postgres itself, using a huge chunk of memory for a (reasonably)
> straightforward query?
My assumption is that it is decomposing that massive list of ORs
recursively, leading to a very deep stack.
So it finds the first OR and calls a function on each side of it, then
one of those finds the second one and does the same thing and so on.
Obviously postgres could be improved by doing that iteratively, or
perhaps by recognising a long chain of ORs and trying to split in the
middle each time to give a more balanced stack that would have a maximum
size defined by lg(n) rather than n.
My guess is that using node_id IN (...) would not need to do that
recursive analysis at all.
None of this is tested however.
Tom
--
Tom Hughes (tom at compton.nu)
http://compton.nu/
More information about the rails-dev
mailing list