原2.0.版本升级2.1.6后UNION ALL 查询常量字段作为条件查询结果返回为空

Viewed 42

with base as (
select
concat(pj_no, unit) as project_unit, WCL, radio, 'TR' as file_type
from
TR
where type = 'day'
UNION ALL
select
concat(pj_no, unit) as project_unit, WCL, radio, 'TP' as file_type
from
TP
where type = 'day'
UNION ALL
select
concat(pj_no, unit) as project_unit,WCL, radio, 'CFA' as file_type
from
CFA
where type = 'day'
)

select
FCD,
file_type,
max(case when project_unit = 'AA1' then WCL else 0 end) as 'AA1完成量',
max(case when project_unit = 'AA1' then radio else 0 end) as 'AA1完成比率',
max(case when project_unit = 'AB1' then WCL else 0 end) as 'AB1完成量',
max(case when project_unit = 'AB1' then radio else 0 end) as 'AB1完成比率',
max(case when project_unit = 'AN1' then WCL else 0 end) as 'AN1完成量',
max(case when project_unit = 'AN1' then radio else 0 end) as 'AN1完成比率',
max(case when project_unit = 'BJ1' then WCL else 0 end) as 'BJ1完成量',
max(case when project_unit = 'BJ1' then radio else 0 end) as 'BJ1完成比率'
from base as a
where file_type = 'TR'
group by FCD, a.file_type

原2.0.版本正常,升级2.1.6后的问题: where file_type = 'TR' 可以查询结果,where file_type = 'TP' or where file_type = 'CFA' 返回结果为空,如果不加条件,所有结果都可以返回。即(查询条件为union第一个select语句字段,可以返回结果,否则不返回查询结果);

1 Answers

问题未复现,用户开启新优化器之后,暂无这个问题。默认情况下,新优化器是开的