Thank you Julian.  

I am able to reproduce your findings.  

I am curious if the results highlight a bug in Calcite where we should expect 4 
to be returned or is this a query that Calcite should not support?

Sean

> On Jun 2, 2021, at 11:37 AM, Julian Hyde <jhyde.apa...@gmail.com> wrote:
> 
> Here’s a query that would give the wrong answer if you trim:
> 
>  select count(*) from (
>    select deptno from scott.emp
>    union
>    select deptno from scott.dept);
> 
> returns 4. Note that ‘deptno’ is not used. But when I trim it away,
> 
>  select count(*) from (
>    select 'a' from scott.emp
>    union
>    select 'a' from scott.dept);
> 
> returns 1. (I included ‘a’ because SQL doesn’t allow an empty SELECT clause. 
> It doesn’t affect the reasoning.)
> 
> Julian
> 
> 
> 
>> On Jun 2, 2021, at 6:03 AM, Sean Broeder <sbroe...@apache.org> wrote:
>> 
>> Currently the RefFieldTrimmer only trims on a UNION ALL operation.  I've
>> been experimenting to see if it is also possible to trim on UNION
>> DISTINCT.  Is there a simple query that demonstrates why this is not
>> possible?
>> 
>> Thanks,
>> Sean
> 

Reply via email to