Skip to content

Commit 25ca90f

Browse files
authored
stats: use GetColOriginDefaultValue to get default value of a column (#60438) (#60439)
close #60194
1 parent 02d0a6f commit 25ca90f

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
@@ -32,6 +32,7 @@ go_library(
3232
"//pkg/statistics/handle/types",
3333
"//pkg/statistics/handle/usage/predicatecolumn",
3434
"//pkg/statistics/handle/util",
35+
"//pkg/table",
3536
"//pkg/types",
3637
"//pkg/util/chunk",
3738
"//pkg/util/compress",

pkg/statistics/handle/storage/save.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"github.com/pingcap/tidb/pkg/statistics/handle/cache"
3131
statslogutil "github.com/pingcap/tidb/pkg/statistics/handle/logutil"
3232
"github.com/pingcap/tidb/pkg/statistics/handle/util"
33+
"github.com/pingcap/tidb/pkg/table"
3334
"github.com/pingcap/tidb/pkg/types"
3435
"github.com/pingcap/tidb/pkg/util/chunk"
3536
"github.com/pingcap/tidb/pkg/util/sqlescape"
@@ -459,8 +460,7 @@ func InsertColStats2KV(
459460
}
460461
count := req.GetRow(0).GetInt64(0)
461462
for _, colInfo := range colInfos {
462-
value := types.NewDatum(colInfo.GetOriginDefaultValue())
463-
value, err = value.ConvertTo(sctx.GetSessionVars().StmtCtx.TypeCtx(), &colInfo.FieldType)
463+
value, err := table.GetColOriginDefaultValue(sctx.GetExprCtx(), colInfo)
464464
if err != nil {
465465
return 0, errors.Trace(err)
466466
}

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)