Skip to content
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
8fe86fc
types, tablecodec, codec: add benchmark baseline for Datum refactor
mjonss Apr 22, 2026
2a3c81e
*: shrink types.Datum from 72 to 56 bytes
mjonss Apr 22, 2026
8b69b51
types: pack Time into Datum.i to kill SetMysqlTime allocation
mjonss Apr 22, 2026
c229ffb
tests/integrationtest: retune TestIndexJoinRangeFallback thresholds
mjonss Apr 22, 2026
ac5a044
types: preserve UnspecifiedFsp through Datum.decimal round-trip
mjonss Apr 22, 2026
604bac5
types: pin Datum.Equals canonical-id collation semantics with a test
mjonss Apr 22, 2026
0ffccbe
types, rowcodec: guard GetMysqlTime against non-Time Datums
mjonss Apr 23, 2026
c591fb1
types: fix consumers stranded by the Time inline-pack refactor
mjonss Apr 23, 2026
b457d8b
planner/core: retune range-fallback thresholds for shrunk Datum
mjonss Apr 23, 2026
8ab1f4d
types, tablecodec, codec: add benchmark baseline for Datum refactor
mjonss Apr 22, 2026
5fc0037
*: shrink types.Datum from 72 to 56 bytes
mjonss Apr 22, 2026
d2e99ee
types: pack Time into Datum.i to kill SetMysqlTime allocation
mjonss Apr 22, 2026
a1e1bee
*: remove KindInterface escape hatch from types.Datum
mjonss Apr 23, 2026
311aef6
types, parser/test_driver: soften KindInterfaceDeprecated doc to avoi…
mjonss Apr 23, 2026
ea7722b
types: replace Datum's x any with decPtr *MyDecimal (56B -> 48B)
mjonss Apr 23, 2026
5ef32c9
Merge branch 'Datum-improvement' into datum-typed-decimal-pointer
mjonss Apr 24, 2026
0f2db44
Merge branch 'datum-time-in-i' into datum-typed-decimal-pointer
mjonss Apr 24, 2026
bdd48db
tests/integrationtest: retune range-fallback thresholds for 48-byte D…
mjonss Apr 28, 2026
2d9baef
types: preserve UnspecifiedFsp sentinel in Datum JSON wire format
mjonss Apr 29, 2026
07d9430
types: remove unused Datum.SetCollationID setter
mjonss Apr 30, 2026
4c0fb3b
types: address review nits on Datum doc and tests
mjonss Apr 30, 2026
f6e5297
Merge branch 'Datum-improvement' into datum-typed-decimal-pointer
mjonss Apr 30, 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
17 changes: 15 additions & 2 deletions pkg/executor/aggfuncs/aggfunc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,11 +369,24 @@ func buildAggTesterWithFieldType(funcName string, ft *types.FieldType, numRows i
dataGen: getDataGenFunc(ft),
}
for _, result := range results {
pt.results = append(pt.results, types.NewDatum(result))
pt.results = append(pt.results, resultToDatum(result))
}
return pt
}

// resultToDatum accepts either an already-built types.Datum (common case for
// aggregate tests whose expected value doesn't map cleanly to a Go primitive,
// e.g. Duration / Time / Decimal) or a primitive Go value that NewDatum can
// wrap. Prior to the KindInterfaceDeprecated removal, passing a types.Datum
// here round-tripped through the escape hatch; NewDatum(someDatum) now panics
// instead, so detect the passthrough explicitly.
func resultToDatum(result any) types.Datum {
if d, ok := result.(types.Datum); ok {
return d
}
return types.NewDatum(result)
}

