Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql/{plan,analyzer}: Cache subquery results when joining against a subquery. #322

Merged
merged 7 commits into from
Mar 2, 2021

Conversation

reltuk
Copy link
Contributor

@reltuk reltuk commented Mar 1, 2021

No description provided.

@reltuk reltuk requested a review from zachmu March 1, 2021 22:02
Copy link
Member

@zachmu zachmu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG!

if i.cache != nil {
if err != nil {
if err == io.EOF {
i.parent.mutex.Lock()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be a little easier to read with fillCacheInParent method

i.parent.cache = i.cache
i.parent.dispose = i.dispose
} else {
i.dispose()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i.cleanUp() for this repeated block?

_, isJoin := parent.(plan.JoinNode)
_, isIndexedJoin := parent.(*plan.IndexedJoin)
if isJoin || isIndexedJoin {
sa, isSubqueryAlias := child.(*plan.SubqueryAlias)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to waste memory unnecessarily if the subquery is the first table in the join and therefore unnecessary to cache. Maybe add a TODO to fix? (algorithm to determine this case doesn't map easily to one of the transform up methods, i don't think)

Copy link
Member

@zachmu zachmu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG!

}
} else if j, isIndexedJoin := parent.(*plan.IndexedJoin); isIndexedJoin {
if j.JoinType() == plan.JoinTypeRight {
return childNum == 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong -- indexed joins always put the primary table as the first table, even if it's a right join

@reltuk reltuk merged commit f6bd31c into master Mar 2, 2021
@Hydrocharged Hydrocharged deleted the aaron/cache-subquery-alias-results-in-joins branch December 8, 2021 06:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants