Changeset: 86deb205b886 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=86deb205b886 Modified Files: sql/backends/monet5/rel_bin.c sql/backends/monet5/sql.c sql/backends/monet5/sql_cat.c sql/backends/monet5/sql_statement.c sql/backends/monet5/sql_upgrades.c sql/common/sql_types.c sql/common/sql_types.h sql/include/sql_catalog.h sql/server/rel_dump.c sql/server/rel_exp.c sql/server/rel_optimizer.c sql/server/rel_propagate.c sql/server/rel_psm.c sql/server/rel_psm.h sql/server/rel_rel.c sql/server/rel_schema.c sql/server/rel_select.c sql/server/rel_select.h sql/server/rel_sequence.c sql/server/rel_unnest.c sql/server/rel_updates.c sql/server/sql_mvc.c sql/server/sql_mvc.h sql/server/sql_parser.y sql/server/sql_privileges.c sql/server/sql_scan.c sql/server/sql_semantic.c sql/server/sql_semantic.h sql/storage/sql_catalog.c Branch: scoping2 Log Message:
Binding sql functions according to scoping rules. Some leftover cleanup is needed, as well test approvals diffs (truncated from 4904 to 300 lines): diff --git a/sql/backends/monet5/rel_bin.c b/sql/backends/monet5/rel_bin.c --- a/sql/backends/monet5/rel_bin.c +++ b/sql/backends/monet5/rel_bin.c @@ -41,22 +41,22 @@ stmt_selectnil( backend *be, stmt *col) } static stmt * -sql_unop_(backend *be, sql_schema *s, const char *fname, stmt *rs) +sql_unop_(backend *be, const char *fname, stmt *rs) { mvc *sql = be->mvc; sql_subtype *rt = NULL; sql_subfunc *f = NULL; - if (!s) - s = sql->session->schema; rt = tail_type(rs); - f = sql_bind_func(sql->sa, s, fname, rt, NULL, F_FUNC); + f = sql_bind_func(sql, "sys", fname, rt, NULL, F_FUNC); /* try to find the function without a type, and convert * the value to the type needed by this function! */ - if (!f && (f = sql_find_func(sql->sa, s, fname, 1, F_FUNC, NULL)) != NULL) { + if (!f && (f = sql_find_func(sql, "sys", fname, 1, F_FUNC, NULL)) != NULL) { sql_arg *a = f->func->ops->h->data; + sql->session->status = 0; + sql->errstr[0] = '\0'; rs = check_types(be, &a->type, rs, type_equal); if (!rs) f = NULL; @@ -72,7 +72,7 @@ sql_unop_(backend *be, sql_schema *s, co } else if (rs) { char *type = tail_type(rs)->type->sqlname; - return sql_error(sql, 02, SQLSTATE(42000) "SELECT: no such unary operator '%s(%s)'", fname, type); + return sql_error(sql, ERR_NOTFOUND, SQLSTATE(42000) "SELECT: no such unary operator '%s(%s)'", fname, type); } return NULL; } @@ -377,10 +377,10 @@ handle_in_exps(backend *be, sql_exp *ce, if (c->nrcols == 0 || (depth && !reduce)) { sql_subtype *bt = sql_bind_localtype("bit"); sql_subfunc *cmp = (in) - ?sql_bind_func(sql->sa, sql->session->schema, "=", tail_type(c), tail_type(c), F_FUNC) - :sql_bind_func(sql->sa, sql->session->schema, "<>", tail_type(c), tail_type(c), F_FUNC); - sql_subfunc *a = (in)?sql_bind_func(sql->sa, sql->session->schema, "or", bt, bt, F_FUNC) - :sql_bind_func(sql->sa, sql->session->schema, "and", bt, bt, F_FUNC); + ?sql_bind_func(sql, "sys", "=", tail_type(c), tail_type(c), F_FUNC) + :sql_bind_func(sql, "sys", "<>", tail_type(c), tail_type(c), F_FUNC); + sql_subfunc *a = (in)?sql_bind_func(sql, "sys", "or", bt, bt, F_FUNC) + :sql_bind_func(sql, "sys", "and", bt, bt, F_FUNC); for( n = nl->h; n; n = n->next) { sql_exp *e = n->data; @@ -547,7 +547,7 @@ exp_bin_or(backend *be, sql_exp *e, stmt return s; if (!sin && sel1 && sel1->nrcols == 0 && s->nrcols == 0) { - sql_subfunc *f = sql_bind_func(be->mvc->sa, be->mvc->session->schema, anti?"or":"and", bt, bt, F_FUNC); + sql_subfunc *f = sql_bind_func(be->mvc, "sys", anti?"or":"and", bt, bt, F_FUNC); assert(f); s = stmt_binop(be, sel1, s, f); } else if (sel1 && (sel1->nrcols == 0 || s->nrcols == 0)) { @@ -574,7 +574,7 @@ exp_bin_or(backend *be, sql_exp *e, stmt return s; if (!sin && sel2 && sel2->nrcols == 0 && s->nrcols == 0) { - sql_subfunc *f = sql_bind_func(be->mvc->sa, be->mvc->session->schema, anti?"or":"and", bt, bt, F_FUNC); + sql_subfunc *f = sql_bind_func(be->mvc, "sys", anti?"or":"and", bt, bt, F_FUNC); assert(f); s = stmt_binop(be, sel2, s, f); } else if (sel2 && (sel2->nrcols == 0 || s->nrcols == 0)) { @@ -589,7 +589,7 @@ exp_bin_or(backend *be, sql_exp *e, stmt sel2 = s; } if (sel1->nrcols == 0 && sel2->nrcols == 0) { - sql_subfunc *f = sql_bind_func(be->mvc->sa, be->mvc->session->schema, anti?"and":"or", bt, bt, F_FUNC); + sql_subfunc *f = sql_bind_func(be->mvc, "sys", anti?"and":"or", bt, bt, F_FUNC); assert(f); return stmt_binop(be, sel1, sel2, f); } @@ -617,9 +617,9 @@ exp2bin_case(backend *be, sql_exp *fe, s int next_cond = 1, single_value = (fe->card <= CARD_ATOM && (!left || !left->nrcols)); char name[16], *nme = NULL; sql_subtype *bt = sql_bind_localtype("bit"); - sql_subfunc *not = sql_bind_func(be->mvc->sa, be->mvc->session->schema, "not", bt, NULL, F_FUNC); - sql_subfunc *or = sql_bind_func(be->mvc->sa, NULL, "or", bt, bt, F_FUNC); - sql_subfunc *and = sql_bind_func(be->mvc->sa, be->mvc->session->schema, "and", bt, bt, F_FUNC); + sql_subfunc *not = sql_bind_func(be->mvc, "sys", "not", bt, NULL, F_FUNC); + sql_subfunc *or = sql_bind_func(be->mvc, "sys", "or", bt, bt, F_FUNC); + sql_subfunc *and = sql_bind_func(be->mvc, "sys", "and", bt, bt, F_FUNC); if (single_value) { /* var_x = nil; */ @@ -721,7 +721,7 @@ exp2bin_case(backend *be, sql_exp *fe, s if (en->next) { cond = stmt_unop(be, cond, not); - sql_subfunc *isnull = sql_bind_func(be->mvc->sa, be->mvc->session->schema, "isnull", bt, NULL, F_FUNC); + sql_subfunc *isnull = sql_bind_func(be->mvc, "sys", "isnull", bt, NULL, F_FUNC); cond = stmt_binop(be, cond, stmt_unop(be, cond, isnull), or); if (ocond) cond = stmt_binop(be, ocond, cond, and); @@ -749,8 +749,8 @@ exp2bin_coalesce(backend *be, sql_exp *f int single_value = (fe->card <= CARD_ATOM && (!left || !left->nrcols)); char name[16], *nme = NULL; sql_subtype *bt = sql_bind_localtype("bit"); - sql_subfunc *and = sql_bind_func(be->mvc->sa, NULL, "and", bt, bt, F_FUNC); - sql_subfunc *not = sql_bind_func(be->mvc->sa, be->mvc->session->schema, "not", bt, NULL, F_FUNC); + sql_subfunc *and = sql_bind_func(be->mvc, "sys", "and", bt, bt, F_FUNC); + sql_subfunc *not = sql_bind_func(be->mvc, "sys", "not", bt, NULL, F_FUNC); if (single_value) { /* var_x = nil; */ @@ -789,7 +789,7 @@ exp2bin_coalesce(backend *be, sql_exp *f stmt *pos = rsel; if (en->next) { - sql_subfunc *a = sql_bind_func(be->mvc->sa, be->mvc->session->schema, "isnotnull", tail_type(es), NULL, F_FUNC); + sql_subfunc *a = sql_bind_func(be->mvc, "sys", "isnotnull", tail_type(es), NULL, F_FUNC); ncond = stmt_unop(be, es, a); if (ncond->nrcols == 0) { stmt *l = bin_first_column(be, left); @@ -829,7 +829,7 @@ exp2bin_coalesce(backend *be, sql_exp *f } else { stmt *cond = ocond; if (en->next) { - sql_subfunc *a = sql_bind_func(be->mvc->sa, be->mvc->session->schema, "isnotnull", tail_type(es), NULL, F_FUNC); + sql_subfunc *a = sql_bind_func(be->mvc, "sys", "isnotnull", tail_type(es), NULL, F_FUNC); ncond = stmt_unop(be, es, a); if (ocond) @@ -1000,7 +1000,7 @@ exp_bin(backend *be, sql_exp *e, stmt *l if (f->func->side_effect && left && left->nrcols > 0) { sql_subfunc *f1 = NULL; /* we cannot assume all SQL functions with no arguments have a correspondent with one argument, so attempt to find it. 'rand' function is the exception */ - if (list_empty(exps) && (strcmp(f->func->base.name, "rand") == 0 || (f1 = sql_find_func(sql->sa, f->func->s, f->func->base.name, 1, f->func->type, NULL)))) { + if (list_empty(exps) && (strcmp(f->func->base.name, "rand") == 0 || (f1 = sql_find_func(sql, f->func->s ? f->func->s->base.name : NULL, f->func->base.name, 1, f->func->type, NULL)))) { if (f1) f = f1; list_append(l, stmt_const(be, bin_first_column(be, left), @@ -1008,6 +1008,8 @@ exp_bin(backend *be, sql_exp *e, stmt *l } else if (exps_card(exps) < CARD_MULTI) { rows = bin_first_column(be, left); } + sql->session->status = 0; /* if the function was not found clean the error */ + sql->errstr[0] = '\0'; } assert(!e->r); if (strcmp(sql_func_mod(f->func), "") == 0 && strcmp(sql_func_imp(f->func), "") == 0 && strcmp(f->func->base.name, "star") == 0) @@ -1276,7 +1278,7 @@ exp_bin(backend *be, sql_exp *e, stmt *l int in_flag = e->flag==mark_in?1:0; if (e->anti) in_flag = !in_flag; - sql_subfunc *f = sql_bind_func(sql->sa, sql->session->schema, in_flag?"=":"<>", tail_type(l), tail_type(l), F_FUNC); + sql_subfunc *f = sql_bind_func(sql, "sys", in_flag?"=":"<>", tail_type(l), tail_type(l), F_FUNC); assert(f); s = stmt_binop(be, l, r, f); if (l->cand) @@ -1284,9 +1286,8 @@ exp_bin(backend *be, sql_exp *e, stmt *l if (r->cand) s->cand = r->cand; } else if (!reduce || (l->nrcols == 0 && r->nrcols == 0)) { - sql_subfunc *f = sql_bind_func(sql->sa, sql->session->schema, - compare_func((comp_type)e->flag, is_anti(e)), - tail_type(l), tail_type(l), F_FUNC); + sql_subfunc *f = sql_bind_func(sql, "sys", compare_func((comp_type)e->flag, is_anti(e)), + tail_type(l), tail_type(l), F_FUNC); assert(f); if (is_semantics(e)) { if (exp_is_null(e->l) && exp_is_null(e->r)) { @@ -1441,10 +1442,9 @@ sql_Nop_(backend *be, const char *fname, list_append(tl, tail_type(a4)); } - f = sql_bind_func_(sql->sa, sql->session->schema, fname, tl, F_FUNC); - if (f) + if ((f = sql_bind_func_(sql, "sys", fname, tl, F_FUNC))) return stmt_Nop(be, stmt_list(be, sl), f); - return sql_error(sql, 02, SQLSTATE(42000) "SELECT: no such operator '%s'", fname); + return sql_error(sql, ERR_NOTFOUND, SQLSTATE(42000) "SELECT: no such operator '%s'", fname); } static stmt * @@ -2029,13 +2029,13 @@ rel2bin_hash_lookup(backend *be, sql_rel if (!s) return NULL; if (h) { - sql_subfunc *xor = sql_bind_func_result(sql->sa, sql->session->schema, "rotate_xor_hash", F_FUNC, lng, 3, lng, it, tail_type(s)); + sql_subfunc *xor = sql_bind_func_result(sql, "sys", "rotate_xor_hash", F_FUNC, lng, 3, lng, it, tail_type(s)); h = stmt_Nop(be, stmt_list(be, list_append( list_append( list_append(sa_list(sql->sa), h), bits), s)), xor); semantics = 1; } else { - sql_subfunc *hf = sql_bind_func_result(sql->sa, sql->session->schema, "hash", F_FUNC, lng, 1, tail_type(s)); + sql_subfunc *hf = sql_bind_func_result(sql, "sys", "hash", F_FUNC, lng, 1, tail_type(s)); h = stmt_unop(be, s, hf); } @@ -2066,11 +2066,11 @@ join_hash_key( backend *be, list *l ) stmt *s = m->data; if (h) { - sql_subfunc *xor = sql_bind_func_result(sql->sa, sql->session->schema, "rotate_xor_hash", F_FUNC, lng, 3, lng, it, tail_type(s)); + sql_subfunc *xor = sql_bind_func_result(sql, "sys", "rotate_xor_hash", F_FUNC, lng, 3, lng, it, tail_type(s)); h = stmt_Nop(be, stmt_list(be, list_append( list_append( list_append(sa_list(sql->sa), h), bits), s )), xor); } else { - sql_subfunc *hf = sql_bind_func_result(sql->sa, sql->session->schema, "hash", F_FUNC, lng, 1, tail_type(s)); + sql_subfunc *hf = sql_bind_func_result(sql, "sys", "hash", F_FUNC, lng, 1, tail_type(s)); h = stmt_unop(be, s, hf); } } @@ -2122,7 +2122,7 @@ releqjoin( backend *be, list *l1, list * stmt * cmp; list *ops; - f = sql_bind_func(sql->sa, sql->session->schema, "=", tail_type(le), tail_type(le), F_FUNC); + f = sql_bind_func(sql, "sys", "=", tail_type(le), tail_type(le), F_FUNC); assert(f); ops = sa_list(be->mvc->sa); @@ -2952,7 +2952,7 @@ rel2bin_except(backend *be, sql_rel *rel lcnt = stmt_append(be, lcnt, ncnt); rcnt = stmt_append(be, rcnt, zero); - min = sql_bind_func(sql->sa, sql->session->schema, "sql_sub", lng, lng, F_FUNC); + min = sql_bind_func(sql, "sys", "sql_sub", lng, lng, F_FUNC); s = stmt_binop(be, lcnt, rcnt, min); /* use count */ /* now we have gid,cnt, blowup to full groupsizes */ @@ -3050,7 +3050,7 @@ rel2bin_inter(backend *be, sql_rel *rel, lcnt = stmt_project(be, lm, lcnt); rcnt = stmt_project(be, rm, rcnt); - min = sql_bind_func(sql->sa, sql->session->schema, "sql_min", lng, lng, F_FUNC); + min = sql_bind_func(sql, "sys", "sql_min", lng, lng, F_FUNC); s = stmt_binop(be, lcnt, rcnt, min); /* now we have gid,cnt, blowup to full groupsizes */ @@ -3136,7 +3136,7 @@ rel2bin_project(backend *be, sql_rel *re return NULL; if (oe) { sql_subtype *lng = sql_bind_localtype("lng"); - sql_subfunc *add = sql_bind_func_result(sql->sa, sql->session->schema, "sql_add", F_FUNC, lng, 2, lng, lng); + sql_subfunc *add = sql_bind_func_result(sql, "sys", "sql_add", F_FUNC, lng, 2, lng, lng); stmt *o = exp_bin(be, oe, NULL, NULL, NULL, NULL, NULL, NULL, 0, 0, 0); if(!o) return NULL; @@ -3590,10 +3590,10 @@ insert_check_ukey(backend *be, list *ins stmt *res; sql_subtype *lng = sql_bind_localtype("lng"); - sql_subfunc *cnt = sql_bind_func(sql->sa, sql->session->schema, "count", sql_bind_localtype("void"), NULL, F_AGGR); + sql_subfunc *cnt = sql_bind_func(sql, "sys", "count", sql_bind_localtype("void"), NULL, F_AGGR); sql_subtype *bt = sql_bind_localtype("bit"); stmt *dels = stmt_tid(be, k->t, 0); - sql_subfunc *ne = sql_bind_func_result(sql->sa, sql->session->schema, "<>", F_FUNC, bt, 2, lng, lng); + sql_subfunc *ne = sql_bind_func_result(sql, "sys", "<>", F_FUNC, bt, 2, lng, lng); if (list_length(k->columns) > 1) { node *m; @@ -3642,7 +3642,7 @@ insert_check_ukey(backend *be, list *ins /* 2nd stage: find out if inserted are unique */ if ((!idx_inserts && ins->nrcols) || (idx_inserts && idx_inserts->nrcols)) { /* insert columns not atoms */ - sql_subfunc *or = sql_bind_func_result(sql->sa, sql->session->schema, "or", F_FUNC, bt, 2, bt, bt); + sql_subfunc *or = sql_bind_func_result(sql, "sys", "or", F_FUNC, bt, 2, bt, bt); stmt *orderby_ids = NULL, *orderby_grp = NULL; stmt *sel = NULL; @@ -3675,7 +3675,7 @@ insert_check_ukey(backend *be, list *ins if (!orderby_grp || !orderby_ids) return NULL; - sum = sql_bind_func(sql->sa, sql->session->schema, "not_unique", tail_type(orderby_grp), NULL, F_AGGR); + sum = sql_bind_func(sql, "sys", "not_unique", tail_type(orderby_grp), NULL, F_AGGR); ssum = stmt_aggr(be, orderby_grp, NULL, NULL, sum, 1, 0, 1); /* combine results */ s = stmt_binop(be, s, ssum, or); @@ -3713,7 +3713,7 @@ insert_check_ukey(backend *be, list *ins if (h->nrcols) { /* insert multiple atoms */ sql_subfunc *sum; stmt *count_sum = NULL; - sql_subfunc *or = sql_bind_func_result(sql->sa, sql->session->schema, "or", F_FUNC, bt, 2, bt, bt); + sql_subfunc *or = sql_bind_func_result(sql, "sys", "or", F_FUNC, bt, 2, bt, bt); stmt *ssum, *ss; stmt *g = list_fetch(inserts, c->c->colnr), *ins = g; @@ -3727,9 +3727,9 @@ insert_check_ukey(backend *be, list *ins g = stmt_group(be, ins, NULL, NULL, NULL, 1); ss = stmt_result(be, g, 2); /* use count */ /* (count(ss) <> sum(ss)) */ - sum = sql_bind_func(sql->sa, sql->session->schema, "sum", lng, NULL, F_AGGR); + sum = sql_bind_func(sql, "sys", "sum", lng, NULL, F_AGGR); ssum = stmt_aggr(be, ss, NULL, NULL, sum, 1, 0, 1); - ssum = sql_Nop_(be, "ifthenelse", sql_unop_(be, NULL, "isnull", ssum), stmt_atom_lng(be, 0), ssum, NULL); + ssum = sql_Nop_(be, "ifthenelse", sql_unop_(be, "isnull", ssum), stmt_atom_lng(be, 0), ssum, NULL); _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list