Dear all,
I have been trying to integrate a BAT UDF to test the performance of MonetDB for a particular query.
I am currently testing on Ubuntu 13.04 with MonetDB 11.15.19.
My BAT UDF works in some cases and in others fails with the error message "b and g must be aligned" in gdk_aggr.c:89. Using gdb I can see that the BATcount() function returns different values for the length of b and g.
For a minimal test case, I created a very simple BAT UDF that just multiples two doubles together in the input bats.
I believe this is related to bug 3396 as passing --forcemito to mserver triggers the bug.
If only the scalar version of the UDF is defined the query works correctly in all cases.
Below I have included my test sql and the query plans of the working and non-working usages.
I hope this enough to help track this down.
Best regards,
Alastair
// SQL
create table tab1 (group_by_col int, index_col int, f float);
create table tab2 (index_col int, f float);
insert into tab1 values (1,1,0.1),(1,2,0.2),(2,1,0.3),(2,2,0.4),(3,1,0.5),(3,2,0.6);
insert into tab2 values (1,0.1),(2,0.2);
select tab1.group_by_col,SUM(udf_multiply_dbl(tab1.f,tab2.f))
from tab2 inner join tab1 on tab1.index_col = tab2.index_col
group by tab1.group_by_col;
drop table tab1;
drop table tab2;
// Working MAL
+-------------------------------------------------------------------------+
| mal |
+=========================================================================+
| function user.s2_1{autoCommit=true}():void; |
| X_36 := nil:bat[:oid,:int]; |
| X_57:bat[:oid,:dbl] := nil:bat[:oid,:dbl]; |
| barrier X_86 := language.dataflow(); |
| X_2 := sql.mvc(); |
| X_3:bat[:oid,:oid] := sql.tid(X_2,"sys","tab1"); |
| X_6 := sql.bind(X_2,"sys","tab1","index_col",0); |
| (X_9,r1_9) := sql.bind(X_2,"sys","tab1","index_col",2); |
| X_12 := sql.bind(X_2,"sys","tab1","index_col",1); |
| X_14 := sql.delta(X_6,X_9,r1_9,X_12); |
| X_15 := algebra.leftfetchjoin(X_3,X_14); |
| X_16:bat[:oid,:oid] := sql.tid(X_2,"sys","tab2"); |
| X_18 := sql.bind(X_2,"sys","tab2","index_col",0); |
| (X_19,r1_19) := sql.bind(X_2,"sys","tab2","index_col",2); |
| X_21 := sql.bind(X_2,"sys","tab2","index_col",1); |
| X_22 := sql.delta(X_18,X_19,r1_19,X_21); |
| X_23 := algebra.leftfetchjoin(X_16,X_22); |
| (X_24,r1_24) := algebra.join(X_15,X_23); |
| X_85 := algebra.leftfetchjoin(X_24,X_3); |
| X_26 := sql.bind(X_2,"sys","tab1","group_by_col",0); |
| (X_28,r1_28) := sql.bind(X_2,"sys","tab1","group_by_col",2); |
| X_30 := sql.bind(X_2,"sys","tab1","group_by_col",1); |
| X_31 := sql.delta(X_26,X_28,r1_28,X_30); |
| X_32:bat[:oid,:int] := algebra.leftfetchjoin(X_85,X_31); |
| (X_33,r1_34,r2_34) := group.subgroupdone(X_32); |
| X_36 := algebra.leftfetchjoin(r1_34,X_32); |
| X_37 := sql.bind(X_2,"sys","tab1","f",0); |
| (X_42,r1_43) := sql.bind(X_2,"sys","tab1","f",2); |
| X_45 := sql.bind(X_2,"sys","tab1","f",1); |
| X_47 := sql.delta(X_37,X_42,r1_43,X_45); |
| X_48:bat[:oid,:dbl] := algebra.leftfetchjoin(X_85,X_47); |
| X_49 := sql.bind(X_2,"sys","tab2","f",0); |
| (X_51,r1_53) := sql.bind(X_2,"sys","tab2","f",2); |
| X_53 := sql.bind(X_2,"sys","tab2","f",1); |
| X_54 := sql.delta(X_49,X_51,r1_53,X_53); |
| X_55:bat[:oid,:dbl] := algebra.leftfetchjoinPath(r1_24,X_16,X_54); |
| X_56:bat[:oid,:dbl] := batudf.udf_multiply_dbl(X_48,X_55); |
| X_57:bat[:oid,:dbl] := aggr.subsum(X_56,X_33,r1_34,true,true); |
| language.pass(X_3); |
| language.pass(X_32); |
| language.pass(X_85); |
| language.pass(X_16); |
| language.pass(r1_34); |
| exit X_86; |
| X_59 := sql.resultSet(2,1,X_36); |
| sql.rsColumn(X_59,"sys.tab1","group_by_col","int",32,0,X_36); |
| sql.rsColumn(X_59,"sys.L1","L1","double",53,0,X_57); |
| X_71 := io.stdout(); |
| sql.exportResult(X_71,X_59); |
| end s2_1; |
+-------------------------------------------------------------------------+
// Non working MAL with --forcemito
+-------------------------------------------------------------------------------------------------------+
| mal |
+=======================================================================================================+
| function user.s2_1{autoCommit=true}():void; |
| X_23 := nil:bat[:oid,:int]; |
| X_41:bat[:oid,:dbl] := nil:bat[:oid,:dbl]; |
| barrier X_196 := language.dataflow(); |
| X_2 := sql.mvc(); |
| X_70:bat[:oid,:oid] := sql.tid(X_2,"sys","tab1",0,4); |
| X_78:bat[:oid,:int] := sql.bind(X_2,"sys","tab1","index_col",0,0,4); |
| (X_82:bat[:oid,:oid] ,X_83:bat[:oid,:int] ) := sql.bind(X_2,"sys","tab1","index_col",2,0,4); |
| X_119 := sql.delta(X_78,X_82,X_83); |
| X_123 := algebra.leftfetchjoin(X_70,X_119); |
| X_10:bat[:oid,:oid] := sql.tid(X_2,"sys","tab2"); |
| X_12 := sql.bind(X_2,"sys","tab2","index_col",0); |
| (X_13,r1_19) := sql.bind(X_2,"sys","tab2","index_col",2); |
| X_15 := sql.bind(X_2,"sys","tab2","index_col",1); |
| X_16 := sql.delta(X_12,X_13,r1_19,X_15); |
| X_17 := algebra.leftfetchjoin(X_10,X_16); |
| (X_127,X_128) := algebra.join(X_123,X_17); |
| X_180 := algebra.leftfetchjoin(X_127,X_70); |
| X_90:bat[:oid,:int] := sql.bind(X_2,"sys","tab1","group_by_col",0,0,4); |
| (X_94:bat[:oid,:oid] ,X_95:bat[:oid,:int] ) := sql.bind(X_2,"sys","tab1","group_by_col",2,0,4); |
| X_136 := sql.delta(X_90,X_94,X_95); |
| X_143:bat[:oid,:int] := algebra.leftfetchjoin(X_180,X_136); |
| (X_147,X_148,X_149) := group.subgroupdone(X_143); |
| X_150 := algebra.leftfetchjoin(X_148,X_143); |
| X_72:bat[:oid,:oid] := sql.tid(X_2,"sys","tab1",1,4); |
| X_79:bat[:oid,:int] := sql.bind(X_2,"sys","tab1","index_col",0,1,4); |
| (X_84:bat[:oid,:oid] ,X_85:bat[:oid,:int] ) := sql.bind(X_2,"sys","tab1","index_col",2,1,4); |
| X_120 := sql.delta(X_79,X_84,X_85); |
| X_124 := algebra.leftfetchjoin(X_72,X_120); |
| (X_129,X_130) := algebra.join(X_124,X_17); |
| X_181 := algebra.leftfetchjoin(X_129,X_72); |
| X_91:bat[:oid,:int] := sql.bind(X_2,"sys","tab1","group_by_col",0,1,4); |
| (X_96:bat[:oid,:oid] ,X_97:bat[:oid,:int] ) := sql.bind(X_2,"sys","tab1","group_by_col",2,1,4); |
| X_138 := sql.delta(X_91,X_96,X_97); |
| X_144:bat[:oid,:int] := algebra.leftfetchjoin(X_181,X_138); |
| (X_151,X_152,X_153) := group.subgroupdone(X_144); |
| X_154 := algebra.leftfetchjoin(X_152,X_144); |
| X_74:bat[:oid,:oid] := sql.tid(X_2,"sys","tab1",2,4); |
| X_80:bat[:oid,:int] := sql.bind(X_2,"sys","tab1","index_col",0,2,4); |
| (X_86:bat[:oid,:oid] ,X_87:bat[:oid,:int] ) := sql.bind(X_2,"sys","tab1","index_col",2,2,4); |
| X_121 := sql.delta(X_80,X_86,X_87); |
| X_125 := algebra.leftfetchjoin(X_74,X_121); |
| (X_131,X_132) := algebra.join(X_125,X_17); |
| X_182 := algebra.leftfetchjoin(X_131,X_74); |
| X_92:bat[:oid,:int] := sql.bind(X_2,"sys","tab1","group_by_col",0,2,4); |
| (X_98:bat[:oid,:oid] ,X_99:bat[:oid,:int] ) := sql.bind(X_2,"sys","tab1","group_by_col",2,2,4); |
| X_140 := sql.delta(X_92,X_98,X_99); |
| X_145:bat[:oid,:int] := algebra.leftfetchjoin(X_182,X_140); |
| (X_155,X_156,X_157) := group.subgroupdone(X_145); |
| X_158 := algebra.leftfetchjoin(X_156,X_145); |
| X_76:bat[:oid,:oid] := sql.tid(X_2,"sys","tab1",3,4); |
| X_81:bat[:oid,:int] := sql.bind(X_2,"sys","tab1","index_col",0,3,4); |
| (X_88:bat[:oid,:oid] ,X_89:bat[:oid,:int] ) := sql.bind(X_2,"sys","tab1","index_col",2,3,4); |
| X_8 := sql.bind(X_2,"sys","tab1","index_col",1); |
| X_122 := sql.delta(X_81,X_88,X_89,X_8); |
| X_126 := algebra.leftfetchjoin(X_76,X_122); |
| (X_133,X_134) := algebra.join(X_126,X_17); |
| X_183 := algebra.leftfetchjoin(X_133,X_76); |
| X_93:bat[:oid,:int] := sql.bind(X_2,"sys","tab1","group_by_col",0,3,4); |
| (X_100:bat[:oid,:oid] ,X_101:bat[:oid,:int] ) := sql.bind(X_2,"sys","tab1","group_by_col",2,3,4); |
| X_19 := sql.bind(X_2,"sys","tab1","group_by_col",1); |
| X_142 := sql.delta(X_93,X_100,X_101,X_19); |
| X_146:bat[:oid,:int] := algebra.leftfetchjoin(X_183,X_142); |
| (X_159,X_160,X_161) := group.subgroupdone(X_146); |
| X_162 := algebra.leftfetchjoin(X_160,X_146); |
| X_184 := mat.packIncrement(X_150,4); |
| X_185 := mat.packIncrement(X_184,X_154); |
| X_186 := mat.packIncrement(X_185,X_158); |
| X_20 := mat.packIncrement(X_186,X_162); |
| (X_21,r1_34,X_163) := group.subgroupdone(X_20); |
| X_23 := algebra.leftfetchjoin(r1_34,X_20); |
| X_103:bat[:oid,:dbl] := sql.bind(X_2,"sys","tab1","f",0,0,4); |
| (X_111:bat[:oid,:oid] ,X_112:bat[:oid,:dbl] ) := sql.bind(X_2,"sys","tab1","f",2,0,4); |
| X_168 := sql.delta(X_103,X_111,X_112); |
| X_172:bat[:oid,:dbl] := algebra.leftfetchjoin(X_180,X_168); |
| X_105:bat[:oid,:dbl] := sql.bind(X_2,"sys","tab1","f",0,1,4); |
| (X_113:bat[:oid,:oid] ,X_114:bat[:oid,:dbl] ) := sql.bind(X_2,"sys","tab1","f",2,1,4); |
| X_169 := sql.delta(X_105,X_113,X_114); |
| X_173:bat[:oid,:dbl] := algebra.leftfetchjoin(X_181,X_169); |
| X_107:bat[:oid,:dbl] := sql.bind(X_2,"sys","tab1","f",0,2,4); |
| (X_115:bat[:oid,:oid] ,X_116:bat[:oid,:dbl] ) := sql.bind(X_2,"sys","tab1","f",2,2,4); |
| X_170 := sql.delta(X_107,X_115,X_116); |
| X_174:bat[:oid,:dbl] := algebra.leftfetchjoin(X_182,X_170); |
| X_109:bat[:oid,:dbl] := sql.bind(X_2,"sys","tab1","f",0,3,4); |
| (X_117:bat[:oid,:oid] ,X_118:bat[:oid,:dbl] ) := sql.bind(X_2,"sys","tab1","f",2,3,4); |
| X_29 := sql.bind(X_2,"sys","tab1","f",1); |
| X_171 := sql.delta(X_109,X_117,X_118,X_29); |
| X_175:bat[:oid,:dbl] := algebra.leftfetchjoin(X_183,X_171); |
| X_188 := mat.packIncrement(X_172,4); |
| X_189 := mat.packIncrement(X_188,X_173); |
| X_190 := mat.packIncrement(X_189,X_174); |
| X_31 := mat.packIncrement(X_190,X_175); |
| X_32 := sql.bind(X_2,"sys","tab2","f",0); |
| (X_34,r1_53) := sql.bind(X_2,"sys","tab2","f",2); |
| X_36 := sql.bind(X_2,"sys","tab2","f",1); |
| X_37 := sql.delta(X_32,X_34,r1_53,X_36); |
| X_38 := algebra.leftfetchjoin(X_10,X_37); |
| X_176 := algebra.leftfetchjoin(X_128,X_38); |
| X_177 := algebra.leftfetchjoin(X_130,X_38); |
| X_178 := algebra.leftfetchjoin(X_132,X_38); |
| X_179 := algebra.leftfetchjoin(X_134,X_38); |
| X_192 := mat.packIncrement(X_176,4); |
| X_193 := mat.packIncrement(X_192,X_177); |
| X_194 := mat.packIncrement(X_193,X_178); |
| X_39 := mat.packIncrement(X_194,X_179); |
| X_40:bat[:oid,:dbl] := batudf.udf_multiply_dbl(X_31,X_39); |
| X_41:bat[:oid,:dbl] := aggr.subsum(X_40,X_21,r1_34,true,true); |
| language.pass(X_70); |
| language.pass(X_143); |
| language.pass(X_72); |
| language.pass(X_144); |
| language.pass(X_74); |
| language.pass(X_145); |
| language.pass(X_17); |
| language.pass(X_76); |
| language.pass(X_146); |
| language.pass(X_20); |
| language.pass(X_180); |
| language.pass(X_181); |
| language.pass(X_182); |
| language.pass(X_183); |
| language.pass(X_10); |
| language.pass(X_38); |
| language.pass(r1_34); |
| exit X_196; |
| X_187:bat[:oid,:int] := nil:bat[:oid,:int]; |
| X_191:bat[:oid,:dbl] := nil:bat[:oid,:dbl]; |
| X_195:bat[:oid,:dbl] := nil:bat[:oid,:dbl]; |
| X_43 := sql.resultSet(2,1,X_23); |
| sql.rsColumn(X_43,"sys.tab1","group_by_col","int",32,0,X_23); |
| sql.rsColumn(X_43,"sys.L1","L1","double",53,0,X_41); |
| X_55 := io.stdout(); |
| sql.exportResult(X_55,X_43); |
| end s2_1; |
+-------------------------------------------------------------------------------------------------------+