fix: close issue 59446 make oct("") same as mysql (#61767)

close pingcap/tidb#59446
This commit is contained in:
yihong
2025-07-15 10:10:51 +08:00
committed by GitHub
parent adbdf3f0c7
commit 2f4f559b83
5 changed files with 36 additions and 4 deletions

View File

@ -2993,6 +2993,11 @@ func (b *builtinOctStringSig) evalString(ctx EvalContext, row chunk.Row) (string
return "", isNull, err
}
// for issue #59446 should return NULL for empty string
if len(val) == 0 {
return "", true, nil
}
negative, overflow := false, false
val = getValidPrefix(strings.TrimSpace(val), 10)
if len(val) == 0 {

View File

@ -1774,8 +1774,15 @@ func (b *builtinOctStringSig) vecEvalString(ctx EvalContext, input *chunk.Chunk,
result.AppendNull()
continue
}
negative, overflow := false, false
// for issue #59446 should return NULL for empty string
str := buf.GetString(i)
if len(str) == 0 {
result.AppendNull()
continue
}
negative, overflow := false, false
str = getValidPrefix(strings.TrimSpace(str), 10)
if len(str) == 0 {
result.AppendString("0")

View File

@ -2007,6 +2007,21 @@ oct("aaaa") oct("-1.9") oct("-9999999999999999999999999") oct("99999999999999999
select oct(-1.9), oct(1.9), oct(-1), oct(1), oct(-9999999999999999999999999), oct(9999999999999999999999999);
oct(-1.9) oct(1.9) oct(-1) oct(1) oct(-9999999999999999999999999) oct(9999999999999999999999999)
1777777777777777777777 1 1777777777777777777777 1 1777777777777777777777 1777777777777777777777
select oct(""), oct(" "), oct(NULL);
oct("") oct(" ") oct(NULL)
NULL 0 NULL
drop table if exists t_oct;
CREATE TABLE t_oct (a VARCHAR(20));
INSERT INTO t_oct VALUES (''), (' '), (NULL), ('123'), ('abc'), ('0'), ('255');
SELECT oct(CONCAT(a, '')) FROM t_oct;
oct(CONCAT(a, ''))
NULL
0
NULL
173
0
0
377
select find_in_set("", ""), find_in_set("", ","), find_in_set("中文", "字符串,中文"), find_in_set("b,", "a,b,c,d");
find_in_set("", "") find_in_set("", ",") find_in_set("中文", "字符串,中文") find_in_set("b,", "a,b,c,d")
0 1 2 0

View File

@ -899,6 +899,11 @@ insert into t values("中国", cast("国" as binary)), ("中国", ""), ("abc", "
select instr(a, b) from t;
select oct("aaaa"), oct("-1.9"), oct("-9999999999999999999999999"), oct("9999999999999999999999999");
select oct(-1.9), oct(1.9), oct(-1), oct(1), oct(-9999999999999999999999999), oct(9999999999999999999999999);
select oct(""), oct(" "), oct(NULL);
drop table if exists t_oct;
CREATE TABLE t_oct (a VARCHAR(20));
INSERT INTO t_oct VALUES (''), (' '), (NULL), ('123'), ('abc'), ('0'), ('255');
SELECT oct(CONCAT(a, '')) FROM t_oct;
select find_in_set("", ""), find_in_set("", ","), find_in_set("中文", "字符串,中文"), find_in_set("b,", "a,b,c,d");
select find_in_set(NULL, ""), find_in_set("", NULL), find_in_set(1, "2,3,1");
select make_set(0, "12"), make_set(3, "aa", "11"), make_set(3, NULL, "中文"), make_set(NULL, "aa");

View File

@ -35587,9 +35587,9 @@
{
"sql": "SELECT OCT('')",
"args": null,
"pass": false,
"known": true,
"comment": "https://github.com/pingcap/tidb/issues/59446"
"pass": true,
"known": false,
"comment": ""
},
{
"sql": "SELECT OCT(8)",