Changeset: 1f39770b506a for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=1f39770b506a Modified Files: monetdb5/modules/mal/pcre.c monetdb5/modules/mal/pcre.mal monetdb5/optimizer/opt_prelude.c monetdb5/optimizer/opt_prelude.h monetdb5/optimizer/opt_pushselect.c monetdb5/optimizer/opt_strengthReduction.c monetdb5/optimizer/opt_support.c monetdb5/optimizer/opt_support.h sql/backends/monet5/LSST/lsst.c sql/backends/monet5/LSST/lsst.h sql/backends/monet5/LSST/lsst.mal sql/backends/monet5/generator/Tests/joins00.stable.out sql/backends/monet5/sql_gencode.c sql/backends/monet5/sql_scenario.c sql/benchmarks/ssbm/Tests/01-explain.stable.out.int128 sql/benchmarks/ssbm/Tests/02-explain.stable.out.int128 sql/benchmarks/ssbm/Tests/03-explain.stable.out.int128 sql/benchmarks/ssbm/Tests/04-explain.stable.out.int128 sql/benchmarks/ssbm/Tests/05-explain.stable.out.int128 sql/benchmarks/ssbm/Tests/06-explain.stable.out.int128 sql/benchmarks/ssbm/Tests/07-explain.stable.out.int128 sql/benchmarks/ssbm/Tests/08-explain.stable.out.int128 sql/benchmarks/ssbm/Tests/09-explain.stable.out.int128 sql/benchmarks/ssbm/Tests/10-explain.stable.out.int128 sql/benchmarks/ssbm/Tests/11-explain.stable.out.int128 sql/benchmarks/ssbm/Tests/12-explain.stable.out.int128 sql/benchmarks/ssbm/Tests/13-explain.stable.out.int128 sql/benchmarks/tpch/Tests/01-explain.stable.out.int128 sql/benchmarks/tpch/Tests/02-explain.stable.out sql/benchmarks/tpch/Tests/03-explain.stable.out.int128 sql/benchmarks/tpch/Tests/04-explain.stable.out sql/benchmarks/tpch/Tests/05-explain.stable.out.int128 sql/benchmarks/tpch/Tests/06-explain.stable.out.int128 sql/benchmarks/tpch/Tests/07-explain.stable.out.int128 sql/benchmarks/tpch/Tests/08-explain.stable.out.int128 sql/benchmarks/tpch/Tests/09-explain.stable.out.int128 sql/benchmarks/tpch/Tests/10-explain.stable.out.int128 sql/benchmarks/tpch/Tests/11-explain.stable.out.int128 sql/benchmarks/tpch/Tests/12-explain.stable.out.int128 sql/benchmarks/tpch/Tests/13-explain.stable.out sql/benchmarks/tpch/Tests/14-explain.stable.out.int128 sql/benchmarks/tpch/Tests/15-explain.stable.out.int128 sql/benchmarks/tpch/Tests/16-explain.stable.out sql/benchmarks/tpch/Tests/17-explain.stable.out.int128 sql/benchmarks/tpch/Tests/18-explain.stable.out.int128 sql/benchmarks/tpch/Tests/19-explain.stable.out.int128 sql/benchmarks/tpch/Tests/20-explain.stable.out.int128 sql/benchmarks/tpch/Tests/21-explain.stable.out sql/benchmarks/tpch/Tests/22-explain.stable.out.int128 sql/common/sql_types.c sql/scripts/09_like.sql sql/server/rel_optimizer.c sql/test/BugTracker-2012/Tests/rewrite_like_into_likesubselect.Bug-3179.stable.out sql/test/BugTracker/Tests/explain.SF-1739353.stable.out sql/test/BugTracker/Tests/jdbc_no_debug.SF-1739356.stable.out Branch: default Log Message:
Change filter functions Filter functions require 3 different mal functions 1) returning bit (while at it create the bat'modulename'.filter version as well) 2) a bat[:oid,:oid] returning 'subselect' like function 3) a (l:bat[:oid,:oid]),r:bat[:oid,:oid]) returning 'subjoin' like function The name of 1 should be given in the create filter function statement. This name is extended with 'subselect' and 'subjoin' for the 2 and 3 cases. Example create filter function "like"(val string, pat string, esc string) external name algebra."like"; expected mal functions: command algebra.like(s:str, pat:str, esc:str):bit address PCRElike3; function algebra.likesubselect(b:bat[:oid,:str], cand:bat[:oid,:oid], pat:str, esc:str, anti:bit) :bat[:oid,:oid]; command algebra.likesubjoin(l:bat[:oid,:str],r:bat[:oid,:str],esc:str,sl:bat[:oid,:oid],sr:bat[:oid,:oid],nil_matches:bit,estimate:lng) (:bat[:oid,:oid],:bat[:oid,:oid]) optional mal function: command batalgebra.like(s:bat[:oid,:str], pat:str, esc:str):bat[:oid,:bit] address BATPCRElike; diffs (truncated from 6128 to 300 lines): diff --git a/monetdb5/modules/mal/pcre.c b/monetdb5/modules/mal/pcre.c --- a/monetdb5/modules/mal/pcre.c +++ b/monetdb5/modules/mal/pcre.c @@ -1358,7 +1358,7 @@ PCRElikesubselect2(bat *ret, bat *bid, b if ((b = BATdescriptor(*bid)) == NULL) { throw(MAL, "algebra.likeselect", RUNTIME_OBJECT_MISSING); } - if (sid && (s = BATdescriptor(*sid)) == NULL) { + if (sid && (*sid) != bat_nil && *sid && (s = BATdescriptor(*sid)) == NULL) { BBPreleaseref(b->batCacheid); throw(MAL, "algebra.likeselect", RUNTIME_OBJECT_MISSING); } @@ -1751,28 +1751,20 @@ PCREsubjoin(bat *r1, bat *r2, bat lid, b throw(MAL, "pcre.join", RUNTIME_OBJECT_MISSING); } -pcre_export str LIKEsubjoin(bat *r1, bat *r2, bat *lid, bat *rid, bat *slid, bat *srid, str *esc); +pcre_export str LIKEsubjoin(bat *r1, bat *r2, bat *lid, bat *rid, str *esc, bat *slid, bat *srid, bit *nil_matches, lng *estimate); str -LIKEsubjoin(bat *r1, bat *r2, bat *lid, bat *rid, bat *slid, bat *srid, str *esc) +LIKEsubjoin(bat *r1, bat *r2, bat *lid, bat *rid, str *esc, bat *slid, bat *srid, bit *nil_matches, lng *estimate) { + (void)nil_matches; + (void)estimate; return PCREsubjoin(r1, r2, *lid, *rid, slid ? *slid : 0, srid ? *srid : 0, *esc, 0); } -pcre_export str ILIKEsubjoin(bat *r1, bat *r2, bat *lid, bat *rid, bat *slid, bat *srid, str *esc); +pcre_export str ILIKEsubjoin(bat *r1, bat *r2, bat *lid, bat *rid, str *esc, bat *slid, bat *srid, bit *nil_matches, lng *estimate); str -ILIKEsubjoin(bat *r1, bat *r2, bat *lid, bat *rid, bat *slid, bat *srid, str *esc) +ILIKEsubjoin(bat *r1, bat *r2, bat *lid, bat *rid, str *esc, bat *slid, bat *srid, bit *nil_matches, lng *estimate) { + (void)nil_matches; + (void)estimate; return PCREsubjoin(r1, r2, *lid, *rid, slid ? *slid : 0, srid ? *srid : 0, *esc, 1); } - -str -PCRElike_join_pcre(int *l, int *r, int *b, int *pat, str *esc) -{ - return PCREsubjoin(l, r, *b, *pat, 0, 0, *esc, 0); -} - -str -PCREilike_join_pcre(int *l, int *r, int *b, int *pat, str *esc) -{ - return PCREsubjoin(l, r, *b, *pat, 0, 0, *esc, 1); -} diff --git a/monetdb5/modules/mal/pcre.mal b/monetdb5/modules/mal/pcre.mal --- a/monetdb5/modules/mal/pcre.mal +++ b/monetdb5/modules/mal/pcre.mal @@ -67,57 +67,9 @@ comment "Initialize pcre"; pcre.prelude(); -command str.like(s:str, pat:str, esc:str):bit -address PCRElike3; - -command str.like(s:str, pat:str):bit -address PCRElike2; - -command str.not_like(s:str, pat:str, esc:str):bit -address PCREnotlike3; - -command str.not_like(s:str, pat:str):bit -address PCREnotlike2; - command str.replace(origin:str,pat:str,repl:str,flags:str):str address PCREreplace_wrap; -command batstr.like(s:bat[:oid,:str], pat:str, esc:str):bat[:oid,:bit] -address BATPCRElike; - -command batstr.like(s:bat[:oid,:str], pat:str):bat[:oid,:bit] -address BATPCRElike2; - -command batstr.not_like(s:bat[:oid,:str], pat:str, esc:str):bat[:oid,:bit] -address BATPCREnotlike; - -command batstr.not_like(s:bat[:oid,:str], pat:str):bat[:oid,:bit] -address BATPCREnotlike2; - -command str.ilike(s:str, pat:str, esc:str):bit -address PCREilike3; - -command str.ilike(s:str, pat:str):bit -address PCREilike2; - -command str.not_ilike(s:str, pat:str, esc:str):bit -address PCREnotilike3; - -command str.not_ilike(s:str, pat:str):bit -address PCREnotilike2; - -command batstr.ilike(s:bat[:oid,:str], pat:str, esc:str):bat[:oid,:bit] -address BATPCREilike; - -command batstr.ilike(s:bat[:oid,:str], pat:str):bat[:oid,:bit] -address BATPCREilike2; - -command batstr.not_ilike(s:bat[:oid,:str], pat:str, esc:str):bat[:oid,:bit] -address BATPCREnotilike; - -command batstr.not_ilike(s:bat[:oid,:str], pat:str):bat[:oid,:bit] -address BATPCREnotilike2; - command algebra.like(s:str, pat:str, esc:str):bit address PCRElike3; command algebra.like(s:str, pat:str):bit address PCRElike2; command algebra.not_like(s:str, pat:str, esc:str):bit address PCREnotlike3; @@ -128,6 +80,7 @@ command algebra.not_ilike(s:str, pat:str command algebra.not_ilike(s:str, pat:str):bit address PCREnotilike2; module batalgebra; + command batalgebra.like(s:bat[:oid,:str], pat:str, esc:str):bat[:oid,:bit] address BATPCRElike; command batalgebra.like(s:bat[:oid,:str], pat:str):bat[:oid,:bit] address BATPCRElike2; command batalgebra.not_like(s:bat[:oid,:str], pat:str, esc:str):bat[:oid,:bit] address BATPCREnotlike; @@ -135,15 +88,7 @@ command batalgebra.not_like(s:bat[:oid,: command batalgebra.ilike(s:bat[:oid,:str], pat:str, esc:str):bat[:oid,:bit] address BATPCREilike; command batalgebra.ilike(s:bat[:oid,:str], pat:str):bat[:oid,:bit] address BATPCREilike2; command batalgebra.not_ilike(s:bat[:oid,:str], pat:str, esc:str):bat[:oid,:bit] address BATPCREnotilike; -command batalgebra.not_ilike(s:bat[:oid,:str], pat:str):bat[:oid,:bit] address BATPCREnotliike2; - -command algebra.likesubselect(b:bat[:oid,:str], pat:str, esc:str, caseignore:bit, anti:bit) :bat[:oid,:oid] -address PCRElikesubselect1 -comment "Select all head values for which the tail value is \"like\" - the given (SQL-style) pattern. - Input is a dense-headed BAT, output is a dense-headed BAT with in - the tail the head value of the input BAT for which the - relationship holds. The output BAT is sorted on the tail value."; +command batalgebra.not_ilike(s:bat[:oid,:str], pat:str):bat[:oid,:bit] address BATPCREnotilike2; command algebra.likesubselect(b:bat[:oid,:str], s:bat[:oid,:oid], pat:str, esc:str, caseignore:bit, anti:bit) :bat[:oid,:oid] address PCRElikesubselect2 @@ -155,24 +100,6 @@ comment "Select all head values of the f the tail the head value of the input BAT for which the relationship holds. The output BAT is sorted on the tail value."; -command algebra.likesubselect(b:bat[:oid,:str], pat:str, esc:str, anti:bit) :bat[:oid,:oid] -address PCRElikesubselect3 -comment "Select all head values of the first input BAT for which the - tail value is \"like\" the given (SQL-style) pattern and for - which the head value occurs in the tail of the second input - BAT. - Input is a dense-headed BAT, output is a dense-headed BAT with in - the tail the head value of the input BAT for which the - relationship holds. The output BAT is sorted on the tail value."; - -#function algebra.likesubselect(b:bat[:oid,:str], pat:str, esc:str, anti:bit) :bat[:oid,:oid]; - #return algebra.likesubselect(b, pat, esc, false, anti); -#end algebra.likesubselect; - -function algebra.ilikesubselect(b:bat[:oid,:str], pat:str, esc:str, anti:bit) :bat[:oid,:oid]; - return algebra.likesubselect(b, pat, esc, true, anti); -end algebra.ilikesubselect; - function algebra.likesubselect(b:bat[:oid,:str], cand:bat[:oid,:oid], pat:str, esc:str, anti:bit) :bat[:oid,:oid]; return algebra.likesubselect(b, cand, pat, esc, false, anti); end algebra.likesubselect; @@ -181,22 +108,34 @@ function algebra.ilikesubselect(b:bat[:o return algebra.likesubselect(b, cand, pat, esc, true, anti); end algebra.ilikesubselect; -command algebra.likesubselect(s:bat[:oid,:str], pat:bat[:oid,:str], esc:str) (l:bat[:oid,:oid],r:bat[:oid,:oid]) -address PCRElike_join_pcre; +function algebra.likesubselect(b:bat[:oid,:str], cand:bat[:oid,:oid], pat:str, anti:bit) :bat[:oid,:oid]; + return algebra.likesubselect(b, cand, pat, "", false, anti); +end algebra.likesubselect; -command algebra.ilikesubselect(s:bat[:oid,:str], pat:bat[:oid,:str], esc:str) (l:bat[:oid,:oid],r:bat[:oid,:oid]) -address PCREilike_join_pcre; +function algebra.ilikesubselect(b:bat[:oid,:str], cand:bat[:oid,:oid], pat:str, anti:bit) :bat[:oid,:oid]; + return algebra.likesubselect(b, cand, pat, "", true, anti); +end algebra.ilikesubselect; -command algebra.likesubjoin(l:bat[:oid,:str],r:bat[:oid,:str],sl:bat[:oid,:oid],sr:bat[:oid,:oid],esc:str) (:bat[:oid,:oid],:bat[:oid,:oid]) +command algebra.likesubjoin(l:bat[:oid,:str],r:bat[:oid,:str],esc:str,sl:bat[:oid,:oid],sr:bat[:oid,:oid],nil_matches:bit,estimate:lng) (:bat[:oid,:oid],:bat[:oid,:oid]) address LIKEsubjoin comment "Join the string bat L with the pattern bat R with optional candidate lists SL and SR using pattern escape string ESC and doing a case sensitive match. The result is two aligned bats with oids of matching rows."; -command algebra.ilikesubjoin(l:bat[:oid,:str],r:bat[:oid,:str],sl:bat[:oid,:oid],sr:bat[:oid,:oid],esc:str) (:bat[:oid,:oid],:bat[:oid,:oid]) +command algebra.ilikesubjoin(l:bat[:oid,:str],r:bat[:oid,:str],esc:str,sl:bat[:oid,:oid],sr:bat[:oid,:oid],nil_matches:bit,estimate:lng) (:bat[:oid,:oid],:bat[:oid,:oid]) address ILIKEsubjoin comment "Join the string bat L with the pattern bat R with optional candidate lists SL and SR using pattern escape string ESC and doing a case insensitive match. The result is two aligned bats with oids of matching rows."; + +function algebra.likesubjoin(l:bat[:oid,:str],r:bat[:oid,:str],sl:bat[:oid,:oid],sr:bat[:oid,:oid],nil_matches:bit,estimate:lng) (:bat[:oid,:oid],:bat[:oid,:oid]); + (lr,rr) := algebra.likesubjoin(l, r, "", sl, sr, nil_matches, estimate); + return (lr,rr); +end algebra.likesubjoin; + +function algebra.ilikesubjoin(l:bat[:oid,:str],r:bat[:oid,:str],sl:bat[:oid,:oid],sr:bat[:oid,:oid],nil_matches:bit,estimate:lng) (:bat[:oid,:oid],:bat[:oid,:oid]); + (lr,rr) := algebra.ilikesubjoin(l, r, "", sl, sr, nil_matches, estimate); + return (lr,rr); +end algebra.ilikesubjoin; 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 @@ -31,6 +31,7 @@ str affectedRowsRef; str aggrRef; str alarmRef; str algebraRef; +str batalgebraRef; str appendidxRef; str appendRef; str assertRef; @@ -290,6 +291,7 @@ void optimizerInit(void) aggrRef = putName("aggr",4); alarmRef = putName("alarm",5); algebraRef = putName("algebra",7); + batalgebraRef = putName("batalgebra",10); appendidxRef = putName("append_idxbat",13); appendRef = putName("append",6); assertRef = putName("assert",6); 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 @@ -29,6 +29,7 @@ opt_export str affectedRowsRef; opt_export str aggrRef; opt_export str alarmRef; opt_export str algebraRef; +opt_export str batalgebraRef; opt_export str appendidxRef; opt_export str appendRef; opt_export str assertRef; diff --git a/monetdb5/optimizer/opt_pushselect.c b/monetdb5/optimizer/opt_pushselect.c --- a/monetdb5/optimizer/opt_pushselect.c +++ b/monetdb5/optimizer/opt_pushselect.c @@ -46,15 +46,12 @@ PushNil(MalBlkPtr mb, InstrPtr p, int po return p; } - static InstrPtr -RemoveArgument(InstrPtr p, int pos) +ReplaceWithNil(MalBlkPtr mb, InstrPtr p, int pos, int tpe) { - int i; - + p = pushNil(mb, p, tpe); /* push at end */ + getArg(p, pos) = getArg(p, p->argc-1); p->argc--; - for (i = pos; i < p->argc; i++) - getArg(p, i) = getArg(p, i+1); return p; } @@ -280,7 +277,7 @@ OPTpushselectImplementation(Client cntxt for (i = 1; i < limit; i++) { p = old[i]; - /* rewrite batstr.like + subselect -> likesubselect */ + /* rewrite batalgebra.like + subselect -> likesubselect */ if (getModuleId(p) == algebraRef && p->retc == 1 && getFunctionId(p) == subselectRef) { int var = getArg(p, 1); InstrPtr q = mb->stmt[vars[var]]; /* BEWARE: the optimizer may not add or remove statements ! */ @@ -317,7 +314,10 @@ OPTpushselectImplementation(Client cntxt int tid = 0; if ((tid = subselect_find_tids(&subselects, getArg(p, 0))) >= 0) { - p = PushArgument(mb, p, tid, 2); + if (getArgType(mb, p, 2) == TYPE_bat) /* empty candidate list bat_nil */ + getArg(p,2) = tid; + else + p = PushArgument(mb, p, tid, 2); /* make sure to resolve again */ p->token = ASSIGNsymbol; p->typechk = TYPE_UNKNOWN; @@ -510,7 +510,8 @@ OPTpushselectImplementation(Client cntxt pushInstruction(mb,r); getArg(s, 0) = newTmpVariable(mb, newBatType(TYPE_oid, TYPE_oid)); getArg(s, 1) = getArg(q, 3); /* updates */ - RemoveArgument(s, 2); /* no candidate list on updates */ + s = ReplaceWithNil(mb, s, 2, TYPE_bat); /* no candidate list */ + setArgType(mb, s, 2, newBatType(TYPE_oid,TYPE_oid)); /* make sure to resolve again */ s->token = ASSIGNsymbol; s->typechk = TYPE_UNKNOWN; diff --git a/monetdb5/optimizer/opt_strengthReduction.c b/monetdb5/optimizer/opt_strengthReduction.c --- a/monetdb5/optimizer/opt_strengthReduction.c +++ b/monetdb5/optimizer/opt_strengthReduction.c @@ -49,6 +49,7 @@ isNewSource(InstrPtr p) { if( mp == batcalcRef) return 1; if( mp == strRef) return 1; if( mp == batstrRef) return 1; + if( mp == batalgebraRef) return 1; if( mp == putName("array",5)) return 1; if( mp == putName("url",3)) return 1; if( mp == putName("daytime",7)) return 1; @@ -139,7 +140,7 @@ OPTstrengthReductionImplementation(Clien continue; } /* - * Limit strength reduction to the type modules and the batcalc, batstr, batcolor _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list