SubQuery doesn't seem to work
The locksAgg query returns results results on it's own, but when added as a subquery, I get zero results. Am I doing something wrong with how I am using subqueries?
12 Replies
genetic-orange•2mo ago
it looks fine... perhaps keep modifying the second query part to see if something gets it to return data
ambitious-aquaOP•2mo ago
OK. I think I may have found a bug.
This query shows results:
but when I include the join, it returns no results.
Is there some kind of bug with including the same collection in the subquery as the main query?
genetic-orange•2mo ago
Shouldn't be but tagging @samwillis
ambitious-aquaOP•2mo ago
If I flip the query around and use votes in the from clause, it returns results:
Seems like there is some kind of cross leaking in the where clause as well
for example this query the overallPercent ends up the same as the vote.percent
But with this query the sum is correct
pleasant-yellow•2mo ago
Yep, it looks like a bug in the optimiser, could you file an issue? I'll try and take a good look asap.
genetic-orange•2mo ago
I had Claude Code run at it for a while https://github.com/TanStack/db/pull/719
GitHub
[Will be closed]: Investigate Discord Bug Report by KyleAMathews ·...
Investigated Discord bug report where using the same collection with the same alias in both a subquery and main query causes:
Empty results when subquery has joins
Aggregation cross-leaking (wrong...
pleasant-yellow•2mo ago
Ah! You reuse the alias between a sub query and main query. If you rename the "vote" in one to "vote2" it should work.
genetic-orange•2mo ago
heh that's an easier fix! Should we validate against this? Or is something we can fix internally?
pleasant-yellow•2mo ago
Validate for now, but we should make it work with duplicates at some point.
genetic-orange•2mo ago
cool, I'll have claude code whip up something 😎
genetic-orange•2mo ago
GitHub
fix: validate against duplicate collection aliases in subqueries by...
Summary
Fixes a Discord bug where using the same collection alias in both a parent query and subquery causes empty results or incorrect aggregation values.
Problem
When both parent and subquery use...
ambitious-aquaOP•2mo ago
Just confirmed that renaming the alias fixes the issue. Thanks, all!