I'm sorry for the flood of e-mails.
When I add a DISTINCT to the creation clause..
count( distinct case when gear in ( 3 , 4 ) then mpg end )*1
..then median() and prod() break as well! Here is the EXPLAIN and TRACE output. Sorry, I should've tried this on fake data sooner!
Now that I know I can re-create this error with public data, should I file a bug report? Thanks!!!!
sql>explain select median( gears ) from mtcars4;
+--------------------------------------------------------------------+
| mal |
+====================================================================+
| function user.s2_2{autoCommit=true}():void; |
| X_17 := nil:lng; |
| barrier X_34 := language.dataflow(); |
| X_2 := sql.mvc(); |
| X_3:bat[:oid,:oid] := sql.tid(X_2,"sys","mtcars4"); |
| X_6 := sql.bind(X_2,"sys","mtcars4","gears",0); |
| (X_9,r1_9) := sql.bind(X_2,"sys","mtcars4","gears",2); |
| X_12 := sql.bind(X_2,"sys","mtcars4","gears",1); |
| X_14 := sql.delta(X_6,X_9,r1_9,X_12); |
| X_15 := algebra.leftfetchjoin(X_3,X_14); |
| X_16 := algebra.selectNotNil(X_15); |
| X_17 := aggr.median(X_16); |
| exit X_34; |
| sql.exportValue(1,"sys.mtcars4","L1","bigint",53,0,6,X_17,""); |
| end s2_2; |
+--------------------------------------------------------------------+
15 tuples (2.267ms)
sql>explain select prod( gears ) from mtcars4;
+--------------------------------------------------------------------+
| mal |
+====================================================================+
| function user.s3_2{autoCommit=true}():void; |
| X_17:lng := nil:lng; |
| barrier X_34 := language.dataflow(); |
| X_2 := sql.mvc(); |
| X_3:bat[:oid,:oid] := sql.tid(X_2,"sys","mtcars4"); |
| X_6 := sql.bind(X_2,"sys","mtcars4","gears",0); |
| (X_9,r1_9) := sql.bind(X_2,"sys","mtcars4","gears",2); |
| X_12 := sql.bind(X_2,"sys","mtcars4","gears",1); |
| X_14 := sql.delta(X_6,X_9,r1_9,X_12); |
| X_15 := algebra.leftfetchjoin(X_3,X_14); |
| X_16 := algebra.selectNotNil(X_15); |
| X_17:lng := aggr.prod(X_16); |
| exit X_34; |
| sql.exportValue(1,"sys.mtcars4","L1","bigint",53,0,6,X_17,""); |
| end s3_2; |
+--------------------------------------------------------------------+
15 tuples (2.173ms)
sql>trace select prod( gears ) from mtcars4;
+------+
| L1 |
+======+
| 0 |
+------+
1 tuple (38.356ms)
+------+----------------------------------------------------------------------+
| tick | stmt |
: s : :
+======+======================================================================+
| 1 | X_17:lng := nil:lng; |
| 3 | X_2 := sql.mvc(); |
| 15 | X_3:bat[:oid,:oid] =<tmp_1070>[6] := sql.tid(X_2=0,"sys","mtcars4"); |
| 16 | X_12=<tmp_33>[0] := sql.bind(X_2=0,"sys","mtcars4","gears",1); |
| 15 | (X_9=<tmp_21>[0],r1_9=<tmp_33>[0]) := sql.bind(X_2=0,"sys","mtcars4" |
: : ,"gears",2); :
| 5 | X_6=<tmp_1237>[6] := sql.bind(X_2=0,"sys","mtcars4","gears",0); |
| 4 | X_14=<tmp_1237>[6] := sql.delta(X_6=<tmp_1237>[6],X_9=<tmp_21>[0],r1 |
: : _9=<tmp_33>[0],X_12=<tmp_33>[0]); :
| 16 | X_15=<tmp_1005>[6] := algebra.leftfetchjoin(X_3=<tmp_1070>:bat[:oid, |
: : :oid][6],X_14=<tmp_1237>[6]); :
| 5 | X_16=<tmp_1005>[6] := algebra.selectNotNil(X_15=<tmp_1005>[6]); |
| 25 | X_17:lng := aggr.prod(X_16=<tmp_1005>[6]); |
| 877 | barrier X_34 := language.dataflow(); |
| 7 | sql.exportValue(1,"sys.mtcars4","L1","bigint",53,0,6,X_17=0:lng,""); |
| 2 | end s3_2; |
| 1073 | X_5:void := user.s3_2(); |
+------+----------------------------------------------------------------------+
14 tuples (43.881ms)
sql>trace select median( gears ) from mtcars4;
+------+
| L1 |
+======+
| 3 |
+------+
1 tuple (5.458ms)
+------+----------------------------------------------------------------------+
| tick | stmt |
: s : :
+======+======================================================================+
| 2 | X_17 := nil:lng; |
| 5 | X_2 := sql.mvc(); |
| 72 | X_3:bat[:oid,:oid] =<tmp_1152>[6] := sql.tid(X_2=0,"sys","mtcars4"); |
| 19 | X_12=<tmp_33>[0] := sql.bind(X_2=0,"sys","mtcars4","gears",1); |
| 19 | (X_9=<tmp_21>[0],r1_9=<tmp_33>[0]) := sql.bind(X_2=0,"sys","mtcars4" |
: : ,"gears",2); :
| 10 | X_6=<tmp_1237>[6] := sql.bind(X_2=0,"sys","mtcars4","gears",0); |
| 7 | X_14=<tmp_1237>[6] := sql.delta(X_6=<tmp_1237>[6],X_9=<tmp_21>[0],r1 |
: : _9=<tmp_33>[0],X_12=<tmp_33>[0]); :
| 28 | X_15=<tmp_1235>[6] := algebra.leftfetchjoin(X_3=<tmp_1152>:bat[:oid, |
: : :oid][6],X_14=<tmp_1237>[6]); :
| 12 | X_16=<tmp_1235>[6] := algebra.selectNotNil(X_15=<tmp_1235>[6]); |
| 63 | bn=<tmp_1231>[1] := aggr.submedian(b=<tmp_1235>[6],false); |
| 7 | return X_4 := algebra.fetch(bn=<tmp_1231>[1],0); |
| 145 | X_17 := aggr.median(X_16=<tmp_1235>[6]); |
| 1280 | barrier X_34 := language.dataflow(); |
| 11 | sql.exportValue(1,"sys.mtcars4","L1","bigint",53,0,6,X_17=3:lng,""); |
| 3 | end s2_2; |
| 1614 | X_5:void := user.s2_2(); |
+------+----------------------------------------------------------------------+
16 tuples (16.329ms)
sql>