Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/pingcap/tidb into winkyao…
Browse files Browse the repository at this point in the history
…/cast_compability
  • Loading branch information
winkyao committed Aug 1, 2017
2 parents 68f0a1d + 289a906 commit 1699498
Show file tree
Hide file tree
Showing 17 changed files with 676 additions and 338 deletions.
15 changes: 15 additions & 0 deletions ast/dml.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ type Join struct {
On *OnCondition
// Using represents join using clause.
Using []*ColumnName
// NaturalJoin represents join is natural join
NaturalJoin bool
}

// Accept implements Node Accept interface.
Expand Down Expand Up @@ -248,6 +250,19 @@ const (
SelectLockInShareMode
)

// String implements fmt.Stringer.
func (slt SelectLockType) String() string {
switch slt {
case SelectLockNone:
return "none"
case SelectLockForUpdate:
return "for update"
case SelectLockInShareMode:
return "in share mode"
}
return "unsupported select lock type"
}

// WildCardField is a special type of select field content.
type WildCardField struct {
node
Expand Down
6 changes: 3 additions & 3 deletions executor/analyze_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ func (s *testSuite) TestAnalyzeTable(c *C) {
tk.MustExec("insert into t1 (a) values (1)")
result := tk.MustQuery("explain select * from t1 where t1.a = 1")
rowStr := fmt.Sprintf("%s", result.Rows())
c.Check(rowStr, Equals, "[[IndexScan_7 cop ] [IndexReader_8 root ]]")
c.Check(rowStr, Equals, "[[IndexScan_7 cop table:t1, index:a, range:[1,1], out of order:true] [IndexReader_8 root index:IndexScan_7]]")
tk.MustExec("analyze table t1")
result = tk.MustQuery("explain select * from t1 where t1.a = 1")
rowStr = fmt.Sprintf("%s", result.Rows())
c.Check(rowStr, Equals, "[[TableScan_4 Selection_5 cop ] [Selection_5 cop eq(test.t1.a, 1)] [TableReader_6 root ]]")
c.Check(rowStr, Equals, "[[TableScan_4 Selection_5 cop table:t1, range:(-inf,+inf), keep order:false] [Selection_5 cop eq(test.t1.a, 1)] [TableReader_6 root data:Selection_5]]")

tk.MustExec("drop table if exists t1")
tk.MustExec("create table t1 (a int)")
Expand All @@ -51,7 +51,7 @@ func (s *testSuite) TestAnalyzeTable(c *C) {
tk.MustExec("analyze table t1 index ind_a")
result = tk.MustQuery("explain select * from t1 where t1.a = 1")
rowStr = fmt.Sprintf("%s", result.Rows())
c.Check(rowStr, Equals, "[[TableScan_4 Selection_5 cop ] [Selection_5 cop eq(test.t1.a, 1)] [TableReader_6 root ]]")
c.Check(rowStr, Equals, "[[TableScan_4 Selection_5 cop table:t1, range:(-inf,+inf), keep order:false] [Selection_5 cop eq(test.t1.a, 1)] [TableReader_6 root data:Selection_5]]")
}

type recordSet struct {
Expand Down
73 changes: 73 additions & 0 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,68 @@ func (s *testSuite) TestSelectWithoutFrom(c *C) {
r.Check(testkit.Rows("string"))
}

func (s *testSuite) TestSelectBackslashN(c *C) {
defer func() {
s.cleanEnv(c)
testleak.AfterTest(c)()
}()
tk := testkit.NewTestKit(c, s.store)

sql := `select \N;`
r := tk.MustQuery(sql)
r.Check(testkit.Rows("<nil>"))
rs, err := tk.Exec(sql)
c.Check(err, IsNil)
fields, err := rs.Fields()
c.Check(err, IsNil)
c.Check(len(fields), Equals, 1)
c.Check(fields[0].Column.Name.O, Equals, "NULL")

sql = `select "\N";`
r = tk.MustQuery(sql)
r.Check(testkit.Rows("N"))
rs, err = tk.Exec(sql)
c.Check(err, IsNil)
fields, err = rs.Fields()
c.Check(err, IsNil)
c.Check(len(fields), Equals, 1)
c.Check(fields[0].Column.Name.O, Equals, `"\N"`)

tk.MustExec("use test;")
tk.MustExec("create table test (`\\N` int);")
tk.MustExec("insert into test values (1);")
tk.CheckExecResult(1, 0)
sql = "select * from test;"
r = tk.MustQuery(sql)
r.Check(testkit.Rows("1"))
rs, err = tk.Exec(sql)
c.Check(err, IsNil)
fields, err = rs.Fields()
c.Check(err, IsNil)
c.Check(len(fields), Equals, 1)
c.Check(fields[0].Column.Name.O, Equals, `\N`)

sql = "select \\N from test;"
r = tk.MustQuery(sql)
r.Check(testkit.Rows("<nil>"))
rs, err = tk.Exec(sql)
c.Check(err, IsNil)
fields, err = rs.Fields()
c.Check(err, IsNil)
c.Check(len(fields), Equals, 1)
c.Check(fields[0].Column.Name.O, Equals, `NULL`)

sql = "select `\\N` from test;"
r = tk.MustQuery(sql)
r.Check(testkit.Rows("1"))
rs, err = tk.Exec(sql)
c.Check(err, IsNil)
fields, err = rs.Fields()
c.Check(err, IsNil)
c.Check(len(fields), Equals, 1)
c.Check(fields[0].Column.Name.O, Equals, `\N`)
}

func (s *testSuite) TestSelectLimit(c *C) {
tk := testkit.NewTestKit(c, s.store)
defer func() {
Expand Down Expand Up @@ -983,6 +1045,17 @@ func (s *testSuite) TestStringBuiltin(c *C) {
result.Check(testutil.RowsWithSep(",", "bar ,bar,,<nil>"))
result = tk.MustQuery(`select rtrim(' bar '), rtrim('bar'), rtrim(''), rtrim(null)`)
result.Check(testutil.RowsWithSep(",", " bar,bar,,<nil>"))

// for trim
result = tk.MustQuery(`select trim(' bar '), trim(leading 'x' from 'xxxbarxxx'), trim(trailing 'xyz' from 'barxxyz'), trim(both 'x' from 'xxxbarxxx')`)
result.Check(testkit.Rows("bar barxxx barx bar"))
result = tk.MustQuery(`select trim(leading from ' bar'), trim('x' from 'xxxbarxxx'), trim('x' from 'bar'), trim('' from ' bar ')`)
result.Check(testutil.RowsWithSep(",", "bar,bar,bar, bar "))
result = tk.MustQuery(`select trim(''), trim('x' from '')`)
result.Check(testutil.RowsWithSep(",", ","))
result = tk.MustQuery(`select trim(null from 'bar'), trim('x' from null), trim(null), trim(leading null from 'bar')`)
// FIXME: the result for trim(leading null from 'bar') should be <nil>, current is 'bar'
result.Check(testkit.Rows("<nil> <nil> <nil> bar"))
}

func (s *testSuite) TestEncryptionBuiltin(c *C) {
Expand Down
186 changes: 0 additions & 186 deletions executor/explain_test.go

This file was deleted.

19 changes: 19 additions & 0 deletions executor/join_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,25 @@ func (s *testSuite) TestUsing(c *C) {
tk.MustExec("select * from (t1 join t2 using (a)) join (t3 join t4 using (a)) on (t2.a = t4.a and t1.a = t3.a)")
}

func (s *testSuite) TestNaturalJoin(c *C) {
defer func() {
s.cleanEnv(c)
testleak.AfterTest(c)()
}()
tk := testkit.NewTestKit(c, s.store)

tk.MustExec("use test")
tk.MustExec("drop table if exists t1, t2")
tk.MustExec("create table t1 (a int, b int)")
tk.MustExec("create table t2 (a int, c int)")
tk.MustExec("insert t1 values (1, 2), (10, 20)")
tk.MustExec("insert t2 values (1, 3), (100, 200)")

tk.MustQuery("select * from t1 natural join t2").Check(testkit.Rows("1 2 3"))
tk.MustQuery("select * from t1 natural left join t2 order by a").Check(testkit.Rows("1 2 3", "10 20 <nil>"))
tk.MustQuery("select * from t1 natural right join t2 order by a").Check(testkit.Rows("1 3 2", "100 200 <nil>"))
}

func (s *testSuite) TestMultiJoin(c *C) {
defer func() {
s.cleanEnv(c)
Expand Down
Loading

0 comments on commit 1699498

Please sign in to comment.