Skip to content

Commit

Permalink
Merge branch 'master' into cost_trace
Browse files Browse the repository at this point in the history
  • Loading branch information
qw4990 authored Dec 13, 2022
2 parents 10eca87 + 3f86a11 commit 2a4a169
Show file tree
Hide file tree
Showing 22 changed files with 10,301 additions and 10,142 deletions.
5 changes: 2 additions & 3 deletions br/pkg/storage/memstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"bytes"
"context"
"io"
"io/ioutil"
"sync"
"testing"
"time"
Expand Down Expand Up @@ -70,7 +69,7 @@ func TestMemStoreBasic(t *testing.T) {
require.Nil(t, err)
r2, err := store.Open(ctx, "/hello.txt")
require.Nil(t, err)
fileContent, err = ioutil.ReadAll(r)
fileContent, err = io.ReadAll(r)
require.Nil(t, err)
require.True(t, bytes.Equal([]byte("hello world 3"), fileContent))
require.Nil(t, r.Close())
Expand All @@ -83,7 +82,7 @@ func TestMemStoreBasic(t *testing.T) {

_, err = r2.Seek(5, io.SeekStart)
require.Nil(t, err)
fileContent, err = ioutil.ReadAll(r2)
fileContent, err = io.ReadAll(r2)
require.Nil(t, err)
require.True(t, bytes.Equal([]byte(" world 3"), fileContent))

Expand Down
6 changes: 3 additions & 3 deletions cmd/explaintest/r/index_merge.result
Original file line number Diff line number Diff line change
Expand Up @@ -455,9 +455,9 @@ c1 c2 c3
///// MEMORY Table
explain select count(c1) from (select /*+ use_index_merge(t_alias), stream_agg() */ count(1) c1 from information_schema.statements_summary where sum_latency >= 0 or max_latency >= 0 order by 1) dt;
id estRows task access object operator info
StreamAgg_10 1.00 root funcs:count(Column#93)->Column#94
└─Sort_11 1.00 root Column#93
└─StreamAgg_14 1.00 root funcs:count(1)->Column#93
StreamAgg_10 1.00 root funcs:count(Column#96)->Column#97
└─Sort_11 1.00 root Column#96
└─StreamAgg_14 1.00 root funcs:count(1)->Column#96
└─MemTableScan_18 10000.00 root table:STATEMENTS_SUMMARY
show warnings;
Level Code Message
Expand Down
2 changes: 1 addition & 1 deletion executor/seqtest/seq_executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ func TestBatchInsertDelete(t *testing.T) {
atomic.StoreUint64(&kv.TxnTotalSizeLimit, originLimit)
}()
// Set the limitation to a small value, make it easier to reach the limitation.
atomic.StoreUint64(&kv.TxnTotalSizeLimit, 5800)
atomic.StoreUint64(&kv.TxnTotalSizeLimit, 5900)

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
Expand Down
3 changes: 1 addition & 2 deletions executor/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"strconv"
"testing"
Expand Down Expand Up @@ -1802,7 +1801,7 @@ func TestSetClusterConfig(t *testing.T) {
httpCnt = 0
tk.Session().SetValue(executor.TestSetConfigHTTPHandlerKey, func(req *http.Request) (*http.Response, error) {
httpCnt++
body, err := ioutil.ReadAll(req.Body)
body, err := io.ReadAll(req.Body)
require.NoError(t, err)
// The `raftstore.` prefix is stripped.
require.JSONEq(t, `{"server.snap-max-write-bytes-per-sec":"500MB"}`, string(body))
Expand Down
3 changes: 3 additions & 0 deletions infoschema/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -1323,6 +1323,9 @@ var tableStatementsSummaryCols = []columnInfo{
{name: stmtsummary.PlanDigestStr, tp: mysql.TypeVarchar, size: 64, comment: "Digest of its execution plan"},
{name: stmtsummary.PlanStr, tp: mysql.TypeBlob, size: types.UnspecifiedLength, comment: "Sampled execution plan"},
{name: stmtsummary.BinaryPlan, tp: mysql.TypeBlob, size: types.UnspecifiedLength, comment: "Sampled binary plan"},
{name: stmtsummary.Charset, tp: mysql.TypeVarchar, size: 64, comment: "Sampled charset"},
{name: stmtsummary.Collation, tp: mysql.TypeVarchar, size: 64, comment: "Sampled collation"},
{name: stmtsummary.PlanHint, tp: mysql.TypeVarchar, size: 64, comment: "Sampled plan hint"},
}

var tableStorageStatsCols = []columnInfo{
Expand Down
30 changes: 30 additions & 0 deletions infoschema/tables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1661,3 +1661,33 @@ func TestMemoryUsageAndOpsHistory(t *testing.T) {
require.Equal(t, row[10], "e3237ec256015a3566757e0c2742507cd30ae04e4cac2fbc14d269eafe7b067b") // SQL_DIGEST
require.Equal(t, row[11], "explain analyze select * from t t1 join t t2 join t t3 on t1.a=t2.a and t1.a=t3.a order by t1.a") // SQL_TEXT
}

func TestAddFieldsForBinding(t *testing.T) {
s := new(clusterTablesSuite)
s.store, s.dom = testkit.CreateMockStoreAndDomain(t)
s.rpcserver, s.listenAddr = s.setUpRPCService(t, "127.0.0.1:0", nil)
s.httpServer, s.mockAddr = s.setUpMockPDHTTPServer()
s.startTime = time.Now()
defer s.httpServer.Close()
defer s.rpcserver.Stop()
tk := s.newTestKitWithRoot(t)

require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil))
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
tk.MustExec("create table t(a int, key(a))")
tk.MustExec("select /*+ ignore_index(t, a)*/ * from t where a = 1")
planDigest := "4e3159169cc63c14b139a4e7d72eae1759875c9a9581f94bb2079aae961189cb"
rows := tk.MustQuery(fmt.Sprintf("select stmt_type, prepared, sample_user, schema_name, query_sample_text, charset, collation, plan_hint, digest_text "+
"from information_schema.cluster_statements_summary where plan_digest = '%s'", planDigest)).Rows()

require.Equal(t, rows[0][0], "Select")
require.Equal(t, rows[0][1], "0")
require.Equal(t, rows[0][2], "root")
require.Equal(t, rows[0][3], "test")
require.Equal(t, rows[0][4], "select /*+ ignore_index(t, a)*/ * from t where a = 1")
require.Equal(t, rows[0][5], "utf8mb4")
require.Equal(t, rows[0][6], "utf8mb4_bin")
require.Equal(t, rows[0][7], "use_index(@`sel_1` `test`.`t` ), ignore_index(`t` `a`)")
require.Equal(t, rows[0][8], "select * from `t` where `a` = ?")
}
64 changes: 47 additions & 17 deletions parser/ast/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ const (
JSONReplace = "json_replace"
JSONRemove = "json_remove"
JSONContains = "json_contains"
JSONMemberOf = "json_memberof"
JSONContainsPath = "json_contains_path"
JSONValid = "json_valid"
JSONArrayAppend = "json_array_append"
Expand Down Expand Up @@ -380,21 +381,9 @@ type FuncCallExpr struct {

// Restore implements Node interface.
func (n *FuncCallExpr) Restore(ctx *format.RestoreCtx) error {
var specialLiteral string
switch n.FnName.L {
case DateLiteral:
specialLiteral = "DATE "
case TimeLiteral:
specialLiteral = "TIME "
case TimestampLiteral:
specialLiteral = "TIMESTAMP "
}
if specialLiteral != "" {
ctx.WritePlain(specialLiteral)
if err := n.Args[0].Restore(ctx); err != nil {
return errors.Annotatef(err, "An error occurred while restore FuncCastExpr.Expr")
}
return nil
done, err := n.customRestore(ctx)
if done {
return err
}

if len(n.Schema.String()) != 0 {
Expand Down Expand Up @@ -495,29 +484,70 @@ func (n *FuncCallExpr) Restore(ctx *format.RestoreCtx) error {
return nil
}

func (n *FuncCallExpr) customRestore(ctx *format.RestoreCtx) (bool, error) {
var specialLiteral string
switch n.FnName.L {
case DateLiteral:
specialLiteral = "DATE "
case TimeLiteral:
specialLiteral = "TIME "
case TimestampLiteral:
specialLiteral = "TIMESTAMP "
}
if specialLiteral != "" {
ctx.WritePlain(specialLiteral)
if err := n.Args[0].Restore(ctx); err != nil {
return true, errors.Annotatef(err, "An error occurred while restore FuncCallExpr.Expr")
}
return true, nil
}
if n.FnName.L == JSONMemberOf {
if err := n.Args[0].Restore(ctx); err != nil {
return true, errors.Annotatef(err, "An error occurred while restore FuncCallExpr.(MEMBER OF).Args[0]")
}
ctx.WriteKeyWord(" MEMBER OF ")
ctx.WritePlain("(")
if err := n.Args[1].Restore(ctx); err != nil {
return true, errors.Annotatef(err, "An error occurred while restore FuncCallExpr.(MEMBER OF).Args[1]")
}
ctx.WritePlain(")")
return true, nil
}
return false, nil
}

// Format the ExprNode into a Writer.
func (n *FuncCallExpr) Format(w io.Writer) {
fmt.Fprintf(w, "%s(", n.FnName.L)
if !n.specialFormatArgs(w) {
fmt.Fprintf(w, "%s(", n.FnName.L)
for i, arg := range n.Args {
arg.Format(w)
if i != len(n.Args)-1 {
fmt.Fprint(w, ", ")
}
}
fmt.Fprint(w, ")")
}
fmt.Fprint(w, ")")
}

// specialFormatArgs formats argument list for some special functions.
func (n *FuncCallExpr) specialFormatArgs(w io.Writer) bool {
switch n.FnName.L {
case DateAdd, DateSub, AddDate, SubDate:
fmt.Fprintf(w, "%s(", n.FnName.L)
n.Args[0].Format(w)
fmt.Fprint(w, ", INTERVAL ")
n.Args[1].Format(w)
fmt.Fprint(w, " ")
n.Args[2].Format(w)
fmt.Fprint(w, ")")
return true
case JSONMemberOf:
n.Args[0].Format(w)
fmt.Fprint(w, " MEMBER OF ")
fmt.Fprint(w, " (")
n.Args[1].Format(w)
fmt.Fprint(w, ")")
return true
}
return false
Expand Down
4 changes: 2 additions & 2 deletions parser/consistent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
package parser

import (
"io/ioutil"
gio "io"
"os"
"sort"
"strings"
Expand All @@ -27,7 +27,7 @@ func TestKeywordConsistent(t *testing.T) {
parserFilename := "parser.y"
parserFile, err := os.Open(parserFilename)
requires.NoError(t, err)
data, err := ioutil.ReadAll(parserFile)
data, err := gio.ReadAll(parserFile)
requires.NoError(t, err)
content := string(data)

Expand Down
4 changes: 2 additions & 2 deletions parser/format/format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ package format

import (
"bytes"
"io/ioutil"
"io"
"strings"
"testing"

Expand All @@ -26,7 +26,7 @@ import (
func checkFormat(t *testing.T, f Formatter, buf *bytes.Buffer, str, expect string) {
_, err := f.Format(str, 3)
require.NoError(t, err)
b, err := ioutil.ReadAll(buf)
b, err := io.ReadAll(buf)
require.NoError(t, err)
require.Equal(t, expect, string(b))
}
Expand Down
10 changes: 7 additions & 3 deletions parser/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,13 +252,17 @@ func (s *Scanner) Lex(v *yySymType) int {
if tok == not && s.sqlMode.HasHighNotPrecedenceMode() {
return not2
}
if tok == as && s.getNextToken() == of {
if (tok == as || tok == member) && s.getNextToken() == of {
_, pos, lit = s.scan()
v.ident = fmt.Sprintf("%s %s", v.ident, lit)
s.lastKeyword = asof
s.lastScanOffset = pos.Offset
v.offset = pos.Offset
return asof
if tok == as {
s.lastKeyword = asof
return asof
}
s.lastKeyword = memberof
return memberof
}
if tok == to {
tok1, tok2 := s.getNextTwoTokens()
Expand Down
2 changes: 2 additions & 0 deletions parser/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ var tokenMap = map[string]int{
"ANY": any,
"APPROX_COUNT_DISTINCT": approxCountDistinct,
"APPROX_PERCENTILE": approxPercentile,
"ARRAY": array,
"AS": as,
"ASC": asc,
"ASCII": ascii,
Expand Down Expand Up @@ -474,6 +475,7 @@ var tokenMap = map[string]int{
"MEDIUMINT": mediumIntType,
"MEDIUMTEXT": mediumtextType,
"MEMORY": memory,
"MEMBER": member,
"MERGE": merge,
"MICROSECOND": microsecond,
"MIN_ROWS": minRows,
Expand Down
Loading

0 comments on commit 2a4a169

Please sign in to comment.