> Thanx for the suggestion. It works with the setting you suggested. > > What does this mean? Do I need to special case this query.
You need to report a bug on https://issues.apache.org/jira/browse/HIVE Because, this needs to get fixed. > Turning off CBO cluster-wide won't be the right thing to do, would it? Nope, CBO is a good thing - a workaround would be to try what Sergey suggested, the '$f0' is probably the auto-generated name for the count(0). Naming that column explicitly on both branches of the UNION ALL, might get CBO back up. Cheers, Gopal