Skip to content

Commit

Permalink
Fix show character set
Browse files Browse the repository at this point in the history
This fixes the implementation for `show character set` by returning all
supported collations and fixing like as well. We also move a bunch of
things from `utf8` to the explicit `utf8mb3` names so that we're better
compatible if MySQL ever decides to change the alias meaning.

Signed-off-by: Dirkjan Bussink <[email protected]>
  • Loading branch information
dbussink committed Jul 21, 2023
1 parent 62c8334 commit 2503965
Show file tree
Hide file tree
Showing 14 changed files with 173 additions and 150 deletions.
4 changes: 2 additions & 2 deletions go/mysql/flavor_mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ const TablesWithSize80 = `SELECT t.table_name,
i.allocated_size
FROM information_schema.tables t
LEFT JOIN information_schema.innodb_tablespaces i
ON i.name = CONCAT(t.table_schema, '/', t.table_name) COLLATE utf8_general_ci
ON i.name = CONCAT(t.table_schema, '/', t.table_name) COLLATE utf8mb3_general_ci
WHERE
t.table_schema = database() AND not t.create_options <=> 'partitioned'
UNION ALL
Expand All @@ -374,7 +374,7 @@ UNION ALL
SUM(i.allocated_size)
FROM information_schema.tables t
LEFT JOIN information_schema.innodb_tablespaces i
ON i.name LIKE (CONCAT(t.table_schema, '/', t.table_name, '#p#%') COLLATE utf8_general_ci )
ON i.name LIKE (CONCAT(t.table_schema, '/', t.table_name, '#p#%') COLLATE utf8mb3_general_ci )
WHERE
t.table_schema = database() AND t.create_options <=> 'partitioned'
GROUP BY
Expand Down
4 changes: 3 additions & 1 deletion go/vt/dbconfigs/dbconfigs.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (

"github.com/spf13/pflag"

"vitess.io/vitess/go/mysql/collations"

"vitess.io/vitess/go/vt/servenv"
"vitess.io/vitess/go/vt/vttls"

Expand Down Expand Up @@ -416,6 +418,6 @@ func NewTestDBConfigs(genParams, appDebugParams mysql.ConnParams, dbname string)
replParams: genParams,
externalReplParams: genParams,
DBName: dbname,
Charset: "utf8mb4_general_ci",
Charset: collations.Default().Get().Name(),
}
}
2 changes: 1 addition & 1 deletion go/vt/sqlparser/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ const (
Utf16Str = "_utf16"
Utf16leStr = "_utf16le"
Utf32Str = "_utf32"
Utf8Str = "_utf8"
Utf8mb3Str = "_utf8mb3"
Utf8mb4Str = "_utf8mb4"
NStringStr = "N"

Expand Down
13 changes: 7 additions & 6 deletions go/vt/sqlparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2599,7 +2599,8 @@ var (
}, {
input: "select 1 from t where foo = _binary 'bar'",
}, {
input: "select 1 from t where foo = _utf8 'bar' and bar = _latin1 'sjösjuk'",
input: "select 1 from t where foo = _utf8 'bar' and bar = _latin1 'sjösjuk'",
output: "select 1 from t where foo = _utf8mb3 'bar' and bar = _latin1 'sjösjuk'",
}, {
input: "select 1 from t where foo = _binary'bar'",
output: "select 1 from t where foo = _binary 'bar'",
Expand All @@ -2610,10 +2611,10 @@ var (
output: "select 1 from t where foo = _utf8mb4 'bar'",
}, {
input: "select 1 from t where foo = _utf8mb3 'bar'",
output: "select 1 from t where foo = _utf8 'bar'",
output: "select 1 from t where foo = _utf8mb3 'bar'",
}, {
input: "select 1 from t where foo = _utf8mb3'bar'",
output: "select 1 from t where foo = _utf8 'bar'",
input: "select 1 from t where foo = _utf8'bar'",
output: "select 1 from t where foo = _utf8mb3 'bar'",
}, {
input: "select match(a) against ('foo') from t",
}, {
Expand Down Expand Up @@ -4036,13 +4037,13 @@ func TestIntroducers(t *testing.T) {
output: "select _utf32 'x' from dual",
}, {
input: "select _utf8 'x'",
output: "select _utf8 'x' from dual",
output: "select _utf8mb3 'x' from dual",
}, {
input: "select _utf8mb4 'x'",
output: "select _utf8mb4 'x' from dual",
}, {
input: "select _utf8mb3 'x'",
output: "select _utf8 'x' from dual",
output: "select _utf8mb3 'x' from dual",
}}
for _, tcase := range validSQL {
t.Run(tcase.input, func(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions go/vt/sqlparser/sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions go/vt/sqlparser/sql.y
Original file line number Diff line number Diff line change
Expand Up @@ -1895,15 +1895,15 @@ underscore_charsets:
}
| UNDERSCORE_UTF8
{
$$ = Utf8Str
$$ = Utf8mb3Str
}
| UNDERSCORE_UTF8MB4
{
$$ = Utf8mb4Str
}
| UNDERSCORE_UTF8MB3
{
$$ = Utf8Str
$$ = Utf8mb3Str
}

literal_or_null:
Expand Down
Loading

0 comments on commit 2503965

Please sign in to comment.