Changeset: ab82fe1e7222 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/ab82fe1e7222
Branch: odbc_loader
Log Message:

merge with default


diffs (truncated from 1296 to 300 lines):

diff --git a/ctest/tools/monetdbe/Tests/example_proxy.SQL.py 
b/ctest/tools/monetdbe/Tests/example_proxy.SQL.py
--- a/ctest/tools/monetdbe/Tests/example_proxy.SQL.py
+++ b/ctest/tools/monetdbe/Tests/example_proxy.SQL.py
@@ -1,4 +1,5 @@
-import os, pymonetdb
+from MonetDBtesting import tpymonetdb as pymonetdb
+import os
 import subprocess
 
 db = os.getenv("TSTDB")
diff --git a/sql/server/rel_optimize_proj.c b/sql/server/rel_optimize_proj.c
--- a/sql/server/rel_optimize_proj.c
+++ b/sql/server/rel_optimize_proj.c
@@ -2504,9 +2504,91 @@ rel_distinct_aggregate_on_unique_values(
 static inline sql_rel *
 rel_remove_const_aggr(visitor *v, sql_rel *rel)
 {
-       if (!rel)
+       if(!rel) {
+               return rel;
+       }
+
+       list *exps = rel->exps;
+
+       if(rel->op != op_groupby || list_empty(exps)) {
                return rel;
-       if (rel && is_groupby(rel->op) && list_length(rel->exps) >= 1 && 
!rel_is_ref(rel)) {
+       }
+
+       if(!list_empty(rel->r)) {
+               /* in the general case in an expression of an aggregate over
+                * a constant can be rewritten as just the const e.g.
+                *   aggr(const) -> const
+                */
+
+               for(node *n = exps->h; n; n = n->next) {
+                       sql_exp *e = n->data;
+
+                       if(e->type != e_aggr) {
+                               continue;
+                       }
+
+                       sql_func *j = ((sql_subfunc *)e->f)->func;
+
+                       /* some aggregates with const values can only be 
eliminated
+                        * under certain circumstances e.g.
+                        *   sum(NULL)   -> NULL, sum(0)  -> 0
+                        *   prod(NULL)  -> NULL, prod(1) -> 1
+                        *   count(NULL) -> 0
+                        */
+                       int sum = strcmp(j->base.name, "sum") == 0,
+                               prd = strcmp(j->base.name, "prod") == 0,
+                               cnt = strcmp(j->base.name, "count") == 0;
+
+                       if(!j->s && j->system == 1) {
+                               list *se = e->l;
+
+                               if(se == NULL) {
+                                       continue;
+                               }
+
+                               for(node *m = se->h; m; m = m->next) {
+                                       sql_exp *w = m->data;
+
+                                       if(w->type == e_atom && w->card == 
CARD_ATOM) {
+                                               atom *wa = w->l;
+
+                                               if(sum && !(wa->isnull || 
atom_is_zero(wa))) {
+                                                       continue;
+                                               }
+
+                                               if(prd && !(wa->isnull || 
atom_is_one(wa))) {
+                                                       continue;
+                                               }
+
+                                               if(cnt) {
+                                                       if(wa->isnull) {
+                                                               
list_remove_node(se, NULL, m);
+
+                                                               
w=exp_atom_lng(v->sql->sa, 0);
+                                                               list_append(se, 
w);
+                                                       }
+                                                       else {
+                                                               continue;
+                                                       }
+                                               }
+
+                                               
exp_setalias(w,e->alias.label,e->alias.rname,e->alias.name);
+
+                                               n->data = w;
+                                               v->changes++;
+                                       }
+                               }
+                       }
+               }
+       }
+
+       /*
+        * Below code replaces GROUP BY with PROJECT in some cases;
+        * Triggers on...
+        * select 1 having true; select 42 from foo group by x; select n from 
foo group by rollup(n);
+       */
+
+       if (!rel_is_ref(rel)) {
                int needed = 0;
                for (node *n = rel->exps->h; n; n = n->next) {
                        sql_exp *exp = (sql_exp*) n->data;
@@ -2524,6 +2606,7 @@ rel_remove_const_aggr(visitor *v, sql_re
                                        if (exp_is_atom(exp))
                                                atoms++;
                                }
+                               /* possible edge case, never triggers in 
coverage tests */
                                if (atoms == list_length(rel->r)) {
                                        list *nexps = sa_list(v->sql->sa);
                                        for (node *n = rel->exps->h; n; ) {
@@ -2588,6 +2671,7 @@ rel_remove_const_aggr(visitor *v, sql_re
                        return nrel;
                }
        }
+
        return rel;
 }
 
@@ -3035,6 +3119,7 @@ rel_optimize_projections_(visitor *v, sq
                return rel;
 
        rel = rel_remove_const_aggr(v, rel);
+
        if (v->value_based_opt) {
                rel = rel_simplify_sum(v, rel);
                rel = rel_simplify_groupby_columns(v, rel);
@@ -3046,6 +3131,7 @@ rel_optimize_projections_(visitor *v, sq
        rel = rel_distinct_aggregate_on_unique_values(v, rel);
        rel = rel_groupby_distinct(v, rel);
        rel = rel_push_count_down(v, rel);
+
        /* only when value_based_opt is on, ie not for dependency resolution */
        if (v->value_based_opt) {
                rel = rel_simplify_count(v, rel);
diff --git a/sql/server/sql_atom.c b/sql/server/sql_atom.c
--- a/sql/server/sql_atom.c
+++ b/sql/server/sql_atom.c
@@ -1080,6 +1080,33 @@ atom_is_zero(atom *a)
 }
 
 int
+atom_is_one(atom *a)
+{
+       if (a->isnull || !ATOMlinear(a->tpe.type->localtype))
+               return 0;
+       switch (ATOMstorage(a->tpe.type->localtype)) {
+       case TYPE_bte:
+               return a->data.val.btval == 1;
+       case TYPE_sht:
+               return a->data.val.shval == 1;
+       case TYPE_int:
+               return a->data.val.ival == 1;
+       case TYPE_lng:
+               return a->data.val.lval == 1;
+#ifdef HAVE_HGE
+       case TYPE_hge:
+               return a->data.val.hval == 1;
+#endif
+       case TYPE_flt:
+               return a->data.val.fval == 1;
+       case TYPE_dbl:
+               return a->data.val.dval == 1;
+       default:
+               return 0;
+       }
+}
+
+int
 atom_is_true(atom *a)
 {
        if (a->isnull)
diff --git a/sql/server/sql_atom.h b/sql/server/sql_atom.h
--- a/sql/server/sql_atom.h
+++ b/sql/server/sql_atom.h
@@ -65,6 +65,7 @@ extern atom *atom_inc(allocator *sa, ato
 extern int atom_is_true(atom *a);
 extern int atom_is_false(atom *a);
 extern int atom_is_zero(atom *a);
+extern int atom_is_one(atom *a);
 
 extern unsigned int atom_digits(atom *a);
 
diff --git a/sql/test/BugTracker-2009/Tests/bit_and.SF-2850341.py 
b/sql/test/BugTracker-2009/Tests/bit_and.SF-2850341.py
--- a/sql/test/BugTracker-2009/Tests/bit_and.SF-2850341.py
+++ b/sql/test/BugTracker-2009/Tests/bit_and.SF-2850341.py
@@ -1,4 +1,5 @@
-import sys, os, pymonetdb
+from MonetDBtesting import tpymonetdb as pymonetdb
+import sys, os
 
 db = os.getenv("TSTDB")
 port = int(os.getenv("MAPIPORT"))
diff --git 
a/sql/test/BugTracker-2011/Tests/interrupted-initialization.Bug-2875.SQL.py 
b/sql/test/BugTracker-2011/Tests/interrupted-initialization.Bug-2875.SQL.py
--- a/sql/test/BugTracker-2011/Tests/interrupted-initialization.Bug-2875.SQL.py
+++ b/sql/test/BugTracker-2011/Tests/interrupted-initialization.Bug-2875.SQL.py
@@ -1,4 +1,5 @@
-import os, sys, tempfile, pymonetdb
+from MonetDBtesting import tpymonetdb as pymonetdb
+import os, sys, tempfile
 try:
     from MonetDBtesting import process
 except ImportError:
diff --git a/sql/test/BugTracker-2011/Tests/many-connects-cache.Bug-2904.SQL.py 
b/sql/test/BugTracker-2011/Tests/many-connects-cache.Bug-2904.SQL.py
--- a/sql/test/BugTracker-2011/Tests/many-connects-cache.Bug-2904.SQL.py
+++ b/sql/test/BugTracker-2011/Tests/many-connects-cache.Bug-2904.SQL.py
@@ -1,4 +1,5 @@
-import sys, os, pymonetdb, threading
+from MonetDBtesting import tpymonetdb as pymonetdb
+import sys, os, threading
 
 db = os.getenv("TSTDB")
 port = int(os.getenv("MAPIPORT"))
diff --git a/sql/test/BugTracker-2011/Tests/python-connections-Bug.2901.SQL.py 
b/sql/test/BugTracker-2011/Tests/python-connections-Bug.2901.SQL.py
--- a/sql/test/BugTracker-2011/Tests/python-connections-Bug.2901.SQL.py
+++ b/sql/test/BugTracker-2011/Tests/python-connections-Bug.2901.SQL.py
@@ -1,4 +1,4 @@
-import pymonetdb
+from MonetDBtesting import tpymonetdb as pymonetdb
 import os
 
 c = pymonetdb.connect(port=int(os.getenv('MAPIPORT')),
diff --git 
a/sql/test/BugTracker-2011/Tests/user_create_temp_table.Bug-2916.SQL.py 
b/sql/test/BugTracker-2011/Tests/user_create_temp_table.Bug-2916.SQL.py
--- a/sql/test/BugTracker-2011/Tests/user_create_temp_table.Bug-2916.SQL.py
+++ b/sql/test/BugTracker-2011/Tests/user_create_temp_table.Bug-2916.SQL.py
@@ -1,4 +1,5 @@
-import sys, os, pymonetdb
+from MonetDBtesting import tpymonetdb as pymonetdb
+import sys, os
 
 db = os.getenv("TSTDB")
 port = int(os.getenv("MAPIPORT"))
diff --git 
a/sql/test/BugTracker-2012/Tests/day-of-month-localization.Bug-2962.SQL.py 
b/sql/test/BugTracker-2012/Tests/day-of-month-localization.Bug-2962.SQL.py
--- a/sql/test/BugTracker-2012/Tests/day-of-month-localization.Bug-2962.SQL.py
+++ b/sql/test/BugTracker-2012/Tests/day-of-month-localization.Bug-2962.SQL.py
@@ -1,4 +1,5 @@
-import time, sys, os, pymonetdb
+from MonetDBtesting import tpymonetdb as pymonetdb
+import time, sys, os
 
 client1 = pymonetdb.connect(database=os.getenv("TSTDB"), 
port=int(os.getenv("MAPIPORT")))
 cur1 = client1.cursor()
diff --git 
a/sql/test/BugTracker-2012/Tests/large-number-operation-strange-results.Bug-2929.py
 
b/sql/test/BugTracker-2012/Tests/large-number-operation-strange-results.Bug-2929.py
--- 
a/sql/test/BugTracker-2012/Tests/large-number-operation-strange-results.Bug-2929.py
+++ 
b/sql/test/BugTracker-2012/Tests/large-number-operation-strange-results.Bug-2929.py
@@ -1,4 +1,5 @@
-import sys, os, pymonetdb
+from MonetDBtesting import tpymonetdb as pymonetdb
+import sys, os
 from decimal import *
 
 db = os.getenv("TSTDB")
diff --git 
a/sql/test/BugTracker-2012/Tests/table_functions_fail_after_restart.Bug-3063.py 
b/sql/test/BugTracker-2012/Tests/table_functions_fail_after_restart.Bug-3063.py
--- 
a/sql/test/BugTracker-2012/Tests/table_functions_fail_after_restart.Bug-3063.py
+++ 
b/sql/test/BugTracker-2012/Tests/table_functions_fail_after_restart.Bug-3063.py
@@ -1,4 +1,5 @@
-import os, sys, tempfile, pymonetdb
+from MonetDBtesting import tpymonetdb as pymonetdb
+import os, sys, tempfile
 
 try:
     from MonetDBtesting import process
diff --git a/sql/test/BugTracker-2013/Tests/binary_copy_into.Bug-3345.SQL.py 
b/sql/test/BugTracker-2013/Tests/binary_copy_into.Bug-3345.SQL.py
--- a/sql/test/BugTracker-2013/Tests/binary_copy_into.Bug-3345.SQL.py
+++ b/sql/test/BugTracker-2013/Tests/binary_copy_into.Bug-3345.SQL.py
@@ -1,4 +1,5 @@
-import os, sys, shutil, pymonetdb
+from MonetDBtesting import tpymonetdb as pymonetdb
+import os, sys, shutil
 
 src = os.environ['RELSRCDIR']
 dst = os.environ['TSTTRGDIR']
diff --git 
a/sql/test/BugTracker-2013/Tests/corrupt-after-restart.Bug-3282.SQL.py 
b/sql/test/BugTracker-2013/Tests/corrupt-after-restart.Bug-3282.SQL.py
--- a/sql/test/BugTracker-2013/Tests/corrupt-after-restart.Bug-3282.SQL.py
+++ b/sql/test/BugTracker-2013/Tests/corrupt-after-restart.Bug-3282.SQL.py
@@ -1,4 +1,5 @@
-import os, sys, tempfile, pymonetdb
+from MonetDBtesting import tpymonetdb as pymonetdb
+import os, sys, tempfile
 try:
     from MonetDBtesting import process
 except ImportError:
diff --git a/sql/test/BugTracker-2013/Tests/empty-strings.Bug-3261.SQL.py 
b/sql/test/BugTracker-2013/Tests/empty-strings.Bug-3261.SQL.py
--- a/sql/test/BugTracker-2013/Tests/empty-strings.Bug-3261.SQL.py
+++ b/sql/test/BugTracker-2013/Tests/empty-strings.Bug-3261.SQL.py
@@ -1,4 +1,5 @@
-import pymonetdb, sys, os
+from MonetDBtesting import tpymonetdb as pymonetdb
+import sys, os
 
 port = int(os.environ['MAPIPORT'])
 db = os.environ['TSTDB']
diff --git a/sql/test/BugTracker-2014/Tests/acidity-fail.Bug-3635.py 
b/sql/test/BugTracker-2014/Tests/acidity-fail.Bug-3635.py
--- a/sql/test/BugTracker-2014/Tests/acidity-fail.Bug-3635.py
+++ b/sql/test/BugTracker-2014/Tests/acidity-fail.Bug-3635.py
@@ -3,7 +3,8 @@ try:
_______________________________________________
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org

Reply via email to