Changeset: d261381833e4 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=d261381833e4
Modified Files:
monetdb5/optimizer/opt_pushselect.c
sql/test/BugTracker-2009/Tests/use_order_column_first.SF-2686008.stable.out
sql/test/BugTracker-2012/Tests/rewrite_like_into_likesubselect.Bug-3179.stable.out
sql/test/BugTracker/Tests/explain.SF-1739353.stable.out
Branch: Jun2020
Log Message:
make sure we push selects through delta's (again)
diffs (truncated from 552 to 300 lines):
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
@@ -296,168 +296,168 @@ OPTpushselectImplementation(Client cntxt
}
}
- if ((!subselects.nr && !nr_topn && !nr_likes) || newMalBlkStmt(mb,
mb->ssize) <0 ) {
- GDKfree(vars);
- goto wrapup;
- }
- pushInstruction(mb,old[0]);
-
- for (i = 1; i < limit; i++) {
- p = old[i];
-
- /* rewrite batalgebra.like + select -> likeselect */
- if (getModuleId(p) == algebraRef && p->retc == 1 &&
getFunctionId(p) == selectRef) {
- int var = getArg(p, 1);
- InstrPtr q = mb->stmt[vars[var]]; /* BEWARE: the
optimizer may not add or remove statements ! */
-
- if (isLikeOp(q)) { /* TODO check if getArg(p, 3) value
== TRUE */
- InstrPtr r = newInstruction(mb, algebraRef,
likeselectRef);
- int has_cand = (getArgType(mb, p, 2) ==
newBatType(TYPE_oid));
- int a, anti = (getFunctionId(q)[0] == 'n'),
ignore_case = (getFunctionId(q)[anti?4:0] == 'i');
-
- getArg(r,0) = getArg(p,0);
- r = addArgument(mb, r, getArg(q, 1));
- if (has_cand)
- r = addArgument(mb, r, getArg(p, 2));
- for(a = 2; a<q->argc; a++)
- r = addArgument(mb, r, getArg(q, a));
- if (r->argc < (4+has_cand))
- r = pushStr(mb, r, ""); /* default esc
*/
- if (r->argc < (5+has_cand))
- r = pushBit(mb, r, ignore_case);
- if (r->argc < (6+has_cand))
- r = pushBit(mb, r, anti);
- freeInstruction(p);
- p = r;
- actions++;
- }
+ if (subselects.nr) {
+ if ((!nr_topn && !nr_likes) || newMalBlkStmt(mb, mb->ssize) <0
) {
+ GDKfree(vars);
+ goto wrapup;
}
- /* inject table ids into subselect
- * s = subselect(c, C1..) => subselect(c, t, C1..)
- */
- if (isSelect(p) && p->retc == 1) {
- int tid = 0;
-
- if ((tid = subselect_find_tids(&subselects, getArg(p,
0))) >= 0) {
- int lastbat = lastbat_arg(mb, p);
- if (getArgType(mb, p, lastbat) == TYPE_bat) /*
empty candidate list bat_nil */
- getArg(p, lastbat) = tid;
- else
- p = PushArgument(mb, p, tid, lastbat+1);
- /* make sure to resolve again */
- p->token = ASSIGNsymbol;
- p->typechk = TYPE_UNKNOWN;
- p->fcn = NULL;
- p->blk = NULL;
- actions++;
- }
- }
- else if ( (GDKdebug & (1<<15)) &&
- isMatJoinOp(p) && p->retc == 2
- ) {
- int ltid = 0, rtid = 0, done = 0;
- int range = 0;
+ pushInstruction(mb,old[0]);
- if ((ltid = subselect_find_tids(&subselects, getArg(p,
0))) >= 0 &&
- (rtid = subselect_find_tids(&subselects, getArg(p,
1))) >= 0) {
- p = PushArgument(mb, p, ltid, 4+range);
- p = PushArgument(mb, p, rtid, 5+range);
- done = 1;
- } else if ((ltid = subselect_find_tids(&subselects,
getArg(p, 0))) >= 0) {
- p = PushArgument(mb, p, ltid, 4+range);
- p = PushNil(mb, p, 5+range, TYPE_bat);
- done = 1;
- } else if ((rtid = subselect_find_tids(&subselects,
getArg(p, 1))) >= 0) {
- p = PushNil(mb, p, 4+range, TYPE_bat);
- p = PushArgument(mb, p, rtid, 5+range);
- done = 1;
- }
- if (done) {
- p = pushBit(mb, p, FALSE); /* do not match nils
*/
- p = pushNil(mb, p, TYPE_lng); /* no estimate */
+ for (i = 1; i < limit; i++) {
+ p = old[i];
- /* make sure to resolve again */
- p->token = ASSIGNsymbol;
- p->typechk = TYPE_UNKNOWN;
- p->fcn = NULL;
- p->blk = NULL;
- actions++;
- }
- }
- /* Leftfetchjoins involving rewriten table ids need to be
flattend
- * l = projection(t, c); => l = c;
- * and
- * l = projection(s, ntids); => l = s;
- */
- else if (getModuleId(p) == algebraRef && getFunctionId(p) ==
projectionRef) {
- int var = getArg(p, 1);
-
- if (subselect_find_subselect(&subselects, var) > 0) {
- InstrPtr q = newAssignment(mb);
-
- getArg(q, 0) = getArg(p, 0);
- (void) addArgument(mb, q, getArg(p, 2));
- actions++;
- freeInstruction(p);
- continue;
- } else { /* deletes/updates use table ids */
- int var = getArg(p, 2);
+ /* rewrite batalgebra.like + select -> likeselect */
+ if (getModuleId(p) == algebraRef && p->retc == 1 &&
getFunctionId(p) == selectRef) {
+ int var = getArg(p, 1);
InstrPtr q = mb->stmt[vars[var]]; /* BEWARE:
the optimizer may not add or remove statements ! */
- if (q->token == ASSIGNsymbol) {
- var = getArg(q, 1);
- q = mb->stmt[vars[var]];
+ if (isLikeOp(q)) { /* TODO check if getArg(p,
3) value == TRUE */
+ InstrPtr r = newInstruction(mb,
algebraRef, likeselectRef);
+ int has_cand = (getArgType(mb, p, 2) ==
newBatType(TYPE_oid));
+ int a, anti = (getFunctionId(q)[0] ==
'n'), ignore_case = (getFunctionId(q)[anti?4:0] == 'i');
+
+ getArg(r,0) = getArg(p,0);
+ r = addArgument(mb, r, getArg(q, 1));
+ if (has_cand)
+ r = addArgument(mb, r,
getArg(p, 2));
+ for(a = 2; a<q->argc; a++)
+ r = addArgument(mb, r,
getArg(q, a));
+ if (r->argc < (4+has_cand))
+ r = pushStr(mb, r, ""); /*
default esc */
+ if (r->argc < (5+has_cand))
+ r = pushBit(mb, r, ignore_case);
+ if (r->argc < (6+has_cand))
+ r = pushBit(mb, r, anti);
+ freeInstruction(p);
+ p = r;
+ actions++;
}
+ }
+
+ /* inject table ids into subselect
+ * s = subselect(c, C1..) => subselect(c, t, C1..)
+ */
+ if (isSelect(p) && p->retc == 1) {
+ int tid = 0;
+
+ if ((tid = subselect_find_tids(&subselects,
getArg(p, 0))) >= 0) {
+ int lastbat = lastbat_arg(mb, p);
+ if (getArgType(mb, p, lastbat) ==
TYPE_bat) /* empty candidate list bat_nil */
+ getArg(p, lastbat) = tid;
+ else
+ p = PushArgument(mb, p, tid,
lastbat+1);
+ /* make sure to resolve again */
+ p->token = ASSIGNsymbol;
+ p->typechk = TYPE_UNKNOWN;
+ p->fcn = NULL;
+ p->blk = NULL;
+ actions++;
+ }
+ } else if ( (GDKdebug & (1<<15)) && isMatJoinOp(p) &&
p->retc == 2) {
+ int ltid = 0, rtid = 0, done = 0;
+ int range = 0;
+
+ if ((ltid = subselect_find_tids(&subselects,
getArg(p, 0))) >= 0 &&
+ (rtid = subselect_find_tids(&subselects,
getArg(p, 1))) >= 0) {
+ p = PushArgument(mb, p, ltid, 4+range);
+ p = PushArgument(mb, p, rtid, 5+range);
+ done = 1;
+ } else if ((ltid =
subselect_find_tids(&subselects, getArg(p, 0))) >= 0) {
+ p = PushArgument(mb, p, ltid, 4+range);
+ p = PushNil(mb, p, 5+range, TYPE_bat);
+ done = 1;
+ } else if ((rtid =
subselect_find_tids(&subselects, getArg(p, 1))) >= 0) {
+ p = PushNil(mb, p, 4+range, TYPE_bat);
+ p = PushArgument(mb, p, rtid, 5+range);
+ done = 1;
+ }
+ if (done) {
+ p = pushBit(mb, p, FALSE); /* do not
match nils */
+ p = pushNil(mb, p, TYPE_lng); /* no
estimate */
+
+ /* make sure to resolve again */
+ p->token = ASSIGNsymbol;
+ p->typechk = TYPE_UNKNOWN;
+ p->fcn = NULL;
+ p->blk = NULL;
+ actions++;
+ }
+ }
+ /* Leftfetchjoins involving rewriten table ids need to
be flattend
+ * l = projection(t, c); => l = c;
+ * and
+ * l = projection(s, ntids); => l = s;
+ */
+ else if (getModuleId(p) == algebraRef &&
getFunctionId(p) == projectionRef) {
+ int var = getArg(p, 1);
+
if (subselect_find_subselect(&subselects, var)
> 0) {
- InstrPtr qq = newAssignment(mb);
- /* TODO: check result */
-
- getArg(qq, 0) = getArg(p, 0);
- (void) addArgument(mb, qq, getArg(p,
1));
+ InstrPtr q = newAssignment(mb);
+
+ getArg(q, 0) = getArg(p, 0);
+ (void) addArgument(mb, q, getArg(p, 2));
actions++;
freeInstruction(p);
continue;
- }
- /* c = sql.delta(b,uid,uval,ins);
- * l = projection(x, c);
- * into
- * l = sql.projectdelta(x,b,uid,uval,ins);
- */
- else if (getModuleId(q) == sqlRef &&
getFunctionId(q) == deltaRef && q->argc == 5) {
- q = copyInstruction(q);
- if( q == NULL){
- for (; i<limit; i++)
- if (old[i])
-
pushInstruction(mb,old[i]);
- GDKfree(slices);
- GDKfree(rslices);
- GDKfree(old);
- GDKfree(vars);
-
throw(MAL,"optimizer.pushselect", SQLSTATE(HY013) MAL_MALLOC_FAIL);
+ } else { /* deletes/updates use table ids */
+ int var = getArg(p, 2);
+ InstrPtr q = mb->stmt[vars[var]]; /*
BEWARE: the optimizer may not add or remove statements ! */
+
+ if (q->token == ASSIGNsymbol) {
+ var = getArg(q, 1);
+ q = mb->stmt[vars[var]];
+ }
+ if
(subselect_find_subselect(&subselects, var) > 0) {
+ InstrPtr qq = newAssignment(mb);
+ /* TODO: check result */
+
+ getArg(qq, 0) = getArg(p, 0);
+ (void) addArgument(mb, qq,
getArg(p, 1));
+ actions++;
+ freeInstruction(p);
+ continue;
}
-
- setFunctionId(q, projectdeltaRef);
- getArg(q, 0) = getArg(p, 0);
- q = PushArgument(mb, q, getArg(p, 1),
1);
- freeInstruction(p);
- p = q;
- actions++;
+ /* c = sql.delta(b,uid,uval,ins);
+ * l = projection(x, c);
+ * into
+ * l =
sql.projectdelta(x,b,uid,uval,ins);
+ */
+ else if (getModuleId(q) == sqlRef &&
getFunctionId(q) == deltaRef && q->argc == 5) {
+ q = copyInstruction(q);
+ if( q == NULL){
+ for (; i<limit; i++)
+ if (old[i])
+
pushInstruction(mb,old[i]);
+ GDKfree(slices);
+ GDKfree(rslices);
+ GDKfree(old);
+ GDKfree(vars);
+
throw(MAL,"optimizer.pushselect", SQLSTATE(HY013) MAL_MALLOC_FAIL);
+ }
+
+ setFunctionId(q,
projectdeltaRef);
+ getArg(q, 0) = getArg(p, 0);
+ q = PushArgument(mb, q,
getArg(p, 1), 1);
+ freeInstruction(p);
+ p = q;
+ actions++;
+ }
}
}
+ pushInstruction(mb,p);
}
- pushInstruction(mb,p);
- }
- for (; i<limit; i++)
- if (old[i])
- pushInstruction(mb,old[i]);
- for (; i<slimit; i++)
- if (old[i])
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list