func testMultiArgsMergePartialResult(t *testing.T, ctx *mock.Context, p multiArgsAggTest) {
srcChk := p.genSrcChk()
iter := chunk.NewIterator4Chunk(srcChk)
Expand Down Expand Up @@ -470,7 +483,7 @@ func buildMultiArgsAggTesterWithFieldType(funcName string, fts []*types.FieldTyp
dataGens: dataGens,
}
for _, result := range results {
mt.results = append(mt.results, types.NewDatum(result))
mt.results = append(mt.results, resultToDatum(result))
}
return mt
}
Expand Down
8 changes: 2 additions & 6 deletions pkg/executor/aggfuncs/func_group_concat.go
Original file line number Diff line number Diff line change
Expand Up @@ -637,11 +637,7 @@ func (*groupConcatDistinctOrder) MergePartialResult(AggFuncUpdateContext, Partia

// GetDatumMemSize calculates the memory size of each types.Datum in sortRow.byItems.
// types.Datum memory size = variable type's memory size + variable value's memory size.
// The collation is stored inline as a uint16 id (counted by unsafe.Sizeof),
func GetDatumMemSize(d *types.Datum) int64 {
var datumMemSize int64
datumMemSize += int64(unsafe.Sizeof(*d))
datumMemSize += int64(len(d.Collation()))
datumMemSize += int64(len(d.GetBytes()))
datumMemSize += getValMemDelta(d.GetInterface()) - DefInterfaceSize
return datumMemSize
return int64(unsafe.Sizeof(*d)) + int64(len(d.GetBytes()))
}
2 changes: 1 addition & 1 deletion pkg/executor/foreign_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func (fkc *FKCheckExec) updateRowNeedToCheck(sc *stmtctx.StatementContext, oldRo
if len(oldVals) == len(newVals) {
isSameValue := true
for i := range oldVals {
cmp, err := oldVals[i].Compare(sc.TypeCtx(), &newVals[i], collate.GetCollator(oldVals[i].Collation()))
cmp, err := oldVals[i].Compare(sc.TypeCtx(), &newVals[i], collate.GetCollatorByID(int(oldVals[i].CollationID())))
if err != nil || cmp != 0 {
isSameValue = false
break
Expand Down
8 changes: 3 additions & 5 deletions pkg/expression/builtin_compare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ func TestIntervalFunc(t *testing.T) {
{types.MakeDatums(uint64(9223372036854775806), 9223372036854775807), 0, false},
{types.MakeDatums(uint64(9223372036854775806), -9223372036854775807), 1, false},
{types.MakeDatums("9007199254740991", "9007199254740992"), 0, false},
{types.MakeDatums(1, uint32(1), uint32(1)), 0, true},
// uint32(...) row retired; MakeDatums now panics on unsupported
// narrow int types (KindInterfaceDeprecated escape hatch removed).
{types.MakeDatums(-1, 2333, nil), 0, false},
{types.MakeDatums(1, nil, nil, nil), 3, false},
{types.MakeDatums(1, nil, nil, nil, 2), 3, false},
Expand Down Expand Up @@ -354,10 +355,7 @@ func TestGreatestLeastFunc(t *testing.T) {
[]any{"123", nil, "123"},
nil, nil, true, false,
},
{
[]any{errors.New("must error"), 123},
nil, nil, false, true,
},
// errors.New(...) row retired; see KindInterfaceDeprecated removal.
{
[]any{794755072.0, 4556, "2000-01-09"},
"794755072", "2000-01-09", false, false,
Expand Down
15 changes: 4 additions & 11 deletions pkg/expression/builtin_control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package expression

import (
"errors"
"testing"
"time"

Expand Down Expand Up @@ -52,10 +51,8 @@ func TestCaseWhen(t *testing.T) {
require.NoError(t, err)
testutil.DatumEqual(t, types.NewDatum(tt.Ret), d)
}
f, err := fc.getFunction(ctx, datumsToConstants(types.MakeDatums(errors.New("can't convert string to bool"), 1, true)))
require.NoError(t, err)
_, err = evalBuiltinFunc(f, ctx, chunk.Row{})
require.Error(t, err)
// errors.New(...) sub-case retired along with the KindInterfaceDeprecated
// escape hatch: MakeDatums now panics on unsupported Go types.
}

func TestIf(t *testing.T) {
Expand Down Expand Up @@ -98,11 +95,8 @@ func TestIf(t *testing.T) {
require.NoError(t, err)
testutil.DatumEqual(t, types.NewDatum(tt.Ret), d)
}
f, err := fc.getFunction(ctx, datumsToConstants(types.MakeDatums(errors.New("must error"), 1, 2)))
require.NoError(t, err)
_, err = evalBuiltinFunc(f, ctx, chunk.Row{})
require.Error(t, err)
_, err = fc.getFunction(ctx, datumsToConstants(types.MakeDatums(1, 2)))
// errors.New(...) sub-case retired; same rationale as TestCaseWhen.
_, err := fc.getFunction(ctx, datumsToConstants(types.MakeDatums(1, 2)))
require.Error(t, err)
}

Expand All @@ -125,7 +119,6 @@ func TestIfNull(t *testing.T) {
{nil, types.Set{Value: 1, Name: "abc"}, "abc", false, false},
{nil, jsonInt.GetMysqlJSON(), jsonInt.GetMysqlJSON(), false, false},
{"abc", nil, "abc", false, false},
{errors.New(""), nil, "", true, true},
}

for _, tt := range tbl {
Expand Down
21 changes: 0 additions & 21 deletions pkg/expression/builtin_op_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"math"
"testing"

"github.com/pingcap/errors"
"github.com/pingcap/tidb/pkg/parser/ast"
"github.com/pingcap/tidb/pkg/parser/mysql"
"github.com/pingcap/tidb/pkg/testkit/testutil"
Expand Down Expand Up @@ -102,8 +101,6 @@ func TestLogicAnd(t *testing.T) {
{[]any{types.NewDecFromStringForTest("0.000001"), 1}, 1, false, false},
{[]any{types.NewDecFromStringForTest("0.000000"), nil}, 0, false, false},
{[]any{types.NewDecFromStringForTest("0.000001"), nil}, 0, true, false},

{[]any{errors.New("must error"), 1}, 0, false, true},
}

for _, c := range cases {
Expand Down Expand Up @@ -141,8 +138,6 @@ func TestLeftShift(t *testing.T) {
{[]any{123, 2}, uint64(492), false, false},
{[]any{-123, 2}, uint64(18446744073709551124), false, false},
{[]any{nil, 1}, 0, true, false},

{[]any{errors.New("must error"), 1}, 0, false, true},
}

for _, c := range cases {
Expand Down Expand Up @@ -173,8 +168,6 @@ func TestRightShift(t *testing.T) {
{[]any{123, 2}, uint64(30), false, false},
{[]any{-123, 2}, uint64(4611686018427387873), false, false},
{[]any{nil, 1}, 0, true, false},

{[]any{errors.New("must error"), 1}, 0, false, true},
}

for _, c := range cases {
Expand Down Expand Up @@ -212,8 +205,6 @@ func TestBitXor(t *testing.T) {
{[]any{123, 321}, uint64(314), false, false},
{[]any{-123, 321}, uint64(18446744073709551300), false, false},
{[]any{nil, 1}, 0, true, false},

{[]any{errors.New("must error"), 1}, 0, false, true},
}

for _, c := range cases {
Expand Down Expand Up @@ -258,8 +249,6 @@ func TestBitOr(t *testing.T) {
{[]any{123, 321}, uint64(379), false, false},
{[]any{-123, 321}, uint64(18446744073709551557), false, false},
{[]any{nil, 1}, 0, true, false},

{[]any{errors.New("must error"), 1}, 0, false, true},
}

for _, c := range cases {
Expand Down Expand Up @@ -325,8 +314,6 @@ func TestLogicOr(t *testing.T) {
{[]any{types.NewDecFromStringForTest("0.000001"), 0}, 1, false, false},
{[]any{types.NewDecFromStringForTest("0.000001"), 1}, 1, false, false},
{[]any{types.NewDecFromStringForTest("0.000001"), nil}, 1, false, false},

{[]any{errors.New("must error"), 1}, 0, false, true},
}

for _, c := range cases {
Expand Down Expand Up @@ -364,8 +351,6 @@ func TestBitAnd(t *testing.T) {
{[]any{123, 321}, 65, false, false},
{[]any{-123, 321}, 257, false, false},
{[]any{nil, 1}, 0, true, false},

{[]any{errors.New("must error"), 1}, 0, false, true},
}

for _, c := range cases {
Expand Down Expand Up @@ -410,8 +395,6 @@ func TestBitNeg(t *testing.T) {
{[]any{123}, uint64(18446744073709551492), false, false},
{[]any{-123}, uint64(122), false, false},
{[]any{nil}, 0, true, false},

{[]any{errors.New("must error")}, 0, false, true},
}

for _, c := range cases {
Expand Down Expand Up @@ -464,8 +447,6 @@ func TestUnaryNot(t *testing.T) {
{[]any{nil}, 0, true, false},
{[]any{types.CreateBinaryJSON(int64(0))}, 1, false, false},
{[]any{types.CreateBinaryJSON(map[string]any{"test": "test"})}, 0, false, false},

{[]any{errors.New("must error")}, 0, false, true},
}

for _, c := range cases {
Expand Down Expand Up @@ -635,8 +616,6 @@ func TestLogicXor(t *testing.T) {
{[]any{types.NewDecFromStringForTest("0.000001"), 1}, 0, false, false},
{[]any{types.NewDecFromStringForTest("0.000000"), nil}, 0, true, false},
{[]any{types.NewDecFromStringForTest("0.000001"), nil}, 0, true, false},

{[]any{errors.New("must error"), 1}, 0, false, true},
}

for _, c := range cases {
Expand Down
2 changes: 1 addition & 1 deletion pkg/expression/builtin_other_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ func TestInFunc(t *testing.T) {
require.NoError(t, err)
d, err := evalBuiltinFunc(fn, ctx, chunk.MutRowFromDatums(types.MakeDatums(tc.args...)).ToRow())
require.NoError(t, err)
require.Equalf(t, tc.res, d.GetValue(), "%v", types.MakeDatums(tc.args))
require.Equalf(t, tc.res, d.GetValue(), "%v", types.MakeDatums(tc.args...))
}
strD1 := types.NewCollationStringDatum("a", "utf8_general_ci")
strD2 := types.NewCollationStringDatum("Á", "utf8_general_ci")
Expand Down
Loading
Loading