!4128 A兼容性数据库下,打开char_coerce_compat时varchar与bpchar的比较包含空格

Merge pull request !4128 from chenxiaobin/fixEasyChar
This commit is contained in:
opengauss_bot
2023-09-14 02:08:54 +00:00
committed by Gitee
6 changed files with 322 additions and 1 deletions

View File

@ -402,6 +402,16 @@ Operator oper(ParseState* pstate, List* opname, Oid ltypeId, Oid rtypeId, bool n
rtypeId = NUMERICOID;
}
/*
* In A_FORMAT compatibility and CHAR_COERCE_COMPAT, we choose TEXT-related
* operators for varchar and bpchar.
*/
if (DB_IS_CMPT(A_FORMAT) && CHAR_COERCE_COMPAT && (((ltypeId == VARCHAROID) && (rtypeId == BPCHAROID)) ||
((rtypeId == VARCHAROID) && (ltypeId == BPCHAROID)))) {
ltypeId = TEXTOID;
rtypeId = TEXTOID;
}
/*
* Try to find the mapping in the lookaside cache.
*/

View File

@ -658,8 +658,16 @@ bool VecExprCodeGen::OpJittable(ExprState* state)
return false;
switch (opexpr->opno) {
case TEXTEQOID:
case TEXTNEOID:
case TEXTLEOID:
case TEXTGEOID:
case TEXTLTOID:
case TEXTGTOID: {
if (DB_IS_CMPT(A_FORMAT) && CHAR_COERCE_COMPAT) {
return false;
}
/* Only support ASCII and UTF-8 encoding */
int current_encoding = GetDatabaseEncoding();
if (current_encoding != PG_SQL_ASCII && current_encoding != PG_UTF8)

View File

@ -765,7 +765,7 @@ vtrim1(PG_FUNCTION_ARGS)
FunctionCallInfoData finfo;
finfo.arg = &args[0];
finfo.flinfo = fcinfo->flinfo;
if (pselection != NULL)
{

View File

@ -165,8 +165,11 @@ typedef FormData_pg_operator *Form_pg_operator;
#define INT1EQOID 5513
#define OID_NAME_REGEXEQ_OP 639
#define OID_TEXT_REGEXEQ_OP 641
#define TEXTNEOID 531
#define TEXTLTOID 664
#define TEXTLEOID 665
#define TEXTGTOID 666
#define TEXTGEOID 667
#define FLOAT8EQOID 670
#define FLOAT8NEOID 671
#define FLOAT8LTOID 672

View File

@ -154,3 +154,236 @@ select length(rtrim('123 '));
(1 row)
set behavior_compat_options = '';
set behavior_compat_options = 'char_coerce_compat';
create table tbl_111 (id int);
insert into tbl_111 values(1);
select count(*) from tbl_111 where cast(' ' as char(5)) = cast(' ' as varchar(5));
count
-------
0
(1 row)
select count(*) from tbl_111 where cast('abc ' as char(10)) = cast('abc ' as varchar(10));
count
-------
0
(1 row)
select count(*) from tbl_111 where cast(' ' as char(5)) != cast(' ' as varchar(5));
count
-------
1
(1 row)
select count(*) from tbl_111 where cast('abc ' as char(10)) != cast('abc ' as varchar(10));
count
-------
1
(1 row)
select count(*) from tbl_111 where cast(' ' as char(5)) > cast(' ' as varchar(5));
count
-------
1
(1 row)
select count(*) from tbl_111 where cast('abc ' as char(10)) > cast('abc ' as varchar(10));
count
-------
1
(1 row)
select count(*) from tbl_111 where cast(' ' as char(5)) >= cast(' ' as varchar(5));
count
-------
1
(1 row)
select count(*) from tbl_111 where cast('abc ' as char(10)) >= cast('abc ' as varchar(10));
count
-------
1
(1 row)
select count(*) from tbl_111 where cast(' ' as char(5)) < cast(' ' as varchar(5));
count
-------
0
(1 row)
select count(*) from tbl_111 where cast('abc ' as char(10)) < cast('abc ' as varchar(10));
count
-------
0
(1 row)
select count(*) from tbl_111 where cast(' ' as char(5)) <= cast(' ' as varchar(5));
count
-------
0
(1 row)
select count(*) from tbl_111 where cast('abc ' as char(10)) <= cast('abc ' as varchar(10));
count
-------
0
(1 row)
drop table tbl_111;
create table tbl_111 (a char(5), b varchar(5));
insert into tbl_111 values (' ', ' ');
insert into tbl_111 values ('abc ', 'abc ');
select count(*) from tbl_111 where a = b;
count
-------
0
(1 row)
select count(*) from tbl_111 where a != b;
count
-------
2
(1 row)
select count(*) from tbl_111 where a > b;
count
-------
2
(1 row)
select count(*) from tbl_111 where a >= b;
count
-------
2
(1 row)
select count(*) from tbl_111 where a < b;
count
-------
0
(1 row)
select count(*) from tbl_111 where a <= b;
count
-------
0
(1 row)
set try_vector_engine_strategy='force';
select count(*) from tbl_111 where a = b;
count
-------
0
(1 row)
select count(*) from tbl_111 where a != b;
count
-------
2
(1 row)
select count(*) from tbl_111 where a > b;
count
-------
2
(1 row)
select count(*) from tbl_111 where a >= b;
count
-------
2
(1 row)
select count(*) from tbl_111 where a < b;
count
-------
0
(1 row)
select count(*) from tbl_111 where a <= b;
count
-------
0
(1 row)
set try_vector_engine_strategy='off';
drop table tbl_111;
create table tbl_111 (a char(5), b varchar(5)) with (orientation = column);
insert into tbl_111 values (' ', ' ');
insert into tbl_111 values ('abc ', 'abc ');
select count(*) from tbl_111 where a = b;
count
-------
0
(1 row)
select count(*) from tbl_111 where a != b;
count
-------
2
(1 row)
select count(*) from tbl_111 where a > b;
count
-------
2
(1 row)
select count(*) from tbl_111 where a >= b;
count
-------
2
(1 row)
select count(*) from tbl_111 where a < b;
count
-------
0
(1 row)
select count(*) from tbl_111 where a <= b;
count
-------
0
(1 row)
set enable_codegen to true;
set codegen_cost_threshold to 0;
select count(*) from tbl_111 where a = b;
count
-------
0
(1 row)
select count(*) from tbl_111 where a != b;
count
-------
2
(1 row)
select count(*) from tbl_111 where a > b;
count
-------
2
(1 row)
select count(*) from tbl_111 where a >= b;
count
-------
2
(1 row)
select count(*) from tbl_111 where a < b;
count
-------
0
(1 row)
select count(*) from tbl_111 where a <= b;
count
-------
0
(1 row)
drop table tbl_111;
set behavior_compat_options = '';

View File

@ -85,3 +85,70 @@ select length(rtrim('123 '));
set behavior_compat_options = 'char_coerce_compat';
select length(rtrim('123 '));
set behavior_compat_options = '';
set behavior_compat_options = 'char_coerce_compat';
create table tbl_111 (id int);
insert into tbl_111 values(1);
select count(*) from tbl_111 where cast(' ' as char(5)) = cast(' ' as varchar(5));
select count(*) from tbl_111 where cast('abc ' as char(10)) = cast('abc ' as varchar(10));
select count(*) from tbl_111 where cast(' ' as char(5)) != cast(' ' as varchar(5));
select count(*) from tbl_111 where cast('abc ' as char(10)) != cast('abc ' as varchar(10));
select count(*) from tbl_111 where cast(' ' as char(5)) > cast(' ' as varchar(5));
select count(*) from tbl_111 where cast('abc ' as char(10)) > cast('abc ' as varchar(10));
select count(*) from tbl_111 where cast(' ' as char(5)) >= cast(' ' as varchar(5));
select count(*) from tbl_111 where cast('abc ' as char(10)) >= cast('abc ' as varchar(10));
select count(*) from tbl_111 where cast(' ' as char(5)) < cast(' ' as varchar(5));
select count(*) from tbl_111 where cast('abc ' as char(10)) < cast('abc ' as varchar(10));
select count(*) from tbl_111 where cast(' ' as char(5)) <= cast(' ' as varchar(5));
select count(*) from tbl_111 where cast('abc ' as char(10)) <= cast('abc ' as varchar(10));
drop table tbl_111;
create table tbl_111 (a char(5), b varchar(5));
insert into tbl_111 values (' ', ' ');
insert into tbl_111 values ('abc ', 'abc ');
select count(*) from tbl_111 where a = b;
select count(*) from tbl_111 where a != b;
select count(*) from tbl_111 where a > b;
select count(*) from tbl_111 where a >= b;
select count(*) from tbl_111 where a < b;
select count(*) from tbl_111 where a <= b;
set try_vector_engine_strategy='force';
select count(*) from tbl_111 where a = b;
select count(*) from tbl_111 where a != b;
select count(*) from tbl_111 where a > b;
select count(*) from tbl_111 where a >= b;
select count(*) from tbl_111 where a < b;
select count(*) from tbl_111 where a <= b;
set try_vector_engine_strategy='off';
drop table tbl_111;
create table tbl_111 (a char(5), b varchar(5)) with (orientation = column);
insert into tbl_111 values (' ', ' ');
insert into tbl_111 values ('abc ', 'abc ');
select count(*) from tbl_111 where a = b;
select count(*) from tbl_111 where a != b;
select count(*) from tbl_111 where a > b;
select count(*) from tbl_111 where a >= b;
select count(*) from tbl_111 where a < b;
select count(*) from tbl_111 where a <= b;
set enable_codegen to true;
set codegen_cost_threshold to 0;
select count(*) from tbl_111 where a = b;
select count(*) from tbl_111 where a != b;
select count(*) from tbl_111 where a > b;
select count(*) from tbl_111 where a >= b;
select count(*) from tbl_111 where a < b;
select count(*) from tbl_111 where a <= b;
drop table tbl_111;
set behavior_compat_options = '';