Changeset: c753f09da805 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/c753f09da805 Modified Files: monetdb5/modules/mal/properties.c monetdb5/modules/mal/properties.h monetdb5/optimizer/opt_prelude.c monetdb5/optimizer/opt_prelude.h monetdb5/optimizer/opt_properties.c sql/backends/monet5/sql_optimizer.c Branch: types Log Message:
Gathering some basic properties and keep them in the MAL plan diffs (219 lines): diff --git a/monetdb5/modules/mal/properties.c b/monetdb5/modules/mal/properties.c --- a/monetdb5/modules/mal/properties.c +++ b/monetdb5/modules/mal/properties.c @@ -19,7 +19,7 @@ // dummy procedures to monitor the generation of the properties code. str -PROPget(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) +PROPinfo(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) { (void) cntxt; (void) mb; @@ -48,10 +48,10 @@ PROPbind(Client cntxt, MalBlkPtr mb, Mal #include "mel.h" mel_func properties_init_funcs[] = { pattern("properties", "bind", PROPbind, false, "Retrieve actual properties from a BAT", args(1,3, arg("",void),batargany("",1),arg("min",int))), - pattern("properties", "get", PROPget, false, "Retrieve actual properties from a BAT", args(1,5, arg("",void),batargany("",1),arg("min",bte),arg("max",bte),arg("nils",lng) )), - pattern("properties", "get", PROPget, false, "Retrieve actual properties from a BAT", args(1,5, arg("",void),batargany("",1),arg("min",sht),arg("max",sht),arg("nils",lng) )), - pattern("properties", "get", PROPget, false, "Retrieve actual properties from a BAT", args(1,5, arg("",void),batargany("",1),arg("min",int),arg("max",int),arg("nils",lng) )), - pattern("properties", "get", PROPget, false, "Retrieve actual properties from a BAT", args(1,5, arg("",void),batargany("",1),arg("min",lng),arg("max",lng),arg("nils",lng) )), + pattern("properties", "info", PROPinfo, false, "Retrieve actual properties from a BAT", args(1,5, arg("",void),batargany("",1),arg("min",bte),arg("max",bte),arg("cnt",lng) )), + pattern("properties", "info", PROPinfo, false, "Retrieve actual properties from a BAT", args(1,5, arg("",void),batargany("",1),arg("min",sht),arg("max",sht),arg("cnt",lng) )), + pattern("properties", "info", PROPinfo, false, "Retrieve actual properties from a BAT", args(1,5, arg("",void),batargany("",1),arg("min",int),arg("max",int),arg("cnt",lng) )), + pattern("properties", "info", PROPinfo, false, "Retrieve actual properties from a BAT", args(1,5, arg("",void),batargany("",1),arg("min",lng),arg("max",lng),arg("cnt",lng) )), { .imp=NULL } }; #include "mal_import.h" diff --git a/monetdb5/modules/mal/properties.h b/monetdb5/modules/mal/properties.h --- a/monetdb5/modules/mal/properties.h +++ b/monetdb5/modules/mal/properties.h @@ -11,6 +11,6 @@ #include "mal.h" #include "mal_interpreter.h" -mal_export str PROPget(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); +mal_export str PROPinfo(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); mal_export str PROPbind(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); #endif /* _PROPS_H */ diff --git a/monetdb5/optimizer/opt_prelude.c b/monetdb5/optimizer/opt_prelude.c --- a/monetdb5/optimizer/opt_prelude.c +++ b/monetdb5/optimizer/opt_prelude.c @@ -153,6 +153,7 @@ const char *identityRef; const char *ifthenelseRef; const char *importColumnRef; const char *importTableRef; +const char *infoRef; const char *intersectcandRef; const char *intersectRef; const char *intRef; @@ -462,6 +463,7 @@ void optimizerInit(void) ifthenelseRef = putName("ifthenelse"); importColumnRef = putName("importColumn"); importTableRef = putName("importTable"); + infoRef= putName("info"); intersectcandRef= putName("intersectcand"); intersectRef = putName("intersect"); intRef = putName("int"); diff --git a/monetdb5/optimizer/opt_prelude.h b/monetdb5/optimizer/opt_prelude.h --- a/monetdb5/optimizer/opt_prelude.h +++ b/monetdb5/optimizer/opt_prelude.h @@ -150,6 +150,7 @@ mal_export const char *identityRef; mal_export const char *ifthenelseRef; mal_export const char *importColumnRef; mal_export const char *importTableRef; +mal_export const char *infoRef; mal_export const char *intersectcandRef; mal_export const char *intersectRef; mal_export const char *intRef; diff --git a/monetdb5/optimizer/opt_properties.c b/monetdb5/optimizer/opt_properties.c --- a/monetdb5/optimizer/opt_properties.c +++ b/monetdb5/optimizer/opt_properties.c @@ -9,7 +9,7 @@ /* author M.Kersten * This optimizer is used to scale-down columns when properties * of the underlying BATs permits it. - * The effect should be a smaller footprint. + * The effect should be a smaller intermediate footprint. */ #include "monetdb_config.h" #include "mal_builder.h" @@ -18,22 +18,56 @@ #define properties(TPE) \ val = BATmax_skipnil(bn, (void*) (&vmax.val.TPE), 1);\ + vmax.vtype = basetype;\ + restype =scaledown(&vmax);\ if( val != &vmax.val.TPE){\ + assert(0);\ /* error */\ }\ val = BATmin_skipnil(bn, (void*) (&vmin.val.TPE), 1);\ + vmin.vtype = basetype;\ + restype =scaledown(&vmin);\ if( val != &vmin.val.TPE){\ /* error */\ } -#define keeparound(TPE)\ +#define keeparound(T, TPE)\ + q = newStmt(mb, propertiesRef, infoRef);\ setArgType(mb, q, 0, TYPE_void);\ q = pushArgument(mb, q, getArg(pci,1));\ - q = pushInt(mb, q, vmin.val.TPE);\ - q = pushInt(mb, q, vmax.val.TPE);\ - q = pushLng(mb, q, nils); + q = push##T(mb, q, vmin.val.TPE);\ + q = push##T(mb, q, vmax.val.TPE);\ + q = pushLng(mb, q, cnt);\ + q->token = REMsymbol + +static int +scaledown(ValPtr v){ + switch(v->vtype){ +#ifdef HAVE_HGE + case TYPE_hge: + if( v->val.lval > - INT_MAX && v->val.lval < INT_MAX){ + v->vtype = TYPE_int; + } else break; +#endif + case TYPE_lng: + if( v->val.lval > - INT_MAX && v->val.lval < INT_MAX){ + v->vtype = TYPE_int; + } else break; + case TYPE_int: + if( v->val.ival > -(1<<16) && v->val.ival < 1<<16){ + v->vtype = TYPE_sht; + } else break; + case TYPE_sht: + if( v->val.shval > -128 && v->val.shval <128){ + v->vtype = TYPE_bte; + } else break; + case TYPE_bte: + break; + } + return v->vtype; +} static str PROPstatistics(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) @@ -41,20 +75,22 @@ PROPstatistics(Client cntxt, MalBlkPtr m InstrPtr q; bat bid; BAT *b, *bn; - int tpe = TYPE_int, basetype= TYPE_any; + int restype = TYPE_any, basetype= TYPE_any; ValRecord vmin, vmax; - lng nils=5; + lng cnt = 0; ptr val; (void) cntxt; (void) mb; (void) stk; + vmin.val.lval = vmax.val.lval = 0; + vmin.vtype = vmax.vtype = TYPE_void; bid = getVarConstant(mb, getArg(pci, 2)).val.ival; basetype = getBatType(getArgType(mb, pci,1)); switch(basetype){ - case TYPE_bte: case TYPE_sht: case TYPE_int: case TYPE_lng: case TYPE_hge: break; + case TYPE_bte: case TYPE_sht: case TYPE_int: case TYPE_lng: case TYPE_hge: case TYPE_flt: case TYPE_dbl: case TYPE_oid:break; default: return MAL_SUCCEED; } @@ -62,18 +98,35 @@ PROPstatistics(Client cntxt, MalBlkPtr m throw(MAL, "algebra.max", SQLSTATE(HY002) RUNTIME_OBJECT_MISSING); } bn = VIEWcreate(b->hseqbase, b); + cnt = (lng) BATcount(bn); // Access a BAT and derive the properties switch(basetype){ - case TYPE_bte: properties(btval); break; - case TYPE_int: properties(ival); break; + case TYPE_bte: properties(btval); break; + case TYPE_sht: properties(shval); break; + case TYPE_int: properties(ival); break; + case TYPE_lng: properties(lval); break; +#ifdef HAVE_HGE + case TYPE_hge: properties(hval); break; +#endif + case TYPE_flt: properties(fval); break; + case TYPE_dbl: properties(dval); break; + case TYPE_oid: properties(oval); break; } // Consolidate the type, looking for the minimum type needed for the min/max value; // Leave the properties behind in the plan - q = newStmt(mb, propertiesRef, getRef); - switch(tpe){ - case TYPE_int: keeparound(ival); break; + switch(restype){ + case TYPE_bte: keeparound(Bte, btval); break; + case TYPE_sht: keeparound(Sht, shval); break; + case TYPE_int: keeparound(Int, ival); break; + case TYPE_lng: keeparound(Lng, lval); break; +#ifdef HAVE_HGE + case TYPE_hge: keeparound(Hge, hval); break; +#endif + case TYPE_flt: keeparound(Flt, fval); break; + case TYPE_dbl: keeparound(Dbl, dval); break; + case TYPE_oid: keeparound(Oid, oval); break; } BBPunfix(bn->batCacheid); BBPunfix(b->batCacheid); diff --git a/sql/backends/monet5/sql_optimizer.c b/sql/backends/monet5/sql_optimizer.c --- a/sql/backends/monet5/sql_optimizer.c +++ b/sql/backends/monet5/sql_optimizer.c @@ -97,6 +97,7 @@ SQLgetSpace(mvc *m, MalBlkPtr mb, int pr q = newStmt(mb, propertiesRef, bindRef); q = pushArgument(mb, q, getArg(p,0)); q = pushInt(mb, q, bid); + q->token = REMsymbol; } /* we have to sum the cost of all three components of a BAT */ if (c && isTable(c->t) && (lasttable == 0 || strcmp(lasttable,tname)==0)) { _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list