zhouqingqing / qpmodel

A Relational Optimizer and Executor
MIT License
64 stars 18 forks source link

Aggregate average contamination #181

Closed arzuschen closed 3 years ago

arzuschen commented 3 years ago

when aggregate need to produce averages, the average output is the same across groups. It is likely that the AggAvg object is contaminated when switching between different groups.

example: (tpch0001) sql = @"select l_returnflag, l_linestatus, avg(l_quantity) as avg_qty, avg(l_extendedprice) as avg_price, avg(l_discount) as avg_disc from lineitem where l_shipdate <= date '1998-12-01' - interval '90' day group by l_returnflag, l_linestatus order by l_returnflag, l_linestatus";

output from PostgreSQL: l_returnflag | l_linestatus | avg_qty | avg_price | avg_disc --------------+--------------+------------------+------------------+-------------------- A | F | 25.3545331529093 | 25419.2318267929 | 0.0508660351826795 N | F | 27.3947368421053 | 27402.6597368421 | 0.0428947368421053 N | O | 25.5586535192112 | 25632.4227711662 | 0.0496973818429107 R | F | 25.0590253946465 | 25100.0969389156 | 0.0500274536719287

zhouqingqing commented 3 years ago

yes, I just noticed that - that's a bug.