Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Some issues with prefetching and related queries #106
(Using pony-0.6, Python 3.3)
I'm seeing some extra queries I don't understand during prefetching and getting related entities. Setup is a simple Forum entity with possible related Topics:
I see the following queries
I assume there are 2 extra
If so, I figured I could add a
and expected to see just one extra query, like
but instead see all of these queries now
At least some of those are logically duplicates, so I'm not sure what's happening there. After further testing, if I add a single field into the
The queries go back to the first example (loading
Further, I have a second (and possibly related) issue. Setup is similar, except instead of
And I see these queries
Again 2 extra queries (without using prefetch), but in
So now not only
Thanks for the reporting, these extra queries were caused by a bug. Roughly speaking, after the retrieving of just primary key column Pony does not believed that this was the entire object and tries to fetch it again. Now this behavior should be fixed, and no object should be fetched more then once.
It is possible to optimize logic of
It is because the prefetching goes recursively. When you call
Anyway, now after the major bug in query logic was fixed the number of queries should be much lower then you initially experienced even without using of prefetching. Tell me what do you think, and thanks again for the reporting!
Thanks! The main bug appears fixed.
I created a couple of patches to reduce the queries further in my specific situation. I don't expect you to merge these necessarily, but here they are in any case (tests are passing, added a couple):
Example output, given the same script as before:
(These patches only affect queries that use