Skip to content

Commit

Permalink
expression: fix timezone for timestamp constant when converting expre…
Browse files Browse the repository at this point in the history
…ssion to pb (pingcap#9473)
  • Loading branch information
tiancaiamao authored and zz-jason committed Feb 27, 2019
1 parent f32a194 commit 9da1749
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
8 changes: 0 additions & 8 deletions expression/expr_to_pb.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,9 @@
package expression

import (
"time"

"github.com/pingcap/parser/ast"
"github.com/pingcap/parser/charset"
"github.com/pingcap/parser/mysql"
"github.com/pingcap/parser/terror"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/sessionctx/stmtctx"
"github.com/pingcap/tidb/types"
Expand Down Expand Up @@ -157,12 +154,7 @@ func (pc *PbConverter) encodeDatum(d types.Datum) (tipb.ExprType, []byte, bool)
case types.KindMysqlTime:
if pc.client.IsRequestTypeSupported(kv.ReqTypeDAG, int64(tipb.ExprType_MysqlTime)) {
tp = tipb.ExprType_MysqlTime
loc := pc.sc.TimeZone
t := d.GetMysqlTime()
if t.Type == mysql.TypeTimestamp && loc != time.UTC {
err := t.ConvertTimeZone(loc, time.UTC)
terror.Log(err)
}
v, err := t.ToPackedUint()
if err != nil {
log.Errorf("Fail to encode value, err: %s", err.Error())
Expand Down
16 changes: 16 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3989,3 +3989,19 @@ func (s *testIntegrationSuite) TestValuesEnum(c *C) {
tk.MustExec(`insert into t values (1, "b") on duplicate key update b = values(b);`)
tk.MustQuery(`select * from t;`).Check(testkit.Rows(`1 b`))
}

func (s *testIntegrationSuite) TestIssue9325(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
tk.MustExec("create table t(a timestamp) partition by range(unix_timestamp(a)) (partition p0 values less than(unix_timestamp('2019-02-16 14:20:00')), partition p1 values less than (maxvalue))")
tk.MustExec("insert into t values('2019-02-16 14:19:59'), ('2019-02-16 14:20:01')")
result := tk.MustQuery("select * from t where a between timestamp'2019-02-16 14:19:00' and timestamp'2019-02-16 14:21:00'")
c.Assert(result.Rows(), HasLen, 2)

tk.MustExec("drop table if exists t")
tk.MustExec("create table t(a timestamp)")
tk.MustExec("insert into t values('2019-02-16 14:19:59'), ('2019-02-16 14:20:01')")
result = tk.MustQuery("select * from t where a < timestamp'2019-02-16 14:21:00'")
result.Check(testkit.Rows("2019-02-16 14:19:59", "2019-02-16 14:20:01"))
}

0 comments on commit 9da1749

Please sign in to comment.