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

Add the EXISTS Operator for Select Where Filters #572

Merged
merged 11 commits into from Sep 28, 2021

Conversation

VinaiRachakonda
Copy link
Contributor

@VinaiRachakonda VinaiRachakonda commented Sep 28, 2021

@VinaiRachakonda VinaiRachakonda changed the title Vinai/exists operator Add the EXISTS Operator for Select Where Filters Sep 28, 2021
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.

LGTM, nice work

@@ -5284,6 +5284,34 @@ var QueryTests = []QueryTest{
{time.Date(2020, 1, 1, 16, 0, 0, 0, time.UTC)},
},
},
{
Query: `SELECT 1 from dual WHERE EXISTS (SELECT 1 from dual);`,
Copy link
Member

Choose a reason for hiding this comment

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

Need a test of the EXISTS expression not in the filter

i.e. SELECT EXISTS (SELECT NULL from dual);

"github.com/dolthub/go-mysql-server/sql/expression"
)

// ExistsSubquery is an expression that checks that a subquery returns a non emptyset result. It's in the plan package,
Copy link
Member

Choose a reason for hiding this comment

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

non-empty result set

return nil, fmt.Errorf("error: exists operator should only work with a subquery")
}

results, err := subquery.HashMultiple(ctx, row)
Copy link
Member

Choose a reason for hiding this comment

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

Oh nice, I forgot about this method, good use of it

Copy link
Member

Choose a reason for hiding this comment

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

For some queries this is going to be really inefficient, would be better to check for only a single row, then close the subquery iterator

You should do this as a followup, write a HasResultRow method on Subquery and use that

@VinaiRachakonda VinaiRachakonda merged commit 88a5e4a into master Sep 28, 2021
@Hydrocharged Hydrocharged deleted the vinai/exists-operator branch December 8, 2021 07:13
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.

None yet

2 participants