Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

util, types: don't let SPM be affected by charset #23161

Merged
merged 26 commits into from
Mar 12, 2021
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
cd75598
util, types: restore without charset
rebelice Mar 8, 2021
d015fb7
Merge branch 'master' into dev_remove_charset
rebelice Mar 8, 2021
f385c86
Merge branch 'master' into dev_remove_charset
rebelice Mar 11, 2021
265cf71
Merge branch 'master' into dev_remove_charset
rebelice Mar 12, 2021
6c20a7c
Merge branch 'master' into dev_remove_charset
rebelice Mar 12, 2021
67c1a77
change parser commit
rebelice Mar 12, 2021
245251d
add test
rebelice Mar 12, 2021
1362b1a
make check
rebelice Mar 12, 2021
996e9dd
fix upgrade
rebelice Mar 12, 2021
6332de3
Merge branch 'master' into dev_remove_charset
rebelice Mar 12, 2021
63c7a89
fix test
rebelice Mar 12, 2021
4198879
Merge branch 'master' into dev_remove_charset
rebelice Mar 12, 2021
fda41e4
address comment
rebelice Mar 12, 2021
0a3bab2
address comment
rebelice Mar 12, 2021
2b77096
Merge branch 'master' into dev_remove_charset
ti-chi-bot Mar 12, 2021
ac5b324
fix tests
rebelice Mar 12, 2021
a426ef6
Merge branch 'master' into dev_remove_charset
rebelice Mar 12, 2021
5bcb48f
merge master
rebelice Mar 12, 2021
e16164b
fix build
rebelice Mar 12, 2021
f1df894
make check
rebelice Mar 12, 2021
ae77d4d
fix test
rebelice Mar 12, 2021
47b9bd7
Merge branch 'master' into dev_remove_charset
rebelice Mar 12, 2021
028ade4
Merge branch 'master' into dev_remove_charset
rebelice Mar 12, 2021
c138a05
Merge branch 'master' into dev_remove_charset
rebelice Mar 12, 2021
cb90df6
address comments
rebelice Mar 12, 2021
fcb136f
address comments
rebelice Mar 12, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions bindinfo/bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2079,3 +2079,16 @@ func (s *testSuite) TestSPMWithoutUseDatabase(c *C) {
tk1.MustExec("select * from test.t")
tk1.MustQuery(`select @@last_plan_from_binding;`).Check(testkit.Rows("1"))
}

