Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into remove-streaming
Browse files Browse the repository at this point in the history
  • Loading branch information
morgo committed Mar 10, 2022
2 parents ea97c33 + 469bc71 commit db4a3b1
Show file tree
Hide file tree
Showing 31 changed files with 933 additions and 1,127 deletions.
6 changes: 6 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ type Config struct {
// TODO: We actually only support mode 2, which keeps the original case, but the comparison is case-insensitive.
LowerCaseTableNames int `toml:"lower-case-table-names" json:"lower-case-table-names"`
ServerVersion string `toml:"server-version" json:"server-version"`
VersionComment string `toml:"version-comment" json:"version-comment"`
TiDBEdition string `toml:"tidb-edition" json:"tidb-edition"`
TiDBReleaseVersion string `toml:"tidb-release-version" json:"tidb-release-version"`
Log Log `toml:"log" json:"log"`
Security Security `toml:"security" json:"security"`
Status Status `toml:"status" json:"status"`
Expand Down Expand Up @@ -645,6 +648,9 @@ var defaultConf = Config{
LowerCaseTableNames: 2,
GracefulWaitBeforeShutdown: 0,
ServerVersion: "",
TiDBEdition: "",
VersionComment: "",
TiDBReleaseVersion: "",
Log: Log{
Level: "info",
Format: "text",
Expand Down
11 changes: 9 additions & 2 deletions executor/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -3101,7 +3101,10 @@ func buildNoRangeTableReader(b *executorBuilder, v *plannercore.PhysicalTableRea
if err != nil {
return nil, err
}
ts := v.GetTableScan()
ts, err := v.GetTableScan()
if err != nil {
return nil, err
}
if err = b.validCanReadTemporaryOrCacheTable(ts.Table); err != nil {
return nil, err
}
Expand Down Expand Up @@ -3205,7 +3208,11 @@ func (b *executorBuilder) buildTableReader(v *plannercore.PhysicalTableReader) E
return nil
}

ts := v.GetTableScan()
ts, err := v.GetTableScan()
if err != nil {
b.err = err
return nil
}
if err = b.validCanReadTemporaryOrCacheTable(ts.Table); err != nil {
b.err = err
return nil
Expand Down
11 changes: 11 additions & 0 deletions executor/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1591,6 +1591,17 @@ func TestShowVar(t *testing.T) {
// Test Hidden tx_read_ts
res = tk.MustQuery("show variables like '%tx_read_ts'")
require.Len(t, res.Rows(), 0)

// Test versions' related variables
res = tk.MustQuery("show variables like 'version%'")
for _, row := range res.Rows() {
line := fmt.Sprint(row)
if strings.HasPrefix(line, "version ") {
require.Equal(t, mysql.ServerVersion, line[len("version "):])
} else if strings.HasPrefix(line, "version_comment ") {
require.Equal(t, variable.GetSysVar(variable.VersionComment), line[len("version_comment "):])
}
}
}

func TestIssue19507(t *testing.T) {
Expand Down
4 changes: 0 additions & 4 deletions executor/tiflash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ func TestReadUnsigedPK(t *testing.T) {

tk.MustExec("set @@session.tidb_isolation_read_engines=\"tiflash\"")
tk.MustExec("set @@session.tidb_allow_mpp=ON")
tk.MustExec("set @@session.tidb_opt_broadcast_join=ON")
// mock executor does not support use outer table as build side for outer join, so need to
// force the inner table as build side
tk.MustExec("set tidb_opt_mpp_outer_join_fixed_build_side=1")
Expand Down Expand Up @@ -345,7 +344,6 @@ func TestTiFlashPartitionTableShuffledHashJoin(t *testing.T) {
}

tk.MustExec("SET tidb_enforce_mpp=1")
tk.MustExec("SET tidb_opt_broadcast_join=0")
tk.MustExec("SET tidb_broadcast_join_threshold_count=0")
tk.MustExec("SET tidb_broadcast_join_threshold_size=0")
tk.MustExec("set @@session.tidb_isolation_read_engines='tiflash'")
Expand Down Expand Up @@ -489,7 +487,6 @@ func TestPartitionTable(t *testing.T) {

tk.MustExec("set @@session.tidb_isolation_read_engines=\"tiflash\"")
tk.MustExec("set @@session.tidb_allow_mpp=ON")
tk.MustExec("set @@session.tidb_opt_broadcast_join=ON")
// test if it is really work.
failpoint.Enable("github.com/pingcap/tidb/executor/checkTotalMPPTasks", `return(8)`)
tk.MustQuery("select count(*) from t1 , t where t1.a = t.a").Check(testkit.Rows("4"))
Expand Down Expand Up @@ -1025,7 +1022,6 @@ func TestTiFlashPartitionTableBroadcastJoin(t *testing.T) {
}
tk.MustExec("set @@session.tidb_isolation_read_engines='tiflash'")
tk.MustExec("set @@session.tidb_enforce_mpp=1")
tk.MustExec("set @@session.tidb_opt_broadcast_join=ON")
// mock executor does not support use outer table as build side for outer join, so need to
// force the inner table as build side
tk.MustExec("set tidb_opt_mpp_outer_join_fixed_build_side=1")
Expand Down
57 changes: 35 additions & 22 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ import (
"github.com/pingcap/tidb/util/kvcache"
"github.com/pingcap/tidb/util/sem"
"github.com/pingcap/tidb/util/sqlexec"
"github.com/pingcap/tidb/util/testutil"
"github.com/pingcap/tidb/util/versioninfo"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -518,16 +521,16 @@ func TestStringBuiltin(t *testing.T) {

// for space
result = tk.MustQuery(`select space(0), space(2), space(-1), space(1.1), space(1.9)`)
result.Check(testkit.RowsWithSep(",", ", ,, , "))
result.Check(testutil.RowsWithSep(",", ", ,, , "))
result = tk.MustQuery(`select space("abc"), space("2"), space("1.1"), space(''), space(null)`)
result.Check(testkit.RowsWithSep(",", ", , ,,<nil>"))
result.Check(testutil.RowsWithSep(",", ", , ,,<nil>"))

// for replace
tk.MustExec("drop table if exists t")
tk.MustExec("create table t(a char(20), b int, c double, d datetime, e time)")
tk.MustExec(`insert into t values('www.mysql.com', 1234, 12.34, "2017-01-01 12:01:01", "12:01:01")`)
result = tk.MustQuery(`select replace(a, 'mysql', 'pingcap'), replace(b, 2, 55), replace(c, 34, 0), replace(d, '-', '/'), replace(e, '01', '22') from t`)
result.Check(testkit.RowsWithSep(",", "www.pingcap.com,15534,12.0,2017/01/01 12:01:01,12:22:22"))
result.Check(testutil.RowsWithSep(",", "www.pingcap.com,15534,12.0,2017/01/01 12:01:01,12:22:22"))
result = tk.MustQuery(`select replace('aaa', 'a', ''), replace(null, 'a', 'b'), replace('a', null, 'b'), replace('a', 'b', null)`)
result.Check(testkit.Rows(" <nil> <nil> <nil>"))

Expand All @@ -551,7 +554,7 @@ func TestStringBuiltin(t *testing.T) {
result = tk.MustQuery(`select substr(a, 3), substr(b, 2, 3), substr(c, -3), substr(d, -8), substr(e, -3, 100) from t`)
result.Check(testkit.Rows("kila 234 .45 12:01:01 :01"))
result = tk.MustQuery(`select substr('Sakila', 100), substr('Sakila', -100), substr('Sakila', -5, 3), substr('Sakila', 2, -1)`)
result.Check(testkit.RowsWithSep(",", ",,aki,"))
result.Check(testutil.RowsWithSep(",", ",,aki,"))
result = tk.MustQuery(`select substr('foobarbar' from 4), substr('Sakila' from -4 for 2)`)
result.Check(testkit.Rows("barbar ki"))
result = tk.MustQuery(`select substr(null, 2, 3), substr('foo', null, 3), substr('foo', 2, null)`)
Expand Down Expand Up @@ -582,7 +585,7 @@ func TestStringBuiltin(t *testing.T) {
result = tk.MustQuery(`select substring_index('www.pingcap.com', '.', 0), substring_index('www.pingcap.com', '.', 100), substring_index('www.pingcap.com', '.', -100)`)
result.Check(testkit.Rows(" www.pingcap.com www.pingcap.com"))
result = tk.MustQuery(`select substring_index('www.pingcap.com', 'd', 1), substring_index('www.pingcap.com', '', 1), substring_index('', '.', 1)`)
result.Check(testkit.RowsWithSep(",", "www.pingcap.com,,"))
result.Check(testutil.RowsWithSep(",", "www.pingcap.com,,"))
result = tk.MustQuery(`select substring_index(null, '.', 1), substring_index('www.pingcap.com', null, 1), substring_index('www.pingcap.com', '.', null)`)
result.Check(testkit.Rows("<nil> <nil> <nil>"))

Expand Down Expand Up @@ -623,13 +626,13 @@ func TestStringBuiltin(t *testing.T) {

// for ltrim and rtrim
result = tk.MustQuery(`select ltrim(' bar '), ltrim('bar'), ltrim(''), ltrim(null)`)
result.Check(testkit.RowsWithSep(",", "bar ,bar,,<nil>"))
result.Check(testutil.RowsWithSep(",", "bar ,bar,,<nil>"))
result = tk.MustQuery(`select rtrim(' bar '), rtrim('bar'), rtrim(''), rtrim(null)`)
result.Check(testkit.RowsWithSep(",", " bar,bar,,<nil>"))
result.Check(testutil.RowsWithSep(",", " bar,bar,,<nil>"))
result = tk.MustQuery(`select ltrim("\t bar "), ltrim(" \tbar"), ltrim("\n bar"), ltrim("\r bar")`)
result.Check(testkit.RowsWithSep(",", "\t bar ,\tbar,\n bar,\r bar"))
result.Check(testutil.RowsWithSep(",", "\t bar ,\tbar,\n bar,\r bar"))
result = tk.MustQuery(`select rtrim(" bar \t"), rtrim("bar\t "), rtrim("bar \n"), rtrim("bar \r")`)
result.Check(testkit.RowsWithSep(",", " bar \t,bar\t,bar \n,bar \r"))
result.Check(testutil.RowsWithSep(",", " bar \t,bar\t,bar \n,bar \r"))

// for reverse
tk.MustExec(`DROP TABLE IF EXISTS t;`)
Expand All @@ -644,11 +647,11 @@ func TestStringBuiltin(t *testing.T) {
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('\t bar\n '), trim(' \rbar \t')`)
result.Check(testkit.RowsWithSep(",", "\t bar\n,\rbar \t"))
result.Check(testutil.RowsWithSep(",", "\t bar\n,\rbar \t"))
result = tk.MustQuery(`select trim(leading from ' bar'), trim('x' from 'xxxbarxxx'), trim('x' from 'bar'), trim('' from ' bar ')`)
result.Check(testkit.RowsWithSep(",", "bar,bar,bar, bar "))
result.Check(testutil.RowsWithSep(",", "bar,bar,bar, bar "))
result = tk.MustQuery(`select trim(''), trim('x' from '')`)
result.Check(testkit.RowsWithSep(",", ","))
result.Check(testutil.RowsWithSep(",", ","))
result = tk.MustQuery(`select trim(null from 'bar'), trim('x' from null), trim(null), trim(leading null from 'bar')`)
result.Check(testkit.Rows("<nil> <nil> <nil> <nil>"))

Expand Down Expand Up @@ -901,7 +904,7 @@ func TestEncryptionBuiltin(t *testing.T) {
result.Check(testkit.Rows(`45ABDD5C4802EFA6771A94C43F805208 45ABDD5C4802EFA6771A94C43F805208 791F1AEB6A6B796E6352BF381895CA0E D0147E2EB856186F146D9F6DE33F9546 <nil>`))
result = tk.MustQuery("select HEX(AES_ENCRYPT(a, 'key', 'iv')), HEX(AES_ENCRYPT(b, 'key', 'iv')) from t")
result.Check(testkit.Rows("B3800B3A3CB4ECE2051A3E80FE373EAC B3800B3A3CB4ECE2051A3E80FE373EAC"))
tk.MustQuery("show warnings").Check(testkit.RowsWithSep("|", "Warning|1618|<IV> option ignored", "Warning|1618|<IV> option ignored"))
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1618|<IV> option ignored", "Warning|1618|<IV> option ignored"))
tk.MustExec("SET block_encryption_mode='aes-128-cbc';")
result = tk.MustQuery("select HEX(AES_ENCRYPT(a, 'key', '1234567890123456')), HEX(AES_ENCRYPT(b, 'key', '1234567890123456')), HEX(AES_ENCRYPT(c, 'key', '1234567890123456')), HEX(AES_ENCRYPT(d, 'key', '1234567890123456')), HEX(AES_ENCRYPT(e, 'key', '1234567890123456')), HEX(AES_ENCRYPT(f, 'key', '1234567890123456')), HEX(AES_ENCRYPT(g, 'key', '1234567890123456')), HEX(AES_ENCRYPT(h, 'key', '1234567890123456')), HEX(AES_ENCRYPT(i, 'key', '1234567890123456')) from t")
result.Check(testkit.Rows("341672829F84CB6B0BE690FEC4C4DAE9 341672829F84CB6B0BE690FEC4C4DAE9 D43734E147A12BB96C6897C4BBABA283 16F2C972411948DCEF3659B726D2CCB04AD1379A1A367FA64242058A50211B67 41E71D0C58967C1F50EEC074523946D1 1117D292E2D39C3EAA3B435371BE56FC 8ACB7ECC0883B672D7BD1CFAA9FA5FAF5B731ADE978244CD581F114D591C2E7E D2B13C30937E3251AEDA73859BA32E4B 2CF4A6051FF248A67598A17AA2C17267"))
Expand Down Expand Up @@ -1192,6 +1195,16 @@ func TestInfoBuiltin(t *testing.T) {
result = tk.MustQuery("select version()")
result.Check(testkit.Rows(mysql.ServerVersion))

// for tidb_version
result = tk.MustQuery("select tidb_version()")
tidbVersionResult := ""
for _, line := range result.Rows() {
tidbVersionResult += fmt.Sprint(line)
}
lines := strings.Split(tidbVersionResult, "\n")
assert.Equal(t, true, strings.Split(lines[0], " ")[2] == mysql.TiDBReleaseVersion, "errors in 'select tidb_version()'")
assert.Equal(t, true, strings.Split(lines[1], " ")[1] == versioninfo.TiDBEdition, "errors in 'select tidb_version()'")

// for row_count
tk.MustExec("drop table if exists t")
tk.MustExec("create table t (a int, b int, PRIMARY KEY (a))")
Expand Down Expand Up @@ -1483,7 +1496,7 @@ func TestArithmeticBuiltin(t *testing.T) {
result.Check(testkit.Rows("2 2 1"))
result = tk.MustQuery("SELECT 1.175494351E-37 div 1.7976931348623157E+308, 1.7976931348623157E+308 div -1.7976931348623157E+307, 1 div 1e-82;")
result.Check(testkit.Rows("0 -1 <nil>"))
tk.MustQuery("show warnings").Check(testkit.RowsWithSep("|",
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|",
"Warning|1292|Truncated incorrect DECIMAL value: '1.7976931348623157e+308'",
"Warning|1292|Truncated incorrect DECIMAL value: '1.7976931348623157e+308'",
"Warning|1292|Truncated incorrect DECIMAL value: '-1.7976931348623158e+307'",
Expand Down Expand Up @@ -1548,7 +1561,7 @@ func TestArithmeticBuiltin(t *testing.T) {
tk.MustExec("insert into t value(1.2)")
result = tk.MustQuery("select * from t where a/0 > 1")
result.Check(testkit.Rows())
tk.MustQuery("show warnings").Check(testkit.RowsWithSep("|", "Warning|1365|Division by 0"))
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1365|Division by 0"))

tk.MustExec("USE test;")
tk.MustExec("DROP TABLE IF EXISTS t;")
Expand Down Expand Up @@ -1759,14 +1772,14 @@ func TestCompareBuiltin(t *testing.T) {
tk.MustQuery("show warnings").Check(testkit.Rows())
result = tk.MustQuery(`select greatest(cast("2017-01-01" as datetime), "123", "234", cast("2018-01-01" as date)), greatest(cast("2017-01-01" as date), "123", null)`)
result.Check(testkit.Rows("234 <nil>"))
tk.MustQuery("show warnings").Check(testkit.RowsWithSep("|", "Warning|1292|Incorrect time value: '123'", "Warning|1292|Incorrect time value: '234'", "Warning|1292|Incorrect time value: '123'"))
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1292|Incorrect time value: '123'", "Warning|1292|Incorrect time value: '234'", "Warning|1292|Incorrect time value: '123'"))
// for least
result = tk.MustQuery(`select least(1, 2, 3), least("a", "b", "c"), least(1.1, 1.2, 1.3), least("123a", 1, 2)`)
result.Check(testkit.Rows("1 a 1.1 1"))
tk.MustQuery("show warnings").Check(testkit.Rows())
result = tk.MustQuery(`select least(cast("2017-01-01" as datetime), "123", "234", cast("2018-01-01" as date)), least(cast("2017-01-01" as date), "123", null)`)
result.Check(testkit.Rows("123 <nil>"))
tk.MustQuery("show warnings").Check(testkit.RowsWithSep("|", "Warning|1292|Incorrect time value: '123'", "Warning|1292|Incorrect time value: '234'", "Warning|1292|Incorrect time value: '123'"))
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1292|Incorrect time value: '123'", "Warning|1292|Incorrect time value: '234'", "Warning|1292|Incorrect time value: '123'"))
tk.MustQuery(`select 1 < 17666000000000000000, 1 > 17666000000000000000, 1 = 17666000000000000000`).Check(testkit.Rows("1 0 0"))

tk.MustExec("drop table if exists t")
Expand Down Expand Up @@ -1948,15 +1961,15 @@ func TestAggregationBuiltinGroupConcat(t *testing.T) {
tk.MustExec("set @@group_concat_max_len=7")
result = tk.MustQuery("select group_concat(a) from t")
result.Check(testkit.Rows("hello,h"))
tk.MustQuery("show warnings").Check(testkit.RowsWithSep("|", "Warning 1260 Some rows were cut by GROUPCONCAT(test.t.a)"))
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning 1260 Some rows were cut by GROUPCONCAT(test.t.a)"))

_, err := tk.Exec("insert into d select group_concat(a) from t")
require.Equal(t, errors.ErrCode(mysql.ErrCutValueGroupConcat), errors.Cause(err).(*terror.Error).Code())

_, err = tk.Exec("set sql_mode=''")
require.NoError(t, err)
tk.MustExec("insert into d select group_concat(a) from t")
tk.MustQuery("show warnings").Check(testkit.RowsWithSep("|", "Warning 1260 Some rows were cut by GROUPCONCAT(test.t.a)"))
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning 1260 Some rows were cut by GROUPCONCAT(test.t.a)"))
tk.MustQuery("select * from d").Check(testkit.Rows("hello,h"))
}

Expand Down Expand Up @@ -2316,7 +2329,7 @@ func TestTimeLiteral(t *testing.T) {

_, err = tk.Exec("select ADDDATE('2008-01-34', -1);")
require.NoError(t, err)
tk.MustQuery("Show warnings;").Check(testkit.RowsWithSep("|",
tk.MustQuery("Show warnings;").Check(testutil.RowsWithSep("|",
"Warning|1292|Incorrect datetime value: '2008-01-34'"))
}

Expand Down Expand Up @@ -2606,12 +2619,12 @@ func TestIssues(t *testing.T) {
tk.MustExec("insert into t values('1e649'),('-1e649');")
r = tk.MustQuery(`SELECT * FROM t where c < 1;`)
r.Check(testkit.Rows("-1e649"))
tk.MustQuery("show warnings").Check(testkit.RowsWithSep("|",
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|",
"Warning|1292|Truncated incorrect DOUBLE value: '1e649'",
"Warning|1292|Truncated incorrect DOUBLE value: '-1e649'"))
r = tk.MustQuery(`SELECT * FROM t where c > 1;`)
r.Check(testkit.Rows("1e649"))
tk.MustQuery("show warnings").Check(testkit.RowsWithSep("|",
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|",
"Warning|1292|Truncated incorrect DOUBLE value: '1e649'",
"Warning|1292|Truncated incorrect DOUBLE value: '-1e649'"))

Expand Down
2 changes: 1 addition & 1 deletion parser/ast/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3430,7 +3430,7 @@ func (n *TableOptimizerHint) Restore(ctx *format.RestoreCtx) error {
ctx.WritePlainf("%d", n.HintData.(uint64))
case "nth_plan":
ctx.WritePlainf("%d", n.HintData.(int64))
case "tidb_hj", "tidb_smj", "tidb_inlj", "hash_join", "merge_join", "inl_join", "broadcast_join", "broadcast_join_local", "inl_hash_join", "inl_merge_join":
case "tidb_hj", "tidb_smj", "tidb_inlj", "hash_join", "merge_join", "inl_join", "broadcast_join", "inl_hash_join", "inl_merge_join":
for i, table := range n.Tables {
if i != 0 {
ctx.WritePlain(", ")
Expand Down
Loading

0 comments on commit db4a3b1

Please sign in to comment.