Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

importinto: fix incorrect index kv group count when table have common handle #51615

Merged
merged 1 commit into from
Mar 8, 2024
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
6 changes: 4 additions & 2 deletions pkg/disttask/importinto/encode_and_sort_operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,10 @@ func getNumOfIndexGenKV(tblInfo *model.TableInfo) int {
if idxInfo.State != model.StatePublic {
continue
}
if idxInfo.Primary && !tblInfo.HasClusteredIndex() {
nonClusteredPK = true
if idxInfo.Primary {
if !tblInfo.HasClusteredIndex() {
nonClusteredPK = true
}
continue
}
count++
Expand Down
42 changes: 25 additions & 17 deletions pkg/disttask/importinto/encode_and_sort_operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@ func TestGetWriterMemorySizeLimit(t *testing.T) {
dataKVMemSizePerCon: 460175067,
perIndexKVMemSizePerCon: 153391689,
},
{
createSQL: "create table t (a int, b int, c int, primary key(a,b,c) clustered, key(b,c), unique(b), unique(c), key(a,b))",
numOfIndexGenKV: 4,
dataKVMemSizePerCon: 460175067,
perIndexKVMemSizePerCon: 153391689,
},
{
createSQL: "create table t (a int, b int, c int, primary key(a,b,c) nonclustered, key(b,c), unique(b), unique(c), key(a,b))",
Copy link
Contributor

@lance6716 lance6716 Mar 8, 2024

Choose a reason for hiding this comment

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

Does it cover the ClusteredIndexDefModeIntOnly? check with that option and a table with non-int PK

Copy link
Contributor Author

@D3Hunter D3Hunter Mar 8, 2024

Choose a reason for hiding this comment

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

// ClusteredIndexDefModeIntOnly indicates only single int primary key will default be clustered.

seems not related, composite clustered int pk is also CommonHandle

Copy link
Contributor

Choose a reason for hiding this comment

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

OK I see that HasClusteredIndex can both check t.PKIsHandle || t.IsCommonHandle

numOfIndexGenKV: 5,
Expand All @@ -195,25 +201,27 @@ func TestGetWriterMemorySizeLimit(t *testing.T) {

for _, c := range cases {
p := parser.New()
node, err := p.ParseOneStmt(c.createSQL, "", "")
require.NoError(t, err)
sctx := utilmock.NewContext()
info, err := ddl.MockTableInfo(sctx, node.(*ast.CreateTableStmt), 1)
require.NoError(t, err)
info.State = model.StatePublic
t.Run(c.createSQL, func(t *testing.T) {
node, err := p.ParseOneStmt(c.createSQL, "", "")
require.NoError(t, err)
sctx := utilmock.NewContext()
info, err := ddl.MockTableInfo(sctx, node.(*ast.CreateTableStmt), 1)
require.NoError(t, err)
info.State = model.StatePublic

require.Equal(t, c.numOfIndexGenKV, getNumOfIndexGenKV(info), c.createSQL)
dataKVMemSizePerCon, perIndexKVMemSizePerCon := getWriterMemorySizeLimit(&proto.StepResource{
Mem: proto.NewAllocatable(2 * units.GiB),
}, &importer.Plan{
DesiredTableInfo: info,
ThreadCnt: 1,
require.Equal(t, c.numOfIndexGenKV, getNumOfIndexGenKV(info), c.createSQL)
dataKVMemSizePerCon, perIndexKVMemSizePerCon := getWriterMemorySizeLimit(&proto.StepResource{
Mem: proto.NewAllocatable(2 * units.GiB),
}, &importer.Plan{
DesiredTableInfo: info,
ThreadCnt: 1,
})
require.Equal(t, c.dataKVMemSizePerCon, dataKVMemSizePerCon, c.createSQL)
if c.numOfIndexGenKV > 0 {
require.Equal(t, c.perIndexKVMemSizePerCon, perIndexKVMemSizePerCon, c.createSQL)
}
require.LessOrEqual(t, c.dataKVMemSizePerCon+c.perIndexKVMemSizePerCon*uint64(c.numOfIndexGenKV), uint64(units.GiB))
})
require.Equal(t, c.dataKVMemSizePerCon, dataKVMemSizePerCon, c.createSQL)
if c.numOfIndexGenKV > 0 {
require.Equal(t, c.perIndexKVMemSizePerCon, perIndexKVMemSizePerCon, c.createSQL)
}
require.LessOrEqual(t, c.dataKVMemSizePerCon+c.perIndexKVMemSizePerCon*uint64(c.numOfIndexGenKV), uint64(units.GiB))
}
}

Expand Down