-
-
Notifications
You must be signed in to change notification settings - Fork 209
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
Conversation
There was a problem hiding this 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);`, |
There was a problem hiding this comment.
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);
sql/plan/existssubquery.go
Outdated
"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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
non-empty result set
sql/plan/existssubquery.go
Outdated
return nil, fmt.Errorf("error: exists operator should only work with a subquery") | ||
} | ||
|
||
results, err := subquery.HashMultiple(ctx, row) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
Adds the exists operator as described here: https://dev.mysql.com/doc/refman/8.0/en/exists-and-not-exists-subqueries.html