Skip to content
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
1 change: 1 addition & 0 deletions pkg/statistics/handle/storage/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ go_library(
"//pkg/statistics/handle/usage/predicatecolumn",
"//pkg/statistics/handle/util",
"//pkg/statistics/util",
"//pkg/table",
"//pkg/types",
"//pkg/util/chunk",
"//pkg/util/compress",
Expand Down
4 changes: 2 additions & 2 deletions pkg/statistics/handle/storage/save.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/pingcap/tidb/pkg/statistics"
statslogutil "github.com/pingcap/tidb/pkg/statistics/handle/logutil"
"github.com/pingcap/tidb/pkg/statistics/handle/util"
"github.com/pingcap/tidb/pkg/table"
"github.com/pingcap/tidb/pkg/types"
"github.com/pingcap/tidb/pkg/util/chunk"
"github.com/pingcap/tidb/pkg/util/sqlescape"
Expand Down Expand Up @@ -444,8 +445,7 @@ func InsertColStats2KV(
}
count := req.GetRow(0).GetInt64(0)
for _, colInfo := range colInfos {
value := types.NewDatum(colInfo.GetOriginDefaultValue())
value, err = value.ConvertTo(sctx.GetSessionVars().StmtCtx.TypeCtx(), &colInfo.FieldType)
value, err := table.GetColOriginDefaultValue(sctx.GetExprCtx(), colInfo)
if err != nil {
return 0, errors.Trace(err)
}
Expand Down
11 changes: 11 additions & 0 deletions tests/integrationtest/r/statistics/handle.result
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,14 @@ insert into t values(1,1),(2,2),(3,3);
alter table t add stats_extended s1 correlation(a,b);
analyze table t;
set session tidb_enable_extended_stats = default;
drop table if exists t;
set time_zone = '+08:00';
create table t(a int);
alter table t add column ts timestamp DEFAULT '1970-01-01 08:00:01';
drop table if exists t;
set time_zone = '+09:00';
create table t(a int);
alter table t add column ts timestamp DEFAULT '1970-01-01 08:00:01';
Error 1067 (42000): Invalid default value for 'ts'
drop table if exists t;
set time_zone = default;
13 changes: 13 additions & 0 deletions tests/integrationtest/t/statistics/handle.test
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,16 @@ alter table t add stats_extended s1 correlation(a,b);
## no error
analyze table t;
set session tidb_enable_extended_stats = default;

# TestHandleDDLEventForTimestampDefaultValue
drop table if exists t;
set time_zone = '+08:00';
create table t(a int);
alter table t add column ts timestamp DEFAULT '1970-01-01 08:00:01';
drop table if exists t;
set time_zone = '+09:00';
create table t(a int);
-- error 1067
alter table t add column ts timestamp DEFAULT '1970-01-01 08:00:01';
drop table if exists t;
set time_zone = default;