Changeset: 58f2d2209093 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/58f2d2209093 Modified Files: sql/server/rel_exp.c sql/server/rel_exp.h sql/server/rel_select.c sql/server/rel_unnest.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: nested Log Message:
merged with default diffs (285 lines): diff --git a/sql/server/rel_exp.c b/sql/server/rel_exp.c --- a/sql/server/rel_exp.c +++ b/sql/server/rel_exp.c @@ -1221,6 +1221,15 @@ exp_equal( sql_exp *e1, sql_exp *e2) } int +is_conflict( sql_exp *e1, sql_exp *e2) +{ + if (e1->alias.label && e1->alias.label == e2->alias.label && + e1->nid && e1->nid != e2->nid) + return 0; + return -1; +} + +int exp_match( sql_exp *e1, sql_exp *e2) { if (exp_cmp(e1, e2) == 0) diff --git a/sql/server/rel_exp.h b/sql/server/rel_exp.h --- a/sql/server/rel_exp.h +++ b/sql/server/rel_exp.h @@ -144,6 +144,7 @@ extern bool rel_find_nid(sql_rel *rel, i extern int exp_cmp( sql_exp *e1, sql_exp *e2); extern int exp_equal( sql_exp *e1, sql_exp *e2); +extern int is_conflict( sql_exp *e1, sql_exp *e2); extern int exp_refers( sql_exp *p, sql_exp *c); extern sql_exp *exps_refers( sql_exp *p, list *exps); extern int exp_match( sql_exp *e1, sql_exp *e2); 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 @@ -383,7 +383,7 @@ rel_with_query(sql_query *query, symbol set_distinct(nrel); rel_setop_n_ary_set_exps(sql, nrel, rel_projections(sql, nrel, NULL, 0, 1), false); set_processed(nrel); - recursive_union->rel_view = rel_dup(nrel); /* extra incref for independent flow */ + recursive_union->rel_view = nrel; } if (!is_project(nrel->op)) { if (is_topn(nrel->op) || is_sample(nrel->op)) { @@ -3128,7 +3128,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 * @@ -3303,8 +3303,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; @@ -3457,7 +3460,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}; @@ -3505,7 +3508,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); @@ -3730,12 +3733,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; @@ -3880,11 +3883,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/rel_unnest.c b/sql/server/rel_unnest.c --- a/sql/server/rel_unnest.c +++ b/sql/server/rel_unnest.c @@ -889,17 +889,25 @@ push_up_project(mvc *sql, sql_rel *rel, } } if (cexps) { - sql_rel *p = l->l = rel_project( sql->sa, l->l, - rel_projections(sql, l->l, NULL, 1, 1)); - p->exps = list_distinct(list_merge(p->exps, cexps, (fdup)NULL), (fcmp)exp_equal, (fdup)NULL); - if (list_empty(nexps)) { - rel->r = l; /* remove empty project */ - } else { - for (n = cexps->h; n; n = n->next) { /* add pushed down renamed expressions */ - sql_exp *e = n->data; - append(nexps, exp_ref(sql, e)); + list *exps = rel_projections(sql, l->l, NULL, 1, 1); + bool dup = false; + for (node *n = cexps->h; n && !dup; n = n->next) + /* do we have an expression which will result in same alias but different origin */ + if (list_find(exps, n->data, (fcmp)&is_conflict)) + dup = true; + + if (!dup) { + exps = list_distinct(list_merge(exps, cexps, (fdup)NULL), (fcmp)exp_equal, (fdup)NULL); + l->l = rel_project( sql->sa, l->l, exps); + if (list_empty(nexps)) { + rel->r = l; /* remove empty project */ + } else { + for (n = cexps->h; n; n = n->next) { /* add pushed down renamed expressions */ + sql_exp *e = n->data; + append(nexps, exp_ref(sql, e)); + } + r->exps = nexps; } - r->exps = nexps; } } } @@ -1600,6 +1608,8 @@ push_up_munion(mvc *sql, sql_rel *rel, l sql_rel *r = iu->h->data; set_recursive(r); append(rlist, rel_dup(r)); + if (is_project(r->op)) + len = list_length(r->exps); } for(node *n = rec?iu->h->next:iu->h; n; n = n->next) { sql_rel *sl = n->data; 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 @@ -4775,10 +4775,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 @@ -5099,13 +5096,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(); @@ -7070,20 +7067,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 ---- -1785 values hashing to 0d815c368d5385ba6ef8574cb153f6ec +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 @@ -3951,6 +3951,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" ] @@ -4219,6 +4220,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 @@ -3951,6 +3951,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" ] @@ -4219,6 +4220,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 @@ -4066,6 +4066,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" ] @@ -4334,6 +4335,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