Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
3b85d7c
tmp save
guo-shaoge Dec 26, 2025
bae4ef7
fix
guo-shaoge Jan 6, 2026
eb11e42
fix
guo-shaoge Jan 8, 2026
44a245f
tmp save(design done)
guo-shaoge Jan 11, 2026
57fa419
impl
guo-shaoge Jan 21, 2026
7e5c761
fix
guo-shaoge Jan 23, 2026
92269a6
refine
guo-shaoge Jan 23, 2026
3eb3a30
check usedEdges
guo-shaoge Jan 24, 2026
bef8026
check all edges used before finish
guo-shaoge Jan 24, 2026
e1e1352
fix
guo-shaoge Jan 25, 2026
61fc874
refine
guo-shaoge Jan 25, 2026
af52953
refine replace children
guo-shaoge Jan 25, 2026
1d89f56
refine check all used edges
guo-shaoge Jan 25, 2026
874eedc
refine
guo-shaoge Jan 25, 2026
4bdcd27
update
guo-shaoge Jan 25, 2026
ace1f72
Merge branch 'master' of github.com:pingcap/tidb into cdc_impl
guo-shaoge Jan 25, 2026
6c8cd3b
refine
guo-shaoge Jan 26, 2026
d266ccf
align schema
guo-shaoge Jan 26, 2026
af405ec
refine makeBushyTree()
guo-shaoge Jan 27, 2026
9e456ac
fix cross product edge; fix bushy join construction
guo-shaoge Jan 27, 2026
a5d67a0
otherCond for non inner join
guo-shaoge Jan 29, 2026
f97223a
refine by mysqltest
guo-shaoge Feb 1, 2026
51cbc2f
update unittest
guo-shaoge Feb 1, 2026
25ede84
bazel
guo-shaoge Feb 2, 2026
e532acc
bazel lint
guo-shaoge Feb 2, 2026
8b4c936
license
guo-shaoge Feb 2, 2026
8106809
fix cartesian
guo-shaoge Feb 2, 2026
9712a7f
fix originalSchema.Clone
guo-shaoge Feb 2, 2026
f902c9d
update case(need check)
guo-shaoge Feb 2, 2026
eb43fd1
fix cartesian
guo-shaoge Feb 2, 2026
ec6f134
Merge branch 'master' of github.com:pingcap/tidb into cdc_impl
guo-shaoge Feb 2, 2026
6b5b097
update case(need check)
guo-shaoge Feb 2, 2026
6a34fa1
update case
guo-shaoge Feb 2, 2026
93010a2
Merge branch 'master' of github.com:pingcap/tidb into cdc_impl
guo-shaoge Feb 2, 2026
42f314f
case
guo-shaoge Feb 2, 2026
662d846
case
guo-shaoge Feb 3, 2026
0b0c1e8
bazel
guo-shaoge Feb 3, 2026
b675e37
fix some todo
guo-shaoge Feb 3, 2026
6ff9695
ci
guo-shaoge Feb 3, 2026
991d5ad
fast intset
guo-shaoge Feb 3, 2026
0f99f69
Merge branch 'cdc_impl' of github.com:guo-shaoge/tidb into cdc_impl_bkp
guo-shaoge Feb 3, 2026
3efff7b
bazel
guo-shaoge Feb 3, 2026
2b50212
remove dup code injectExpr
guo-shaoge Feb 3, 2026
6dac2f6
remove dup code(SetNewJoinMethodHint)
guo-shaoge Feb 3, 2026
8d0f3f2
remove some todos
guo-shaoge Feb 3, 2026
dcb1d6b
refine
guo-shaoge Feb 3, 2026
529a65d
comment
guo-shaoge Feb 3, 2026
284adfd
refine
guo-shaoge Feb 3, 2026
dd76b69
remove dup code(hint related)
guo-shaoge Feb 3, 2026
a899f59
Merge branch 'cdc_impl' of github.com:guo-shaoge/tidb into cdc_impl_bkp
guo-shaoge Feb 3, 2026
f1d0bff
refine
guo-shaoge Feb 3, 2026
86e74fd
milestone-1(ok but still duplicated hint func)
guo-shaoge Feb 3, 2026
b92650e
Merge branch 'cdc_impl_bkp' of github.com:guo-shaoge/tidb into cdc_impl
guo-shaoge Feb 3, 2026
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
49 changes: 24 additions & 25 deletions pkg/executor/test/indexmergereadtest/index_merge_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,31 +228,30 @@ func TestPessimisticLockOnPartitionForIndexMerge(t *testing.T) {
where t1.c1 < 10 or t1.c2 < 10 for update`).Check(testkit.Rows(
"Projection 16635.64 root test.t1.c1",
"└─SelectLock 16635.64 root for update 0",
" └─Projection 16635.64 root test.t1.c1, test.t1._tidb_rowid, test.t1._tidb_tid, test.t2._tidb_rowid",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did this test change? Is this expected?

" └─HashJoin 16635.64 root CARTESIAN inner join, other cond:ge(test.t1.c_datetime, test.t2.c_datetime)",
" ├─IndexReader(Build) 3.00 root index:IndexFullScan",
" │ └─IndexFullScan 3.00 cop[tikv] table:t2, index:c_datetime(c_datetime) keep order:false",
" └─PartitionUnion(Probe) 5545.21 root ",
" ├─Projection 5542.21 root test.t1.c_datetime, test.t1.c1, test.t1._tidb_rowid, test.t1._tidb_tid",
" │ └─IndexMerge 5542.21 root type: union",
" │ ├─IndexRangeScan(Build) 3323.33 cop[tikv] table:t1, partition:p0, index:c1(c1) range:[-inf,10), keep order:false, stats:pseudo",
" │ ├─IndexRangeScan(Build) 3323.33 cop[tikv] table:t1, partition:p0, index:c2(c2) range:[-inf,10), keep order:false, stats:pseudo",
" │ └─TableRowIDScan(Probe) 5542.21 cop[tikv] table:t1, partition:p0 keep order:false, stats:pseudo",
" ├─Projection 1.00 root test.t1.c_datetime, test.t1.c1, test.t1._tidb_rowid, test.t1._tidb_tid",
" │ └─IndexMerge 1.00 root type: union",
" │ ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t1, partition:p1, index:c1(c1) range:[-inf,10), keep order:false",
" │ ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t1, partition:p1, index:c2(c2) range:[-inf,10), keep order:false",
" │ └─TableRowIDScan(Probe) 1.00 cop[tikv] table:t1, partition:p1 keep order:false",
" ├─Projection 1.00 root test.t1.c_datetime, test.t1.c1, test.t1._tidb_rowid, test.t1._tidb_tid",
" │ └─IndexMerge 1.00 root type: union",
" │ ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t1, partition:p2, index:c1(c1) range:[-inf,10), keep order:false",
" │ ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t1, partition:p2, index:c2(c2) range:[-inf,10), keep order:false",
" │ └─TableRowIDScan(Probe) 1.00 cop[tikv] table:t1, partition:p2 keep order:false",
" └─Projection 1.00 root test.t1.c_datetime, test.t1.c1, test.t1._tidb_rowid, test.t1._tidb_tid",
" └─IndexMerge 1.00 root type: union",
" ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t1, partition:p3, index:c1(c1) range:[-inf,10), keep order:false",
" ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t1, partition:p3, index:c2(c2) range:[-inf,10), keep order:false",
" └─TableRowIDScan(Probe) 1.00 cop[tikv] table:t1, partition:p3 keep order:false",
" └─HashJoin 16635.64 root CARTESIAN inner join, other cond:ge(test.t1.c_datetime, test.t2.c_datetime)",
" ├─IndexReader(Build) 3.00 root index:IndexFullScan",
" │ └─IndexFullScan 3.00 cop[tikv] table:t2, index:c_datetime(c_datetime) keep order:false",
" └─PartitionUnion(Probe) 5545.21 root ",
" ├─Projection 5542.21 root test.t1.c_datetime, test.t1.c1, test.t1._tidb_rowid, test.t1._tidb_tid",
" │ └─IndexMerge 5542.21 root type: union",
" │ ├─IndexRangeScan(Build) 3323.33 cop[tikv] table:t1, partition:p0, index:c1(c1) range:[-inf,10), keep order:false, stats:pseudo",
" │ ├─IndexRangeScan(Build) 3323.33 cop[tikv] table:t1, partition:p0, index:c2(c2) range:[-inf,10), keep order:false, stats:pseudo",
" │ └─TableRowIDScan(Probe) 5542.21 cop[tikv] table:t1, partition:p0 keep order:false, stats:pseudo",
" ├─Projection 1.00 root test.t1.c_datetime, test.t1.c1, test.t1._tidb_rowid, test.t1._tidb_tid",
" │ └─IndexMerge 1.00 root type: union",
" │ ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t1, partition:p1, index:c1(c1) range:[-inf,10), keep order:false",
" │ ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t1, partition:p1, index:c2(c2) range:[-inf,10), keep order:false",
" │ └─TableRowIDScan(Probe) 1.00 cop[tikv] table:t1, partition:p1 keep order:false",
" ├─Projection 1.00 root test.t1.c_datetime, test.t1.c1, test.t1._tidb_rowid, test.t1._tidb_tid",
" │ └─IndexMerge 1.00 root type: union",
" │ ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t1, partition:p2, index:c1(c1) range:[-inf,10), keep order:false",
" │ ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t1, partition:p2, index:c2(c2) range:[-inf,10), keep order:false",
" │ └─TableRowIDScan(Probe) 1.00 cop[tikv] table:t1, partition:p2 keep order:false",
" └─Projection 1.00 root test.t1.c_datetime, test.t1.c1, test.t1._tidb_rowid, test.t1._tidb_tid",
" └─IndexMerge 1.00 root type: union",
" ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t1, partition:p3, index:c1(c1) range:[-inf,10), keep order:false",
" ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t1, partition:p3, index:c2(c2) range:[-inf,10), keep order:false",
" └─TableRowIDScan(Probe) 1.00 cop[tikv] table:t1, partition:p3 keep order:false",
))
tk.MustQuery(`select /*+ use_index_merge(t1) */ c1 from t1 join t2
on t1.c_datetime >= t2.c_datetime
Expand Down
9 changes: 9 additions & 0 deletions pkg/expression/column.go
Original file line number Diff line number Diff line change
Expand Up @@ -870,3 +870,12 @@ func (col *Column) MemoryUsage() (sum int64) {
}
return
}

