Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,7 @@ var
# Personal config files
/*config.toml
.cache

# Claude Code runtime state (per-user, not part of repo)
.claude/scheduled_tasks.lock
.claude/settings.local.json
26 changes: 26 additions & 0 deletions pkg/bindinfo/binding_auto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ package bindinfo_test

import (
"fmt"
"slices"
"strings"
"testing"

"github.com/pingcap/tidb/pkg/bindinfo"
"github.com/pingcap/tidb/pkg/parser"
"github.com/pingcap/tidb/pkg/parser/auth"
"github.com/pingcap/tidb/pkg/sessionctx/vardef"
"github.com/pingcap/tidb/pkg/testkit"
"github.com/pingcap/tidb/pkg/testkit/testdata"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -211,6 +213,30 @@ func TestRelevantOptVarsAndFixes(t *testing.T) {
}
}

func TestRelevantOptVarsCorrelateSubquery(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec(`create table t1 (a int, b int, key(a))`)
tk.MustExec(`create table t2 (a int, b int, key(a))`)

p := parser.New()
sql := "select * from t1 where a in (select a from t2)"

// The alternative logical plans variable is recorded as relevant because the
// code path where it affects plan choice (correlate-to-Apply) was reached.
for _, enabled := range []string{"OFF", "ON"} {
tk.MustExec("set tidb_opt_enable_alternative_logical_plans = " + enabled)
p.Reset()
stmt, err := p.ParseOneStmt(sql, "", "")
require.NoError(t, err)
vars, _, err := bindinfo.RecordRelevantOptVarsAndFixes(tk.Session(), stmt)
require.NoError(t, err)
require.True(t, slices.Contains(vars, vardef.TiDBOptEnableAlternativeLogicalPlans),
"enabled=%s: expected %s in recorded vars %v", enabled, vardef.TiDBOptEnableAlternativeLogicalPlans, vars)
}
}

func TestExplainExploreAnalyze(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
Expand Down
6 changes: 5 additions & 1 deletion pkg/bindinfo/binding_plan_generation.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,8 @@ func genPlanUnderState(sctx sessionctx.Context, stmt ast.StmtNode, state *state)
sctx.GetSessionVars().EnableSemiJoinRewrite = state.varValues[i].(bool)
case vardef.TiDBOptSelectivityFactor:
sctx.GetSessionVars().SelectivityFactor = state.varValues[i].(float64)
case vardef.TiDBOptEnableAlternativeLogicalPlans:
sctx.GetSessionVars().EnableAlternativeLogicalPlans = state.varValues[i].(bool)
default:
return nil, fmt.Errorf("unsupported variable %s in plan generation", varName)
}
Expand Down Expand Up @@ -507,7 +509,7 @@ func adjustVar(varName string, varVal any) (newVarVal any, err error) {
}
// increase 0.1 each step
return v + 0.1, nil
case vardef.TiDBOptPreferRangeScan, vardef.TiDBOptEnableNoDecorrelateInSelect, vardef.TiDBOptAlwaysKeepJoinKey, vardef.TiDBOptEnableSemiJoinRewrite: // flip the switch
case vardef.TiDBOptPreferRangeScan, vardef.TiDBOptEnableNoDecorrelateInSelect, vardef.TiDBOptAlwaysKeepJoinKey, vardef.TiDBOptEnableSemiJoinRewrite, vardef.TiDBOptEnableAlternativeLogicalPlans: // flip the switch
return !varVal.(bool), nil
}
return nil, fmt.Errorf("unsupported variable %s in plan generation", varName)
Expand Down Expand Up @@ -600,6 +602,8 @@ func getStartState(vars []string, fixes []uint64, indexHintCount int) (*state, e
s.varValues = append(s.varValues, vardef.DefOptSelectivityFactor)
case vardef.TiDBOptCartesianJoinOrderThreshold:
s.varValues = append(s.varValues, vardef.DefOptCartesianJoinOrderThreshold)
case vardef.TiDBOptEnableAlternativeLogicalPlans:
s.varValues = append(s.varValues, vardef.DefOptEnableAlternativeLogicalPlans)
default:
return nil, fmt.Errorf("unsupported variable %s in plan generation", varName)
}
Expand Down
7 changes: 6 additions & 1 deletion pkg/ddl/ingest/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,11 @@ go_library(
go_test(
name = "ingest_internal_test",
size = "small",
timeout = "short",
srcs = ["engine_mgr_test.go"],
embed = [":ingest"],
flaky = True,
shard_count = 32,
deps = [
"//pkg/lightning/backend",
"//pkg/meta/model",
Expand All @@ -82,22 +85,24 @@ go_test(
timeout = "moderate",
srcs = [
"checkpoint_test.go",
"engine_mgr_test.go",
"env_test.go",
"integration_test.go",
"main_test.go",
"mem_root_test.go",
],
embed = [":ingest"],
flaky = True,
race = "on",
shard_count = 31,
deps = [
":ingest",
"//pkg/config",
"//pkg/config/kerneltype",
"//pkg/ddl/ingest/testutil",
"//pkg/ddl/session",
"//pkg/ddl/testutil",
"//pkg/errno",
"//pkg/lightning/backend",
"//pkg/meta/model",
"//pkg/testkit",
"//pkg/testkit/testfailpoint",
Expand Down
4 changes: 3 additions & 1 deletion pkg/dxf/importinto/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ go_test(
],
embed = [":importinto"],
flaky = True,
shard_count = 31,
shard_count = 42,
deps = [
"//pkg/config",
"//pkg/config/kerneltype",
Expand Down Expand Up @@ -144,9 +144,11 @@ go_test(
"//pkg/objstore/storeapi",
"//pkg/parser",
"//pkg/parser/ast",
"//pkg/parser/mysql",
"//pkg/planner/core",
"//pkg/resourcemanager/pool/workerpool",
"//pkg/session",
"//pkg/sessionctx",
"//pkg/store",
"//pkg/store/driver/error",
"//pkg/store/mockstore",
Expand Down
2 changes: 1 addition & 1 deletion pkg/dxf/importinto/conflictedkv/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ go_test(
],
embed = [":conflictedkv"],
flaky = True,
shard_count = 6,
shard_count = 7,
deps = [
"//pkg/config/kerneltype",
"//pkg/executor/importer",
Expand Down
2 changes: 1 addition & 1 deletion pkg/executor/importer/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ go_test(
embed = [":importer"],
flaky = True,
race = "on",
shard_count = 35,
shard_count = 42,
deps = [
"//br/pkg/mock",
"//br/pkg/streamhelper",
Expand Down
2 changes: 2 additions & 0 deletions pkg/expression/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ go_library(
"expression.go",
"extension.go",
"fts_helper.go",
"fts_to_like.go",
"function_traits.go",
"grouping_sets.go",
"helper.go",
Expand Down Expand Up @@ -199,6 +200,7 @@ go_test(
"evaluator_test.go",
"expr_to_pb_test.go",
"expression_test.go",
"fts_to_like_test.go",
"function_traits_test.go",
"grouping_sets_test.go",
"helper_test.go",
Expand Down
6 changes: 4 additions & 2 deletions pkg/expression/builtin_fts.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,10 @@ func (c *ftsMysqlMatchAgainstFunctionClass) getFunction(ctx BuildContext, args [

func (b *builtinFtsMysqlMatchAgainstSig) evalReal(ctx EvalContext, row chunk.Row) (float64, bool, error) {
// Matching NULL returns 0.
if b.args[0].(*Constant).Value.IsNull() {
return 0, false, nil
// args[0] is validated to be a *Constant by getFunction; guard defensively
// since the sig may be reconstructed via the distsql path without that check.
if constArg, ok := b.args[0].(*Constant); ok && constArg.Value.IsNull() {
return 0, true, nil
}
// Reject executing match against in TiDB side
return 0, false, errors.Errorf("cannot use 'MATCH ... AGAINST' outside of fulltext index")
Expand Down
7 changes: 7 additions & 0 deletions pkg/expression/distsql_builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -1158,6 +1158,13 @@ func getSignatureByPB(ctx BuildContext, sigCode tipb.ScalarFuncSig, tp *tipb.Fie
f = &builtinVecL2NormSig{base}
case tipb.ScalarFuncSig_FTSMatchWord:
f = &builtinFtsMatchWordSig{base}
case tipb.ScalarFuncSig_FTSMatchExpression:
// NOTE: builtinFtsMysqlMatchAgainstSig.modifier is not serialized in the
// protobuf encoding because the tipb schema has no FTS metadata message.
// The reconstructed sig therefore uses the zero modifier value
// (FulltextSearchModifierNaturalLanguageMode). TiFlash must derive the
// search mode from other context when executing this expression.
f = &builtinFtsMysqlMatchAgainstSig{baseBuiltinFunc: base}
default:
e = ErrFunctionNotExists.GenWithStackByArgs("FUNCTION", sigCode)
return nil, e
Expand Down
Loading