forked from huawei/openGauss-server
fixed the bug of join
This commit is contained in:
parent
7f9a1f5428
commit
4c0a495a18
|
|
@ -1181,6 +1181,17 @@ static Node* pull_up_simple_subquery(PlannerInfo* root, Node* jtnode, RangeTblEn
|
|||
return jtnode;
|
||||
}
|
||||
|
||||
/*
|
||||
* We must flatten any join alias Vars in the subquery's targetlist,
|
||||
* because pulling up the subquery's subqueries might have changed their
|
||||
* expansions into arbitrary expressions, which could affect
|
||||
* pullup_replace_vars' decisions about whether PlaceHolderVar wrappers
|
||||
* are needed for tlist entries. (Likely it'd be better to do
|
||||
* flatten_join_alias_vars on the whole query tree at some earlier stage,
|
||||
* maybe even in the rewriter; but for now let's just fix this case here.)
|
||||
*/
|
||||
subquery->targetList = (List *) flatten_join_alias_vars(subroot, (Node *) subquery->targetList);
|
||||
|
||||
/*
|
||||
* Adjust level-0 varnos in subquery so that we can append its rangetable
|
||||
* to upper query's. We have to fix the subquery's append_rel_list as
|
||||
|
|
|
|||
|
|
@ -0,0 +1,55 @@
|
|||
CREATE TABLE t11 (
|
||||
sec_code character(6) NOT NULL,
|
||||
issue_type character(3) NOT NULL
|
||||
);
|
||||
CREATE TABLE t22 (
|
||||
company_code character(6) NOT NULL,
|
||||
list_profit_flag character(1) NOT NULL
|
||||
);
|
||||
CREATE TABLE t33 (
|
||||
company_code character(6) NOT NULL,
|
||||
issue_flag character(6) NOT NULL
|
||||
);
|
||||
insert into t11 values(1,'S04');
|
||||
insert into t22 values(1,'Y');
|
||||
insert into t33 values(1,'1');
|
||||
insert into t33 values(2,'2');
|
||||
select
|
||||
T5.issue_type
|
||||
,T6.is_type
|
||||
from
|
||||
(
|
||||
select T1.sec_code
|
||||
,issue_type
|
||||
--,case when list_profit_flag='Y' then '是' else '否' end as list_profit_flag
|
||||
from
|
||||
(
|
||||
select sec_code
|
||||
,case when issue_type in ('S04','S05','S06','S09') then '增发'
|
||||
when issue_type in ('S01','S02') then '首发'
|
||||
else '其他' end as issue_type
|
||||
from t11
|
||||
)T1
|
||||
left join
|
||||
(
|
||||
select list_profit_flag
|
||||
,company_code
|
||||
from t22
|
||||
)T2
|
||||
on T1.sec_code=T2.company_code
|
||||
)T5
|
||||
full join
|
||||
(
|
||||
SELECT CASE
|
||||
WHEN issue_flag = ANY (ARRAY['1'::bpchar, '3'::bpchar, '11'::bpchar]) THEN '首发'::text
|
||||
ELSE '增发'::text
|
||||
END AS is_type from t33
|
||||
)T6
|
||||
on T5.issue_type=T6.is_type
|
||||
;
|
||||
issue_type | is_type
|
||||
------------+---------
|
||||
增发 | 增发
|
||||
| 首发
|
||||
(2 rows)
|
||||
|
||||
|
|
@ -916,3 +916,4 @@ test: fdw_audit
|
|||
test: gs_global_config_audit
|
||||
test: detail
|
||||
test: gs_dump_encrypt
|
||||
test: join_test_alias
|
||||
|
|
|
|||
|
|
@ -0,0 +1,53 @@
|
|||
CREATE TABLE t11 (
|
||||
sec_code character(6) NOT NULL,
|
||||
issue_type character(3) NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE t22 (
|
||||
company_code character(6) NOT NULL,
|
||||
list_profit_flag character(1) NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE t33 (
|
||||
company_code character(6) NOT NULL,
|
||||
issue_flag character(6) NOT NULL
|
||||
);
|
||||
|
||||
insert into t11 values(1,'S04');
|
||||
insert into t22 values(1,'Y');
|
||||
insert into t33 values(1,'1');
|
||||
insert into t33 values(2,'2');
|
||||
|
||||
select
|
||||
T5.issue_type
|
||||
,T6.is_type
|
||||
from
|
||||
(
|
||||
select T1.sec_code
|
||||
,issue_type
|
||||
--,case when list_profit_flag='Y' then '是' else '否' end as list_profit_flag
|
||||
from
|
||||
(
|
||||
select sec_code
|
||||
,case when issue_type in ('S04','S05','S06','S09') then '增发'
|
||||
when issue_type in ('S01','S02') then '首发'
|
||||
else '其他' end as issue_type
|
||||
from t11
|
||||
)T1
|
||||
left join
|
||||
(
|
||||
select list_profit_flag
|
||||
,company_code
|
||||
from t22
|
||||
)T2
|
||||
on T1.sec_code=T2.company_code
|
||||
)T5
|
||||
full join
|
||||
(
|
||||
SELECT CASE
|
||||
WHEN issue_flag = ANY (ARRAY['1'::bpchar, '3'::bpchar, '11'::bpchar]) THEN '首发'::text
|
||||
ELSE '增发'::text
|
||||
END AS is_type from t33
|
||||
)T6
|
||||
on T5.issue_type=T6.is_type
|
||||
;
|
||||
Loading…
Reference in New Issue