func (s *testSuite) TestBindingWithoutCharset(c *C) {
tk := testkit.NewTestKit(c, s.store)
s.cleanBindingEnv(tk)
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
tk.MustExec("create table t (a varchar(10) CHARACTER SET utf8)")
tk.MustExec("create global binding for select * from t where a = 'aa' using select * from t where a = 'aa'")
rows := tk.MustQuery("show global bindings").Rows()
c.Assert(len(rows), Equals, 1)
c.Assert(rows[0][0], Equals, "select * from `test` . `t` where `a` = ?")
c.Assert(rows[0][1], Equals, "SELECT * FROM test.t WHERE a = 'aa'")
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ require (
github.com/pingcap/goleveldb v0.0.0-20191226122134-f82aafb29989
github.com/pingcap/kvproto v0.0.0-20210223121704-3cd2fc5fad22
github.com/pingcap/log v0.0.0-20201112100606-8f1e84a3abc8
github.com/pingcap/parser v0.0.0-20210303061548-f6776f61e268
github.com/pingcap/parser v0.0.0-20210310110710-c7333a4927e6
github.com/pingcap/sysutil v0.0.0-20210221112134-a07bda3bde99
github.com/pingcap/tidb-tools v4.0.9-0.20201127090955-2707c97b3853+incompatible
github.com/pingcap/tipb v0.0.0-20210308034246-066a76fd4e1b
Expand Down Expand Up @@ -80,7 +80,7 @@ require (
gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0
gopkg.in/yaml.v2 v2.3.0 // indirect
honnef.co/go/tools v0.1.2 // indirect
honnef.co/go/tools v0.1.3 // indirect
sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0
sourcegraph.com/sourcegraph/appdash-data v0.0.0-20151005221446-73f23eafcf67
)
Expand Down
7 changes: 4 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,8 @@ github.com/pingcap/log v0.0.0-20200117041106-d28c14d3b1cd/go.mod h1:4rbK1p9ILyIf
github.com/pingcap/log v0.0.0-20200511115504-543df19646ad/go.mod h1:4rbK1p9ILyIfb6hU7OG2CiWSqMXnp3JMbiaVJ6mvoY8=
github.com/pingcap/log v0.0.0-20201112100606-8f1e84a3abc8 h1:M+DNpOu/I3uDmwee6vcnoPd6GgSMqND4gxvDQ/W584U=
github.com/pingcap/log v0.0.0-20201112100606-8f1e84a3abc8/go.mod h1:4rbK1p9ILyIfb6hU7OG2CiWSqMXnp3JMbiaVJ6mvoY8=
github.com/pingcap/parser v0.0.0-20210303061548-f6776f61e268 h1:yWlvSEhQPDVQU6pgFZv5sEWf94t/dUAMuBRFmLgkpek=
github.com/pingcap/parser v0.0.0-20210303061548-f6776f61e268/go.mod h1:GbEr2PgY72/4XqPZzmzstlOU/+il/wrjeTNFs6ihsSE=
github.com/pingcap/parser v0.0.0-20210310110710-c7333a4927e6 h1:V/6ioJmVUN4q6/aUpNdnT6OOPc48R3tnojcVfTrt4QU=
github.com/pingcap/parser v0.0.0-20210310110710-c7333a4927e6/go.mod h1:GbEr2PgY72/4XqPZzmzstlOU/+il/wrjeTNFs6ihsSE=
github.com/pingcap/sysutil v0.0.0-20200206130906-2bfa6dc40bcd/go.mod h1:EB/852NMQ+aRKioCpToQ94Wl7fktV+FNnxf3CX/TTXI=
github.com/pingcap/sysutil v0.0.0-20210221112134-a07bda3bde99 h1:/ogXgm4guJzow4UafiyXZ6ciAIPzxImaXYiFvTpKzKY=
github.com/pingcap/sysutil v0.0.0-20210221112134-a07bda3bde99/go.mod h1:EB/852NMQ+aRKioCpToQ94Wl7fktV+FNnxf3CX/TTXI=
Expand Down Expand Up @@ -466,7 +466,6 @@ github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sasha-s/go-deadlock v0.2.0/go.mod h1:StQn567HiB1fF2yJ44N9au7wOhrPS3iZqiDbRupzT10=
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/sergi/go-diff v1.0.1-0.20180205163309-da645544ed44 h1:tB9NOR21++IjLyVx3/PCPhWMwqGNCMQEH96A6dMZ/gc=
github.com/sergi/go-diff v1.0.1-0.20180205163309-da645544ed44/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/shirou/gopsutil v2.19.10+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/shirou/gopsutil v3.20.12+incompatible h1:6VEGkOXP/eP4o2Ilk8cSsX0PhOEfX6leqAnD+urrp9M=
Expand Down Expand Up @@ -848,6 +847,8 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
honnef.co/go/tools v0.1.2 h1:SMdYLJl312RXuxXziCCHhRsp/tvct9cGKey0yv95tZM=
honnef.co/go/tools v0.1.2/go.mod h1:NgwopIslSNH47DimFoV78dnkksY2EFtX0ajyb3K/las=
honnef.co/go/tools v0.1.3 h1:qTakTkI6ni6LFD5sBwwsdSO+AQqbSIxOauHTTQKZ/7o=
honnef.co/go/tools v0.1.3/go.mod h1:NgwopIslSNH47DimFoV78dnkksY2EFtX0ajyb3K/las=
k8s.io/klog v1.0.0/go.mod h1:4Bi6QPql/J/LkTDqv7R/cd3hPo4k2DG6Ptcz060Ez5I=
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
sigs.k8s.io/yaml v1.1.0 h1:4A07+ZFc2wgJwo8YNlQpr1rVlgUDlxXHhPJciaPY5gs=
Expand Down
1 change: 1 addition & 0 deletions types/parser_driver/value_expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ func (n *ValueExpr) Restore(ctx *format.RestoreCtx) error {
// This part is used to process flag HasStringWithoutDefaultCharset, which means if we have this flag and the
// charset is mysql.DefaultCharset, we don't need to write the default.
if n.Type.Charset != "" &&
!ctx.Flags.HasStringWithoutCharset() &&
(!ctx.Flags.HasStringWithoutDefaultCharset() || n.Type.Charset != mysql.DefaultCharset) {
ctx.WritePlain("_")
ctx.WriteKeyWord(n.Type.Charset)
Expand Down
4 changes: 2 additions & 2 deletions util/parser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ func RestoreWithDefaultDB(node ast.StmtNode, defaultDB string) string {
// Three flags for restore with default DB:
// 1. RestoreStringSingleQuotes specifies to use single quotes to surround the string;
// 2. RestoreSpacesAroundBinaryOperation specifies to add space around binary operation;
// 3. RestoreStringWithoutDefaultCharset specifies to not print default charset before string;
ctx := format.NewRestoreCtx(format.RestoreStringSingleQuotes|format.RestoreSpacesAroundBinaryOperation|format.RestoreStringWithoutDefaultCharset, &sb)
// 3. RestoreStringWithoutCharset specifies to not print charset before string;
ctx := format.NewRestoreCtx(format.RestoreStringSingleQuotes|format.RestoreSpacesAroundBinaryOperation|format.RestoreStringWithoutCharset, &sb)
eurekaka marked this conversation as resolved.
Show resolved Hide resolved
ctx.DefaultDB = defaultDB
if err := node.Restore(ctx); err != nil {
return ""
Expand Down