!1596 恢复代码

Merge pull request !1596 from 胡正超/misscode
This commit is contained in:
opengauss-bot 2022-03-16 12:35:59 +00:00 committed by Gitee
commit 9963364bfa
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
8 changed files with 159 additions and 33 deletions

View File

@ -3806,7 +3806,7 @@ static text* pg_get_expr_worker(text* expr, Oid relid, const char* relname, int
exprstr = text_to_cstring(expr);
/* Convert expression to node tree */
node = (Node*)stringToNode(exprstr);
node = (Node*)stringToNode_skip_extern_fields(exprstr);
pfree_ext(exprstr);

View File

@ -675,7 +675,7 @@ Datum bpcharlen(PG_FUNCTION_ARGS)
int len;
/* get number of bytes, ignoring trailing spaces */
if (DB_IS_CMPT(PG_FORMAT)) {
if (DB_IS_CMPT(PG_FORMAT | B_FORMAT)) {
len = bcTruelen(arg);
} else {
len = VARSIZE_ANY_EXHDR(arg);

View File

@ -921,8 +921,8 @@ template<bool calCharLength> int MbCharClipLen(const char* mbstr, int len, int l
*/
int pg_mbcharcliplen(const char* mbstr, int len, int limit)
{
bool pgFormat = DB_IS_CMPT(PG_FORMAT);
if (pgFormat) {
bool calCharLength = DB_IS_CMPT(PG_FORMAT | B_FORMAT);
if (calCharLength) {
return MbCharClipLen<true>(mbstr, len, limit);
} else {
return MbCharClipLen<false>(mbstr, len, limit);

View File

@ -269,9 +269,9 @@ select cast('s' as int);
--------------- limit #,#-------------------
-- limit case in postgresql
\c regression
create table test(a int);
insert into test values (1),(2),(3),(4),(5);
select * from test order by 1 limit 2,3;
create table test_limit(a int);
insert into test_limit values (1),(2),(3),(4),(5);
select * from test_limit order by 1 limit 2,3;
a
---
3
@ -279,7 +279,7 @@ select * from test order by 1 limit 2,3;
5
(3 rows)
select * from test order by 1 limit 2,6;
select * from test_limit order by 1 limit 2,6;
a
---
3
@ -287,17 +287,17 @@ select * from test order by 1 limit 2,6;
5
(3 rows)
select * from test order by 1 limit 6,2;
select * from test_limit order by 1 limit 6,2;
a
---
(0 rows)
drop table test;
drop table test_limit;
-- limit case in b
\c b
create table test(a int);
insert into test values (1),(2),(3),(4),(5);
select * from test order by 1 limit 2,3;
create table test_limit(a int);
insert into test_limit values (1),(2),(3),(4),(5);
select * from test_limit order by 1 limit 2,3;
a
---
3
@ -305,7 +305,7 @@ select * from test order by 1 limit 2,3;
5
(3 rows)
select * from test order by 1 limit 2,6;
select * from test_limit order by 1 limit 2,6;
a
---
3
@ -313,12 +313,12 @@ select * from test order by 1 limit 2,6;
5
(3 rows)
select * from test order by 1 limit 6,2;
select * from test_limit order by 1 limit 6,2;
a
---
(0 rows)
drop table test;
drop table test_limit;
--------------timestampdiff-----------------
-- timestamp with time zone
-- timestamp1 > timestamp2
@ -635,7 +635,7 @@ select timestampdiff(second, '2018-01-01', now());
select timestampdiff(microsecond, '2018-01-01', now());
timestamp_diff
----------------
-----------------
--?.*
(1 row)
@ -731,5 +731,79 @@ select timestampdiff(microsecond, '2018-01-01 01:01:01.000001', b) from timestam
(1 row)
drop table timestamp;
-- test char/varchar length
create table char_test(a char(10),b varchar(10));
insert into char_test values('零一二三四五六七八九','零一二三四五六七八九');
insert into char_test values('零1二3四5六7八9','零1二3四5六7八9');
insert into char_test values('零1二3四5六7八9','零1二3四5六7八90');
ERROR: value too long for type character varying(10)
CONTEXT: referenced column: b
insert into char_test values('零1二3四5六7八90','零1二3四5六7八9');
ERROR: value too long for type character(10)
CONTEXT: referenced column: a
insert into char_test values('零0','零1二3');
insert into char_test values('零0 ','零1二3');
insert into char_test values('零0','零1二3 ');
insert into char_test values('','');
insert into char_test values(null,null);
insert into char_test values('0','0');
select length(a),length(b) from char_test;
length | length
--------+--------
10 | 10
10 | 10
2 | 4
2 | 4
2 | 6
0 | 0
|
1 | 1
(8 rows)
select lengthb(a),lengthb(b) from char_test;
lengthb | lengthb
---------+---------
30 | 30
20 | 20
10 | 8
10 | 8
10 | 10
10 | 0
|
10 | 1
(8 rows)
select bit_length(a),bit_length(b) from char_test;
bit_length | bit_length
------------+------------
240 | 240
160 | 160
32 | 64
32 | 64
32 | 80
0 | 0
|
8 | 8
(8 rows)
create index a on char_test(a);
create index b on char_test(b);
set enable_seqscan to off;
select * from char_test where a = '零0';
a | b
-----------+----------
零0 | 零1二3
零0 | 零1二3
零0 | 零1二3
(3 rows)
select * from char_test where b = '零1二3';
a | b
-----------+--------
零0 | 零1二3
零0 | 零1二3
(2 rows)
drop table char_test;
\c regression
drop database b;

View File

@ -1,9 +1,34 @@
create role samedb_schema_cn_role_02_001 password 'Ttest_234';
create schema authorization samedb_schema_cn_role_02_001
create table samedb_schema_cn_role_02_001.cn_table_00 (cn_a int, cn_b text , cn_c date ,cn_d interval)
create table samedb_schema_cn_role_02_001.cn_table_00 (cn_a int, cn_b text , cn_c date ,cn_d interval, cn_e serial)
create view cn_view_00 as
select cn_b,cn_d, cn_c from cn_table_00;
NOTICE: CREATE TABLE will create implicit sequence "cn_table_00_cn_e_seq" for serial column "cn_table_00.cn_e"
\d+ samedb_schema_cn_role_02_001.cn_table_00
Table "samedb_schema_cn_role_02_001.cn_table_00"
Column | Type | Modifiers | Storage | Stats target | Description
--------+--------------------------------+-----------------------------------------------------------------------------------------+----------+--------------+-------------
cn_a | integer | | plain | |
cn_b | text | | extended | |
cn_c | timestamp(0) without time zone | | plain | |
cn_d | interval | | plain | |
cn_e | integer | not null default nextval('samedb_schema_cn_role_02_001.cn_table_00_cn_e_seq'::regclass) | plain | |
Has OIDs: no
Options: orientation=row, compression=no
alter schema samedb_schema_cn_role_02_001 rename to samedb_schema_cn_role_02_001_bak;
\d+ samedb_schema_cn_role_02_001_bak.cn_table_00
Table "samedb_schema_cn_role_02_001_bak.cn_table_00"
Column | Type | Modifiers | Storage | Stats target | Description
--------+--------------------------------+---------------------------------------------------------------------------------------------+----------+--------------+-------------
cn_a | integer | | plain | |
cn_b | text | | extended | |
cn_c | timestamp(0) without time zone | | plain | |
cn_d | interval | | plain | |
cn_e | integer | not null default nextval('samedb_schema_cn_role_02_001_bak.cn_table_00_cn_e_seq'::regclass) | plain | |
Has OIDs: no
Options: orientation=row, compression=no
alter view samedb_schema_cn_role_02_001_bak.cn_view_00 rename to cn_view_00_bak;
drop view samedb_schema_cn_role_02_001_bak.cn_view_00_bak;
drop table samedb_schema_cn_role_02_001_bak.cn_table_00;

View File

@ -749,7 +749,7 @@ test: copy2 temp
test: truncate
#test: temp_table
#test: b_compatibility
test: b_compatibility
test: hw_compatibility
test: hw_groupingsets hw_row_grouping_set
test: char_truncation_common char_truncation_cast

View File

@ -82,21 +82,21 @@ select cast('s' as int);
--------------- limit #,#-------------------
-- limit case in postgresql
\c regression
create table test(a int);
insert into test values (1),(2),(3),(4),(5);
select * from test order by 1 limit 2,3;
select * from test order by 1 limit 2,6;
select * from test order by 1 limit 6,2;
drop table test;
create table test_limit(a int);
insert into test_limit values (1),(2),(3),(4),(5);
select * from test_limit order by 1 limit 2,3;
select * from test_limit order by 1 limit 2,6;
select * from test_limit order by 1 limit 6,2;
drop table test_limit;
-- limit case in b
\c b
create table test(a int);
insert into test values (1),(2),(3),(4),(5);
select * from test order by 1 limit 2,3;
select * from test order by 1 limit 2,6;
select * from test order by 1 limit 6,2;
drop table test;
create table test_limit(a int);
insert into test_limit values (1),(2),(3),(4),(5);
select * from test_limit order by 1 limit 2,3;
select * from test_limit order by 1 limit 2,6;
select * from test_limit order by 1 limit 6,2;
drop table test_limit;
--------------timestampdiff-----------------
-- timestamp with time zone
@ -189,6 +189,29 @@ select timestampdiff(second, '2018-01-01 01:01:01.000001', b) from timestamp;
select timestampdiff(microsecond, '2018-01-01 01:01:01.000001', b) from timestamp;
drop table timestamp;
-- test char/varchar length
create table char_test(a char(10),b varchar(10));
insert into char_test values('零一二三四五六七八九','零一二三四五六七八九');
insert into char_test values('零1二3四5六7八9','零1二3四5六7八9');
insert into char_test values('零1二3四5六7八9','零1二3四5六7八90');
insert into char_test values('零1二3四5六7八90','零1二3四5六7八9');
insert into char_test values('零0','零1二3');
insert into char_test values('零0 ','零1二3');
insert into char_test values('零0','零1二3 ');
insert into char_test values('','');
insert into char_test values(null,null);
insert into char_test values('0','0');
select length(a),length(b) from char_test;
select lengthb(a),lengthb(b) from char_test;
select bit_length(a),bit_length(b) from char_test;
create index a on char_test(a);
create index b on char_test(b);
set enable_seqscan to off;
select * from char_test where a = '零0';
select * from char_test where b = '零1二3';
drop table char_test;
\c regression
drop database b;

View File

@ -1,12 +1,16 @@
create role samedb_schema_cn_role_02_001 password 'Ttest_234';
create schema authorization samedb_schema_cn_role_02_001
create table samedb_schema_cn_role_02_001.cn_table_00 (cn_a int, cn_b text , cn_c date ,cn_d interval)
create table samedb_schema_cn_role_02_001.cn_table_00 (cn_a int, cn_b text , cn_c date ,cn_d interval, cn_e serial)
create view cn_view_00 as
select cn_b,cn_d, cn_c from cn_table_00;
\d+ samedb_schema_cn_role_02_001.cn_table_00
alter schema samedb_schema_cn_role_02_001 rename to samedb_schema_cn_role_02_001_bak;
\d+ samedb_schema_cn_role_02_001_bak.cn_table_00
alter view samedb_schema_cn_role_02_001_bak.cn_view_00 rename to cn_view_00_bak;
drop view samedb_schema_cn_role_02_001_bak.cn_view_00_bak;