Skip to content

Commit e829920

Browse files
wjhuang2016qw4990
authored andcommitted
planner: fix plus prefix for select constant (#9707)
1 parent 915b12c commit e829920

File tree

3 files changed

+45
-6
lines changed

3 files changed

+45
-6
lines changed

cmd/explaintest/r/select.result

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,24 @@ select + - 1, --1, +-+-+1, + "123";
140140
+ - 1 --1 +-+-+1 123
141141
-1 1 1 123
142142
select --------------------1, ++++++++++++++++++++1;
143-
--------------------1 ++++++++++++++++++++1
143+
--------------------1 1
144144
1 1
145+
select +(+(1)), (-+1), ((+1)), +1.23, +1e23, +1E23, +null, +true, +false, + ( ( 1 ) );
146+
1 (-+1) 1 1.23 1e23 1E23 NULL TRUE FALSE 1
147+
1 -1 1 1.23 1e23 1e23 NULL 1 0 1
148+
select +
149+
(
150+
+
151+
(
152+
1
153+
)
154+
)
155+
;
156+
1
157+
1
158+
select + ( + 1 );
159+
1
160+
1
145161
select --+(1 + 1), +-+-(1 * 1);
146162
--+(1 + 1) +-+-(1 * 1)
147163
2 1

cmd/explaintest/t/select.test

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,16 @@ select !(1 + 2);
8989
# - +
9090
select + - 1, --1, +-+-+1, + "123";
9191
select --------------------1, ++++++++++++++++++++1;
92+
select +(+(1)), (-+1), ((+1)), +1.23, +1e23, +1E23, +null, +true, +false, + ( ( 1 ) );
93+
select +
94+
(
95+
+
96+
(
97+
1
98+
)
99+
)
100+
;
101+
select + ( + 1 );
92102
select --+(1 + 1), +-+-(1 * 1);
93103

94104
# where static condition

planner/core/logical_plan_builder.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -610,12 +610,25 @@ func (b *PlanBuilder) buildProjectionFieldNameFromExpressions(field *ast.SelectF
610610
case types.KindNull:
611611
// See #4053, #3685
612612
return model.NewCIStr("NULL"), nil
613-
default:
614-
// Keep as it is.
615-
if innerExpr.Text() != "" {
616-
return model.NewCIStr(innerExpr.Text()), nil
617-
}
613+
case types.KindBinaryLiteral:
614+
// Don't rewrite BIT literal or HEX literals
618615
return model.NewCIStr(field.Text()), nil
616+
case types.KindInt64:
617+
// See #9683
618+
// TRUE or FALSE can be a int64
619+
if mysql.HasIsBooleanFlag(valueExpr.Type.Flag) {
620+
if i := valueExpr.GetValue().(int64); i == 0 {
621+
return model.NewCIStr("FALSE"), nil
622+
}
623+
return model.NewCIStr("TRUE"), nil
624+
}
625+
fallthrough
626+
627+
default:
628+
fieldName := field.Text()
629+
fieldName = strings.TrimLeft(fieldName, "\t\n +(")
630+
fieldName = strings.TrimRight(fieldName, "\t\n )")
631+
return model.NewCIStr(fieldName), nil
619632
}
620633
}
621634

0 commit comments

Comments
 (0)