From 87a2cf7c232a521b56149b8795203a3d53d13b8b Mon Sep 17 00:00:00 2001 From: ti-srebot <66930949+ti-srebot@users.noreply.github.com> Date: Wed, 28 Oct 2020 15:34:19 +0800 Subject: [PATCH] table: should not skip when default value is not null (#20491) (#20532) --- ddl/db_integration_test.go | 13 +++++++++++++ go.mod | 2 +- go.sum | 4 ++-- table/tables/tables.go | 4 ++-- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/ddl/db_integration_test.go b/ddl/db_integration_test.go index 4d64c5b0064c8..5f251057ababa 100644 --- a/ddl/db_integration_test.go +++ b/ddl/db_integration_test.go @@ -2046,3 +2046,16 @@ func (s *testIntegrationSuite3) TestCreateTableWithAutoIdCache(c *C) { c.Assert(err, NotNil) c.Assert(err.Error(), Equals, "table option auto_id_cache overflows int64") } + +func (s *testIntegrationSuite3) TestIssue20490(c *C) { + tk := testkit.NewTestKit(c, s.store) + tk.MustExec("use test;") + tk.MustExec("create table issue20490 (a int);") + tk.MustExec("insert into issue20490(a) values(1);") + tk.MustExec("alter table issue20490 add b int not null default 1;") + tk.MustExec("insert into issue20490(a) values(2);") + tk.MustExec("alter table issue20490 modify b int null;") + tk.MustExec("insert into issue20490(a) values(3);") + + tk.MustQuery("select b from issue20490 order by a;").Check(testkit.Rows("1", "1", "")) +} diff --git a/go.mod b/go.mod index 6a90e2c0b0375..b75e807359617 100644 --- a/go.mod +++ b/go.mod @@ -38,7 +38,7 @@ require ( github.com/pingcap/goleveldb v0.0.0-20171020122428-b9ff6c35079e github.com/pingcap/kvproto v0.0.0-20200311073257-e53d835099b0 github.com/pingcap/log v0.0.0-20190715063458-479153f07ebd - github.com/pingcap/parser v3.0.17-0.20200917074335-8b16316f8a6e+incompatible + github.com/pingcap/parser v3.0.17-0.20201028064329-c7f5d9fee686+incompatible github.com/pingcap/pd v1.1.0-beta.0.20191223090411-ea2b748f6ee2 github.com/pingcap/tidb-tools v3.0.6-0.20191119150227-ff0a3c6e5763+incompatible github.com/pingcap/tipb v0.0.0-20200426072559-d2c068e96eb3 diff --git a/go.sum b/go.sum index 6e325e6fa3ace..c032205b5b144 100644 --- a/go.sum +++ b/go.sum @@ -158,8 +158,8 @@ github.com/pingcap/kvproto v0.0.0-20200311073257-e53d835099b0 h1:dXXNHvDwAEN1YNg github.com/pingcap/kvproto v0.0.0-20200311073257-e53d835099b0/go.mod h1:QMdbTAXCHzzygQzqcG9uVUgU2fKeSN1GmfMiykdSzzY= github.com/pingcap/log v0.0.0-20190715063458-479153f07ebd h1:hWDol43WY5PGhsh3+8794bFHY1bPrmu6bTalpssCrGg= github.com/pingcap/log v0.0.0-20190715063458-479153f07ebd/go.mod h1:WpHUKhNZ18v116SvGrmjkA9CBhYmuUTKL+p8JC9ANEw= -github.com/pingcap/parser v3.0.17-0.20200917074335-8b16316f8a6e+incompatible h1:A82fSnaJr+jRR9X0DquF+JhHdygw1I+YV5rrqWf95DY= -github.com/pingcap/parser v3.0.17-0.20200917074335-8b16316f8a6e+incompatible/go.mod h1:1FNvfp9+J0wvc4kl8eGNh7Rqrxveg15jJoWo/a0uHwA= +github.com/pingcap/parser v3.0.17-0.20201028064329-c7f5d9fee686+incompatible h1:OGSmvyHh8eQOogkqUGEAawcM1NAr8wp1rEaEBSEDPYo= +github.com/pingcap/parser v3.0.17-0.20201028064329-c7f5d9fee686+incompatible/go.mod h1:1FNvfp9+J0wvc4kl8eGNh7Rqrxveg15jJoWo/a0uHwA= github.com/pingcap/pd v1.1.0-beta.0.20191223090411-ea2b748f6ee2 h1:NL23b8tsg6M1QpSQedK14/Jx++QeyKL2rGiBvXAQVfA= github.com/pingcap/pd v1.1.0-beta.0.20191223090411-ea2b748f6ee2/go.mod h1:b4gaAPSxaVVtaB+EHamV4Nsv8JmTdjlw0cTKmp4+dRQ= github.com/pingcap/tidb-tools v3.0.6-0.20191119150227-ff0a3c6e5763+incompatible h1:I8HirWsu1MZp6t9G/g8yKCEjJJxtHooKakEgccvdJ4M= diff --git a/table/tables/tables.go b/table/tables/tables.go index b1bab30e94806..870526d5bdfef 100644 --- a/table/tables/tables.go +++ b/table/tables/tables.go @@ -1032,13 +1032,13 @@ func (t *tableCommon) canSkip(col *table.Column, value types.Datum) bool { // CanSkip is for these cases, we can skip the columns in encoded row: // 1. the column is included in primary key; -// 2. the column's default value is null, and the value equals to that; +// 2. the column's default value is null, and the value equals to that but has no origin default; // 3. the column is virtual generated. func CanSkip(info *model.TableInfo, col *table.Column, value types.Datum) bool { if col.IsPKHandleColumn(info) { return true } - if col.GetDefaultValue() == nil && value.IsNull() { + if col.GetDefaultValue() == nil && value.IsNull() && col.GetOriginDefaultValue() == nil { return true } if col.IsGenerated() && !col.GeneratedStored {