Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

executor: fix a bug that the generated column doesn't handle bad null value #20193

Merged
merged 2 commits into from
Sep 25, 2020
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
4 changes: 4 additions & 0 deletions executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1706,6 +1706,10 @@ func FillVirtualColumnValue(virtualRetTypes []*types.FieldType, virtualColumnInd
if err != nil {
return err
}
// Handle the bad null error.
if (mysql.HasNotNullFlag(columns[idx].Flag) || mysql.HasPreventNullInsertFlag(columns[idx].Flag)) && castDatum.IsNull() {
castDatum = table.GetZeroValue(columns[idx])
}
virCols.AppendDatum(i, &castDatum)
}
req.SetCol(idx, virCols.Column(i))
Expand Down
5 changes: 5 additions & 0 deletions executor/union_scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"runtime/trace"

"github.com/pingcap/parser/model"
"github.com/pingcap/parser/mysql"
"github.com/pingcap/tidb/expression"
"github.com/pingcap/tidb/kv"
plannercore "github.com/pingcap/tidb/planner/core"
Expand Down Expand Up @@ -134,6 +135,10 @@ func (us *UnionScanExec) Next(ctx context.Context, req *chunk.Chunk) error {
if err != nil {
return err
}
// Handle the bad null error.
if (mysql.HasNotNullFlag(us.columns[idx].Flag) || mysql.HasPreventNullInsertFlag(us.columns[idx].Flag)) && castDatum.IsNull() {
castDatum = table.GetZeroValue(us.columns[idx])
}
mutableRow.SetDatum(idx, castDatum)
}

Expand Down
15 changes: 15 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7330,6 +7330,21 @@ func (s *testIntegrationSerialSuite) TestIssue18949(c *C) {
c.Assert(result, Matches, `(?s).*enum\('a','b ',' c'\).*set\('a','b ',' c'\).*`)
}

func (s *testIntegrationSuite) TestIssue17767(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t0;")
tk.MustExec("CREATE TABLE t0(c0 INTEGER AS (NULL) NOT NULL, c1 INT);")
tk.MustExec("CREATE INDEX i0 ON t0(c0, c1);")
tk.MustExec("INSERT IGNORE INTO t0(c1) VALUES (0);")
tk.MustQuery("SELECT * FROM t0").Check(testkit.Rows("0 0"))

tk.MustExec("begin")
tk.MustExec("INSERT IGNORE INTO t0(c1) VALUES (0);")
tk.MustQuery("SELECT * FROM t0").Check(testkit.Rows("0 0", "0 0"))
tk.MustExec("rollback")
}

func (s *testIntegrationSuite) TestIssue19596(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
Expand Down