Skip to content

Commit f8f667e

Browse files
authored
planner: return error if binding sql is too long (pingcap#59982)
ref pingcap#51347
1 parent dbf6a6e commit f8f667e

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

pkg/bindinfo/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ go_test(
5454
embed = [":bindinfo"],
5555
flaky = True,
5656
race = "on",
57-
shard_count = 32,
57+
shard_count = 33,
5858
deps = [
5959
"//pkg/parser",
6060
"//pkg/parser/ast",

pkg/bindinfo/binding_operator.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ func (op *bindingOperator) CreateBinding(sctx sessionctx.Context, bindings []*Bi
9393
binding.CreateTime = now
9494
binding.UpdateTime = now
9595

96+
// TODO: update the sql_mode or sctx.types.Flag to let execution engine returns errors like dataTooLong,
97+
// overflow directly.
98+
9699
// Insert the Bindings to the storage.
97100
_, err = exec(
98101
sctx,
@@ -118,6 +121,14 @@ func (op *bindingOperator) CreateBinding(sctx sessionctx.Context, bindings []*Bi
118121
if err != nil {
119122
return err
120123
}
124+
125+
warnings, _, err := execRows(sctx, "show warnings")
126+
if err != nil {
127+
return err
128+
}
129+
if len(warnings) != 0 {
130+
return errors.New(warnings[0].GetString(2))
131+
}
121132
}
122133
return nil
123134
})

pkg/bindinfo/binding_operator_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package bindinfo_test
1717
import (
1818
"context"
1919
"fmt"
20+
"strings"
2021
"testing"
2122
"time"
2223

@@ -875,6 +876,21 @@ func TestBindingQueryInList(t *testing.T) {
875876
}
876877
}
877878

879+
func TestTooLongBinding(t *testing.T) {
880+
store := testkit.CreateMockStore(t)
881+
tk := testkit.NewTestKit(t, store)
882+
883+
tk.MustExec(`use test`)
884+
tk.MustExec(`create table t (a int)`)
885+
predicates := make([]string, 0, 65535)
886+
for i := 0; i < cap(predicates); i++ {
887+
predicates = append(predicates, fmt.Sprintf("t.a=%d", i))
888+
}
889+
bindingSQL := fmt.Sprintf("create global binding using select * from t where %s", strings.Join(predicates, " or "))
890+
err := tk.ExecToErr(bindingSQL)
891+
require.ErrorContains(t, err, "Data too long")
892+
}
893+
878894
// TestBindingInListWithSingleLiteral tests sql with "IN (Lit)", fixes #44298
879895
func TestBindingInListWithSingleLiteral(t *testing.T) {
880896
store, dom := testkit.CreateMockStoreAndDomain(t)

0 commit comments

Comments
 (0)