Skip to content

Commit 5d9b1f6

Browse files
ti-chi-bothawkingrei
authored andcommitted
*: support tidb_redact_log for explain (pingcap#54553) (pingcap#55308)
close pingcap#54565
1 parent 5d5a2be commit 5d9b1f6

File tree

78 files changed

+4731
-165
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+4731
-165
lines changed

pkg/executor/aggfuncs/func_group_concat.go

+8
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"sync/atomic"
2222
"unsafe"
2323

24+
"github.com/pingcap/errors"
2425
"github.com/pingcap/tidb/pkg/expression"
2526
plannercore "github.com/pingcap/tidb/pkg/planner/core"
2627
"github.com/pingcap/tidb/pkg/planner/util"
@@ -72,10 +73,17 @@ func (e *baseGroupConcat4String) AppendFinalResult2Chunk(_ sessionctx.Context, p
7273

7374
func (e *baseGroupConcat4String) handleTruncateError(sctx sessionctx.Context) (err error) {
7475
if atomic.CompareAndSwapInt32(e.truncated, 0, 1) {
76+
<<<<<<< HEAD
7577
if !sctx.GetSessionVars().StmtCtx.TruncateAsWarning {
7678
return expression.ErrCutValueGroupConcat.GenWithStackByArgs(e.args[0].String())
7779
}
7880
sctx.GetSessionVars().StmtCtx.AppendWarning(expression.ErrCutValueGroupConcat.GenWithStackByArgs(e.args[0].String()))
81+
=======
82+
if !tc.Flags().TruncateAsWarning() {
83+
return expression.ErrCutValueGroupConcat.GenWithStackByArgs(e.args[0].StringWithCtx(errors.RedactLogDisable))
84+
}
85+
tc.AppendWarning(expression.ErrCutValueGroupConcat.FastGenByArgs(e.args[0].StringWithCtx(errors.RedactLogDisable)))
86+
>>>>>>> a7df4f9845 (*: support tidb_redact_log for explain (#54553) (#55308))
7987
}
8088
return nil
8189
}

pkg/executor/importer/import.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ func (p *Plan) initParameters(plan *plannercore.ImportInto) error {
756756
optionMap := make(map[string]interface{}, len(plan.Options))
757757
for _, opt := range plan.Options {
758758
if opt.Value != nil {
759-
val := opt.Value.String()
759+
val := opt.Value.StringWithCtx(errors.RedactLogDisable)
760760
if opt.Name == cloudStorageURIOption {
761761
val = ast.RedactURL(val)
762762
}

pkg/expression/BUILD.bazel

+1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ go_library(
105105
"//pkg/util/password-validation",
106106
"//pkg/util/plancodec",
107107
"//pkg/util/printer",
108+
"//pkg/util/redact",
108109
"//pkg/util/sem",
109110
"//pkg/util/set",
110111
"//pkg/util/size",

pkg/expression/aggregation/agg_to_pb.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func AggFuncToPBExpr(sctx sessionctx.Context, client kv.Client, aggFunc *AggFunc
111111
for _, arg := range aggFunc.Args {
112112
pbArg := pc.ExprToPB(arg)
113113
if pbArg == nil {
114-
return nil, errors.New(aggFunc.String() + " can't be converted to PB.")
114+
return nil, errors.New(aggFunc.StringWithCtx(errors.RedactLogDisable) + " can't be converted to PB.")
115115
}
116116
children = append(children, pbArg)
117117
}
@@ -126,7 +126,7 @@ func AggFuncToPBExpr(sctx sessionctx.Context, client kv.Client, aggFunc *AggFunc
126126
for _, arg := range aggFunc.OrderByItems {
127127
pbArg := expression.SortByItemToPB(sc, client, arg.Expr, arg.Desc)
128128
if pbArg == nil {
129-
return nil, errors.New(aggFunc.String() + " can't be converted to PB.")
129+
return nil, errors.New(aggFunc.StringWithCtx(errors.RedactLogDisable) + " can't be converted to PB.")
130130
}
131131
orderBy = append(orderBy, pbArg)
132132
}

pkg/expression/aggregation/base_func.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,15 @@ func (a *baseFuncDesc) clone() *baseFuncDesc {
7373

7474
// String implements the fmt.Stringer interface.
7575
func (a *baseFuncDesc) String() string {
76+
return a.StringWithCtx(errors.RedactLogDisable)
77+
}
78+
79+
// StringWithCtx returns the string within given context.
80+
func (a *baseFuncDesc) StringWithCtx(redact string) string {
7681
buffer := bytes.NewBufferString(a.Name)
7782
buffer.WriteString("(")
7883
for i, arg := range a.Args {
79-
buffer.WriteString(arg.String())
84+
buffer.WriteString(arg.StringWithCtx(redact))
8085
if i+1 != len(a.Args) {
8186
buffer.WriteString(", ")
8287
}
@@ -150,7 +155,7 @@ func (a *baseFuncDesc) typeInfer4ApproxPercentile(ctx sessionctx.Context) error
150155
}
151156
percent, isNull, err := a.Args[1].EvalInt(ctx, chunk.Row{})
152157
if err != nil {
153-
return fmt.Errorf("APPROX_PERCENTILE: Invalid argument %s", a.Args[1].String())
158+
return fmt.Errorf("APPROX_PERCENTILE: Invalid argument %s", a.Args[1].StringWithCtx(errors.RedactLogDisable))
154159
}
155160
if percent <= 0 || percent > 100 || isNull {
156161
if isNull {

pkg/expression/aggregation/concat.go

+4
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,11 @@ func (cf *concatFunction) Update(evalCtx *AggEvaluateContext, sc *stmtctx.Statem
104104
}
105105
evalCtx.Buffer.Truncate(i)
106106
if !cf.truncated {
107+
<<<<<<< HEAD
107108
sc.AppendWarning(expression.ErrCutValueGroupConcat.GenWithStackByArgs(cf.Args[0].String()))
109+
=======
110+
sc.AppendWarning(expression.ErrCutValueGroupConcat.FastGenByArgs(cf.Args[0].StringWithCtx(errors.RedactLogDisable)))
111+
>>>>>>> a7df4f9845 (*: support tidb_redact_log for explain (#54553) (#55308))
108112
}
109113
cf.truncated = true
110114
}

pkg/expression/aggregation/descriptor.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,18 @@ func NewAggFuncDescForWindowFunc(ctx sessionctx.Context, desc *WindowFuncDesc, h
6666

6767
// String implements the fmt.Stringer interface.
6868
func (a *AggFuncDesc) String() string {
69+
return a.StringWithCtx(errors.RedactLogDisable)
70+
}
71+
72+
// StringWithCtx returns the string representation within given ctx.
73+
func (a *AggFuncDesc) StringWithCtx(redact string) string {
6974
buffer := bytes.NewBufferString(a.Name)
7075
buffer.WriteString("(")
7176
if a.HasDistinct {
7277
buffer.WriteString("distinct ")
7378
}
7479
for i, arg := range a.Args {
75-
buffer.WriteString(arg.String())
80+
buffer.WriteString(arg.StringWithCtx(redact))
7681
if i+1 != len(a.Args) {
7782
buffer.WriteString(", ")
7883
}
@@ -81,7 +86,7 @@ func (a *AggFuncDesc) String() string {
8186
buffer.WriteString(" order by ")
8287
}
8388
for i, arg := range a.OrderByItems {
84-
buffer.WriteString(arg.String())
89+
buffer.WriteString(arg.StringWithCtx(redact))
8590
if i+1 != len(a.OrderByItems) {
8691
buffer.WriteString(", ")
8792
}

pkg/expression/bench_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"time"
3030

3131
"github.com/google/uuid"
32+
perrors "github.com/pingcap/errors"
3233
"github.com/pingcap/tidb/pkg/parser/ast"
3334
"github.com/pingcap/tidb/pkg/parser/auth"
3435
"github.com/pingcap/tidb/pkg/parser/charset"
@@ -1379,7 +1380,7 @@ func benchmarkVectorizedEvalOneVec(b *testing.B, vecExprCases vecExprBenchCases)
13791380
for funcName, testCases := range vecExprCases {
13801381
for _, testCase := range testCases {
13811382
expr, _, input, output := genVecExprBenchCase(ctx, funcName, testCase)
1382-
exprName := expr.String()
1383+
exprName := expr.StringWithCtx(perrors.RedactLogDisable)
13831384
if sf, ok := expr.(*ScalarFunction); ok {
13841385
exprName = fmt.Sprintf("%v", reflect.TypeOf(sf.Function))
13851386
tmp := strings.Split(exprName, ".")

pkg/expression/builtin_arithmetic.go

+20-19
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"fmt"
1919
"math"
2020

21+
"github.com/pingcap/errors"
2122
"github.com/pingcap/tidb/pkg/parser/mysql"
2223
"github.com/pingcap/tidb/pkg/parser/terror"
2324
"github.com/pingcap/tidb/pkg/sessionctx"
@@ -231,25 +232,25 @@ func (s *builtinArithmeticPlusIntSig) evalInt(row chunk.Row) (val int64, isNull
231232
switch {
232233
case isLHSUnsigned && isRHSUnsigned:
233234
if uint64(a) > math.MaxUint64-uint64(b) {
234-
return 0, true, types.ErrOverflow.GenWithStackByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%s + %s)", s.args[0].String(), s.args[1].String()))
235+
return 0, true, types.ErrOverflow.GenWithStackByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%s + %s)", s.args[0].StringWithCtx(errors.RedactLogDisable), s.args[1].StringWithCtx(errors.RedactLogDisable)))
235236
}
236237
case isLHSUnsigned && !isRHSUnsigned:
237238
if b < 0 && uint64(-b) > uint64(a) {
238-
return 0, true, types.ErrOverflow.GenWithStackByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%s + %s)", s.args[0].String(), s.args[1].String()))
239+
return 0, true, types.ErrOverflow.GenWithStackByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%s + %s)", s.args[0].StringWithCtx(errors.RedactLogDisable), s.args[1].StringWithCtx(errors.RedactLogDisable)))
239240
}
240241
if b > 0 && uint64(a) > math.MaxUint64-uint64(b) {
241-
return 0, true, types.ErrOverflow.GenWithStackByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%s + %s)", s.args[0].String(), s.args[1].String()))
242+
return 0, true, types.ErrOverflow.GenWithStackByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%s + %s)", s.args[0].StringWithCtx(errors.RedactLogDisable), s.args[1].StringWithCtx(errors.RedactLogDisable)))
242243
}
243244
case !isLHSUnsigned && isRHSUnsigned:
244245
if a < 0 && uint64(-a) > uint64(b) {
245-
return 0, true, types.ErrOverflow.GenWithStackByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%s + %s)", s.args[0].String(), s.args[1].String()))
246+
return 0, true, types.ErrOverflow.GenWithStackByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%s + %s)", s.args[0].StringWithCtx(errors.RedactLogDisable), s.args[1].StringWithCtx(errors.RedactLogDisable)))
246247
}
247248
if a > 0 && uint64(b) > math.MaxUint64-uint64(a) {
248-
return 0, true, types.ErrOverflow.GenWithStackByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%s + %s)", s.args[0].String(), s.args[1].String()))
249+
return 0, true, types.ErrOverflow.GenWithStackByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%s + %s)", s.args[0].StringWithCtx(errors.RedactLogDisable), s.args[1].StringWithCtx(errors.RedactLogDisable)))
249250
}
250251
case !isLHSUnsigned && !isRHSUnsigned:
251252
if (a > 0 && b > math.MaxInt64-a) || (a < 0 && b < math.MinInt64-a) {
252-
return 0, true, types.ErrOverflow.GenWithStackByArgs("BIGINT", fmt.Sprintf("(%s + %s)", s.args[0].String(), s.args[1].String()))
253+
return 0, true, types.ErrOverflow.GenWithStackByArgs("BIGINT", fmt.Sprintf("(%s + %s)", s.args[0].StringWithCtx(errors.RedactLogDisable), s.args[1].StringWithCtx(errors.RedactLogDisable)))
253254
}
254255
}
255256

@@ -279,7 +280,7 @@ func (s *builtinArithmeticPlusDecimalSig) evalDecimal(row chunk.Row) (*types.MyD
279280
err = types.DecimalAdd(a, b, c)
280281
if err != nil {
281282
if err == types.ErrOverflow {
282-
err = types.ErrOverflow.GenWithStackByArgs("DECIMAL", fmt.Sprintf("(%s + %s)", s.args[0].String(), s.args[1].String()))
283+
err = types.ErrOverflow.GenWithStackByArgs("DECIMAL", fmt.Sprintf("(%s + %s)", s.args[0].StringWithCtx(errors.RedactLogDisable), s.args[1].StringWithCtx(errors.RedactLogDisable)))
283284
}
284285
return nil, true, err
285286
}
@@ -309,7 +310,7 @@ func (s *builtinArithmeticPlusRealSig) evalReal(row chunk.Row) (float64, bool, e
309310
return 0, true, nil
310311
}
311312
if !mathutil.IsFinite(a + b) {
312-
return 0, true, types.ErrOverflow.GenWithStackByArgs("DOUBLE", fmt.Sprintf("(%s + %s)", s.args[0].String(), s.args[1].String()))
313+
return 0, true, types.ErrOverflow.GenWithStackByArgs("DOUBLE", fmt.Sprintf("(%s + %s)", s.args[0].StringWithCtx(errors.RedactLogDisable), s.args[1].StringWithCtx(errors.RedactLogDisable)))
313314
}
314315
return a + b, false, nil
315316
}
@@ -375,7 +376,7 @@ func (s *builtinArithmeticMinusRealSig) evalReal(row chunk.Row) (float64, bool,
375376
return 0, isNull, err
376377
}
377378
if !mathutil.IsFinite(a - b) {
378-
return 0, true, types.ErrOverflow.GenWithStackByArgs("DOUBLE", fmt.Sprintf("(%s - %s)", s.args[0].String(), s.args[1].String()))
379+
return 0, true, types.ErrOverflow.GenWithStackByArgs("DOUBLE", fmt.Sprintf("(%s - %s)", s.args[0].StringWithCtx(errors.RedactLogDisable), s.args[1].StringWithCtx(errors.RedactLogDisable)))
379380
}
380381
return a - b, false, nil
381382
}
@@ -403,7 +404,7 @@ func (s *builtinArithmeticMinusDecimalSig) evalDecimal(row chunk.Row) (*types.My
403404
err = types.DecimalSub(a, b, c)
404405
if err != nil {
405406
if err == types.ErrOverflow {
406-
err = types.ErrOverflow.GenWithStackByArgs("DECIMAL", fmt.Sprintf("(%s - %s)", s.args[0].String(), s.args[1].String()))
407+
err = types.ErrOverflow.GenWithStackByArgs("DECIMAL", fmt.Sprintf("(%s - %s)", s.args[0].StringWithCtx(errors.RedactLogDisable), s.args[1].StringWithCtx(errors.RedactLogDisable)))
407408
}
408409
return nil, true, err
409410
}
@@ -441,7 +442,7 @@ func (s *builtinArithmeticMinusIntSig) evalInt(row chunk.Row) (val int64, isNull
441442
}
442443
overflow := s.overflowCheck(isLHSUnsigned, isRHSUnsigned, signed, a, b)
443444
if overflow {
444-
return 0, true, types.ErrOverflow.GenWithStackByArgs(errType, fmt.Sprintf("(%s - %s)", s.args[0].String(), s.args[1].String()))
445+
return 0, true, types.ErrOverflow.GenWithStackByArgs(errType, fmt.Sprintf("(%s - %s)", s.args[0].StringWithCtx(errors.RedactLogDisable), s.args[1].StringWithCtx(errors.RedactLogDisable)))
445446
}
446447

447448
return a - b, false, nil
@@ -586,7 +587,7 @@ func (s *builtinArithmeticMultiplyRealSig) evalReal(row chunk.Row) (float64, boo
586587
}
587588
result := a * b
588589
if math.IsInf(result, 0) {
589-
return 0, true, types.ErrOverflow.GenWithStackByArgs("DOUBLE", fmt.Sprintf("(%s * %s)", s.args[0].String(), s.args[1].String()))
590+
return 0, true, types.ErrOverflow.GenWithStackByArgs("DOUBLE", fmt.Sprintf("(%s * %s)", s.args[0].StringWithCtx(errors.RedactLogDisable), s.args[1].StringWithCtx(errors.RedactLogDisable)))
590591
}
591592
return result, false, nil
592593
}
@@ -604,7 +605,7 @@ func (s *builtinArithmeticMultiplyDecimalSig) evalDecimal(row chunk.Row) (*types
604605
err = types.DecimalMul(a, b, c)
605606
if err != nil && !terror.ErrorEqual(err, types.ErrTruncated) {
606607
if err == types.ErrOverflow {
607-
err = types.ErrOverflow.GenWithStackByArgs("DECIMAL", fmt.Sprintf("(%s * %s)", s.args[0].String(), s.args[1].String()))
608+
err = types.ErrOverflow.GenWithStackByArgs("DECIMAL", fmt.Sprintf("(%s * %s)", s.args[0].StringWithCtx(errors.RedactLogDisable), s.args[1].StringWithCtx(errors.RedactLogDisable)))
608609
}
609610
return nil, true, err
610611
}
@@ -624,7 +625,7 @@ func (s *builtinArithmeticMultiplyIntUnsignedSig) evalInt(row chunk.Row) (val in
624625
unsignedB := uint64(b)
625626
result := unsignedA * unsignedB
626627
if unsignedA != 0 && result/unsignedA != unsignedB {
627-
return 0, true, types.ErrOverflow.GenWithStackByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%s * %s)", s.args[0].String(), s.args[1].String()))
628+
return 0, true, types.ErrOverflow.GenWithStackByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%s * %s)", s.args[0].StringWithCtx(errors.RedactLogDisable), s.args[1].StringWithCtx(errors.RedactLogDisable)))
628629
}
629630
return int64(result), false, nil
630631
}
@@ -640,7 +641,7 @@ func (s *builtinArithmeticMultiplyIntSig) evalInt(row chunk.Row) (val int64, isN
640641
}
641642
result := a * b
642643
if (a != 0 && result/a != b) || (result == math.MinInt64 && a == -1) {
643-
return 0, true, types.ErrOverflow.GenWithStackByArgs("BIGINT", fmt.Sprintf("(%s * %s)", s.args[0].String(), s.args[1].String()))
644+
return 0, true, types.ErrOverflow.GenWithStackByArgs("BIGINT", fmt.Sprintf("(%s * %s)", s.args[0].StringWithCtx(errors.RedactLogDisable), s.args[1].StringWithCtx(errors.RedactLogDisable)))
644645
}
645646
return result, false, nil
646647
}
@@ -705,7 +706,7 @@ func (s *builtinArithmeticDivideRealSig) evalReal(row chunk.Row) (float64, bool,
705706
}
706707
result := a / b
707708
if math.IsInf(result, 0) {
708-
return 0, true, types.ErrOverflow.GenWithStackByArgs("DOUBLE", fmt.Sprintf("(%s / %s)", s.args[0].String(), s.args[1].String()))
709+
return 0, true, types.ErrOverflow.GenWithStackByArgs("DOUBLE", fmt.Sprintf("(%s / %s)", s.args[0].StringWithCtx(errors.RedactLogDisable), s.args[1].StringWithCtx(errors.RedactLogDisable)))
709710
}
710711
return result, false, nil
711712
}
@@ -734,7 +735,7 @@ func (s *builtinArithmeticDivideDecimalSig) evalDecimal(row chunk.Row) (*types.M
734735
err = c.Round(c, s.baseBuiltinFunc.tp.GetDecimal(), types.ModeHalfUp)
735736
}
736737
} else if err == types.ErrOverflow {
737-
err = types.ErrOverflow.GenWithStackByArgs("DECIMAL", fmt.Sprintf("(%s / %s)", s.args[0].String(), s.args[1].String()))
738+
err = types.ErrOverflow.GenWithStackByArgs("DECIMAL", fmt.Sprintf("(%s / %s)", s.args[0].StringWithCtx(errors.RedactLogDisable), s.args[1].StringWithCtx(errors.RedactLogDisable)))
738739
}
739740
return c, false, err
740741
}
@@ -869,14 +870,14 @@ func (s *builtinArithmeticIntDivideDecimalSig) evalInt(row chunk.Row) (ret int64
869870
ret = int64(0)
870871
return ret, false, nil
871872
}
872-
return 0, true, types.ErrOverflow.GenWithStackByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%s DIV %s)", s.args[0].String(), s.args[1].String()))
873+
return 0, true, types.ErrOverflow.GenWithStackByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%s DIV %s)", s.args[0].StringWithCtx(errors.RedactLogDisable), s.args[1].StringWithCtx(errors.RedactLogDisable)))
873874
}
874875
ret = int64(val)
875876
} else {
876877
ret, err = c.ToInt()
877878
// err returned by ToInt may be ErrTruncated or ErrOverflow, only handle ErrOverflow, ignore ErrTruncated.
878879
if err == types.ErrOverflow {
879-
return 0, true, types.ErrOverflow.GenWithStackByArgs("BIGINT", fmt.Sprintf("(%s DIV %s)", s.args[0].String(), s.args[1].String()))
880+
return 0, true, types.ErrOverflow.GenWithStackByArgs("BIGINT", fmt.Sprintf("(%s DIV %s)", s.args[0].StringWithCtx(errors.RedactLogDisable), s.args[1].StringWithCtx(errors.RedactLogDisable)))
880881
}
881882
}
882883

0 commit comments

Comments
 (0)