Skip to content

Commit fa8a374

Browse files
YangKeaozeminzhou
authored andcommitted
stats: use GetColOriginDefaultValue to get default value of a column (pingcap#60438)
close pingcap#60194
1 parent 3381348 commit fa8a374

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

pkg/statistics/handle/storage/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ go_library(
3333
"//pkg/statistics/handle/usage/predicatecolumn",
3434
"//pkg/statistics/handle/util",
3535
"//pkg/statistics/util",
36+
"//pkg/table",
3637
"//pkg/types",
3738
"//pkg/util/chunk",
3839
"//pkg/util/compress",

pkg/statistics/handle/storage/save.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"github.com/pingcap/tidb/pkg/statistics"
3030
statslogutil "github.com/pingcap/tidb/pkg/statistics/handle/logutil"
3131
"github.com/pingcap/tidb/pkg/statistics/handle/util"
32+
"github.com/pingcap/tidb/pkg/table"
3233
"github.com/pingcap/tidb/pkg/types"
3334
"github.com/pingcap/tidb/pkg/util/chunk"
3435
"github.com/pingcap/tidb/pkg/util/sqlescape"
@@ -444,8 +445,7 @@ func InsertColStats2KV(
444445
}
445446
count := req.GetRow(0).GetInt64(0)
446447
for _, colInfo := range colInfos {
447-
value := types.NewDatum(colInfo.GetOriginDefaultValue())
448-
value, err = value.ConvertTo(sctx.GetSessionVars().StmtCtx.TypeCtx(), &colInfo.FieldType)
448+
value, err := table.GetColOriginDefaultValue(sctx.GetExprCtx(), colInfo)
449449
if err != nil {
450450
return 0, errors.Trace(err)
451451
}

tests/integrationtest/r/statistics/handle.result

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,14 @@ insert into t values(1,1),(2,2),(3,3);
7979
alter table t add stats_extended s1 correlation(a,b);
8080
analyze table t;
8181
set session tidb_enable_extended_stats = default;
82+
drop table if exists t;
83+
set time_zone = '+08:00';
84+
create table t(a int);
85+
alter table t add column ts timestamp DEFAULT '1970-01-01 08:00:01';
86+
drop table if exists t;
87+
set time_zone = '+09:00';
88+
create table t(a int);
89+
alter table t add column ts timestamp DEFAULT '1970-01-01 08:00:01';
90+
Error 1067 (42000): Invalid default value for 'ts'
91+
drop table if exists t;
92+
set time_zone = default;

tests/integrationtest/t/statistics/handle.test

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,16 @@ alter table t add stats_extended s1 correlation(a,b);
8282
## no error
8383
analyze table t;
8484
set session tidb_enable_extended_stats = default;
85+
86+
# TestHandleDDLEventForTimestampDefaultValue
87+
drop table if exists t;
88+
set time_zone = '+08:00';
89+
create table t(a int);
90+
alter table t add column ts timestamp DEFAULT '1970-01-01 08:00:01';
91+
drop table if exists t;
92+
set time_zone = '+09:00';
93+
create table t(a int);
94+
-- error 1067
95+
alter table t add column ts timestamp DEFAULT '1970-01-01 08:00:01';
96+
drop table if exists t;
97+
set time_zone = default;

0 commit comments

Comments
 (0)