!2402 修复a outerjoin (+)的bug

Merge pull request !2402 from pengjiong/fix_case
This commit is contained in:
opengauss-bot
2022-11-08 09:30:09 +00:00
committed by Gitee
3 changed files with 63 additions and 1 deletions

View File

@ -657,7 +657,7 @@ bool plus_outerjoin_precheck(const OperatorPlusProcessContext* ctx, Node* expr,
}
/* Report Error when t_noplus and t_hasplus is the same RTE */
if (strcmp(t_noplus->eref->aliasname, t_hasplus->eref->aliasname) == 0) {
if (t_noplus == t_hasplus) {
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("\"%s\" is not allowed to outer join with itself.", t_noplus->eref->aliasname)));

View File

@ -1528,6 +1528,47 @@ reset enable_mergejoin;
reset enable_hashjoin;
reset enable_seqscan;
reset enable_index_nestloop;
--test (+) with itself
create table public.join_t1(col int, col2 int);
create schema join_schema;
create table join_schema.join_t1(col int, col2 int);
insert into public.join_t1 values(1,11),(2,22);
insert into join_schema.join_t1 values(1,10);
--ok
select * from public.join_t1, join_schema.join_t1 where public.join_t1.col (+)=join_schema.join_t1.col;
col | col2 | col | col2
-----+------+-----+------
1 | 11 | 1 | 10
(1 row)
select * from public.join_t1 t1, join_schema.join_t1 t2 where t1.col (+)=t2.col;
col | col2 | col | col2
-----+------+-----+------
1 | 11 | 1 | 10
(1 row)
select * from public.join_t1 t1 ,public.join_t1 t2 where t1.col (+)=t2.col2 order by t2.col;
col | col2 | col | col2
-----+------+-----+------
| | 1 | 11
| | 2 | 22
(2 rows)
select * from public.join_t1 t1 ,public.join_t1 t2 where t1.col (+)=t2.col order by t2.col;
col | col2 | col | col2
-----+------+-----+------
1 | 11 | 1 | 11
2 | 22 | 2 | 22
(2 rows)
--fail
select * from public.join_t1 t1 ,public.join_t1 t2 where t1.col (+)=t1.col;
ERROR: "t1" is not allowed to outer join with itself.
select * from public.join_t1 t1 ,public.join_t1 t2 where t1.col (+)=t1.col2;
ERROR: "t1" is not allowed to outer join with itself.
drop table public.join_t1;
drop table join_schema.join_t1;
drop schema join_schema;
drop view plus_v;
drop function plus_join_test_1();
drop table t1;

View File

@ -399,6 +399,27 @@ reset enable_hashjoin;
reset enable_seqscan;
reset enable_index_nestloop;
--test (+) with itself
create table public.join_t1(col int, col2 int);
create schema join_schema;
create table join_schema.join_t1(col int, col2 int);
insert into public.join_t1 values(1,11),(2,22);
insert into join_schema.join_t1 values(1,10);
--ok
select * from public.join_t1, join_schema.join_t1 where public.join_t1.col (+)=join_schema.join_t1.col;
select * from public.join_t1 t1, join_schema.join_t1 t2 where t1.col (+)=t2.col;
select * from public.join_t1 t1 ,public.join_t1 t2 where t1.col (+)=t2.col2 order by t2.col;
select * from public.join_t1 t1 ,public.join_t1 t2 where t1.col (+)=t2.col order by t2.col;
--fail
select * from public.join_t1 t1 ,public.join_t1 t2 where t1.col (+)=t1.col;
select * from public.join_t1 t1 ,public.join_t1 t2 where t1.col (+)=t1.col2;
drop table public.join_t1;
drop table join_schema.join_t1;
drop schema join_schema;
drop view plus_v;
drop function plus_join_test_1();
drop table t1;