Skip to content

decompose tuple inequalities#3575

Merged
jycor merged 5 commits into
mainfrom
james/tuples
Jun 4, 2026
Merged

decompose tuple inequalities#3575
jycor merged 5 commits into
mainfrom
james/tuples

Conversation

@jycor
Copy link
Copy Markdown
Contributor

@jycor jycor commented Jun 4, 2026

This PR extends the tuple in filter decomposition logic to cover tuples in equallities and inequalities.

@jycor jycor requested a review from nicktobey June 4, 2026 17:21
Comment thread sql/analyzer/costed_index_scan.go Outdated

leftTuple, ok := left.(expression.Tuple)
if !ok {
// TODO: if len(leftTuple) == 0 or len(rightTuple) == 0, just return false?
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

"just return false" as in replace the expression with false? I don't think we can do that. For example, () = () would be true. But I also imagine that zero-length tuples will end up being handled correctly by the individual cases.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Don't forget about this

Comment thread sql/analyzer/costed_index_scan.go Outdated
switch e := e.(type) {
case *expression.InTuple, *expression.HashInTuple:
newExpr, ok = c.transformInTupleForIndexCosting(leftTuple, rightTuple)
case *expression.Equals: // TODO: *expression.NullSafeEquals?
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This probably shouldn't be a TODO.

Experimenting with MySQL, it seems that a normal tuple comparison is equivalent to normal comparing each element, and null safe tuple comparison is equivalent to null-safe comparing each element.

Dolt appears to get this wrong: dolthub/dolt#11024

Comment thread sql/analyzer/costed_index_scan_test.go
Comment thread sql/analyzer/costed_index_scan.go Outdated

leftTuple, ok := left.(expression.Tuple)
if !ok {
// TODO: if len(leftTuple) == 0 or len(rightTuple) == 0, just return false?
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Don't forget about this

@jycor jycor enabled auto-merge (squash) June 4, 2026 20:19
Copy link
Copy Markdown
Contributor

@nicktobey nicktobey left a comment

Choose a reason for hiding this comment

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

Looks good!

@jycor jycor merged commit aa06987 into main Jun 4, 2026
8 checks passed
@jycor jycor deleted the james/tuples branch June 4, 2026 20:25
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