I ran those queries against Calcite. Calcite gives the correct result. 
RelFieldTrimmer does the right thing.

I was explaining, in simple terms, what would break if you made your proposed 
change to RelFieldTrimmer.

> On Jun 2, 2021, at 3:12 PM, Sean Broeder <[email protected]> wrote:
> 
> 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 <[email protected]> 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 <[email protected]> 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