-
Notifications
You must be signed in to change notification settings - Fork 6k
expression: fix tikv crash when bool like cast(bit as char)
#57484
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -1581,7 +1581,9 @@ func TestExprPushDownToTiKV(t *testing.T) { | |||||||||||||||||||||
require.Len(t, pushed, 0) | ||||||||||||||||||||||
require.Len(t, remained, len(exprs)) | ||||||||||||||||||||||
|
||||||||||||||||||||||
// Test Conv function | ||||||||||||||||||||||
// Test Conv function, `conv` function for a BIT column should not be pushed down for its special behavior which | ||||||||||||||||||||||
// is only handled in TiDB currently. | ||||||||||||||||||||||
// see issue: https://github.com/pingcap/tidb/issues/51877 | ||||||||||||||||||||||
exprs = exprs[:0] | ||||||||||||||||||||||
function, err = NewFunction(mock.NewContext(), ast.Conv, types.NewFieldType(mysql.TypeString), stringColumn, intColumn, intColumn) | ||||||||||||||||||||||
require.NoError(t, err) | ||||||||||||||||||||||
|
@@ -1590,7 +1592,11 @@ func TestExprPushDownToTiKV(t *testing.T) { | |||||||||||||||||||||
require.Len(t, pushed, len(exprs)) | ||||||||||||||||||||||
require.Len(t, remained, 0) | ||||||||||||||||||||||
exprs = exprs[:0] | ||||||||||||||||||||||
castByteAsStringFunc, err := NewFunction(mock.NewContext(), ast.Cast, types.NewFieldType(mysql.TypeString), byteColumn) | ||||||||||||||||||||||
// when conv a column with type BIT, a cast function will be used to cast bit to a binary string | ||||||||||||||||||||||
castTp := types.NewFieldType(mysql.TypeString) | ||||||||||||||||||||||
castTp.SetCharset(charset.CharsetBin) | ||||||||||||||||||||||
castTp.SetCollate(charset.CollationBin) | ||||||||||||||||||||||
castByteAsStringFunc, err := NewFunction(mock.NewContext(), ast.Cast, castTp, byteColumn) | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function can not be push down to TiKV because There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no, I think it's the issue: #51877 The tidb have some special logic for function See: tidb/pkg/expression/builtin_math.go Lines 1281 to 1290 in 9530fdc
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added a comment in this test There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test is not related with this issue, but we should update it to set to casted type as bin collations to make the test pass. |
||||||||||||||||||||||
require.NoError(t, err) | ||||||||||||||||||||||
function, err = NewFunction(mock.NewContext(), ast.Conv, types.NewFieldType(mysql.TypeString), castByteAsStringFunc, intColumn, intColumn) | ||||||||||||||||||||||
require.NoError(t, err) | ||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_test") | ||
|
||
go_test( | ||
name = "pushdowntest_test", | ||
timeout = "short", | ||
srcs = [ | ||
"expr_test.go", | ||
"main_test.go", | ||
], | ||
flaky = True, | ||
deps = [ | ||
"//pkg/testkit", | ||
"//tests/realtikvtest", | ||
"@com_github_stretchr_testify//require", | ||
], | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright 2024 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package pushdowntest | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/pingcap/tidb/pkg/testkit" | ||
"github.com/pingcap/tidb/tests/realtikvtest" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
// TestBitCastInTiKV see issue: https://github.com/pingcap/tidb/issues/56494 | ||
func TestBitCastInTiKV(t *testing.T) { | ||
store := realtikvtest.CreateMockStoreAndSetup(t) | ||
tk := testkit.NewTestKit(t, store) | ||
tk.MustExec("use test") | ||
tk.MustExec("drop table if exists t1") | ||
defer tk.MustExec("drop table if exists t1") | ||
tk.MustExec("create table t1(a bit(24))") | ||
tk.MustExec("insert into t1 values(0xffffff)") | ||
err := tk.QueryToErr("select a from t1 where false not like convert(a, char)") | ||
require.EqualError(t, err, "[tikv:3854]Cannot convert string '\\xFF\\xFF\\xFF' from binary to utf8mb4") | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright 2024 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package pushdowntest | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/pingcap/tidb/tests/realtikvtest" | ||
) | ||
|
||
func TestMain(m *testing.M) { | ||
realtikvtest.RunTestMain(m) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For other type that store binary string like
Blob
, will TiDB meet the same problem?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, only the "hybrid" types will address this issue. Their "EvalType" may return
ETInt
, but when converting them to strings, we should be recognized as bytes instead.I did not handle other hybrid types like enum and set in this PR, because in most time their should have a legal encoding and another reason is to introduce less logic change in this fix.