Changeset: 9855331416db for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/9855331416db
Modified Files:
        sql/backends/monet5/rel_physical.c
        sql/server/rel_select.c
        sql/server/sql_parser.y
        sql/test/Dependencies/Tests/dependency_owner_schema_3.test
        sql/test/emptydb/Tests/check.stable.out
        sql/test/emptydb/Tests/check.stable.out.32bit
        sql/test/emptydb/Tests/check.stable.out.int128
Branch: default
Log Message:

handle ordered aggregates again after parser changes


diffs (224 lines):

diff --git a/sql/backends/monet5/rel_physical.c 
b/sql/backends/monet5/rel_physical.c
--- a/sql/backends/monet5/rel_physical.c
+++ b/sql/backends/monet5/rel_physical.c
@@ -91,22 +91,12 @@ exp_timezone(visitor *v, sql_rel *rel, s
        return e;
 }
 
-static sql_rel *
-rel_add_ref4_rec_union(visitor *v, sql_rel *rel)
-{
-       (void)v;
-       if (is_recursive(rel))
-               rel = rel_dup(rel);
-       return rel;
-}
-
 sql_rel *
 rel_physical(mvc *sql, sql_rel *rel)
 {
        visitor v = { .sql = sql };
 
        rel = rel_visitor_bottomup(&v, rel, &rel_add_orderby);
-       rel = rel_visitor_topdown(&v, rel, &rel_add_ref4_rec_union);
        rel = rel_exp_visitor_topdown(&v, rel, &exp_timezone, true);
 
 #ifdef HAVE_HGE
diff --git a/sql/server/rel_select.c b/sql/server/rel_select.c
--- a/sql/server/rel_select.c
+++ b/sql/server/rel_select.c
@@ -3130,7 +3130,7 @@ rel_logical_exp(sql_query *query, sql_re
        /* never reached, as all switch cases have a `return` */
 }
 
-static sql_exp * _rel_aggr(sql_query *query, sql_rel **rel, int distinct, char 
*sname, char *aname, dnode *arguments, int f);
+static sql_exp * _rel_aggr(sql_query *query, sql_rel **rel, int distinct, char 
*sname, char *aname, dnode *arguments, symbol *orderby, int f);
 static sql_exp *rel_aggr(sql_query *query, sql_rel **rel, symbol *se, int f);
 
 sql_exp *
@@ -3305,8 +3305,11 @@ rel_nop(sql_query *query, sql_rel **rel,
                        nargs++;
 
                /* first try aggregate */
-               if (find_func(sql, sname, fname, nargs, F_AGGR, false, NULL, 
NULL))
-                       return _rel_aggr(query, rel, l->next->data.i_val, 
sname, fname, l->next->next->data.lval->h, fs);
+               if (find_func(sql, sname, fname, nargs, F_AGGR, false, NULL, 
NULL)) {
+                       dnode *dn = l->next->next;
+                       symbol *orderby = dn->next?dn->next->data.sym:NULL;
+                       return _rel_aggr(query, rel, l->next->data.i_val, 
sname, fname, dn->data.lval->h, orderby, fs);
+               }
        }
 
        int nr_args = 0;
@@ -3459,7 +3462,7 @@ exps_valid(sql_query *query, list *exps,
 static list * rel_order_by(sql_query *query, sql_rel **R, symbol *orderby, int 
needs_distinct, int f);
 
 static sql_exp *
-_rel_aggr(sql_query *query, sql_rel **rel, int distinct, char *sname, char 
*aname, dnode *args, int f)
+_rel_aggr(sql_query *query, sql_rel **rel, int distinct, char *sname, char 
*aname, dnode *args, symbol *orderby, int f)
 {
        mvc *sql = query->sql;
        exp_kind ek = {type_value, card_column, FALSE};
@@ -3507,7 +3510,7 @@ static sql_exp *
                bool arguments_correlated = true, all_const = true;
 
                all_freevar = all_aggr?1:0;
-               for (i = 0; args && args->data.sym && args->data.sym->token != 
SQL_ORDERBY; args = args->next, i++) {
+               for (i = 0; args && args->data.sym; args = args->next, i++) {
                        int base = (!groupby || !is_project(groupby->op) || 
is_base(groupby->op) || is_processed(groupby));
                        sql_rel *gl = base?groupby:groupby->l, *ogl = gl; /* 
handle case of subqueries without correlation */
                        sql_exp *e = rel_value_exp(query, &gl, args->data.sym, 
(f | sql_aggr)& ~sql_farg, ek);
@@ -3732,12 +3735,12 @@ static sql_exp *
 
        list *obe = NULL;
        bool handled_order = true;
-       if (args && args->data.sym && args->data.sym->token != SQL_ORDERBY)
+       if (args)
                        return NULL;
-       if (args && args->data.sym) { /* handle order by */
+       if (orderby) { /* handle order by */
                int base = (!groupby || !is_project(groupby->op) || 
is_base(groupby->op) || is_processed(groupby));
                sql_rel *gl = base?groupby:groupby->l;//, *ogl = gl; /* handle 
case of subqueries without correlation */
-               obe = rel_order_by(query, &gl, args->data.sym, 0, f);
+               obe = rel_order_by(query, &gl, orderby, 0, f);
                if (!obe)
                        return NULL;
                handled_order = false;
@@ -3882,11 +3885,12 @@ rel_aggr(sql_query *query, sql_rel **rel
 {
        dlist *l = se->data.lval;
        dnode *d = l->h->next->next;
+       symbol *orderby = d->next?d->next->data.sym:NULL;
        int distinct = l->h->next->data.i_val;
        char *aname = qname_schema_object(l->h->data.lval);
        char *sname = qname_schema(l->h->data.lval);
 
-       return _rel_aggr(query, rel, distinct, sname, aname, d, f);
+       return _rel_aggr(query, rel, distinct, sname, aname, 
d->data.lval?d->data.lval->h:NULL, orderby, f);
 }
 
 static sql_exp *
diff --git a/sql/server/sql_parser.y b/sql/server/sql_parser.y
--- a/sql/server/sql_parser.y
+++ b/sql/server/sql_parser.y
@@ -4720,10 +4720,7 @@ value_exp:
        { dlist *l = L();
                append_list(l, append_string(L(), "grouping"));
                append_int(l, FALSE); /* ignore distinct */
-               for (dnode *dn = $3->h ; dn ; dn = dn->next) {
-                       symbol *sym = dn->data.sym; /* do like a aggrN */
-                       append_symbol(l, _symbol_create_list(SQL_COLUMN, 
sym->data.lval));
-               }
+               append_list(l, $3);
                $$ = _symbol_create_list(SQL_AGGR, l); }
  |  NEXT VALUE FOR qname                  { $$ = _symbol_create_list(SQL_NEXT, 
$4); }
  |  null
@@ -5051,13 +5048,13 @@ aggr_or_window_ref:
                { dlist *l = L();
                  append_list(l, $1);
                  append_int(l, FALSE); /* ignore distinct */
-                 append_symbol(l, NULL);
+                 append_list(l, NULL);
                  $$ = _symbol_create_list(SQL_AGGR, l ); }
  |  qfunc '(' column_id '.' '*' ')'
                { dlist *l = L();
                  append_list(l, $1);
                  append_int(l, FALSE); /* ignore distinct */
-                 append_symbol(l, NULL);
+                 append_list(l, NULL);
                  $$ = _symbol_create_list(SQL_AGGR, l ); }
  |  qfunc '(' ')'
                { dlist *l = L();
@@ -7020,20 +7017,12 @@ XML_aggregate:
        {
          dlist *aggr = L();
 
-         if ($4) {
-               if ($3 != NULL && $3->token == SQL_SELECT) {
-                       SelectNode *s = (SelectNode*)$3;
-                       s->orderby = $4;
-               } else {
-                       yyerror(m, "ORDER BY: missing select operator");
-                       YYABORT;
-               }
-         }
          append_list(aggr, append_string(append_string(L(), "sys"), "xmlagg"));
          append_int(aggr, FALSE); /* ignore distinct */
-         append_symbol(aggr, $3);
+         append_list(aggr, append_symbol(L(), $3));
+         append_symbol(aggr, $4);
          /* int returning not used */
-         $$ = _symbol_create_list( SQL_AGGR, aggr);
+         $$ = _symbol_create_list( SQL_NOP, aggr);
        }
  ;
 
diff --git a/sql/test/Dependencies/Tests/dependency_owner_schema_3.test 
b/sql/test/Dependencies/Tests/dependency_owner_schema_3.test
--- a/sql/test/Dependencies/Tests/dependency_owner_schema_3.test
+++ b/sql/test/Dependencies/Tests/dependency_owner_schema_3.test
@@ -886,7 +886,7 @@ DEP_FUNC
 query TTT nosort
 SELECT distinct c.name, v.name, 'DEP_VIEW' from sys.columns as c, sys.tables 
as v, sys.dependencies as dep where c.id = dep.id AND v.id = dep.depend_id AND 
dep.depend_type = 5 AND v.type in (1, 11, 21, 31) order by c.name, v.name
 ----
-1782 values hashing to 88adfb6235ea1b5387ae4b7625859b0c
+1788 values hashing to a7640c35ae84fb0995f708b8b88e01d0
 
 query TTT nosort
 SELECT c.name, k.name, 'DEP_KEY' from sys.columns as c,  sys.objects as kc, 
sys.keys as k where kc."name" = c.name AND kc.id = k.id AND k.table_id = 
c.table_id AND k.rkey = -1 order by c.name, k.name
diff --git a/sql/test/emptydb/Tests/check.stable.out 
b/sql/test/emptydb/Tests/check.stable.out
--- a/sql/test/emptydb/Tests/check.stable.out
+++ b/sql/test/emptydb/Tests/check.stable.out
@@ -3947,6 +3947,7 @@ select 'null in fkeys.delete_action', de
 [ "column used by view",       "sys",  "args", "func_id",      "sys",  
"describe_functions",   "VIEW"  ]
 [ "column used by view",       "sys",  "args", "inout",        "sys",  
"describe_functions",   "VIEW"  ]
 [ "column used by view",       "sys",  "args", "name", "sys",  
"describe_functions",   "VIEW"  ]
+[ "column used by view",       "sys",  "args", "number",       "sys",  
"describe_functions",   "VIEW"  ]
 [ "column used by view",       "sys",  "args", "type", "sys",  
"describe_functions",   "VIEW"  ]
 [ "column used by view",       "sys",  "args", "type_digits",  "sys",  
"describe_functions",   "VIEW"  ]
 [ "column used by view",       "sys",  "args", "type_scale",   "sys",  
"describe_functions",   "VIEW"  ]
@@ -4215,6 +4216,7 @@ select 'null in fkeys.delete_action', de
 [ "column used by view",       "tmp",  "keys", "table_id",     "sys",  
"fkeys",        "VIEW"  ]
 [ "column used by view",       "tmp",  "keys", "type", "sys",  "fkeys",        
"VIEW"  ]
 [ "column used by view",       "sys",  "args", "func_id",      "sys",  
"fully_qualified_functions",    "VIEW"  ]
+[ "column used by view",       "sys",  "args", "number",       "sys",  
"fully_qualified_functions",    "VIEW"  ]
 [ "column used by view",       "sys",  "args", "type", "sys",  
"fully_qualified_functions",    "VIEW"  ]
 [ "column used by view",       "sys",  "args", "type_digits",  "sys",  
"fully_qualified_functions",    "VIEW"  ]
 [ "column used by view",       "sys",  "args", "type_scale",   "sys",  
"fully_qualified_functions",    "VIEW"  ]
diff --git a/sql/test/emptydb/Tests/check.stable.out.32bit 
b/sql/test/emptydb/Tests/check.stable.out.32bit
--- a/sql/test/emptydb/Tests/check.stable.out.32bit
+++ b/sql/test/emptydb/Tests/check.stable.out.32bit
@@ -3947,6 +3947,7 @@ select 'null in fkeys.delete_action', de
 [ "column used by view",       "sys",  "args", "func_id",      "sys",  
"describe_functions",   "VIEW"  ]
 [ "column used by view",       "sys",  "args", "inout",        "sys",  
"describe_functions",   "VIEW"  ]
 [ "column used by view",       "sys",  "args", "name", "sys",  
"describe_functions",   "VIEW"  ]
+[ "column used by view",       "sys",  "args", "number",       "sys",  
"describe_functions",   "VIEW"  ]
 [ "column used by view",       "sys",  "args", "type", "sys",  
"describe_functions",   "VIEW"  ]
 [ "column used by view",       "sys",  "args", "type_digits",  "sys",  
"describe_functions",   "VIEW"  ]
 [ "column used by view",       "sys",  "args", "type_scale",   "sys",  
"describe_functions",   "VIEW"  ]
@@ -4215,6 +4216,7 @@ select 'null in fkeys.delete_action', de
 [ "column used by view",       "tmp",  "keys", "table_id",     "sys",  
"fkeys",        "VIEW"  ]
 [ "column used by view",       "tmp",  "keys", "type", "sys",  "fkeys",        
"VIEW"  ]
 [ "column used by view",       "sys",  "args", "func_id",      "sys",  
"fully_qualified_functions",    "VIEW"  ]
+[ "column used by view",       "sys",  "args", "number",       "sys",  
"fully_qualified_functions",    "VIEW"  ]
 [ "column used by view",       "sys",  "args", "type", "sys",  
"fully_qualified_functions",    "VIEW"  ]
 [ "column used by view",       "sys",  "args", "type_digits",  "sys",  
"fully_qualified_functions",    "VIEW"  ]
 [ "column used by view",       "sys",  "args", "type_scale",   "sys",  
"fully_qualified_functions",    "VIEW"  ]
diff --git a/sql/test/emptydb/Tests/check.stable.out.int128 
b/sql/test/emptydb/Tests/check.stable.out.int128
--- a/sql/test/emptydb/Tests/check.stable.out.int128
+++ b/sql/test/emptydb/Tests/check.stable.out.int128
@@ -4062,6 +4062,7 @@ select 'null in fkeys.delete_action', de
 [ "column used by view",       "sys",  "args", "func_id",      "sys",  
"describe_functions",   "VIEW"  ]
 [ "column used by view",       "sys",  "args", "inout",        "sys",  
"describe_functions",   "VIEW"  ]
 [ "column used by view",       "sys",  "args", "name", "sys",  
"describe_functions",   "VIEW"  ]
+[ "column used by view",       "sys",  "args", "number",       "sys",  
"describe_functions",   "VIEW"  ]
 [ "column used by view",       "sys",  "args", "type", "sys",  
"describe_functions",   "VIEW"  ]
 [ "column used by view",       "sys",  "args", "type_digits",  "sys",  
"describe_functions",   "VIEW"  ]
 [ "column used by view",       "sys",  "args", "type_scale",   "sys",  
"describe_functions",   "VIEW"  ]
@@ -4330,6 +4331,7 @@ select 'null in fkeys.delete_action', de
 [ "column used by view",       "tmp",  "keys", "table_id",     "sys",  
"fkeys",        "VIEW"  ]
 [ "column used by view",       "tmp",  "keys", "type", "sys",  "fkeys",        
"VIEW"  ]
 [ "column used by view",       "sys",  "args", "func_id",      "sys",  
"fully_qualified_functions",    "VIEW"  ]
+[ "column used by view",       "sys",  "args", "number",       "sys",  
"fully_qualified_functions",    "VIEW"  ]
 [ "column used by view",       "sys",  "args", "type", "sys",  
"fully_qualified_functions",    "VIEW"  ]
 [ "column used by view",       "sys",  "args", "type_digits",  "sys",  
"fully_qualified_functions",    "VIEW"  ]
 [ "column used by view",       "sys",  "args", "type_scale",   "sys",  
"fully_qualified_functions",    "VIEW"  ]
_______________________________________________
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org

Reply via email to