// Cols2Exprs converts Columns to an Expressions.
func Cols2Exprs(cols []*Column) []Expression {
exprs := make([]Expression, 0, len(cols))
for _, c := range cols {
exprs = append(exprs, c)
}
return exprs
}
16 changes: 16 additions & 0 deletions pkg/expression/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,22 @@ func (s *Schema) Clone() *Schema {
return schema
}

// Equal checks if two schemas are equal.
func (s *Schema) Equal(other *Schema) bool {
if other == nil {
return false
}
if len(s.Columns) != len(other.Columns) {
return false
}
for i, col := range s.Columns {
if !col.EqualColumn(other.Columns[i]) {
return false
}
}
return true
}

// ExprReferenceSchema checks if any column of this expression are from the schema.
func ExprReferenceSchema(expr Expression, schema *Schema) bool {
switch v := expr.(type) {
Expand Down
1 change: 1 addition & 0 deletions pkg/planner/core/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ go_library(
"//pkg/planner/cascades/memo",
"//pkg/planner/core/base",
"//pkg/planner/core/cost",
"//pkg/planner/core/joinorder",
"//pkg/planner/core/metrics",
"//pkg/planner/core/operator/baseimpl",
"//pkg/planner/core/operator/logicalop",
Expand Down
1 change: 1 addition & 0 deletions pkg/planner/core/base/plan_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ func GetGEAndLogicalOp[T LogicalPlan](super LogicalPlan) (ge GroupExpression, lo
// JoinType contains CrossJoin, InnerJoin, LeftOuterJoin, RightOuterJoin, SemiJoin, AntiJoin.
type JoinType int

// NOTE: keep the order and value unchanged, because they are used in conflict_detector.go!!!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add an intest.Assert instead.

const (
// InnerJoin means inner join.
InnerJoin JoinType = iota
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,19 @@
"SQL": "explain analyze format = 'binary' select sum(t.a) from t join t2",
"BinaryPlan": {
"main": {
"name": "HashAgg_12",
"name": "HashAgg_13",
"children": [
{
"name": "Projection_60",
"name": "Projection_61",
"children": [
{
"name": "HashJoin_31",
"name": "HashJoin_32",
"children": [
{
"name": "IndexReader_36",
"name": "IndexReader_37",
"children": [
{
"name": "IndexFullScan_35",
"name": "IndexFullScan_36",
"cost": 1628000.000001,
"est_rows": 10000,
"act_rows": 2,
Expand All @@ -97,13 +97,13 @@
"act_rows": 2,
"task_type": 1,
"store_type": 1,
"operator_info": "index:IndexFullScan_35"
"operator_info": "index:IndexFullScan_36"
},
{
"name": "TableReader_38",
"name": "TableReader_39",
"children": [
{
"name": "TableFullScan_37",
"name": "TableFullScan_38",
"cost": 4546159.475587022,
"est_rows": 10000,
"act_rows": 4,
Expand All @@ -120,7 +120,7 @@
"act_rows": 4,
"task_type": 1,
"store_type": 1,
"operator_info": "data:TableFullScan_37"
"operator_info": "data:TableFullScan_38"
}
],
"cost": 1128387.631705868,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,19 @@
"SQL": "explain analyze format = 'binary' select sum(t.a) from t join t2",
"BinaryPlan": {
"main": {
"name": "HashAgg_12",
"name": "HashAgg_13",
"children": [
{
"name": "Projection_60",
"name": "Projection_61",
"children": [
{
"name": "HashJoin_31",
"name": "HashJoin_32",
"children": [
{
"name": "IndexReader_36",
"name": "IndexReader_37",
"children": [
{
"name": "IndexFullScan_35",
"name": "IndexFullScan_36",
"cost": 1628000.000001,
"est_rows": 10000,
"act_rows": 2,
Expand All @@ -97,13 +97,13 @@
"act_rows": 2,
"task_type": 1,
"store_type": 1,
"operator_info": "index:IndexFullScan_35"
"operator_info": "index:IndexFullScan_36"
},
{
"name": "TableReader_38",
"name": "TableReader_39",
"children": [
{
"name": "TableFullScan_37",
"name": "TableFullScan_38",
"cost": 4546159.475587022,
"est_rows": 10000,
"act_rows": 4,
Expand All @@ -120,7 +120,7 @@
"act_rows": 4,
"task_type": 1,
"store_type": 1,
"operator_info": "data:TableFullScan_37"
"operator_info": "data:TableFullScan_38"
}
],
"cost": 1128387.631705868,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@
"│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo",
"└─IndexReader(Probe) 12475.01 root index:Selection",
" └─Selection 12475.01 cop[tikv] not(isnull(test.t2.a)), not(isnull(test.t2.c))",
" └─IndexRangeScan 12500.00 cop[tikv] table:t2, index:idx(a, b, c) range: decided by [eq(test.t2.a, test.t1.a) lt(test.t2.b, plus(test.t1.b, 1)) gt(test.t2.b, minus(test.t1.b, 1))], keep order:false, stats:pseudo"
" └─IndexRangeScan 12500.00 cop[tikv] table:t2, index:idx(a, b, c) range: decided by [eq(test.t2.a, test.t1.a) gt(test.t2.b, minus(test.t1.b, 1)) lt(test.t2.b, plus(test.t1.b, 1))], keep order:false, stats:pseudo"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@
"│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo",
"└─IndexReader(Probe) 12475.01 root index:Selection",
" └─Selection 12475.01 cop[tikv] not(isnull(test.t2.a)), not(isnull(test.t2.c))",
" └─IndexRangeScan 12500.00 cop[tikv] table:t2, index:idx(a, b, c) range: decided by [eq(test.t2.a, test.t1.a) lt(test.t2.b, plus(test.t1.b, 1)) gt(test.t2.b, minus(test.t1.b, 1))], keep order:false, stats:pseudo"
" └─IndexRangeScan 12500.00 cop[tikv] table:t2, index:idx(a, b, c) range: decided by [eq(test.t2.a, test.t1.a) gt(test.t2.b, minus(test.t1.b, 1)) lt(test.t2.b, plus(test.t1.b, 1))], keep order:false, stats:pseudo"
]
},
{
Expand Down
1 change: 1 addition & 0 deletions pkg/planner/core/casetest/enforcempp/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ go_test(
"//pkg/testkit/testsetup",
"//pkg/util/collate",
"//pkg/util/context",
"@com_github_stretchr_testify//assert",
"@com_github_stretchr_testify//require",
"@org_uber_go_goleak//:goleak",
],
Expand Down
13 changes: 12 additions & 1 deletion pkg/planner/core/casetest/enforcempp/enforce_mpp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/pingcap/tidb/pkg/testkit/testdata"
"github.com/pingcap/tidb/pkg/util/collate"
contextutil "github.com/pingcap/tidb/pkg/util/context"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -86,11 +87,21 @@ func TestEnforceMPP(t *testing.T) {
output[i].Plan = testdata.ConvertRowsToStrings(testKit.MustQuery(tt).Rows())
output[i].Warn = testdata.ConvertSQLWarnToStrings(filterWarnings(testKit.Session().GetSessionVars().StmtCtx.GetWarnings()))
})
require.Eventually(t,
var lastPlan []string
ok := assert.Eventually(t,
func() bool {
res := testKit.MustQuery(tt)
lastPlan = testdata.ConvertRowsToStrings(res.Rows())
return res.Equal(testkit.Rows(output[i].Plan...))
}, 1*time.Second, 100*time.Millisecond)
if !ok {
t.Fatalf("plan mismatch (cascades=%s)\nSQL:\n%s\nExpected:\n%s\nActual:\n%s",
cascades,
tt,
strings.Join(output[i].Plan, "\n"),
strings.Join(lastPlan, "\n"),
)
}
require.Equal(t, output[i].Warn, testdata.ConvertSQLWarnToStrings(filterWarnings(testKit.Session().GetSessionVars().StmtCtx.GetWarnings())))
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1921,9 +1921,7 @@
" └─TableReader(Probe) 10000.00 root data:TableFullScan",
" └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo"
],
"Warn": [
"Warning 1815 leading hint is inapplicable, check if the leading hint table has join conditions with other tables"
]
"Warn": null
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1921,9 +1921,7 @@
" └─TableReader(Probe) 10000.00 root data:TableFullScan",
" └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo"
],
"Warn": [
"Warning 1815 leading hint is inapplicable, check if the leading hint table has join conditions with other tables"
]
"Warn": null
}
]
},
Expand Down
Loading