diff --git a/pkg/planner/core/exhaust_physical_plans.go b/pkg/planner/core/exhaust_physical_plans.go index d86a344aa57b6..7e4baa00dbddd 100644 --- a/pkg/planner/core/exhaust_physical_plans.go +++ b/pkg/planner/core/exhaust_physical_plans.go @@ -1107,11 +1107,6 @@ func buildIndexJoinInner2TableScan( lastColMng = indexJoinResult.lastColManager } joins = make([]base.PhysicalPlan, 0, 3) - failpoint.Inject("MockOnlyEnableIndexHashJoin", func(val failpoint.Value) { - if val.(bool) && !p.SCtx().GetSessionVars().InRestrictedSQL { - failpoint.Return(constructIndexHashJoin(p, prop, outerIdx, innerTask, nil, keyOff2IdxOff, path, lastColMng)) - } - }) joins = append(joins, constructIndexJoin(p, prop, outerIdx, innerTask, ranges, keyOff2IdxOff, path, lastColMng, true)...) // We can reuse the `innerTask` here since index nested loop hash join // do not need the inner child to promise the order. @@ -1148,11 +1143,6 @@ func buildIndexJoinInner2IndexScan( joins = make([]base.PhysicalPlan, 0, 3) rangeInfo, maxOneRow := indexJoinPathGetRangeInfoAndMaxOneRow(p.SCtx(), outerJoinKeys, indexJoinResult) innerTask := constructInnerIndexScanTask(p, prop, wrapper, indexJoinResult.chosenPath, indexJoinResult.chosenRanges.Range(), indexJoinResult.chosenRemained, indexJoinResult.idxOff2KeyOff, rangeInfo, false, false, avgInnerRowCnt, maxOneRow) - failpoint.Inject("MockOnlyEnableIndexHashJoin", func(val failpoint.Value) { - if val.(bool) && !p.SCtx().GetSessionVars().InRestrictedSQL && innerTask != nil { - failpoint.Return(constructIndexHashJoin(p, prop, outerIdx, innerTask, indexJoinResult.chosenRanges, keyOff2IdxOff, indexJoinResult.chosenPath, indexJoinResult.lastColManager)) - } - }) if innerTask != nil { joins = append(joins, constructIndexJoin(p, prop, outerIdx, innerTask, indexJoinResult.chosenRanges, keyOff2IdxOff, indexJoinResult.chosenPath, indexJoinResult.lastColManager, true)...) // We can reuse the `innerTask` here since index nested loop hash join @@ -2667,12 +2657,6 @@ func tryToGetMppHashJoin(super base.LogicalPlan, prop *property.PhysicalProperty // If the hint is not figured, we will pick all candidates. func exhaustPhysicalPlans4LogicalJoin(super base.LogicalPlan, prop *property.PhysicalProperty) ([]base.PhysicalPlan, bool, error) { ge, p := base.GetGEAndLogicalOp[*logicalop.LogicalJoin](super) - failpoint.Inject("MockOnlyEnableIndexHashJoin", func(val failpoint.Value) { - if val.(bool) && !p.SCtx().GetSessionVars().InRestrictedSQL { - indexJoins, _ := tryToGetIndexJoin(p, prop) - failpoint.Return(indexJoins, true, nil) - } - }) if !isJoinHintSupportedInMPPMode(p.PreferJoinType) { if hasMPPJoinHints(p.PreferJoinType) { diff --git a/pkg/util/ranger/detacher.go b/pkg/util/ranger/detacher.go index b2df0a6f3ba47..4eb84af912b17 100644 --- a/pkg/util/ranger/detacher.go +++ b/pkg/util/ranger/detacher.go @@ -129,51 +129,43 @@ func getPotentialEqOrInColOffset(sctx *rangerctx.RangerContext, expr expression. } return offset case ast.EQ, ast.NullEQ, ast.LE, ast.GE, ast.LT, ast.GT: - if c, ok := f.GetArgs()[0].(*expression.Column); ok { - if c.RetType.EvalType() == types.ETString && !collate.CompatibleCollate(c.RetType.GetCollate(), collation) { - return -1 - } - if (f.FuncName.L == ast.LT || f.FuncName.L == ast.GT) && c.RetType.EvalType() != types.ETInt { + var constVal *expression.Constant + c, ok := f.GetArgs()[0].(*expression.Column) + idxConst := 1 + if !ok { + idxConst = 0 + if c, ok = f.GetArgs()[1].(*expression.Column); !ok { return -1 } - if constVal, ok := f.GetArgs()[1].(*expression.Constant); ok { - val, err := constVal.Eval(evalCtx, chunk.Row{}) - intest.AssertFunc(func() bool { - if sctx.ExprCtx.ConnectionID() == 0 { - return sctx.RegardNULLAsPoint - } - return true - }) - if err != nil || (!sctx.RegardNULLAsPoint && val.IsNull()) || (f.FuncName.L == ast.NullEQ && val.IsNull()) { - // treat col<=>null as range scan instead of point get to avoid incorrect results - // when nullable unique index has multiple matches for filter x is null - return -1 - } - for i, col := range cols { - // When cols are a generated expression col, compare them in terms of virtual expr. - if col.EqualByExprAndID(evalCtx, c) { - return i - } - } - } } - if c, ok := f.GetArgs()[1].(*expression.Column); ok { - if c.RetType.EvalType() == types.ETString && !collate.CompatibleCollate(c.RetType.GetCollate(), collation) { - return -1 - } - if (f.FuncName.L == ast.LT || f.FuncName.L == ast.GT) && c.RetType.EvalType() != types.ETInt { - return -1 + + if c.RetType.EvalType() == types.ETString && !collate.CompatibleCollate(c.RetType.GetCollate(), collation) { + return -1 + } + if (f.FuncName.L == ast.LT || f.FuncName.L == ast.GT) && c.RetType.EvalType() != types.ETInt { + return -1 + } + + if constVal, ok = f.GetArgs()[idxConst].(*expression.Constant); !ok { + return -1 + } + + val, err := constVal.Eval(evalCtx, chunk.Row{}) + intest.AssertFunc(func() bool { + if sctx.ExprCtx.ConnectionID() == 0 { + return sctx.RegardNULLAsPoint } - if constVal, ok := f.GetArgs()[0].(*expression.Constant); ok { - val, err := constVal.Eval(evalCtx, chunk.Row{}) - if err != nil || (!sctx.RegardNULLAsPoint && val.IsNull()) { - return -1 - } - for i, col := range cols { - if col.EqualColumn(c) { - return i - } - } + return true + }) + if err != nil || (!sctx.RegardNULLAsPoint && val.IsNull()) || (f.FuncName.L == ast.NullEQ && val.IsNull()) { + // treat col<=>null as range scan instead of point get to avoid incorrect results + // when nullable unique index has multiple matches for filter x is null + return -1 + } + for i, col := range cols { + // When cols are a generated expression col, compare them in terms of virtual expr. + if col.EqualByExprAndID(evalCtx, c) { + return i } } case ast.In: