在修复相关缺陷时发现不同的数据库有不同的语义,因此整理不同数据库的关系如下。
MySql
create table
create table table_char_test
(
charColumn char(3) null,
varCharColumn varchar(3) null
);
insert into calcite.table_char_test values ('a','a');
insert into calcite.table_char_test values ('ab','ab');
insert into calcite.table_char_test values ('ab ','ab ');
insert into calcite.table_char_test values ('abc','abc');
insert into calcite.table_char_test values ('abc','abcd');
insert into calcite.table_char_test values ('abcd','abc');
select * from calcite.table_char_test where charColumn in ('ab ');
select * from calcite.table_char_test where charColumn in ('ab');
select * from calcite.table_char_test where charColumn in ('ab ');
select * from calcite.table_char_test where charColumn in ('ab ');
select * from calcite.table_char_test where varCharColumn in ('ab ','abc');
结论
在MySql中,默认没有设置PAD_CHAR_TO_FULL_LENGTH属性,则Char只在存储时占指定字符空间。其在查询时候都按照插入时候truncate掉尾部多余的值进行比较,in列表中的字符串长度不变,转为bpchar[],如果是单个值则为bp。 如果设置PAD_CHAR_TO_FULL_LENGTH,则将列值添加空字符串直到规定长度,然后直接和列值做比较。
PostGreSQL
create table
create table table_char_test
(
charColumn character (3) null,
varCharColumn character varying(3) null
);
insert into calcite.table_char_test values ('a','a');
insert into calcite.table_char_test values ('ab','ab');
insert into calcite.table_char_test values ('ab ','ab ');
insert into calcite.table_char_test values ('abc','abc');
insert into calcite.table_char_test values ('abc','abcd');
insert into calcite.table_char_test values ('abcd','abc');
select * from table_char_test where charColumn in ('ab');
select * from calcite.table_char_test where charColumn in ('ab ');
select * from calcite.table_char_test where charColumn in ('ab ');
select * from table_char_test where charColumn in ('ab ','abc ')
select * from table_char_test where charColumn in ('ab b','abc ')
select * from calcite.table_char_test where varCharColumn in ('ab ','abc');
结论: charColumn 与 list中谁少谁进行填充,都填充到最大的那个值。
|