From c34e92b64f43a660dd1636a11d337dd7d28181a5 Mon Sep 17 00:00:00 2001 From: totaj Date: Tue, 8 Nov 2022 16:26:31 +0800 Subject: [PATCH] Fix a outer join bug. --- .../backend/parser/parse_compatibility.cpp | 2 +- .../expected/a_outerjoin_conversion.out | 41 +++++++++++++++++++ .../regress/sql/a_outerjoin_conversion.sql | 21 ++++++++++ 3 files changed, 63 insertions(+), 1 deletion(-) diff --git a/src/common/backend/parser/parse_compatibility.cpp b/src/common/backend/parser/parse_compatibility.cpp index f51ba92f3d..12000c9f66 100644 --- a/src/common/backend/parser/parse_compatibility.cpp +++ b/src/common/backend/parser/parse_compatibility.cpp @@ -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))); diff --git a/src/test/regress/expected/a_outerjoin_conversion.out b/src/test/regress/expected/a_outerjoin_conversion.out index 7afa87f93b..6e7e21e42b 100644 --- a/src/test/regress/expected/a_outerjoin_conversion.out +++ b/src/test/regress/expected/a_outerjoin_conversion.out @@ -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; diff --git a/src/test/regress/sql/a_outerjoin_conversion.sql b/src/test/regress/sql/a_outerjoin_conversion.sql index 229c6c89a1..62e46319c5 100644 --- a/src/test/regress/sql/a_outerjoin_conversion.sql +++ b/src/test/regress/sql/a_outerjoin_conversion.sql @@ -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; -- Gitee