@@ -62,11 +62,17 @@ func NewInTuple(left sql.Expression, right sql.Expression) *InTuple {
62
62
63
63
// validateAndEvalRightTuple will evaluate the right tuple, check if leftType and the right Tuple are comparable,
64
64
// determine what type to use to compare the two sides, and indicate if right Tuple contains any NULL elements.
65
- // The NULL handling for IN expressions is tricky. According to
66
- // https://dev.mysql.com/doc/refman/8.0/en/comparison-operators.html#operator_in:
67
- // To comply with the SQL standard, IN() returns NULL not only if the expression on the left hand side is NULL, but
68
- // also if no match is found in the list and one of the expressions in the list is NULL.
65
+ // Returns
66
+ // - slice of the evaluated elements
67
+ // - sql.Type to convert elements to before hashing
68
+ // - bool indicating if there are null elements
69
+ // - error
69
70
func validateAndEvalRightTuple (ctx * sql.Context , lType sql.Type , right Tuple , row sql.Row ) ([]any , sql.Type , bool , error ) {
71
+ // The NULL handling for IN expressions is tricky. According to
72
+ // https://dev.mysql.com/doc/refman/8.0/en/comparison-operators.html#operator_in:
73
+ // To comply with the SQL standard, IN() returns NULL not only if the expression on the left hand side is NULL, but
74
+ // also if no match is found in the list and one of the expressions in the list is NULL.
75
+
70
76
// If left is StringType and ANY of the right is NumberType, then we should use Double Type for comparison
71
77
// If left is NumberType and ANT of the left is StringType, then we should use Double Type for comparison
72
78
lColCount := types .NumColumns (lType )
@@ -112,7 +118,10 @@ func validateAndEvalRightTuple(ctx *sql.Context, lType sql.Type, right Tuple, ro
112
118
} else if types .IsEnum (lType ) || types .IsSet (lType ) || types .IsText (lType ) {
113
119
cmpType = lType
114
120
} else {
115
- cmpType = types .GetCompareType (lType , right [0 ].Type ())
121
+ cmpType = lType
122
+ for _ , el := range right {
123
+ cmpType = types .GetCompareType (cmpType , el .Type ())
124
+ }
116
125
}
117
126
118
127
return rVals , cmpType , rHasNull , nil
@@ -240,6 +249,11 @@ func NewHashInTuple(ctx *sql.Context, left, right sql.Expression) (*HashInTuple,
240
249
}
241
250
242
251
// newInMap hashes static expressions in the right child Tuple of a InTuple node
252
+ // returns
253
+ // - map of the hashed elements
254
+ // - sql.Type to convert elements to before hashing
255
+ // - bool indicating if there are null elements
256
+ // - error
243
257
func newInMap (ctx * sql.Context , lType sql.Type , right Tuple ) (map [uint64 ]struct {}, sql.Type , bool , error ) {
244
258
if lType == types .Null {
245
259
return nil , nil , true , nil
0 commit comments