Skip to content

Commit

Permalink
planner: disable collate clause support for enum or set column (#35684)
Browse files Browse the repository at this point in the history
close #31637
  • Loading branch information
wjhuang2016 authored Jun 24, 2022
1 parent db02b4a commit 11f06e0
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 48 deletions.
32 changes: 12 additions & 20 deletions cmd/explaintest/r/collation_agg_func_disabled.result
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,9 @@ select min(b) from tt;
min(b)
B
desc format='brief' select min(b collate utf8mb4_bin) from tt;
id estRows task access object operator info
StreamAgg 1.00 root funcs:min(Column#8)->Column#6
└─TableReader 1.00 root data:StreamAgg
└─StreamAgg 1.00 cop[tikv] funcs:min(cast(collation_agg_func.tt.b, enum('a','B','c')))->Column#8
└─TableFullScan 10000.00 cop[tikv] table:tt keep order:false, stats:pseudo
Error 1235: This version of TiDB doesn't yet support 'use collate clause for enum or set'
select min(b collate utf8mb4_bin) from tt;
Error 1235: This version of TiDB doesn't yet support 'use collate clause for enum or set'
desc format='brief' select max(b) from tt;
id estRows task access object operator info
StreamAgg 1.00 root funcs:max(Column#8)->Column#6
Expand All @@ -215,11 +213,9 @@ select max(b) from tt;
max(b)
c
desc format='brief' select max(b collate utf8mb4_bin) from tt;
id estRows task access object operator info
StreamAgg 1.00 root funcs:max(Column#8)->Column#6
└─TableReader 1.00 root data:StreamAgg
└─StreamAgg 1.00 cop[tikv] funcs:max(cast(collation_agg_func.tt.b, enum('a','B','c')))->Column#8
└─TableFullScan 10000.00 cop[tikv] table:tt keep order:false, stats:pseudo
Error 1235: This version of TiDB doesn't yet support 'use collate clause for enum or set'
select max(b collate utf8mb4_bin) from tt;
Error 1235: This version of TiDB doesn't yet support 'use collate clause for enum or set'
desc format='brief' select min(c) from tt;
id estRows task access object operator info
HashAgg 1.00 root funcs:min(collation_agg_func.tt.c)->Column#6
Expand All @@ -229,11 +225,9 @@ select min(c) from tt;
min(c)
B
desc format='brief' select min(c collate utf8mb4_bin) from tt;
id estRows task access object operator info
HashAgg 1.00 root funcs:min(Column#7)->Column#6
└─Projection 10000.00 root cast(collation_agg_func.tt.c, set('a','B','c'))->Column#7
└─TableReader 10000.00 root data:TableFullScan
└─TableFullScan 10000.00 cop[tikv] table:tt keep order:false, stats:pseudo
Error 1235: This version of TiDB doesn't yet support 'use collate clause for enum or set'
select min(c collate utf8mb4_bin) from tt;
Error 1235: This version of TiDB doesn't yet support 'use collate clause for enum or set'
desc format='brief' select max(c) from tt;
id estRows task access object operator info
HashAgg 1.00 root funcs:max(collation_agg_func.tt.c)->Column#6
Expand All @@ -243,11 +237,9 @@ select max(c) from tt;
max(c)
c
desc format='brief' select max(c collate utf8mb4_bin) from tt;
id estRows task access object operator info
HashAgg 1.00 root funcs:max(Column#7)->Column#6
└─Projection 10000.00 root cast(collation_agg_func.tt.c, set('a','B','c'))->Column#7
└─TableReader 10000.00 root data:TableFullScan
└─TableFullScan 10000.00 cop[tikv] table:tt keep order:false, stats:pseudo
Error 1235: This version of TiDB doesn't yet support 'use collate clause for enum or set'
select max(c collate utf8mb4_bin) from tt;
Error 1235: This version of TiDB doesn't yet support 'use collate clause for enum or set'
desc format='brief' select min(d) from tt;
id estRows task access object operator info
StreamAgg 1.00 root funcs:min(collation_agg_func.tt.d)->Column#6
Expand Down
32 changes: 12 additions & 20 deletions cmd/explaintest/r/collation_agg_func_enabled.result
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,9 @@ select min(b) from tt;
min(b)
a
desc format='brief' select min(b collate utf8mb4_bin) from tt;
id estRows task access object operator info
StreamAgg 1.00 root funcs:min(Column#8)->Column#6
└─TableReader 1.00 root data:StreamAgg
└─StreamAgg 1.00 cop[tikv] funcs:min(cast(collation_agg_func.tt.b, enum('a','B','c')))->Column#8
└─TableFullScan 10000.00 cop[tikv] table:tt keep order:false, stats:pseudo
Error 1235: This version of TiDB doesn't yet support 'use collate clause for enum or set'
select min(b collate utf8mb4_bin) from tt;
Error 1235: This version of TiDB doesn't yet support 'use collate clause for enum or set'
desc format='brief' select max(b) from tt;
id estRows task access object operator info
StreamAgg 1.00 root funcs:max(Column#8)->Column#6
Expand All @@ -212,11 +210,9 @@ select max(b) from tt;
max(b)
c
desc format='brief' select max(b collate utf8mb4_bin) from tt;
id estRows task access object operator info
StreamAgg 1.00 root funcs:max(Column#8)->Column#6
└─TableReader 1.00 root data:StreamAgg
└─StreamAgg 1.00 cop[tikv] funcs:max(cast(collation_agg_func.tt.b, enum('a','B','c')))->Column#8
└─TableFullScan 10000.00 cop[tikv] table:tt keep order:false, stats:pseudo
Error 1235: This version of TiDB doesn't yet support 'use collate clause for enum or set'
select max(b collate utf8mb4_bin) from tt;
Error 1235: This version of TiDB doesn't yet support 'use collate clause for enum or set'
desc format='brief' select min(c) from tt;
id estRows task access object operator info
HashAgg 1.00 root funcs:min(collation_agg_func.tt.c)->Column#6
Expand All @@ -226,11 +222,9 @@ select min(c) from tt;
min(c)
a
desc format='brief' select min(c collate utf8mb4_bin) from tt;
id estRows task access object operator info
HashAgg 1.00 root funcs:min(Column#7)->Column#6
└─Projection 10000.00 root cast(collation_agg_func.tt.c, set('a','B','c'))->Column#7
└─TableReader 10000.00 root data:TableFullScan
└─TableFullScan 10000.00 cop[tikv] table:tt keep order:false, stats:pseudo
Error 1235: This version of TiDB doesn't yet support 'use collate clause for enum or set'
select min(c collate utf8mb4_bin) from tt;
Error 1235: This version of TiDB doesn't yet support 'use collate clause for enum or set'
desc format='brief' select max(c) from tt;
id estRows task access object operator info
HashAgg 1.00 root funcs:max(collation_agg_func.tt.c)->Column#6
Expand All @@ -240,11 +234,9 @@ select max(c) from tt;
max(c)
c
desc format='brief' select max(c collate utf8mb4_bin) from tt;
id estRows task access object operator info
HashAgg 1.00 root funcs:max(Column#7)->Column#6
└─Projection 10000.00 root cast(collation_agg_func.tt.c, set('a','B','c'))->Column#7
└─TableReader 10000.00 root data:TableFullScan
└─TableFullScan 10000.00 cop[tikv] table:tt keep order:false, stats:pseudo
Error 1235: This version of TiDB doesn't yet support 'use collate clause for enum or set'
select max(c collate utf8mb4_bin) from tt;
Error 1235: This version of TiDB doesn't yet support 'use collate clause for enum or set'
desc format='brief' select min(d) from tt;
id estRows task access object operator info
StreamAgg 1.00 root funcs:min(collation_agg_func.tt.d)->Column#6
Expand Down
20 changes: 12 additions & 8 deletions cmd/explaintest/t/collation_agg_func.test
Original file line number Diff line number Diff line change
Expand Up @@ -66,24 +66,28 @@ desc format='brief' select max(a collate utf8mb4_bin) from tt;
select max(a collate utf8mb4_bin) from tt;
desc format='brief' select min(b) from tt;
select min(b) from tt;
--error 1235
desc format='brief' select min(b collate utf8mb4_bin) from tt;
# Fix me later.
# select min(b collate utf8mb4_bin) from tt;
--error 1235
select min(b collate utf8mb4_bin) from tt;
desc format='brief' select max(b) from tt;
select max(b) from tt;
--error 1235
desc format='brief' select max(b collate utf8mb4_bin) from tt;
# Fix me later.
# select max(b collate utf8mb4_bin) from tt;
--error 1235
select max(b collate utf8mb4_bin) from tt;
desc format='brief' select min(c) from tt;
select min(c) from tt;
--error 1235
desc format='brief' select min(c collate utf8mb4_bin) from tt;
# Fix me later.
# select min(c collate utf8mb4_bin) from tt;
--error 1235
select min(c collate utf8mb4_bin) from tt;
desc format='brief' select max(c) from tt;
select max(c) from tt;
--error 1235
desc format='brief' select max(c collate utf8mb4_bin) from tt;
# Fix me later.
# select max(c collate utf8mb4_bin) from tt;
--error 1235
select max(c collate utf8mb4_bin) from tt;
desc format='brief' select min(d) from tt;
select min(d) from tt;
--error 1253
Expand Down
4 changes: 4 additions & 0 deletions planner/core/expression_rewriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -1199,6 +1199,10 @@ func (er *expressionRewriter) Leave(originInNode ast.Node) (retNode ast.Node, ok
}
// SetCollationExpr sets the collation explicitly, even when the evaluation type of the expression is non-string.
if _, ok := arg.(*expression.Column); ok {
if arg.GetType().GetType() == mysql.TypeEnum || arg.GetType().GetType() == mysql.TypeSet {
er.err = ErrNotSupportedYet.GenWithStackByArgs("use collate clause for enum or set")
break
}
// Wrap a cast here to avoid changing the original FieldType of the column expression.
exprType := arg.GetType().Clone()
exprType.SetCollate(v.Collate)
Expand Down

0 comments on commit 11f06e0

Please sign in to comment.