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

expression,executor: fix DIV() as partition expression behavior under ERROR_FOR_DIVISION_BY_ZERO sql_mode (#17302) #17314

Merged
merged 3 commits into from
May 20, 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
13 changes: 13 additions & 0 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5533,3 +5533,16 @@ func (s *testSuite1) TestInsertValuesWithSubQuery(c *C) {
tk.MustExec("insert into t2 set a = 3, b = 5, c = b")
tk.MustQuery("select * from t2").Check(testkit.Rows("2 4 2", "3 5 5"))
}

func (s *testSuite1) TestDIVZeroInPartitionExpr(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test;")
tk.MustExec("drop table if exists t1")
tk.MustExec("create table t1(a int) partition by range (10 div a) (partition p0 values less than (10), partition p1 values less than maxvalue)")
defer tk.MustExec("drop table if exists t1")

tk.MustExec("set @@sql_mode=''")
tk.MustExec("insert into t1 values (NULL), (0), (1)")
tk.MustExec("set @@sql_mode='STRICT_ALL_TABLES,ERROR_FOR_DIVISION_BY_ZERO'")
tk.MustGetErrCode("insert into t1 values (NULL), (0), (1)", mysql.ErrDivisionByZero)
}
10 changes: 7 additions & 3 deletions expression/builtin_arithmetic.go
Original file line number Diff line number Diff line change
Expand Up @@ -747,16 +747,20 @@ func (s *builtinArithmeticIntDivideDecimalSig) Clone() builtinFunc {
}

func (s *builtinArithmeticIntDivideIntSig) evalInt(row chunk.Row) (int64, bool, error) {
b, isNull, err := s.args[1].EvalInt(s.ctx, row)
return s.evalIntWithCtx(s.ctx, row)
}

func (s *builtinArithmeticIntDivideIntSig) evalIntWithCtx(sctx sessionctx.Context, row chunk.Row) (int64, bool, error) {
b, isNull, err := s.args[1].EvalInt(sctx, row)
if isNull || err != nil {
return 0, isNull, err
}

if b == 0 {
return 0, true, handleDivisionByZeroError(s.ctx)
return 0, true, handleDivisionByZeroError(sctx)
}

a, isNull, err := s.args[0].EvalInt(s.ctx, row)
a, isNull, err := s.args[0].EvalInt(sctx, row)
if isNull || err != nil {
return 0, isNull, err
}
Expand Down