Changeset: 7d0c1a66f48b for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/7d0c1a66f48b Modified Files: sql/backends/monet5/rel_bin.c sql/server/rel_dump.c sql/server/rel_rel.h sql/server/rel_select.c sql/server/sql_partition.c sql/test/emptydb/Tests/check.stable.out.int128 Branch: balanced_union Log Message:
merged with default diffs (truncated from 1797 to 300 lines): diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -12,10 +12,3 @@ References to the old MonetDB5 name have been removed. All packages are now just MonetDB. -* Wed May 8 2024 Niels Nes <ni...@cwi.nl> -- Add support for select exp, count(*) group by 1 order by 1; ie. using - numeric references Added support for group by all and order by all. The - later is ordering on all columns of the selection. The group by all - finds all expressions from the selections which aren't aggregations - and groups on those. All can also be replaced by '*'. - diff --git a/clients/odbc/ChangeLog b/clients/odbc/ChangeLog --- a/clients/odbc/ChangeLog +++ b/clients/odbc/ChangeLog @@ -9,7 +9,6 @@ CERTHASH / Server Certificate Hash = sha256:HEXDIGITS CLIENTKEY / Client Key = PATH CLIENTCERT / Client Certificate = PATH - AUTOCOMMIT / Autocommit = ON/OFF - Several more connection properties have been made configurable: SCHEMA / Schema = NAME TIMEZONE / Time Zone = Minutes East Of UTC @@ -17,8 +16,10 @@ LOGFILE / Log File = PATH LOGINTIMEOUT / Login Timeout = MILLISECONDS CONNECTIONTIMEOUT / Connection Timeout = MILLISECONDS + AUTOCOMMIT / Autocommit = ON/OFF SOCK / Unix Socket = PATH (unix only) -- SQLBrowseConnect adds On/Off suggestions to boolean settings +- SQLBrowseConnect() adds On/Off suggestions to boolean settings and prioritizes the DATABASE attribute if it notices monetdbd requires one. Apart from that only UID/User and PWD/Password are required, all others have sensible defaults. + diff --git a/sql/ChangeLog b/sql/ChangeLog --- a/sql/ChangeLog +++ b/sql/ChangeLog @@ -1,10 +1,20 @@ # ChangeLog file for sql # This file is updated with Maddlog -* Mon May 13 2024 Niels Nes <niels....@monetdbsolutions.com> +* Mon May 13 2024 Niels Nes <ni...@cwi.nl> - Extended sys.generate_series() to generate dates. Added 2 new functions: - sys.generate_series(first date, "limit" date, stepsize interval month) - sys.generate_series(first date, "limit" date, stepsize interval day) + sys.generate_series(first date, "limit" date, stepsize interval month) and + sys.generate_series(first date, "limit" date, stepsize interval day). + +* Wed May 8 2024 Niels Nes <ni...@cwi.nl> +- Added support for select exp, count(*) group by 1 order by 1; + ie. using numeric references in group by clause. +- Added support for GROUP BY ALL. This finds all expressions from the + selections which aren't aggregations and groups on those. + At least one aggregation must be specified. + The ALL keyword can also be replaced by '*', so: GROUP BY *. +- Added support for ORDER BY ALL. This orders on all columns of the selection. + The ALL keyword can also be replaced by '*', so: ORDER BY *. * Thu May 2 2024 Martin van Dinther <martin.van.dint...@monetdbsolutions.com> - Removed the obsolete ANALYZE statement syntax options: SAMPLE nn and 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 @@ -16,6 +16,7 @@ #include "rel_rel.h" #include "rel_basetable.h" #include "rel_exp.h" +#include "rel_dump.h" #include "rel_psm.h" #include "rel_prop.h" #include "rel_select.h" @@ -5054,6 +5055,35 @@ sql_insert_triggers(backend *be, sql_tab return res; } +static void +sql_insert_check(backend *be, sql_key *key, sql_rel *inserts, list *refs) +{ + mvc *sql = be->mvc; + node *m, *n; + + inserts = rel_copy(sql, inserts, 1); + list* exps = inserts->exps; + + for (n = ol_first_node(key->t->columns), m = exps->h; n && m; + n = n->next, m = m->next) { + sql_exp *i = m->data; + sql_column *c = n->data; + i->alias.rname= sa_strdup(sql->sa, c->t->base.name); + i->alias.name= sa_strdup(sql->sa, c->base.name); + } + + int pos = 0; + sql_rel* rel = rel_read(sql, sa_strdup(sql->sa, key->check), &pos, sa_list(sql->sa)); + rel->l = inserts; + stmt* s = subrel_bin(be, rel, refs); + sql_subtype *bt = sql_bind_localtype("bit"); + s = stmt_uselect(be, column(be, s), stmt_atom(be, atom_zero_value(sql->sa, bt)), cmp_equal, NULL, 0, 1); + sql_subfunc *cnt = sql_bind_func(sql, "sys", "count", sql_bind_localtype("void"), NULL, F_AGGR, true, true); + s = stmt_aggr(be, s, NULL, NULL, cnt, 1, 0, 1); + char *msg = sa_message(sql->sa, SQLSTATE(40002) "INSERT INTO: CHECK constraint violated: %s", key->base.name); + (void)stmt_exception(be, s, msg, 00001); +} + static sql_table * sql_insert_check_null(backend *be, sql_table *t, list *inserts) { @@ -5132,6 +5162,12 @@ rel2bin_insert(backend *be, sql_rel *rel if (idx_ins) pin = refs_find_rel(refs, prel); + for (n = ol_first_node(t->keys); n; n = n->next) { + sql_key * key = n->data; + if (key->type == ckey) + sql_insert_check(be, key, rel->r, refs); + } + if (!sql_insert_check_null(be, t, inserts->op4.lval)) return NULL; @@ -6014,6 +6050,61 @@ sql_update_triggers(backend *be, sql_tab } static void +sql_update_check(backend *be, sql_key * key, sql_rel *updates, list *refs) +{ + mvc *sql = be->mvc; + int pos = 0; + + + stack_push_frame(be->mvc, "ALTER TABLE ADD CONSTRAINT CHECK"); + sql_schema* ss = key->t->s; + frame_push_table(sql, key->t); + key->t->s = ss; // recover the schema because frame_push_table removes it + + sql_rel* rel = rel_read(sql, sa_strdup(sql->sa, key->check), &pos, sa_list(sql->sa)); + stack_pop_frame(sql); + + if (!key->base.new) { + sql_rel* base = rel->l; + assert(strcmp(((sql_exp*) updates->exps->h->data)->alias.name, TID) == 0); + list_append(base->exps, exp_copy(sql, updates->exps->h->data)); + + bool need_join = 0; + list* pexps = sa_list(sql->sa); + sql_exp* tid_exp = exp_copy(sql, updates->exps->h->data); + unsigned label = ++sql->label; + exp_setrelname(sql->sa, tid_exp, label); + list_append(pexps, tid_exp); + for (node* m = base->exps->h; m; m = m->next) { + if (exps_find_exp( updates->exps, m->data) == NULL) { + pexps = list_append(pexps, exp_copy(sql, m->data)); + need_join = 1; + } + } + + if (need_join) { + base = rel_project(sql->sa, base, pexps); + sql_rel* join = rel_crossproduct(sql->sa, base, updates, op_join); + sql_exp* join_cond = exp_compare(sql->sa, exp_ref(sql, base->exps->h->data), exp_ref(sql, updates->exps->h->data), cmp_equal); + join->exps = sa_list(sql->sa); + join->exps = list_append(join->exps, join_cond); + rel->l = join; + } + else { + rel->l = updates; + } + } + + sql_subfunc *cnt = sql_bind_func(sql, "sys", "count", sql_bind_localtype("void"), NULL, F_AGGR, true, true); + sql_subtype *bt = sql_bind_localtype("bit"); + stmt* s = subrel_bin(be, rel, refs); + s = stmt_uselect(be, column(be, s), stmt_atom(be, atom_zero_value(sql->sa, bt)), cmp_equal, NULL, 0, 1); + s = stmt_aggr(be, s, NULL, NULL, cnt, 1, 0, 1); + char *msg = sa_message(sql->sa, SQLSTATE(40002) "UPDATE: CHECK constraint violated: %s", key->base.name); + (void)stmt_exception(be, s, msg, 00001); +} + +static void sql_update_check_null(backend *be, sql_table *t, stmt **updates) { mvc *sql = be->mvc; @@ -6116,9 +6207,15 @@ rel2bin_update(backend *be, sql_rel *rel return NULL; t = rel_ddl_table_get(tr); - /* no columns to update (probably an new pkey!) */ - if (!rel->exps) + /* no columns to update (probably an new pkey or ckey!) */ + if (!rel->exps) { + for (m = ol_first_node(t->keys); m; m = m->next) { + sql_key * key = m->data; + if (key->type == ckey && key->base.new) + sql_update_check(be, key, rel->r, refs); + } return ddl; + } } if (rel->r) /* first construct the update relation */ @@ -6142,6 +6239,12 @@ rel2bin_update(backend *be, sql_rel *rel if (c) updates[c->colnr] = bin_find_column(be, update, ce->l, ce->r); } + + for (m = ol_first_node(t->keys); m; m = m->next) { + sql_key * key = m->data; + if (key->type == ckey) + sql_update_check(be, key, rel->r, refs); + } sql_update_check_null(be, t, updates); /* check keys + get idx */ diff --git a/sql/backends/monet5/sql_gencode.c b/sql/backends/monet5/sql_gencode.c --- a/sql/backends/monet5/sql_gencode.c +++ b/sql/backends/monet5/sql_gencode.c @@ -316,36 +316,6 @@ static int return -1; } -static str -rel2str( mvc *sql, sql_rel *rel) -{ - buffer *b = NULL; - stream *s = NULL; - list *refs = NULL; - char *res = NULL; - - b = buffer_create(1024); - if(b == NULL) - goto cleanup; - s = buffer_wastream(b, "rel_dump"); - if(s == NULL) - goto cleanup; - refs = sa_list(sql->sa); - if (!refs) - goto cleanup; - - rel_print_refs(sql, s, rel, 0, refs, 0); - rel_print_(sql, s, rel, 0, refs, 0); - mnstr_printf(s, "\n"); - res = buffer_get_buf(b); - -cleanup: - if(b) - buffer_destroy(b); - if(s) - close_stream(s); - return res; -} /* stub and remote function */ static int @@ -360,7 +330,7 @@ static int node *n; int i, q, v, res = -1, added_to_cache = 0, *lret, *rret; size_t len = 1024, nr, pwlen = 0; - char *lname = NULL, *buf = NULL, *mal_session_uuid, *err = NULL, *pwhash = NULL; + char *lname = NULL, *rel_str, *buf = NULL, *mal_session_uuid, *err = NULL, *pwhash = NULL; str username = NULL, password = NULL, msg = NULL; sql_rel *r = rel; @@ -517,23 +487,21 @@ static int pushInstruction(curBlk, o); p = pushArgument(curBlk, p, getArg(o,0)); - if (!(buf = rel2str(m, rel))) { + if (!(rel_str = rel2str(m, rel))) { freeInstruction(p); sql_error(m, 10, SQLSTATE(HY013) MAL_MALLOC_FAIL); goto cleanup; } o = newFcnCall(curBlk, remoteRef, putRef); if (o == NULL) { - free(buf); freeInstruction(p); sql_error(m, 10, SQLSTATE(HY013) MAL_MALLOC_FAIL); goto cleanup; } o = pushArgument(curBlk, o, q); - o = pushStr(curBlk, o, buf); /* relational plan */ + o = pushStr(curBlk, o, rel_str); /* relational plan */ pushInstruction(curBlk, o); p = pushArgument(curBlk, p, getArg(o,0)); - free(buf); if (!(buf = sa_alloc(m->ta, len))) { freeInstruction(p); diff --git a/sql/backends/monet5/sql_upgrades.c b/sql/backends/monet5/sql_upgrades.c --- a/sql/backends/monet5/sql_upgrades.c +++ b/sql/backends/monet5/sql_upgrades.c @@ -7157,6 +7157,27 @@ sql_update_default(Client c, mvc *sql, s end: sa_destroy(sql->sa); sql->sa = old_sa; + _______________________________________________ checkin-list mailing list -- checkin-list@monetdb.org To unsubscribe send an email to checkin-list-le...@monetdb.org