@@ -62,11 +62,17 @@ func NewInTuple(left sql.Expression, right sql.Expression) *InTuple {
6262
6363// validateAndEvalRightTuple will evaluate the right tuple, check if leftType and the right Tuple are comparable,
6464// 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
6970func 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+
7076 // If left is StringType and ANY of the right is NumberType, then we should use Double Type for comparison
7177 // If left is NumberType and ANT of the left is StringType, then we should use Double Type for comparison
7278 lColCount := types .NumColumns (lType )
@@ -112,7 +118,10 @@ func validateAndEvalRightTuple(ctx *sql.Context, lType sql.Type, right Tuple, ro
112118 } else if types .IsEnum (lType ) || types .IsSet (lType ) || types .IsText (lType ) {
113119 cmpType = lType
114120 } 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+ }
116125 }
117126
118127 return rVals , cmpType , rHasNull , nil
@@ -240,6 +249,11 @@ func NewHashInTuple(ctx *sql.Context, left, right sql.Expression) (*HashInTuple,
240249}
241250
242251// 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
243257func newInMap (ctx * sql.Context , lType sql.Type , right Tuple ) (map [uint64 ]struct {}, sql.Type , bool , error ) {
244258 if lType == types .Null {
245259 return nil , nil , true , nil
0 commit comments