Changeset: 823846e177a2 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=823846e177a2
Modified Files:
        monetdb5/optimizer/opt_pushproject.c
        
sql/test/BugTracker-2019/Tests/duplicates-not-eliminated-long-CASE-stmt.Bug-6697.stable.out
Branch: opt_pushoptimizer
Log Message:

clean up some issues


diffs (truncated from 1469 to 300 lines):

diff --git a/monetdb5/optimizer/opt_pushproject.c 
b/monetdb5/optimizer/opt_pushproject.c
--- a/monetdb5/optimizer/opt_pushproject.c
+++ b/monetdb5/optimizer/opt_pushproject.c
@@ -44,123 +44,133 @@ OPTpushprojectImplementation(Client cntx
                 goto wrapup;
         }
 
-        // Consolidate the actual need for variables
+        // Locate the actual projection statements
         for (i = 0; i < limit; i++) {
-                p = old[i];
-                if( p == 0)
-                        continue; //left behind by others?
+                       p = old[i];
+                       if( p == 0)
+                                       continue; //left behind by others?
+
+                       /* collect all projection operations*/
+                       if ( getFunctionId(p) == projectionRef && p->argc ==3 
&& 
+                               isVarCList(mb, getArg(p,0)) && 
+                               isVarCList(mb, getArg(p,1)) && 
+                               isaBatType(getArgType(mb, p, 2))){
+                               projects[getArg(p,0)] = i;
+                       }
+                       /* projection over the last column in a projection path 
could be replaced with the original */
+                       if ( getModuleId(p) == algebraRef && getFunctionId(p) 
== projectionpathRef && projects[getArg(p, p->argc-1)] ){
+                               q = old[projects[getArg(p, p->argc-1)]];
+                               getArg(p, p->argc-1) = getArg(q,1);
+                               p= pushArgument(mb, p, getArg(q,2));
+                               actions++;
+                       }
+                       /* BATcalc can use candidate lists, use the simple 
cases first
+                               X_347:bat[:lng] := 
algebra.projection(C_335:bat[:oid], X_264=:bat[:lng]); 
+                               X_358:bat[:lng] := batcalc.-(100:lng, 
X_347=:bat[:lng], nil:BAT); 
 
-                if ( getModuleId(p) == algebraRef && getFunctionId(p) == 
projectionRef && p->argc ==3 && isVarCList(mb, getArg(p,1)) && 
isaBatType(getArgType(mb, p, 2))){
-                       // keep projection , probably restrict to pure 
projections with candidate argument
-                       projects[getArg(p,0)] = i;
-               }
-               if ( getModuleId(p) == algebraRef && getFunctionId(p) == 
projectionpathRef && projects[getArg(p, p->argc-1)] ){
-                       q = old[projects[getArg(p, p->argc-1)]];
-                       getArg(p, p->argc-1) = getArg(q,1);
-                       p= pushArgument(mb, p, getArg(q,2));
-                       actions++;
-               }
-               /*
-                [ 64428,   X_347:bat[:lng] := 
algebra.projection(C_335:bat[:oid], X_264=:bat[:lng]); ]
-                       [ 239922,   X_358]:bat[:lng] := batcalc.-(100:lng, 
X_347=:bat[:lng], nil:BAT);    ]
-
-                       Into
-                        239922,   X_358:bat[:lng] := batcalc.-(100:lng, 
X_264:bat[:lng], C_335:bat[:oid]);    ]
-               */
-               if ( getModuleId(p) == batcalcRef && p->argc == 3 && 
projects[getArg(p, p->argc-1)] ){
-                       // keep it simple for now
-                       if( getFunctionId(p)[0] == '-' ||
-                           getFunctionId(p)[0] == '+' ||
-                           getFunctionId(p)[0] == '/' ||
-                           getFunctionId(p)[0] == '*' ||
-                           getFunctionId(p)[0] == '%' ){
-                               // Inject the projection arguments
-                               if( projects[getArg(p, p->argc-1)]){
-                                       q = old[projects[getArg(p, p->argc-1)]];
-                                       getArg(p, p->argc-1) = getArg(q,1);
-                                       p= pushArgument(mb, p, getArg(q,2));
-                                       actions++;
+                               Into
+                                X_358:bat[:lng] := batcalc.-(100:lng, 
X_264:bat[:lng], C_335:bat[:oid]); 
+                       */
+                       if ( getModuleId(p) == batcalcRef && p->argc == 3 && 
(projects[getArg(p, 2)] || projects[getArg(p, 1)]) ){
+                               // keep it simple for now
+                               if( getFunctionId(p)[0] == '-' ||
+                                       getFunctionId(p)[0] == '+' ||
+                                       getFunctionId(p)[0] == '/' ||
+                                       getFunctionId(p)[0] == '*' ||
+                                       getFunctionId(p)[0] == '%' ){
+                                       // Inject the projection arguments
+                                       if( projects[getArg(p, 1)]){
+                                               q = old[projects[getArg(p,1)]];
+                                               getArg(p, 1) = getArg(q,2);
+                                               p= pushArgument(mb, p, 
getArg(q,1));
+                                               actions++;
+                                       }
+                                       if( projects[getArg(p, 2)]){
+                                               q = old[projects[getArg(p, 2)]];
+                                               getArg(p, 2) = getArg(q,2);
+                                               p= pushArgument(mb, p, 
getArg(q,1));
+                                               actions++;
+                                       }
                                }
                        }
-               }
-               if ( getModuleId(p) == batcalcRef && p->argc == 4 ){
-                       // keep it simple for now
-                       if( getFunctionId(p)[0] == '-' ||
-                           getFunctionId(p)[0] == '+' ||
-                           getFunctionId(p)[0] == '/' ||
-                           getFunctionId(p)[0] == '*' ||
-                           getFunctionId(p)[0] == '%' ){
-                               // Inject the projection arguments
-                               if( projects[getArg(p, p->retc)]){
+                       if ( getModuleId(p) == batcalcRef && p->argc == 4 ){
+                               // keep it simple for now
+                               if( getFunctionId(p)[0] == '-' ||
+                                       getFunctionId(p)[0] == '+' ||
+                                       getFunctionId(p)[0] == '/' ||
+                                       getFunctionId(p)[0] == '*' ||
+                                       getFunctionId(p)[0] == '%' ){
+                                       // Inject the projection arguments
+                                       if( projects[getArg(p, 1)]){
+                                               q = old[projects[getArg(p, 1)]];
+                                               getArg(p, 1) = getArg(q,2);
+                                               getArg(p, 3) = getArg(q,1);
+                                               actions++;
+                                       }
+                                       if( projects[getArg(p, 2)]){
+                                               q = old[projects[getArg(p, 2)]];
+                                               getArg(p, 2 ) = getArg(q,2);
+                                               getArg(p, 3) = getArg(q,1);
+                                               actions++;
+                                       }
+                               }
+                       }
+                       /* same for the first argument */
+                       if ( getModuleId(p) == batcalcRef && p->argc == 5 && 
(projects[getArg(p, p->retc)] || projects[getArg(p, p->retc+1)]) ){
+                               // keep it simple for now
+                               if( getFunctionId(p)[0] == '-' ||
+                                       getFunctionId(p)[0] == '+' ||
+                                       getFunctionId(p)[0] == '/' ||
+                                       getFunctionId(p)[0] == '*' ||
+                                       getFunctionId(p)[0] == '%' ){
+                                       // Inject the projection arguments
+                                       if( projects[getArg(p, 1)]){
+                                               q = old[projects[getArg(p, 1)]];
+                                               getArg(p, 1) = getArg(q,2);
+                                               getArg(p, 3) = getArg(q,1);
+                                               actions++;
+                                       }
+                                       if( projects[getArg(p, 2)]){
+                                               q = old[projects[getArg(p, 2)]];
+                                               getArg(p, 2) = getArg(q,2);
+                                               getArg(p, 4) = getArg(q,1);
+                                               actions++;
+                                       }
+                               }
+                       }
+                       /*  X_357:bat[:str] := 
algebra.projection(C_333:bat[:oid], X_303bat[:str]);
+                               (X_414:bat[:oid], C_415=[4]:bat[:oid]) := 
group.subgroupdone(X_357:bat[:str], X_386:bat[:oid]); 
+                                
+                               INTO
+                               (X_405:bat[:oid], C_406=[4]:bat[:oid]) := 
group.subgroupdone(X_303:bat[:str],C_333:bat[:oid],  X_386:bat[:oid]);
+                               INCORRECT. oids change in the projection
+
+                               if ( getModuleId(p) == groupRef && 
getFunctionId(p) == subgroupdoneRef && projects[getArg(p, p->retc)] ){
                                        q = old[projects[getArg(p, p->retc)]];
-                                       getArg(p, p->retc) = getArg(q,2);
-                                       getArg(p, p->argc-1) = getArg(q,1);
-                                       actions++;
-                               }
-                               if( projects[getArg(p, p->retc + 1)]){
-                                       q = old[projects[getArg(p, p->retc + 
1)]];
-                                       getArg(p, p->retc +1 ) = getArg(q,2);
-                                       getArg(p, p->argc-1) = getArg(q,1);
+                                       getArg(p,p->retc) = getArg(q,2);
+                                       setArgument(mb, p, p->retc +1, 
getArg(q,1));
                                        actions++;
                                }
-                       }
-               }
-               /* same for the first argument */
-               if ( getModuleId(p) == batcalcRef && p->argc == 5 && 
(projects[getArg(p, p->retc)] || projects[getArg(p, p->retc+1)]) ){
-                       // keep it simple for now
-                       if( getFunctionId(p)[0] == '-' ||
-                           getFunctionId(p)[0] == '+' ||
-                           getFunctionId(p)[0] == '/' ||
-                           getFunctionId(p)[0] == '*' ||
-                           getFunctionId(p)[0] == '%' ){
-                               // Inject the projection arguments
-                               if( projects[getArg(p, p->retc)]){
-                                       q = old[projects[getArg(p, p->retc)]];
-                                       getArg(p, p->retc) = getArg(q,2);
-                                       getArg(p, p->retc+2) = getArg(q,1);
-                                       actions++;
-                               }
-                               if( projects[getArg(p, p->retc+1)]){
-                                       q = old[projects[getArg(p, p->retc+1)]];
-                                       getArg(p, p->retc+1) = getArg(q,2);
-                                       getArg(p, p->retc+3) = getArg(q,1);
+                       */
+                       /* Raises error during startup  in Mtest
+                        * Case Q1.2
+                               X_343:bat[:str] := 
algebra.projection(C_415=[:bat[:oid], X_357=[:bat[:str]);
+                               X_417:bat[:str] := 
algebra.projection(C_394=]:bat[:oid], X_343=:bat[:str]);
+
+                               INTO
+                               X_420:bat[:str] := 
algebra.projectionpath(C_394=]:bat[:oid], C_415=[:bat[:oid], X_357=[:bat[:str])
+                               INCORRECT, the OIDs in C_394 are not aligned 
with X_357. They get reassigned
+                       
+                               if ( getModuleId(p) == algebraRef && 
getFunctionId(p) == projectionRef && projects[getArg(p, p->argc-1)] ){
+                                       // Inject the projection arguments
+                                       q = old[projects[getArg(p, p->argc-1)]];
+                                       getArg(p, p->retc) = getArg(q,1);
+                                       setFunctionId(p, projectionpathRef);
+                                       p= setArgument(mb, p, p->retc+1, 
getArg(q,2));
                                        actions++;
                                }
-                       }
-               }
-               /*  [ 33941,   X_357:bat[:str] := 
algebra.projection(C_333:bat[:oid], X_303bat[:str]); ]
-                       [ 250871,   (X_414:bat[:oid], C_415=[4]:bat[:oid]) := 
group.subgroupdone(X_357:bat[:str], X_386:bat[:oid]);  ]
-                        
-                       INTO
-                       [ 250871,   (X_405:bat[:oid], C_406=[4]:bat[:oid]) := 
group.subgroupdone(X_303:bat[:str],C_333:bat[:oid],  X_386:bat[:oid]);
-                       Incorrect. oids change in the projection
-
-               if ( getModuleId(p) == groupRef && getFunctionId(p) == 
subgroupdoneRef && projects[getArg(p, p->retc)] ){
-                       q = old[projects[getArg(p, p->retc)]];
-                       getArg(p,p->retc) = getArg(q,2);
-                       setArgument(mb, p, p->retc +1, getArg(q,1));
-                       actions++;
-               }
-               */
-               /* Raises error during startup  in Mtest
-                * Case Q1.2
-                       [ 33941,  X_343:bat[:str] := 
algebra.projection(C_415=[:bat[:oid], X_357=[:bat[:str]);
-                       [ 19,   "X_417:bat[:str] := 
algebra.projection(C_394=]:bat[:oid], X_343=:bat[:str]);"   ]
-
-                       INTO
-                       X_420:bat[:str] := 
algebra.projectionpath(C_394=]:bat[:oid], C_415=[:bat[:oid], X_357=[:bat[:str])
-                       Incorrect, the OIDs in C_394 are not aligned with 
X_357. They get reassigned
-               
-                if ( getModuleId(p) == algebraRef && getFunctionId(p) == 
projectionRef && projects[getArg(p, p->argc-1)] ){
-                       // Inject the projection arguments
-                       q = old[projects[getArg(p, p->argc-1)]];
-                       getArg(p, p->retc) = getArg(q,1);
-                       setFunctionId(p, projectionpathRef);
-                       p= setArgument(mb, p, p->retc+1, getArg(q,2));
-                       actions++;
-               }
-               */
-                pushInstruction(mb, p);
+                       */
+                       pushInstruction(mb, p);
         }
        for(; i<slimit; i++)
        if( old[i])
@@ -174,7 +184,7 @@ OPTpushprojectImplementation(Client cntx
                        msg = chkDeclarations(mb);
        }
     /* keep all actions taken as a post block comment */
-        usec = GDKusec()- usec;
+       usec = GDKusec()- usec;
     snprintf(buf,256,"%-20s actions=%2d time=" LLFMT " 
usec","pushproject",actions, usec);
     newComment(mb,buf);
     if( actions > 0)
diff --git 
a/sql/test/BugTracker-2019/Tests/duplicates-not-eliminated-long-CASE-stmt.Bug-6697.stable.out
 
b/sql/test/BugTracker-2019/Tests/duplicates-not-eliminated-long-CASE-stmt.Bug-6697.stable.out
--- 
a/sql/test/BugTracker-2019/Tests/duplicates-not-eliminated-long-CASE-stmt.Bug-6697.stable.out
+++ 
b/sql/test/BugTracker-2019/Tests/duplicates-not-eliminated-long-CASE-stmt.Bug-6697.stable.out
@@ -34,7 +34,7 @@ stdout of test 'duplicates-not-eliminate
 % 1023 # length
 function user.main():void;
     X_1:void := querylog.define("explain select sys.timestamp_to_str(case when 
task0.\"sys_created_on\" >= \\'1999-10-31 09:00:00\\' and 
task0.\"sys_created_on\" < \\'2000-04-02 10:00:00\\' then 
task0.\"sys_created_on\" + interval \\'-28800\\' second when 
task0.\"sys_created_on\" >= \\'2000-04-02 10:00:00\\' and 
task0.\"sys_created_on\" < \\'2000-10-29 09:00:00\\' then 
task0.\"sys_created_on\" + interval \\'-25200\\' second when 
task0.\"sys_created_on\" >= \\'2000-10-29 09:00:00\\' and 
task0.\"sys_created_on\" < \\'2001-04-01 10:00:00\\' then 
task0.\"sys_created_on\" + interval \\'-28800\\' second when 
task0.\"sys_created_on\" >= \\'2001-04-01 10:00:00\\' and 
task0.\"sys_created_on\" < \\'2001-10-28 09:00:00\\' then 
task0.\"sys_created_on\" + interval \\'-25200\\' second when 
task0.\"sys_created_on\" >= \\'2001-10-28 09:00:00\\' and 
task0.\"sys_created_on\" < \\'2002-04-07 10:00:00\\' then 
task0.\"sys_created_on\" + interval \\'-28800\\' second when 
task0.\"sys_created_on\" >= \\'20
 02-04-07 10:00:00\\' and t
-barrier X_1247:bit := language.dataflow();
+barrier X_1301:bit := language.dataflow();
     X_43:bat[:str] := bat.new(nil:str);
     X_56:bat[:timestamp] := algebra.project(X_43:bat[:str], nil:timestamp);
     X_45:bat[:timestamp] := bat.new(nil:timestamp);
@@ -44,612 +44,611 @@ barrier X_1247:bit := language.dataflow(
     X_64:bat[:timestamp] := algebra.projection(C_58:bat[:oid], 
X_61:bat[:timestamp]);
     X_65:bat[:timestamp] := bat.replace(X_56:bat[:timestamp], C_58:bat[:oid], 
X_64:bat[:timestamp], true:bit);
     X_66:bat[:bit] := batcalc.not(X_51:bat[:bit]);
-    X_69:bat[:bit] := batcalc.isnil(X_66:bat[:bit]);
+    X_69:bat[:bit] := batcalc.isnil(X_51:bat[:bit]);
     X_71:bat[:bit] := batcalc.or(X_66:bat[:bit], X_69:bat[:bit]);
-    X_76:bat[:bit] := batcalc.between(X_45:bat[:timestamp], "2000-04-02 
10:00:00.000000":timestamp, "2000-10-29 09:00:00.000000":timestamp, false:bit, 
true:bit, false:bit, false:bit, false:bit);
-    X_78:bat[:bit] := batcalc.and(X_71:bat[:bit], X_76:bat[:bit]);
-    C_81:bat[:oid] := algebra.thetaselect(X_78:bat[:bit], true:bit, "==":str);
-    X_85:bat[:timestamp] := 
batmtime.timestamp_add_msec_interval(X_45:bat[:timestamp], -25200000:lng);
-    X_86:bat[:timestamp] := algebra.projection(C_81:bat[:oid], 
X_85:bat[:timestamp]);
-    X_87:bat[:timestamp] := bat.replace(X_65:bat[:timestamp], C_81:bat[:oid], 
X_86:bat[:timestamp], true:bit);
-    X_88:bat[:bit] := batcalc.not(X_76:bat[:bit]);
-    X_89:bat[:bit] := batcalc.isnil(X_88:bat[:bit]);
-    X_90:bat[:bit] := batcalc.or(X_88:bat[:bit], X_89:bat[:bit]);
-    X_91:bat[:bit] := batcalc.and(X_71:bat[:bit], X_90:bat[:bit]);
-    X_96:bat[:bit] := batcalc.between(X_45:bat[:timestamp], "2000-10-29 
09:00:00.000000":timestamp, "2001-04-01 10:00:00.000000":timestamp, false:bit, 
true:bit, false:bit, false:bit, false:bit);
-    X_99:bat[:bit] := batcalc.and(X_91:bat[:bit], X_96:bat[:bit]);
-    C_102:bat[:oid] := algebra.thetaselect(X_99:bat[:bit], true:bit, "==":str);
-    X_108:bat[:timestamp] := algebra.projection(C_102:bat[:oid], 
X_61:bat[:timestamp]);
-    X_109:bat[:timestamp] := bat.replace(X_87:bat[:timestamp], 
C_102:bat[:oid], X_108:bat[:timestamp], true:bit);
-    X_111:bat[:bit] := batcalc.not(X_96:bat[:bit]);
-    X_113:bat[:bit] := batcalc.isnil(X_111:bat[:bit]);
-    X_115:bat[:bit] := batcalc.or(X_111:bat[:bit], X_113:bat[:bit]);
-    X_117:bat[:bit] := batcalc.and(X_91:bat[:bit], X_115:bat[:bit]);
-    X_122:bat[:bit] := batcalc.between(X_45:bat[:timestamp], "2001-04-01 
10:00:00.000000":timestamp, "2001-10-28 09:00:00.000000":timestamp, false:bit, 
true:bit, false:bit, false:bit, false:bit);
-    X_123:bat[:bit] := batcalc.and(X_117:bat[:bit], X_122:bat[:bit]);
-    C_125:bat[:oid] := algebra.thetaselect(X_123:bat[:bit], true:bit, 
"==":str);
-    X_130:bat[:timestamp] := algebra.projection(C_125:bat[:oid], 
X_85:bat[:timestamp]);
-    X_131:bat[:timestamp] := bat.replace(X_109:bat[:timestamp], 
C_125:bat[:oid], X_130:bat[:timestamp], true:bit);
-    X_132:bat[:bit] := batcalc.not(X_122:bat[:bit]);
-    X_134:bat[:bit] := batcalc.isnil(X_132:bat[:bit]);
-    X_135:bat[:bit] := batcalc.or(X_132:bat[:bit], X_134:bat[:bit]);
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to