Changeset: e2fec4e3eefa for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=e2fec4e3eefa Branch: default Log Message:
Merged indirect-privs into default diffs (truncated from 13366 to 300 lines): diff --git a/clients/Tests/MAL-signatures.stable.out b/clients/Tests/MAL-signatures.stable.out --- a/clients/Tests/MAL-signatures.stable.out +++ b/clients/Tests/MAL-signatures.stable.out @@ -9513,7 +9513,7 @@ stdout of test 'MAL-signatures` in direc [ "sqlcatalog", "alter_seq", "pattern sqlcatalog.alter_seq(X_1:str, X_2:str, X_3:ptr, X_4:lng):void ", "SQLalter_seq;", "" ] [ "sqlcatalog", "alter_set_table", "pattern sqlcatalog.alter_set_table(X_1:str, X_2:str, X_3:int):void ", "SQLalter_set_table;", "" ] [ "sqlcatalog", "alter_table", "pattern sqlcatalog.alter_table(X_1:str, X_2:str, X_3:ptr, X_4:int):void ", "SQLalter_table;", "" ] -[ "sqlcatalog", "alter_user", "pattern sqlcatalog.alter_user(X_1:str, X_2:str, X_3:int, X_4:str, X_5:str):void ", "SQLalter_user;", "" ] +[ "sqlcatalog", "alter_user", "pattern sqlcatalog.alter_user(X_1:str, X_2:str, X_3:int, X_4:str, X_5:str, X_6:str):void ", "SQLalter_user;", "" ] [ "sqlcatalog", "comment_on", "pattern sqlcatalog.comment_on(X_1:int, X_2:str):void ", "SQLcomment_on;", "" ] [ "sqlcatalog", "create_function", "pattern sqlcatalog.create_function(X_1:str, X_2:str, X_3:ptr):void ", "SQLcreate_function;", "" ] [ "sqlcatalog", "create_role", "pattern sqlcatalog.create_role(X_1:str, X_2:str, X_3:int):void ", "SQLcreate_role;", "" ] @@ -9522,7 +9522,7 @@ stdout of test 'MAL-signatures` in direc [ "sqlcatalog", "create_table", "pattern sqlcatalog.create_table(X_1:str, X_2:str, X_3:ptr, X_4:int):void ", "SQLcreate_table;", "" ] [ "sqlcatalog", "create_trigger", "pattern sqlcatalog.create_trigger(X_1:str, X_2:str, X_3:str, X_4:int, X_5:int, X_6:int, X_7:str, X_8:str, X_9:str, X_10:str):void ", "SQLcreate_trigger;", "" ] [ "sqlcatalog", "create_type", "pattern sqlcatalog.create_type(X_1:str, X_2:str, X_3:str):void ", "SQLcreate_type;", "" ] -[ "sqlcatalog", "create_user", "pattern sqlcatalog.create_user(X_1:str, X_2:str, X_3:int, X_4:str, X_5:str):void ", "SQLcreate_user;", "" ] +[ "sqlcatalog", "create_user", "pattern sqlcatalog.create_user(X_1:str, X_2:str, X_3:int, X_4:str, X_5:str, X_6:str):void ", "SQLcreate_user;", "" ] [ "sqlcatalog", "create_view", "pattern sqlcatalog.create_view(X_1:str, X_2:str, X_3:ptr, X_4:int):void ", "SQLcreate_view;", "" ] [ "sqlcatalog", "drop_constraint", "pattern sqlcatalog.drop_constraint(X_1:str, X_2:str, X_3:int, X_4:int):void ", "SQLdrop_constraint;", "" ] [ "sqlcatalog", "drop_function", "pattern sqlcatalog.drop_function(X_1:str, X_2:str, X_3:int, X_4:int, X_5:int):void ", "SQLdrop_function;", "" ] diff --git a/clients/Tests/MAL-signatures.stable.out.int128 b/clients/Tests/MAL-signatures.stable.out.int128 --- a/clients/Tests/MAL-signatures.stable.out.int128 +++ b/clients/Tests/MAL-signatures.stable.out.int128 @@ -12836,7 +12836,7 @@ stdout of test 'MAL-signatures` in direc [ "sqlcatalog", "alter_seq", "pattern sqlcatalog.alter_seq(X_1:str, X_2:str, X_3:ptr, X_4:lng):void ", "SQLalter_seq;", "" ] [ "sqlcatalog", "alter_set_table", "pattern sqlcatalog.alter_set_table(X_1:str, X_2:str, X_3:int):void ", "SQLalter_set_table;", "" ] [ "sqlcatalog", "alter_table", "pattern sqlcatalog.alter_table(X_1:str, X_2:str, X_3:ptr, X_4:int):void ", "SQLalter_table;", "" ] -[ "sqlcatalog", "alter_user", "pattern sqlcatalog.alter_user(X_1:str, X_2:str, X_3:int, X_4:str, X_5:str):void ", "SQLalter_user;", "" ] +[ "sqlcatalog", "alter_user", "pattern sqlcatalog.alter_user(X_1:str, X_2:str, X_3:int, X_4:str, X_5:str, X_6:str):void ", "SQLalter_user;", "" ] [ "sqlcatalog", "comment_on", "pattern sqlcatalog.comment_on(X_1:int, X_2:str):void ", "SQLcomment_on;", "" ] [ "sqlcatalog", "create_function", "pattern sqlcatalog.create_function(X_1:str, X_2:str, X_3:ptr):void ", "SQLcreate_function;", "" ] [ "sqlcatalog", "create_role", "pattern sqlcatalog.create_role(X_1:str, X_2:str, X_3:int):void ", "SQLcreate_role;", "" ] @@ -12845,7 +12845,7 @@ stdout of test 'MAL-signatures` in direc [ "sqlcatalog", "create_table", "pattern sqlcatalog.create_table(X_1:str, X_2:str, X_3:ptr, X_4:int):void ", "SQLcreate_table;", "" ] [ "sqlcatalog", "create_trigger", "pattern sqlcatalog.create_trigger(X_1:str, X_2:str, X_3:str, X_4:int, X_5:int, X_6:int, X_7:str, X_8:str, X_9:str, X_10:str):void ", "SQLcreate_trigger;", "" ] [ "sqlcatalog", "create_type", "pattern sqlcatalog.create_type(X_1:str, X_2:str, X_3:str):void ", "SQLcreate_type;", "" ] -[ "sqlcatalog", "create_user", "pattern sqlcatalog.create_user(X_1:str, X_2:str, X_3:int, X_4:str, X_5:str):void ", "SQLcreate_user;", "" ] +[ "sqlcatalog", "create_user", "pattern sqlcatalog.create_user(X_1:str, X_2:str, X_3:int, X_4:str, X_5:str, X_6:str):void ", "SQLcreate_user;", "" ] [ "sqlcatalog", "create_view", "pattern sqlcatalog.create_view(X_1:str, X_2:str, X_3:ptr, X_4:int):void ", "SQLcreate_view;", "" ] [ "sqlcatalog", "drop_constraint", "pattern sqlcatalog.drop_constraint(X_1:str, X_2:str, X_3:int, X_4:int):void ", "SQLdrop_constraint;", "" ] [ "sqlcatalog", "drop_function", "pattern sqlcatalog.drop_function(X_1:str, X_2:str, X_3:int, X_4:int, X_5:int):void ", "SQLdrop_function;", "" ] diff --git a/clients/mapiclient/dump.c b/clients/mapiclient/dump.c --- a/clients/mapiclient/dump.c +++ b/clients/mapiclient/dump.c @@ -2196,7 +2196,8 @@ dump_database(Mapi mid, stream *toConsol "SELECT ui.name, " "ui.fullname, " "password_hash(ui.name), " - "s.name " + "s.name, " + "ui.schema_path " "FROM sys.db_user_info ui, " "sys.schemas s " "WHERE ui.default_schema = s.id " @@ -2439,6 +2440,7 @@ dump_database(Mapi mid, stream *toConsol const char *fullname = mapi_fetch_field(hdl, 1); const char *pwhash = mapi_fetch_field(hdl, 2); const char *sname = mapi_fetch_field(hdl, 3); + const char *spath = mapi_fetch_field(hdl, 4); mnstr_printf(toConsole, "CREATE USER "); dquoted_print(toConsole, uname, " "); @@ -2447,7 +2449,8 @@ dump_database(Mapi mid, stream *toConsol mnstr_printf(toConsole, " NAME "); squoted_print(toConsole, fullname, '\'', false); mnstr_printf(toConsole, " SCHEMA "); - dquoted_print(toConsole, describe ? sname : "sys", ";\n"); + dquoted_print(toConsole, describe ? sname : "sys", " "); + mnstr_printf(toConsole, "SCHEMA PATH '%s';\n", spath); } if (mapi_error(mid)) goto bailout; diff --git a/clients/mapiclient/mhelp.c b/clients/mapiclient/mhelp.c --- a/clients/mapiclient/mhelp.c +++ b/clients/mapiclient/mhelp.c @@ -82,7 +82,8 @@ SQLhelp sqlhelp1[] = { "ALTER USER ident RENAME TO ident\n" "ALTER USER SET [ENCRYPTED | UNENCRYPTED] PASSWORD string USING OLD PASSWORD string\n" "ALTER USER ident WITH [ENCRYPTED | UNENCRYPTED] PASSWORD string\n" - "ALTER USER ident [ WITH [ENCRYPTED | UNENCRYPTED] PASSWORD string ] SET SCHEMA ident", + "ALTER USER ident [WITH [ENCRYPTED | UNENCRYPTED] PASSWORD string] SET SCHEMA ident\n" + "ALTER USER ident [WITH [ENCRYPTED | UNENCRYPTED] PASSWORD string] SCHEMA PATH string", "ident", "See also https://www.monetdb.org/Documentation/SQLreference/Users"}, {"ANALYZE", @@ -229,7 +230,7 @@ SQLhelp sqlhelp1[] = { NULL}, {"CREATE USER", "Create a new database user", - "CREATE USER ident WITH [ENCRYPTED | UNENCRYPTED] PASSWORD string NAME string SCHEMA ident", + "CREATE USER ident WITH [ENCRYPTED | UNENCRYPTED] PASSWORD string NAME string SCHEMA ident [SCHEMA PATH string]", "ident", "See also https://www.monetdb.org/Documentation/SQLreference/Users"}, {"CREATE VIEW", diff --git a/sql/ChangeLog.scoping2 b/sql/ChangeLog.scoping2 new file mode 100644 --- /dev/null +++ b/sql/ChangeLog.scoping2 @@ -0,0 +1,27 @@ +# ChangeLog file for sql +# This file is updated with Maddlog + +* Mon Nov 30 2020 Pedro Ferreira <pedro.ferre...@monetdbsolutions.com> +- Added 'schema path' property to user, specifying a list of schemas + to be searched on to find SQL objects such as tables and + functions. The scoping rules have been updated to support this feature + and it now finds SQL objects in the following order: + 1. On occasions with multiple tables (e.g. add foreign key constraint, + add table to a merge table), the child will be searched on the + parent's schema. + 2. For tables only, declared tables on the stack. + 3. 'tmp' schema if not listed on the 'schema path'. + 4. Session's current schema. + 5. Each schema from the 'schema path' in order. + 6. 'sys' schema if not listed on the 'schema path'. + Whenever the full path is specified, ie "schema"."object", no search will + be made besides on the explicit schema. +- To update the schema path ALTER USER x SCHEMA PATH y; statement was added. + [SCHEMA PATH string] syntax was added to the CREATE USER statement. + The schema path must be a single string where each schema must be between + double quotes and separated with a single comma, e.g. '"sch1","sch2"' + For every created user, if the schema path is not given, '"sys"' will be + the default schema path. +- Changes in the schema path won't be reflected on currently connected users, + therefore they have to re-connect to see the change. Non existent schemas + on the path will be ignored. diff --git a/sql/backends/monet5/generator/Tests/crash.Bug-3609.stable.err b/sql/backends/monet5/generator/Tests/crash.Bug-3609.stable.err --- a/sql/backends/monet5/generator/Tests/crash.Bug-3609.stable.err +++ b/sql/backends/monet5/generator/Tests/crash.Bug-3609.stable.err @@ -32,7 +32,7 @@ stderr of test 'crash.Bug-3609` in direc MAPI = (monetdb) /var/tmp/mtest-30092/.s.monetdb.31340 QUERY = select generate_series(0,2,1); -ERROR = !SELECT: no such operator 'generate_series' +ERROR = !SELECT: no such operator 'generate_series'(tinyint, tinyint, tinyint) CODE = 42000 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) @@ -1004,7 +1004,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), @@ -1013,6 +1013,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) @@ -1278,7 +1280,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) @@ -1286,9 +1288,8 @@ exp_bin(backend *be, sql_exp *e, stmt *l _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list