<br>Thanks for the reply and giving me some more background. In fact I wasn't planning to use the temporary table queries I included within rails - but to assemble the data for streaming for the C++ implementation I'm working on. Which, using the aforementioned SQL, shouldn't need to have a memory footprint above a few kilobytes. But I guess this is at the expense of relying on MySQL to behave sensibly when working on queries that return large datasets (i.e. to assemble the data lazily as it's needed by the caller - rather than to assemble it all at once in memory).<br>
<br>On your point about MySQL's rubbish optimiser: is it genuinely so bad that it's better in this case to send a huge number of ids back into the db for subsequent queries rather than build that id set up locally in the db? I can believe it in general for more complicated queries - but it strikes me (perhaps naiviely) that the example I sent is sufficiently trivial that MySQL should be able to handle it if it can do any form of optimisation on joins whatsover. Perhaps I should set up some test-cases to resolve either way...<br>
<br>Cheers,<br><br>Alex<br><br><div class="gmail_quote">2008/5/26 Tom Hughes <<a href="mailto:tom@compton.nu">tom@compton.nu</a>>:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
In message <<a href="mailto:44d06e000805240124h26649f42g9de9dc8541bd041c@mail.gmail.com">44d06e000805240124h26649f42g9de9dc8541bd041c@mail.gmail.com</a>><br>
<div class="Ih2E3d">          "Alex Wilson" <<a href="mailto:alex_wilson@pobox.com">alex_wilson@pobox.com</a>> wrote:<br>
<br>
> I've been looking at the rails_port implementation of the map query. As I<br>
> understand it, it seems to be retrieving all nodes within the bounding box<br>
> into ruby, then sending this list back out to the db to retrieve all ways,<br>
> then sending all the way ids out for finally retrieving the extra nodes and<br>
> associated relations. So there's quite a lot of (rather inefficient) data<br>
> movement between the ruby code and the database.<br>
<br>
</div>There are far bigger issues, like that fact that we create an<br>
enourmous rails activerecord object for each node...<br>
<br>
In theory we could just do a join instead of sending all the IDs<br>
back but MySQL is so rubbish that it is incapable of executing such<br>
a query in a sensible way.<br>
<div class="Ih2E3d"><br>
> I would imagine that it would be more efficient to do this all on the<br>
> database using temporary tables: rather than try to explain what I mean,<br>
> below is an example of something that works. The last three lines of which<br>
> return all the data - so you only bring back only the stuff that's needed,<br>
> only send through the bbox coords - and that resultant data can be streamed<br>
> easily and doesn't need to be in memory at once (apart from in the db -<br>
> which is designed to handle this kind of thing). Is there a particular<br>
> reason that this hasn't been done before -  am I missing something obvious?<br>
<br>
</div>Ye gads no. Potlatch already uses temporary tables which I would<br>
prefer it didn't...<br>
<br>
Even with temporary tables (and as I said, they aren't really needed<br>
as you can just join to the table that already exists) you will need<br>
to do fairly complicated joins that will most likely defeat MySQL's<br>
optimiser.<br>
<br>
The code will also no longer be "rails code" but will essentially be<br>
raw SQL at which point why would be bother to carry on using the rails<br>
framework, which costs us far more than sending the IDs back to the<br>
database does.<br>
<div><div></div><div class="Wj3C7c"><br>
Tom<br>
<br>
--<br>
Tom Hughes (<a href="mailto:tom@compton.nu">tom@compton.nu</a>)<br>
<a href="http://www.compton.nu/" target="_blank">http://www.compton.nu/</a><br>
<br>
_______________________________________________<br>
dev mailing list<br>
<a href="mailto:dev@openstreetmap.org">dev@openstreetmap.org</a><br>
<a href="http://lists.openstreetmap.org/cgi-bin/mailman/listinfo/dev" target="_blank">http://lists.openstreetmap.org/cgi-bin/mailman/listinfo/dev</a><br>
</div></div></blockquote></div><br>