Inconsistant results with "Rollup" & "count distinct" in V2R6?

Database
Fan

Inconsistant results with "Rollup" & "count distinct" in V2R6?

I've run into a problem with a report, where I'd like to use grouping sets and rollups to summarize a few hundred million transactions. Here's a test case showing my problem, but with only fifteen rows.

It starts with a two tables, one showing sales, another showing "bonus programs" that some customers subscribe to:

Sales
txn_id txn_date item price cust_id
1 2009/02/01 shirt $30 1
2 2009/02/01 pants $50 1
3 2009/02/02 shirt $15 2
4 2009/02/02 skirt $25 2
5 2009/02/02 skirt $40 3
6 2009/02/02 belt $12 4
7 2009/02/02 watch $100 4
8 2009/02/03 pants $60 4
9 2009/02/03 belt $30 5
10 2009/02/03 socks $4 6

Bonus_program
cust_id bonus_type
2 1
3 2
4 1
5 1
6 2

Let’s say we want to see some totals and counts for sales by bonus program, plus all sales that are to customers with no bonus programs:

select b.bonus_type,
sum(s.price) tot, count(distinct s.cust_id) num_custs, count(distinct s.txn_date) num_days
from Sales s
left join Bonus_program b
on s.cust_id = b.cust_id
group by b.bonus_type
order by b.bonus_type;

bonus_type tot num_custs num_days
? 80 1 1
1 242 3 2
2 44 2 2

That’s perfect. Now, let’s say I want to also get a total, and do it with a rollup:

select b.bonus_type btype, grouping(b.bonus_type) grping,
sum(s.price) tot, count(distinct s.cust_id) num_custs, count(distinct s.txn_date) num_days
from Sales s
left join Bonus_program b
on s.cust_id = b.cust_id
group by rollup(b.bonus_type)
order by b.bonus_type;

btype grping tot num_custs num_days
? 1 366 6 3
? 1 366 1 3
? 0 80 6 1
? 0 80 1 1
1 0 242 3 2
2 0 44 2 2

Why are the rows with a null bonus_type doubled, with different customer counts, but other columns identical?

I've tried wrapping it up in a subselect, using "grouping sets" or "cube", and putting bonus_type inside "zeroifnull", and gotten the same results or worse. We're using "Teradata Database Release is V2R.06.01.01.97" . Edit--> Same results with V12.0 Demo, running on my laptop. If this is a bug, then it's still in later TD releases.

If you want to try it in your own db, here's the sql to create the sample tables:

create table Sales(
txn_id integer ,
txn_date date,
item char(30),
price decimal (6,2),
cust_id integer
) unique primary index(txn_id);

insert into Sales values(1, '2009/02/01','shirt',30 ,1);
insert into Sales values(2, '2009/02/01','pants',50 ,1);
insert into Sales values(3, '2009/02/02','shirt',15 ,2);
insert into Sales values(4, '2009/02/02','skirt',25 ,2);
insert into Sales values(5, '2009/02/02','skirt',40 ,3);
insert into Sales values(6, '2009/02/02','belt',12 ,4);
insert into Sales values(7, '2009/02/02','watch',100 ,4);
insert into Sales values(8, '2009/02/03','pants',60 ,4);
insert into Sales values(9, '2009/02/03','belt',30 ,5);
insert into Sales values(10,'2009/02/03','socks',4 ,6);

create table Bonus_program(
cust_id integer,
bonus_type smallint
) unique primary index(cust_id);

insert into Bonus_program values(2,1);
insert into Bonus_program values(3,2);
insert into Bonus_program values(4,1);
insert into Bonus_program values(5,1);
insert into Bonus_program values(6,2);