Changeset: a92ae9caed14 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=a92ae9caed14
Modified Files:
        monetdb5/extras/crackers/opt_selcrack.mx
Branch: holindex
Log Message:

Crackers: minor optimizer change:

replace
x1 := uselect(x0,...);
x2 := leftjoin(x1,x0);
by
x2 := select(x0,...);

in case of
select a from t where a between X and Y;


diffs (138 lines):

diff --git a/monetdb5/extras/crackers/opt_selcrack.mx 
b/monetdb5/extras/crackers/opt_selcrack.mx
--- a/monetdb5/extras/crackers/opt_selcrack.mx
+++ b/monetdb5/extras/crackers/opt_selcrack.mx
@@ -59,7 +59,7 @@ OPTselcrackImplementation(Client cntxt, 
 {
        InstrPtr p, *old;
        int update= 0, i, limit, actions=0, j;
-
+       int no_of_leftjoins=0;  
        
        str tables[maxTables];
        int crackedTables=0;
@@ -69,10 +69,22 @@ OPTselcrackImplementation(Client cntxt, 
 
        OPTDEBUGselcrack
                printf("Crack optimizer started\n");
-       (void) cntxt;
-       (void) stk; 
+
+       (void) cntxt;/* Tell compilers that we know that we do not */
+        (void) stk; /* use these function parameters, here.       */ 
        (void) pci;
        
+        /* In general, a MAL optimizer transforms a given MAL program into a
+         * modified one by sequentially walking through the given program
+         * and concurrently creating a new one from scratch by
+         * (1) copying statements as is, modified, or in a different order,
+         * or (2) omitting statements or (3) introducing new statements.
+         */
+
+        /* check for logical error: mb must never be NULL */
+        assert (mb != NULL);
+
+        /* safe the old stage of the MAL block */
        limit = mb->stop;
        old = mb->stmt;
        
@@ -85,7 +97,15 @@ OPTselcrackImplementation(Client cntxt, 
        }
        if (update)
                return 0;
+       /*If there are more than one leftjoins in the plan, we do not want to 
replace or delete none of them*/
+       for (i = 0; i < limit; i++) {
+               p = old[i];
+               if (match2(old[j], algebraRef, leftjoinRef))
+                       no_of_leftjoins++;
+       }
 
+
+       /* iterate over the instructions of the input MAL program */
        for (i = 0; i < limit; i++) {
                p = old[i];
 
@@ -110,10 +130,12 @@ OPTselcrackImplementation(Client cntxt, 
                        if (mb->var[getArg(p,5)]->value.val.ival != 0 ) 
                                continue;               
                                
-                       varSetProp(mb, getArg(p, 0), canBeCrackedProp, 0, NULL);
+                       varSetProp(mb, getArg(p, 0), canBeCrackedProp, 0, 
NULL); /* add a property "can be cracked" to every base relation that is a 
candidate for selection cracking */
 
-                       vp = VALset(&v, TYPE_str, 
GDKstrdup(getVar(mb,getArg(p,2))->value.val.sval));
+
+                       vp = VALset(&v, TYPE_str, 
GDKstrdup(getVar(mb,getArg(p,2))->value.val.sval));  /* also, for every 
candidate bat, maintain the table name */
                        varSetProp(mb, getArg(p,0), tableProp, op_eq, vp);
+
                        continue;
                }
 
@@ -147,6 +169,11 @@ OPTselcrackImplementation(Client cntxt, 
                if (match2(p, algebraRef, selectRef) ||
                    match2(p, algebraRef, uselectRef) || 
                    match2(p, algebraRef, thetauselectRef)){ 
+                               
+                       
+                       int j=0,k=0,m=0;
+                       bit found = FALSE;
+                       bit found2 = FALSE;
 
                        if (varGetProp(mb, getArg(p,1), canBeCrackedProp) != 
NULL){
                                bit alreadyCracked = FALSE;
@@ -160,10 +187,56 @@ OPTselcrackImplementation(Client cntxt, 
                                if (!alreadyCracked){
                                        
tables[crackedTables]=GDKstrdup(varGetProp(mb, getArg(p,1), 
tableProp)->value.val.sval);
                                        crackedTables++;
-                                       setModuleId(p,putName("crackers",8));
+                                       if (match2(p, algebraRef, uselectRef))
+                                       {
+                                               setFunctionId(p, 
putName("select", 6));
+       
+                                       }
+                                       else if (match2(p, algebraRef, 
thetauselectRef))
+                                       {
+                                               setFunctionId(p, 
putName("thetaselect", 11));
+       
+                                       }
+                                       
+                                       setModuleId(p, putName("crackers", 8));
+                                       
+                                       setVarType(mb, getArg(p,0), 
getArgType(mb,p,1)); /*We force the return type to be equal to the type of the 
first argument*/
+                                       setVarUDFtype(mb, getArg(p,0));
+
+                                               for (j = i+1; !found  && j < 
limit; j++){
+                                               if(match2(old[j], algebraRef, 
semijoinRef) || no_of_leftjoins>1)
+                                               { break; }
+                                               if (match2(old[j], algebraRef, 
leftjoinRef)){
+                                                       for (k = old[j]->retc; 
!found && k < old[j]->argc; k++)
+                                                               found = 
(getArg(old[j], k) == getArg(p, 1));
+                                                       if(found)
+                                                       {
+                                                               for (m = j+1; m 
< limit; m++)
+                                                               {
+                                                                       for (k 
= old[m]->retc; k < old[m]->argc; k++){
+                                                                               
found2 = (getArg(old[m], k) == getArg(old[j], 0));
+                                                                               
if (found2) 
+                                                                               
        break;
+                                                                       
+                                                                       }
+                                                                       
getArg(old[m], k) = getArg(p, 0);
+                                                                       
+                                                                       
+                                                                       
continue;
+                                                                       
+                                                               }
+                                                       
+                                                       }
+                                               }
+                                               
+                                               continue;
+                                       }
+                                       
+       
                                        actions++;
                                        continue;
                                }
+                               
                        }
 
                }
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to