-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
exec: handle some mixed type comparison expressions #39464
exec: handle some mixed type comparison expressions #39464
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.
Reviewed 7 of 16 files at r1.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @jordanlewis, @rafiss, and @rohany)
pkg/sql/distsqlrun/column_exec_setup.go, line 911 at r1 (raw file):
// handles invalid types for the IN and NOT IN operations at this point, // and we allow a comparison between t and t tuple. if t.Operator == tree.In || t.Operator == tree.NotIn {
I don't think we should remove this? I don't think the same rules apply for IN/NOT IN
pkg/sql/exec/execgen/cmd/execgen/overloads.go, line 373 at r1 (raw file):
} func (c intCustomizer) getCmpOpCompareFunc() compareFunc {
is the idea that we add more functions like this + compatible types below to add support for mixed type operations?
pkg/sql/exec/compare.go, line 16 at r1 (raw file):
// compareInts compares two int values. This function allows us to easily // handle mixec-type integer comparison.
[nit] misspelled
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.
Nice work! A few nits from me.
Reviewed 9 of 16 files at r1.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @jordanlewis and @rafiss)
pkg/sql/distsqlrun/column_exec_setup.go, line 849 at r1 (raw file):
} if rConstArg, rConst := right.(tree.Datum); rConst {
[nit]: extra newline.
pkg/sql/exec/execgen/cmd/execgen/projection_ops_gen.go, line 221 at r1 (raw file):
{{range $left := .ConstSides}} // GetProjectionConstOperator returns the appropriate constant projection // operator for the given column type and comparison.
[nit]: this comment needs minor update as well.
pkg/sql/exec/execgen/cmd/execgen/projection_ops_gen.go, line 289 at r1 (raw file):
// GetProjectionOperator returns the appropriate projection operator for the // given column type and comparison.
ditto
pkg/sql/exec/execgen/cmd/execgen/selection_ops_gen.go, line 253 at r1 (raw file):
typToOverloads := make(map[types.T][]*overload) for _, overload := range comparisonOpOverloads { if overload.LTyp != overload.RTyp {
[nit]: a comment why we're skipping mixed types here might be helpful.
pkg/sql/exec/types/types.go, line 66 at r1 (raw file):
CompatibleTypes[Bytes] = append(CompatibleTypes[Bytes], Bytes) CompatibleTypes[Decimal] = append(CompatibleTypes[Decimal], Decimal) CompatibleTypes[Int8] = append(CompatibleTypes[Int8], Int8)
[nit]: it might be cleaner to define "all int types" and use that to append to compatible types.
pkg/sql/logictest/testdata/logic_test/vectorize, line 70 at r1 (raw file):
# Mixed type comparison query IB SELECT c, c > 1 FROM a LIMIT 3
[nit]: I think you might be able to cast an INT8 to INT4 here to make it explicit mixed-type comparison (then you'd also not need a new column). Additionally, it'd be nice to see comparison with other int types.
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.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @jordanlewis, @rafiss, @rohany, and @yuzefovich)
pkg/sql/distsqlrun/column_exec_setup.go, line 849 at r1 (raw file):
Previously, yuzefovich wrote…
[nit]: extra newline.
done
pkg/sql/distsqlrun/column_exec_setup.go, line 911 at r1 (raw file):
Previously, rohany (Rohan Yadav) wrote…
I don't think we should remove this? I don't think the same rules apply for IN/NOT IN
Not sure I follow -- previously we already were returning a nil
error here in the case of IN/NOT IN. We will continue to do that.
pkg/sql/exec/execgen/cmd/execgen/overloads.go, line 373 at r1 (raw file):
Previously, rohany (Rohan Yadav) wrote…
is the idea that we add more functions like this + compatible types below to add support for mixed type operations?
yeah, that was my thinking. though to really support mixed types, we'd need to have customizer
s that are like intDecimal (etc), not just between different ints.
pkg/sql/exec/execgen/cmd/execgen/projection_ops_gen.go, line 221 at r1 (raw file):
Previously, yuzefovich wrote…
[nit]: this comment needs minor update as well.
done
pkg/sql/exec/execgen/cmd/execgen/projection_ops_gen.go, line 289 at r1 (raw file):
Previously, yuzefovich wrote…
ditto
done
pkg/sql/exec/execgen/cmd/execgen/selection_ops_gen.go, line 253 at r1 (raw file):
Previously, yuzefovich wrote…
[nit]: a comment why we're skipping mixed types here might be helpful.
actually, on further consideration, we should support mixed types here too
pkg/sql/exec/compare.go, line 16 at r1 (raw file):
Previously, rohany (Rohan Yadav) wrote…
[nit] misspelled
done
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.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @jordanlewis, @rafiss, @rohany, and @yuzefovich)
pkg/sql/distsqlrun/column_exec_setup.go, line 911 at r1 (raw file):
Previously, rafiss (Rafi Shamim) wrote…
Not sure I follow -- previously we already were returning a
nil
error here in the case of IN/NOT IN. We will continue to do that.
Yeah never mind, I think I misunderstood.
446730d
to
6c6395c
Compare
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.
Reviewed 14 of 14 files at r2.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @jordanlewis, @rafiss, @rohany, and @yuzefovich)
pkg/col/coltypes/types.go, line 66 at r2 (raw file):
CompatibleTypes[Bytes] = append(CompatibleTypes[Bytes], Bytes) CompatibleTypes[Decimal] = append(CompatibleTypes[Decimal], Decimal) CompatibleTypes[Int8] = append(CompatibleTypes[Int8], Int8)
[nit]: it might be cleaner to define "all int types" and use that to append to compatible types.
pkg/sql/distsqlrun/column_exec_setup.go, line 915 at r2 (raw file):
} if !left.Identical(right) {
I think this part needs to be kept though, right?
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.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @jordanlewis, @rafiss, @rohany, and @yuzefovich)
pkg/sql/distsqlrun/column_exec_setup.go, line 915 at r2 (raw file):
Previously, yuzefovich wrote…
I think this part needs to be kept though, right?
This part is removed because we will now allow comparisons to happen even if the left and right type are not identical.
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.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @jordanlewis, @rafiss, @rohany, and @yuzefovich)
pkg/col/coltypes/types.go, line 66 at r2 (raw file):
Previously, yuzefovich wrote…
[nit]: it might be cleaner to define "all int types" and use that to append to compatible types.
yeah i like that idea. i'll do it
6c6395c
to
a1a1024
Compare
This is ready for another review, whenever someone has a chance |
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.
but I haven't thought much about mixed-type comparisons, so ideally I'd wait for Rohan's approval.
Reviewed 1 of 1 files at r3.
Reviewable status: complete! 1 of 0 LGTMs obtained (waiting on @jordanlewis, @rafiss, @rohany, and @yuzefovich)
pkg/sql/distsqlrun/column_exec_setup.go, line 915 at r2 (raw file):
Previously, rafiss (Rafi Shamim) wrote…
This part is removed because we will now allow comparisons to happen even if the left and right type are not identical.
Ok, SGTM.
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.
This LGTM, should probably work with matt next to get tests that stress the mixed type operations here.
Reviewable status: complete! 1 of 0 LGTMs obtained (waiting on @jordanlewis, @rafiss, @rohany, and @yuzefovich)
a1a1024
to
5ecb366
Compare
This adds support for int-int comparisons and float-float comparisons (of different sizes), as well as various string comparisons. This is necessary to support TPC-H queries 7, 16, 19, and 21 (though there are still other issues to address before those are fully supported). There is some refactoring here so that as a next step we can support comparisons between different types entirely (e.g. int-decimal). touches cockroachdb#39189 Release note: None
5ecb366
to
bc09926
Compare
thanks all! bors r+ |
39464: exec: handle some mixed type comparison expressions r=rafiss a=rafiss This adds support for int-int comparisons and float-float comparisons (of different sizes), as well as various string comparisons. This is necessary to support TPC-H queries 7, 16, 19, and 21 (though there are still other issues to address before those are fully supported). There is some refactoring here so that as a next step we can support comparisons between different types entirely (e.g. int-decimal). touches #39189 Release note: None 39472: opt: prune RHS of a semi/anti join r=ridwanmsharif a=ridwanmsharif Fixes #38704. This change adds a PruneSemiAntiJoinRightCols to prune columns in the RHS of a semi/anti join. Alternatively, we could just tag the PruneJoinRightCols rule as higher priority to achieve the same effect (previously that rule was never triggered because the `EliminateProjects` rule would fire and remove the projections after `PruneJoinLeftCols` rule is applied). I prefer this rule because it avoids requiring an ordering of transformations. Release note: None Co-authored-by: Rafi Shamim <[email protected]> Co-authored-by: Ridwan Sharif <[email protected]>
Build succeeded |
This adds support for int-int comparisons and float-float comparisons
(of different sizes), as well as various string comparisons. This
is necessary to support TPC-H queries 7, 16, 19, and 21 (though there
are still other issues to address before those are fully supported).
There is some refactoring here so that as a next step we can support
comparisons between different types entirely (e.g. int-decimal).
touches #39189
Release note: None