Changeset: 8dea6abd4c90 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=8dea6abd4c90
Added Files:
monetdb5/optimizer/opt_pushselect.c
monetdb5/optimizer/opt_pushselect.h
Modified Files:
monetdb5/optimizer/Makefile.ag
monetdb5/optimizer/opt_pipes.c
monetdb5/optimizer/opt_prelude.c
monetdb5/optimizer/opt_prelude.h
monetdb5/optimizer/opt_pushranges.c
monetdb5/optimizer/opt_support.c
monetdb5/optimizer/opt_support.h
monetdb5/optimizer/opt_wrapper.c
monetdb5/optimizer/optimizer.mal
sql/backends/monet5/UDF/Tests/udf-fuse.stable.out
sql/backends/monet5/UDF/Tests/udf-reverse.stable.out
sql/backends/monet5/sql.mx
sql/backends/monet5/sql_gencode.c
sql/server/bin_optimizer.c
sql/server/rel_bin.c
sql/server/sql_parser.y
sql/server/sql_rel2bin.c
sql/server/sql_statement.c
sql/server/sql_statement.h
sql/storage/bat/bat_storage.c
sql/storage/store.c
sql/test/BugTracker-2009/Tests/POWER_vs_prod.SF-2596114.stable.out
sql/test/BugTracker-2009/Tests/explain_gives_crash.SF-2741829.stable.out
sql/test/BugTracker-2010/Tests/LIMIT_OFFSET_big-endian.Bug-2622.stable.out
sql/test/BugTracker-2010/Tests/group-by_ordered_column.Bug-2564.stable.out
sql/test/BugTracker-2011/Tests/exists-select.Bug-2933.stable.out
sql/test/BugTracker-2011/Tests/func_iter_vs_bulk.Bug-2826.stable.out
sql/test/BugTracker/Tests/explain.SF-1739353.stable.out
sql/test/BugTracker/Tests/jdbc_no_debug.SF-1739356.stable.out
sql/test/Tests/setoptimizer.stable.out
sql/test/Tests/trace.stable.out
sql/test/leaks/Tests/check0.stable.out
sql/test/leaks/Tests/check1.stable.out
sql/test/leaks/Tests/check2.stable.out
sql/test/leaks/Tests/check3.stable.out
sql/test/leaks/Tests/check4.stable.out
sql/test/leaks/Tests/check5.stable.out
Branch: default
Log Message:
add small (example) pushselect down optimizer
Only pushes candidate lists into subselects.
diffs (truncated from 3185 to 300 lines):
diff --git a/monetdb5/optimizer/Makefile.ag b/monetdb5/optimizer/Makefile.ag
--- a/monetdb5/optimizer/Makefile.ag
+++ b/monetdb5/optimizer/Makefile.ag
@@ -69,6 +69,7 @@ lib_optimizer = {
opt_strengthReduction.c opt_strengthReduction.h \
opt_support.c opt_support.h \
opt_centipede.c opt_centipede.h \
+ opt_pushselect.c opt_pushselect.h \
opt_wrapper.c
}
diff --git a/monetdb5/optimizer/opt_pipes.c b/monetdb5/optimizer/opt_pipes.c
--- a/monetdb5/optimizer/opt_pipes.c
+++ b/monetdb5/optimizer/opt_pipes.c
@@ -69,6 +69,7 @@ struct PIPELINES {
"optimizer.coercions();"
"optimizer.emptySet();"
"optimizer.aliases();"
+ "optimizer.pushselect();"
// "optimizer.mitosis();"
// "optimizer.mergetable();"
"optimizer.deadcode();"
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
@@ -43,6 +43,9 @@ str batstrRef;
str batmtimeRef;
str batmmathRef;
str bbpRef;
+str tidRef;
+str deltaRef;
+str delta_projectRef;
str binddbatRef;
str bindidxRef;
str bindRef;
@@ -74,6 +77,8 @@ str deleteRef;
str depositRef;
str deriveRef;
str differenceRef;
+str tdifferenceRef;
+str tintersectRef;
str divRef;
str disconnectRef;
str evalRef;
@@ -107,6 +112,7 @@ str kdifferenceRef;
str kunionRef;
str kuniqueRef;
str languageRef;
+str leftfetchjoinRef;
str leftjoinRef;
str leftjoinPathRef;
str likeselectRef;
@@ -212,6 +218,9 @@ str unlockRef;
str unpackRef;
str unpinRef;
str updateRef;
+str subselectRef;
+str thetasubselectRef;
+str likesubselectRef;
str uselectRef;
str userRef;
str vectorRef;
@@ -269,6 +278,9 @@ void optimizerInit(void){
batmtimeRef = putName("batmtime",8);
batmmathRef = putName("batmmath",8);
bbpRef = putName("bbp",3);
+ tidRef = putName("tid",3);
+ deltaRef = putName("delta",5);
+ delta_projectRef = putName("delta_project",13);
binddbatRef = putName("bind_dbat",9);
bindidxRef = putName("bind_idxbat",11);
bindRef = putName("bind",4);
@@ -300,6 +312,8 @@ void optimizerInit(void){
depositRef = putName("deposit",7);
deriveRef = putName("derive",6);
differenceRef= putName("difference",10);
+ tdifferenceRef= putName("tdifference",11);
+ tintersectRef= putName("tintersect",10);
divRef = putName("/",1);
disconnectRef= putName("disconnect",10);
evalRef = putName("eval",4);
@@ -333,6 +347,7 @@ void optimizerInit(void){
kunionRef= putName("kunion",6);
kuniqueRef= putName("kunique",7);
languageRef= putName("language",8);
+ leftfetchjoinRef = putName("leftfetchjoin",13);
leftjoinRef = putName("leftjoin",8);
leftjoinPathRef = putName("leftjoinPath",12);
likeselectRef = putName("like_select",11);
@@ -438,6 +453,9 @@ void optimizerInit(void){
unpackRef = putName("unpack",6);
unpinRef = putName("unpin",5);
updateRef = putName("update",6);
+ subselectRef = putName("subselect",9);
+ thetasubselectRef = putName("thetasubselect",14);
+ likesubselectRef = putName("likesubselect",13);
uselectRef = putName("uselect",7);
vectorRef = putName("vector",6);
antiuselectRef = putName("antiuselect",11);
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
@@ -42,6 +42,9 @@ opt_export str batstrRef;
opt_export str batmtimeRef;
opt_export str batmmathRef;
opt_export str bbpRef;
+opt_export str tidRef;
+opt_export str deltaRef;
+opt_export str delta_projectRef;
opt_export str binddbatRef;
opt_export str bindidxRef;
opt_export str bindRef;
@@ -73,6 +76,8 @@ opt_export str deleteRef;
opt_export str depositRef;
opt_export str deriveRef;
opt_export str differenceRef;
+opt_export str tdifferenceRef;
+opt_export str tintersectRef;
opt_export str divRef;
opt_export str disconnectRef;
opt_export str evalRef;
@@ -106,6 +111,7 @@ opt_export str kdifferenceRef;
opt_export str kunionRef;
opt_export str kuniqueRef;
opt_export str languageRef;
+opt_export str leftfetchjoinRef;
opt_export str leftjoinRef;
opt_export str leftjoinPathRef;
opt_export str likeselectRef;
@@ -211,6 +217,9 @@ opt_export str unpackRef;
opt_export str unpinRef;
opt_export str unlockRef;
opt_export str updateRef;
+opt_export str subselectRef;
+opt_export str thetasubselectRef;
+opt_export str likesubselectRef;
opt_export str uselectRef;
opt_export str userRef;
opt_export str vectorRef;
diff --git a/monetdb5/optimizer/opt_pushranges.c
b/monetdb5/optimizer/opt_pushranges.c
--- a/monetdb5/optimizer/opt_pushranges.c
+++ b/monetdb5/optimizer/opt_pushranges.c
@@ -74,7 +74,8 @@ OPTpushrangesImplementation(Client cntxt
range[getArg(p,j)].lastupdate= i;
if( range[getArg(p,j)].lastrange == 0)
range[getArg(p,j)].lastrange= i;
- } if( getModuleId(p)== algebraRef &&
+ }
+ if( getModuleId(p)== algebraRef &&
( getFunctionId(p)== selectRef || getFunctionId(p)==
uselectRef) ){
/*
* The operation X:= algebra.select(Y,L,H,Li,Hi) is
analysed.
diff --git a/monetdb5/optimizer/opt_pushselect.c
b/monetdb5/optimizer/opt_pushselect.c
new file mode 100644
--- /dev/null
+++ b/monetdb5/optimizer/opt_pushselect.c
@@ -0,0 +1,258 @@
+/*
+ * The contents of this file are subject to the MonetDB Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.monetdb.org/Legal/MonetDBLicense
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is the MonetDB Database System.
+ *
+ * The Initial Developer of the Original Code is CWI.
+ * Portions created by CWI are Copyright (C) 1997-July 2008 CWI.
+ * Copyright August 2008-2012 MonetDB B.V.
+ * All Rights Reserved.
+*/
+#include "monetdb_config.h"
+#include "opt_pushselect.h"
+#include "mal_interpreter.h" /* for showErrors() */
+
+static InstrPtr
+PushArgument(MalBlkPtr mb, InstrPtr p, int arg, int pos)
+{
+ int i;
+
+ p = pushArgument(mb, p, arg); /* push at end */
+ for (i = p->argc-1; i > pos; i--)
+ getArg(p, i) = getArg(p, i-1);
+ getArg(p, pos) = arg;
+ return p;
+}
+
+#define MAX_TABLES 64
+
+typedef struct subselect_t {
+ int nr;
+ int tid[MAX_TABLES];
+ int subselect[MAX_TABLES];
+} subselect_t;
+
+static int
+subselect_add( subselect_t *subselects, int tid, int subselect )
+{
+ int i;
+
+ for (i = 0; i<subselects->nr; i++) {
+ if (subselects->tid[i] == tid) {
+ if (subselects->subselect[i] == subselect)
+ return i;
+ else
+ return -1;
+ }
+ }
+ if (i >= MAX_TABLES)
+ return -1;
+ subselects->nr++;
+ subselects->tid[i] = tid;
+ subselects->subselect[i] = subselect;
+ return i;
+}
+
+static int
+subselect_find_tids( subselect_t *subselects, int subselect)
+{
+ int i;
+
+ for (i = 0; i<subselects->nr; i++) {
+ if (subselects->subselect[i] == subselect) {
+ return subselects->tid[i];
+ }
+ }
+ return -1;
+}
+
+static int
+subselect_find_subselect( subselect_t *subselects, int tid)
+{
+ int i;
+
+ for (i = 0; i<subselects->nr; i++) {
+ if (subselects->tid[i] == tid) {
+ return subselects->subselect[i];
+ }
+ }
+ return -1;
+}
+
+int
+OPTpushselectImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk,
InstrPtr pci)
+{
+ int i, j, limit, slimit, actions=0, *vars;
+ InstrPtr p, *old;
+ subselect_t subselects;
+
+ subselects.nr = 0;
+ if( mb->errors)
+ return 0;
+
+ OPTDEBUGpushselect
+ mnstr_printf(cntxt->fdout,"#Range select optimizer started\n");
+ (void) stk;
+ (void) pci;
+ vars= (int*) GDKmalloc(sizeof(int)* mb->vtop);
+ limit = mb->stop;
+ slimit= mb->ssize;
+ old = mb->stmt;
+
+ /* check for bailout conditions */
+ for (i = 1; i < limit; i++) {
+ p = old[i];
+
+ for (j = 0; j<p->retc; j++) {
+ int res = getArg(p, j);
+ vars[res] = i;
+ }
+
+ if (getModuleId(p) == algebraRef &&
+ (getFunctionId(p) == tintersectRef || getFunctionId(p)
== tdifferenceRef))
+ return 0;
+
+ if (getModuleId(p) == sqlRef && getFunctionId(p) == tidRef) {
/* rewrite equal tids */
+ int sname = getArg(p, 2), tname = getArg(p, 3), s;
+
+ for (s = 0; s < subselects.nr; s++) {
+ InstrPtr q = old[vars[subselects.tid[s]]];
+ int Qsname = getArg(q, 2), Qtname = getArg(q,
3);
+
+ if (sname == Qsname && tname == Qtname) {
+ clrFunction(p);
+ p->retc = 1;
+ p->argc = 2;
+ getArg(p, 1) = getArg(q, 0);
+ }
+ }
+ }
+ if (getModuleId(p) == algebraRef &&
+ (getFunctionId(p) == subselectRef || getFunctionId(p) ==
thetasubselectRef ||
+ (getFunctionId(p) == likesubselectRef &&
!isaBatType(getArgType(mb, p, 2)) && !isaBatType(getArgType(mb, p, 3)))) &&
+ /* no cand list */ getArgType(mb, p, 2) !=
newBatType(TYPE_oid, TYPE_oid)) {
+ int i1 = getArg(p, 1), tid = 0;
+ InstrPtr q = old[vars[i1]];
_______________________________________________
checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list