@@ -698,13 +698,18 @@ func (er *expressionRewriter) handleCompareSubquery(ctx context.Context, planCtx
698
698
er .err = err
699
699
return v , true
700
700
}
701
+ << << << < HEAD
701
702
702
703
noDecorrelate := hintFlags & hint .HintFlagNoDecorrelate > 0
703
704
if noDecorrelate && len (extractCorColumnsBySchema4LogicalPlan (np , planCtx .plan .Schema ())) == 0 {
704
705
b .ctx .GetSessionVars ().StmtCtx .SetHintWarning (
705
706
"NO_DECORRELATE() is inapplicable because there are no correlated columns." )
706
707
noDecorrelate = false
707
708
}
709
+ == == == =
710
+ corCols := coreusage .ExtractCorColumnsBySchema4LogicalPlan (np , planCtx .plan .Schema ())
711
+ noDecorrelate := isNoDecorrelate (planCtx , corCols , hintFlags )
712
+ >> >> >> > 9331 aeab088 (collate : latin1_bin has the same collate with utf8mb4_bin ,utf8_bin (#60702 ))
708
713
709
714
// Only (a,b,c) = any (...) and (a,b,c) != all (...) can use row expression.
710
715
canMultiCol := (! v .All && v .Op == opcode .EQ ) || (v .All && v .Op == opcode .NE )
@@ -1007,13 +1012,18 @@ func (er *expressionRewriter) handleExistSubquery(ctx context.Context, planCtx *
1007
1012
return v , true
1008
1013
}
1009
1014
np = er .popExistsSubPlan (planCtx , np )
1015
+ << << << < HEAD
1010
1016
1011
1017
noDecorrelate := hintFlags & hint .HintFlagNoDecorrelate > 0
1012
1018
if noDecorrelate && len (extractCorColumnsBySchema4LogicalPlan (np , planCtx .plan .Schema ())) == 0 {
1013
1019
b .ctx .GetSessionVars ().StmtCtx .SetHintWarning (
1014
1020
"NO_DECORRELATE() is inapplicable because there are no correlated columns." )
1015
1021
noDecorrelate = false
1016
1022
}
1023
+ == == == =
1024
+ corCols := coreusage .ExtractCorColumnsBySchema4LogicalPlan (np , planCtx .plan .Schema ())
1025
+ noDecorrelate := isNoDecorrelate (planCtx , corCols , hintFlags )
1026
+ >> >> >> > 9331 aeab088 (collate : latin1_bin has the same collate with utf8mb4_bin ,utf8_bin (#60702 ))
1017
1027
semiJoinRewrite := hintFlags & hint .HintFlagSemiJoinRewrite > 0
1018
1028
if semiJoinRewrite && noDecorrelate {
1019
1029
b .ctx .GetSessionVars ().StmtCtx .SetHintWarning (
@@ -1180,6 +1190,7 @@ func (er *expressionRewriter) handleInSubquery(ctx context.Context, planCtx *exp
1180
1190
// If the leftKey and the rightKey have different collations, don't convert the sub-query to an inner-join
1181
1191
// since when converting we will add a distinct-agg upon the right child and this distinct-agg doesn't have the right collation.
1182
1192
// To keep it simple, we forbid this converting if they have different collations.
1193
+ << << << < HEAD
1183
1194
lt , rt := lexpr .GetType (), rexpr .GetType ()
1184
1195
collFlag := collate .CompatibleCollate (lt .GetCollate (), rt .GetCollate ())
1185
1196
@@ -1190,6 +1201,13 @@ func (er *expressionRewriter) handleInSubquery(ctx context.Context, planCtx *exp
1190
1201
"NO_DECORRELATE() is inapplicable because there are no correlated columns." )
1191
1202
noDecorrelate = false
1192
1203
}
1204
+ == == == =
1205
+ // tested by TestCollateSubQuery.
1206
+ lt , rt := lexpr .GetType (er .sctx .GetEvalCtx ()), rexpr .GetType (er .sctx .GetEvalCtx ())
1207
+ collFlag := collate .CompatibleCollate (lt .GetCollate (), rt .GetCollate ())
1208
+ corCols := coreusage .ExtractCorColumnsBySchema4LogicalPlan (np , planCtx .plan .Schema ())
1209
+ noDecorrelate := isNoDecorrelate (planCtx , corCols , hintFlags )
1210
+ >> >> >> > 9331 aeab088 (collate : latin1_bin has the same collate with utf8mb4_bin ,utf8_bin (#60702 ))
1193
1211
1194
1212
// If it's not the form of `not in (SUBQUERY)`,
1195
1213
// and has no correlated column from the current level plan(if the correlated column is from upper level,
@@ -1234,6 +1252,16 @@ func (er *expressionRewriter) handleInSubquery(ctx context.Context, planCtx *exp
1234
1252
return v , true
1235
1253
}
1236
1254
1255
+ func isNoDecorrelate (planCtx * exprRewriterPlanCtx , corCols []* expression.CorrelatedColumn , hintFlags uint64 ) bool {
1256
+ noDecorrelate := hintFlags & hint .HintFlagNoDecorrelate > 0
1257
+ if noDecorrelate && len (corCols ) == 0 {
1258
+ planCtx .builder .ctx .GetSessionVars ().StmtCtx .SetHintWarning (
1259
+ "NO_DECORRELATE() is inapplicable because there are no correlated columns." )
1260
+ noDecorrelate = false
1261
+ }
1262
+ return noDecorrelate
1263
+ }
1264
+
1237
1265
func (er * expressionRewriter ) handleScalarSubquery (ctx context.Context , planCtx * exprRewriterPlanCtx , v * ast.SubqueryExpr ) (ast.Node , bool ) {
1238
1266
intest .AssertNotNil (planCtx )
1239
1267
ci := planCtx .builder .prepareCTECheckForSubQuery ()
@@ -1244,13 +1272,18 @@ func (er *expressionRewriter) handleScalarSubquery(ctx context.Context, planCtx
1244
1272
return v , true
1245
1273
}
1246
1274
np = planCtx .builder .buildMaxOneRow (np )
1275
+ << << << < HEAD
1247
1276
1248
1277
noDecorrelate := hintFlags & hint .HintFlagNoDecorrelate > 0
1249
1278
if noDecorrelate && len (extractCorColumnsBySchema4LogicalPlan (np , planCtx .plan .Schema ())) == 0 {
1250
1279
planCtx .builder .ctx .GetSessionVars ().StmtCtx .SetHintWarning (
1251
1280
"NO_DECORRELATE() is inapplicable because there are no correlated columns." )
1252
1281
noDecorrelate = false
1253
1282
}
1283
+ == == == =
1284
+ correlatedColumn := coreusage .ExtractCorColumnsBySchema4LogicalPlan (np , planCtx .plan .Schema ())
1285
+ noDecorrelate := isNoDecorrelate (planCtx , correlatedColumn , hintFlags )
1286
+ >> >> >> > 9331 aeab088 (collate : latin1_bin has the same collate with utf8mb4_bin ,utf8_bin (#60702 ))
1254
1287
1255
1288
if planCtx .builder .disableSubQueryPreprocessing || len (ExtractCorrelatedCols4LogicalPlan (np )) > 0 || hasCTEConsumerInSubPlan (np ) {
1256
1289
planCtx .plan = planCtx .builder .buildApplyWithJoinType (planCtx .plan , np , LeftOuterJoin , noDecorrelate )
0 commit comments