Skip to content

Commit

Permalink
Merge branch 'sql_select_limit' of https://github.com/qw4990/tidb int…
Browse files Browse the repository at this point in the history
…o sql_select_limit
  • Loading branch information
qw4990 committed Nov 23, 2021
2 parents 192d65f + 364f239 commit 7ffb832
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 18 deletions.
23 changes: 9 additions & 14 deletions br/pkg/redact/redact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,24 @@
package redact_test

import (
"encoding/hex"
"testing"

. "github.com/pingcap/check"
"github.com/pingcap/tidb/br/pkg/redact"
"github.com/stretchr/testify/require"
"go.uber.org/goleak"
)

type testRedactSuite struct{}
func TestRedact(t *testing.T) {
defer goleak.VerifyNone(t)

func (s *testRedactSuite) SetUpSuite(c *C) {}
func (s *testRedactSuite) TearDownSuite(c *C) {}

var _ = Suite(&testRedactSuite{})

func TestT(t *testing.T) {}

func (s *testRedactSuite) TestRedact(c *C) {
redacted, secret := "?", "secret"

redact.InitRedact(false)
c.Assert(redact.String(secret), Equals, secret)
c.Assert(redact.Key([]byte(secret)), Equals, secret)
require.Equal(t, redact.String(secret), secret)
require.Equal(t, redact.Key([]byte(secret)), hex.EncodeToString([]byte(secret)))

redact.InitRedact(true)
c.Assert(redact.String(secret), Equals, redacted)
c.Assert(redact.Key([]byte(secret)), Equals, redacted)
require.Equal(t, redact.String(secret), redacted)
require.Equal(t, redact.Key([]byte(secret)), redacted)
}
14 changes: 14 additions & 0 deletions ddl/db_change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1819,6 +1819,8 @@ func (s *serialTestStateChangeSuite) TestCreateExpressionIndex(c *C) {
stateWriteOnlySQLs := []string{"insert into t values (8, 8)", "begin pessimistic;", "insert into t select * from t", "rollback", "insert into t set b = 9", "update t set b = 7 where a = 2", "delete from t where b = 3"}
stateWriteReorganizationSQLs := []string{"insert into t values (10, 10)", "begin pessimistic;", "insert into t select * from t", "rollback", "insert into t set b = 11", "update t set b = 7 where a = 5", "delete from t where b = 6"}

// If waitReorg timeout, the worker may enter writeReorg more than 2 times.
reorgTime := 0
var checkErr error
d := s.dom.DDL()
originalCallback := d.GetHook()
Expand Down Expand Up @@ -1848,6 +1850,11 @@ func (s *serialTestStateChangeSuite) TestCreateExpressionIndex(c *C) {
}
// (1, 7), (2, 7), (5, 5), (0, 6), (8, 8), (0, 9)
case model.StateWriteReorganization:
if reorgTime < 2 {
reorgTime++
} else {
return
}
for _, sql := range stateWriteReorganizationSQLs {
_, checkErr = tk1.Exec(sql)
if checkErr != nil {
Expand Down Expand Up @@ -1880,6 +1887,8 @@ func (s *serialTestStateChangeSuite) TestCreateUniqueExpressionIndex(c *C) {

stateDeleteOnlySQLs := []string{"insert into t values (5, 5)", "begin pessimistic;", "insert into t select * from t", "rollback", "insert into t set b = 6", "update t set b = 7 where a = 1", "delete from t where b = 4"}

// If waitReorg timeout, the worker may enter writeReorg more than 2 times.
reorgTime := 0
var checkErr error
d := s.dom.DDL()
originalCallback := d.GetHook()
Expand Down Expand Up @@ -1932,6 +1941,11 @@ func (s *serialTestStateChangeSuite) TestCreateUniqueExpressionIndex(c *C) {
}
// (1, 7), (2, 7), (5, 5), (0, 6), (8, 8), (0, 9)
case model.StateWriteReorganization:
if reorgTime < 2 {
reorgTime++
} else {
return
}
_, checkErr = tk1.Exec("insert into t values (10, 10) on duplicate key update a = 11")
if checkErr != nil {
return
Expand Down
3 changes: 3 additions & 0 deletions expression/builtin_cast.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,9 @@ func (c *castAsStringFunctionClass) getFunction(ctx sessionctx.Context, args []E
argTp := args[0].GetType().EvalType()
switch argTp {
case types.ETInt:
if bf.tp.Flen == types.UnspecifiedLength {
bf.tp.Flen = args[0].GetType().Flen
}
sig = &builtinCastIntAsStringSig{bf}
sig.setPbCode(tipb.ScalarFuncSig_CastIntAsString)
case types.ETReal:
Expand Down
13 changes: 13 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10627,3 +10627,16 @@ func (s *testIntegrationSuite) TestIssue29244(c *C) {
tk.MustExec("set tidb_enable_vectorized_expression = off;")
tk.MustQuery("select microsecond(a) from t;").Check(testkit.Rows("123500", "123500"))
}

func (s *testIntegrationSuite) TestIssue29513(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustQuery("select '123' union select cast(45678 as char);").Sort().Check(testkit.Rows("123", "45678"))
tk.MustQuery("select '123' union select cast(45678 as char(2));").Sort().Check(testkit.Rows("123", "45"))

tk.MustExec("drop table if exists t")
tk.MustExec("create table t(a int);")
tk.MustExec("insert into t values(45678);")
tk.MustQuery("select '123' union select cast(a as char) from t;").Sort().Check(testkit.Rows("123", "45678"))
tk.MustQuery("select '123' union select cast(a as char(2)) from t;").Sort().Check(testkit.Rows("123", "45"))
}
8 changes: 4 additions & 4 deletions expression/typeinfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@ func (s *InferTypeSuite) createTestCase4Constants() []typeInferTestCase {

func (s *InferTypeSuite) createTestCase4Cast() []typeInferTestCase {
return []typeInferTestCase{
{"CAST(c_int_d AS BINARY)", mysql.TypeVarString, charset.CharsetBin, mysql.BinaryFlag, -1, -1}, // TODO: Flen should be 11.
{"CAST(c_int_d AS BINARY)", mysql.TypeVarString, charset.CharsetBin, mysql.BinaryFlag, 11, -1},
{"CAST(c_int_d AS BINARY(5))", mysql.TypeString, charset.CharsetBin, mysql.BinaryFlag, 5, -1},
{"CAST(c_int_d AS CHAR)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, -1, -1}, // TODO: Flen should be 11.
{"CAST(c_int_d AS CHAR)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 11, -1},
{"CAST(c_int_d AS CHAR(5))", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 5, -1},
{"CAST(c_int_d AS DATE)", mysql.TypeDate, charset.CharsetBin, mysql.BinaryFlag, 10, 0},
{"CAST(c_int_d AS DATETIME)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 19, 0},
Expand Down Expand Up @@ -430,8 +430,8 @@ func (s *InferTypeSuite) createTestCase4StrFuncs() []typeInferTestCase {

{"reverse(c_int_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 20, types.UnspecifiedLength},
{"reverse(c_bigint_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 20, types.UnspecifiedLength},
{"reverse(c_float_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, -1, types.UnspecifiedLength},
{"reverse(c_double_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, -1, types.UnspecifiedLength},
{"reverse(c_float_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, types.UnspecifiedLength, types.UnspecifiedLength},
{"reverse(c_double_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, types.UnspecifiedLength, types.UnspecifiedLength},
{"reverse(c_decimal )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 9, types.UnspecifiedLength},
{"reverse(c_char )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 20, types.UnspecifiedLength},
{"reverse(c_varchar )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 20, types.UnspecifiedLength},
Expand Down

0 comments on commit 7ffb832

Please sign in to comment.