Changeset: abb4077f60d0 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/abb4077f60d0 Modified Files: gdk/gdk_bbp.c sql/server/sql_parser.y sql/server/sql_scan.c Branch: default Log Message:
Merge default with Dec2023. diffs (truncated from 1021 to 300 lines): diff --git a/gdk/gdk_bbp.c b/gdk/gdk_bbp.c --- a/gdk/gdk_bbp.c +++ b/gdk/gdk_bbp.c @@ -3896,7 +3896,7 @@ BBPbackup(BAT *b, bool subcommit) return GDK_SUCCEED; } assert(b->theap->parentid == b->batCacheid); - if (b->oldtail) { + if (b->oldtail && b->oldtail != (Heap *) 1) { bi.h = b->oldtail; bi.hdirty = b->oldtail->dirty; } 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 @@ -1570,7 +1570,7 @@ exp_bin(backend *be, sql_exp *e, stmt *l /*if (rows && en == exps->h && f->func->type != F_LOADER) es = stmt_const(be, rows, es);*/ else if (f->func->type == F_ANALYTIC && es->nrcols == 0) { - if (en == exps->h && left->nrcols) + if (en == exps->h && left && left->nrcols) es = stmt_const(be, bin_find_smallest_column(be, left), es); /* ensure the first argument is a column */ if (!f->func->s && !strcmp(f->func->base.name, "window_bound") && exps->h->next && list_length(f->func->ops) == 6 && en == exps->h->next && left->nrcols) @@ -2592,6 +2592,8 @@ rel2bin_hash_lookup(backend *be, sql_rel h = stmt_unop(be, s, NULL, hf); } } + if (n != NULL) /* need to use all cols of the index */ + return NULL; if (h && h->nrcols) { if (!swap_rel) { return stmt_join(be, idx, h, 0, cmp_equal, 0, semantics, false); 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 @@ -1066,17 +1066,6 @@ backend_dumpstmt_body(backend *be, MalBl } pushInstruction(mb, q); } - /* generate a dummy return assignment for functions */ - if (getArgType(mb, getInstrPtr(mb, 0), 0) != TYPE_void && getInstrPtr(mb, mb->stop - 1)->barrier != RETURNsymbol) { - q = newAssignment(mb); - if (q == NULL) { - sql_error(m, 10, SQLSTATE(HY013) MAL_MALLOC_FAIL); - return -1; - } - getArg(q, 0) = getArg(getInstrPtr(mb, 0), 0); - q->barrier = RETURNsymbol; - pushInstruction(mb, q); - } if (add_end) pushEndInstruction(mb); if (querylog) diff --git a/sql/backends/monet5/sql_statement.c b/sql/backends/monet5/sql_statement.c --- a/sql/backends/monet5/sql_statement.c +++ b/sql/backends/monet5/sql_statement.c @@ -595,7 +595,7 @@ stmt_tid(backend *be, sql_table *t, int if (t && isTable(t) && partition) { sql_trans *tr = be->mvc->session->tr; sqlstore *store = tr->store; - BUN rows = (BUN) store->storage_api.count_col(tr, ol_first_node(t->columns)->data, QUICK); + BUN rows = (BUN) store->storage_api.count_col(tr, ol_first_node(t->columns)->data, RDONLY); setRowCnt(mb,getArg(q,0),rows); } diff --git a/sql/server/rel_basetable.c b/sql/server/rel_basetable.c --- a/sql/server/rel_basetable.c +++ b/sql/server/rel_basetable.c @@ -487,7 +487,7 @@ rel_rename_part(mvc *sql, sql_rel *p, sq for (node *n = mt_rel->exps->h; n; n = n->next) { sql_exp *e = n->data; node *cn = NULL, *ci = NULL; - const char *nname = exp_name(e); + const char *nname = e->r; if (nname[0] == '%' && strcmp(nname, TID) == 0) { list_append(p->exps, exp_alias(sql->sa, mtalias, TID, pname, TID, sql_bind_localtype("oid"), CARD_MULTI, 0, 1, 1)); @@ -496,7 +496,7 @@ rel_rename_part(mvc *sql, sql_rel *p, sq sql_column *c = cn->data, *rc = ol_fetch(t->columns, c->colnr); /* with name find column in merge table, with colnr find column in member */ - sql_exp *ne = exp_alias(sql->sa, mtalias, c->base.name, pname, rc->base.name, &rc->type, CARD_MULTI, rc->null, is_column_unique(rc), 0); + sql_exp *ne = exp_alias(sql->sa, mtalias, exp_name(e), pname, rc->base.name, &rc->type, CARD_MULTI, rc->null, is_column_unique(rc), 0); if (rc->t->pkey && ((sql_kc*)rc->t->pkey->k.columns->h->data)->c == rc) { prop *p = ne->p = prop_create(sql->sa, PROP_HASHCOL, ne->p); p->value.pval = rc->t->pkey; 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 @@ -322,9 +322,11 @@ sql_exp * exp_compare_func(mvc *sql, sql_exp *le, sql_exp *re, const char *compareop, int quantifier) { sql_subfunc *cmp_func = sql_bind_func(sql, "sys", compareop, exp_subtype(le), exp_subtype(le), F_FUNC, true); - sql_exp *e; - - assert(cmp_func); + sql_exp *e = NULL; + + if (cmp_func == NULL) + return NULL; + e = exp_binop(sql->sa, le, re, cmp_func); if (e) { e->flag = quantifier; @@ -2881,8 +2883,11 @@ exp_copy(mvc *sql, sql_exp * e) ne = exp_aggr(sql->sa, l, e->f, need_distinct(e), need_no_nil(e), e->card, has_nil(e)); if (e->r) { /* copy obe and gbe lists */ list *er = (list*) e->r; - assert(list_length(er) == 2); - ne->r = list_append(list_append(sa_list(sql->sa), exps_copy(sql, er->h->data)), exps_copy(sql, er->h->next->data)); + assert(list_length(er) <= 2); + if (list_length(er) == 2) + ne->r = list_append(list_append(sa_list(sql->sa), exps_copy(sql, er->h->data)), exps_copy(sql, er->h->next->data)); + else + ne->r = list_append(sa_list(sql->sa), exps_copy(sql, er->h->data)); } break; } diff --git a/sql/server/rel_optimizer.c b/sql/server/rel_optimizer.c --- a/sql/server/rel_optimizer.c +++ b/sql/server/rel_optimizer.c @@ -92,7 +92,7 @@ merge_table_prune_and_unionize(visitor * if (cname[0] == '%') /* Ignore TID and indexes here */ continue; - mt_col = ol_find_name(mt->columns, exp_name(e))->data; + mt_col = ol_find_name(mt->columns, cname)->data; col = ol_fetch(pt->columns, mt_col->colnr); assert(e && e->type == e_column && col); diff --git a/sql/server/rel_propagate.c b/sql/server/rel_propagate.c --- a/sql/server/rel_propagate.c +++ b/sql/server/rel_propagate.c @@ -410,6 +410,8 @@ rel_alter_table_add_partition_list(sql_q symbol* next = dn->data.sym; sql_exp *pnext = generate_partition_limits(query, &rel_psm, next, tpe, true); + if (!pnext) + return NULL; if (next->token == SQL_NULL) return sql_error(sql, 02, SQLSTATE(42000) "ALTER TABLE: a list value cannot be null"); append(lvals, pnext); 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 @@ -3713,6 +3713,9 @@ static sql_exp * if (is_sql_groupby(f)) { char *uaname = SA_NEW_ARRAY(sql->ta, char, strlen(aname) + 1); return sql_error(sql, 02, SQLSTATE(42000) "%s: aggregate function '%s' not allowed in GROUP BY clause", toUpperCopy(uaname, aname), aname); + } else if (is_sql_from(f)) { + char *uaname = SA_NEW_ARRAY(sql->ta, char, strlen(aname) + 1); + return sql_error(sql, 02, SQLSTATE(42000) "%s: aggregate functions not allowed in functions in FROM", toUpperCopy(uaname, aname)); } else if (is_sql_aggr(f) && groupby->grouped) { char *uaname = SA_NEW_ARRAY(sql->ta, char, strlen(aname) + 1); return sql_error(sql, 02, SQLSTATE(42000) "%s: aggregate functions cannot be nested", toUpperCopy(uaname, aname)); @@ -3725,9 +3728,6 @@ static sql_exp * } else if (is_sql_where(f)) { char *uaname = SA_NEW_ARRAY(sql->ta, char, strlen(aname) + 1); return sql_error(sql, 02, SQLSTATE(42000) "%s: aggregate functions not allowed in WHERE clause", toUpperCopy(uaname, aname)); - } else if (is_sql_from(f)) { - char *uaname = SA_NEW_ARRAY(sql->ta, char, strlen(aname) + 1); - return sql_error(sql, 02, SQLSTATE(42000) "%s: aggregate functions not allowed in functions in FROM", toUpperCopy(uaname, aname)); } else if (!all_aggr && !list_empty(ungrouped_cols)) { for (node *n = ungrouped_cols->h ; n ; n = n->next) { sql_rel *outer; @@ -4816,11 +4816,13 @@ rel_order_by(sql_query *query, sql_rel * if (!found) { if (needs_distinct) return sql_error(sql, 02, SQLSTATE(42000) "SELECT: with DISTINCT ORDER BY expressions must appear in select list"); - append(rel->exps, e); + if (!is_freevar(e)) + append(rel->exps, e); } else { e = found; } - e = exp_ref(sql, e); + if (!is_freevar(e)) + e = exp_ref(sql, e); } } diff --git a/sql/server/rel_statistics.c b/sql/server/rel_statistics.c --- a/sql/server/rel_statistics.c +++ b/sql/server/rel_statistics.c @@ -33,6 +33,10 @@ comparison_find_column(sql_exp *input, s } } +/* multi lo <= col <= hi, maybe still be false even if lo or hi are NULL, possibly similar for filter on multiple + * columns */ +#define comp_single_column(c) (!c->f) + static sql_exp * rel_propagate_column_ref_statistics(mvc *sql, sql_rel *rel, sql_exp *e) { @@ -69,7 +73,7 @@ rel_propagate_column_ref_statistics(mvc *rval_min = find_prop_and_get(re->p, PROP_MIN), *rval_max = find_prop_and_get(re->p, PROP_MAX); /* not semantics found or if explicitly filtering not null values from the column */ - found_without_semantics |= !is_semantics(comp) || (comp->flag == cmp_equal && lne && is_anti(comp) && exp_is_null(re)); + found_without_semantics |= (!is_semantics(comp) && comp_single_column(comp)) || (comp->flag == cmp_equal && lne && is_anti(comp) && exp_is_null(re)); still_unique |= comp->flag == cmp_equal && is_unique(le) && is_unique(re); /* unique if only equi-joins on unique columns are there */ if (is_full(rel->op) || (is_left(rel->op) && found_left) || (is_right(rel->op) && found_right)) /* on outer joins, min and max cannot be propagated on some cases */ continue; diff --git a/sql/server/rel_statistics_functions.c b/sql/server/rel_statistics_functions.c --- a/sql/server/rel_statistics_functions.c +++ b/sql/server/rel_statistics_functions.c @@ -720,6 +720,8 @@ static void sql_min_max_propagate_statistics(mvc *sql, sql_exp *e) { list *l = e->l; + if (list_empty(l)) + return; sql_exp *first = l->h->data; atom *omin, *omax; 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 @@ -1144,8 +1144,6 @@ exp_is_count(sql_exp *e, sql_rel *rel) sql_exp *ne = rel_find_exp(rel->l, e); return exp_is_count(ne, rel->l); } - if (is_convert(e->type)) - return exp_is_count(e->l, rel); if (is_aggr(e->type) && exp_aggr_is_count(e)) return 1; return 0; @@ -1193,10 +1191,19 @@ push_up_groupby(mvc *sql, sql_rel *rel, /* count_nil(* or constant) -> count(t.TID) */ if (exp_is_count(e, r) && (!e->l || exps_is_constant(e->l))) { sql_rel *p = r->l; /* ugh */ + sql_rel *pp = r; + while(p && p->l && (!is_project(p->op) && !is_base(p->op))) { /* find first project */ + pp = p; + p = p->l; + } + if (p && p->l && is_project(p->op) && list_empty(p->exps)) { /* skip empty project */ + pp = p; + p = p->l; + } sql_exp *col = list_length(p->exps) ? p->exps->t->data : NULL; const char *cname = col ? exp_name(col) : NULL; - if ((!cname || strcmp(cname, TID) != 0) && !(r->l = p = rel_add_identity(sql, p, &col))) + if ((!cname || strcmp(cname, TID) != 0) && !(pp->l = p = rel_add_identity(sql, p, &col))) return NULL; col = exp_ref(sql, col); append(e->l=sa_list(sql->sa), col); @@ -2373,7 +2380,7 @@ rel_set_type(visitor *v, sql_rel *rel) } } else { e->tpe = *exp_subtype(te); - if (e->l) + if (e->l && e->type == e_atom) e->l = atom_set_type(v->sql->sa, e->l, &e->tpe); } } @@ -3179,7 +3186,6 @@ rewrite_compare(visitor *v, sql_rel *rel if (!is_tuple && !lsq && !rsq) { /* trivial case, just re-write into a comparison */ e->flag = 0; /* remove quantifier */ - rel_bind_var(v->sql, rel, re); if (rel_convert_types(v->sql, NULL, NULL, &le, &re, 1, type_equal) < 0) return NULL; if (depth == 0 && is_select(rel->op)) { 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 @@ -444,7 +444,6 @@ int yydebug=1; XML_PI_target opt_optimizer opt_default_role - multi_arg_func_name %type <l> argument_list @@ -642,7 +641,7 @@ int yydebug=1; /* sql prefixes to avoid name clashes on various architectures */ %token <sval> - IDENT UIDENT aTYPE ALIAS RANK sqlINT OIDNUM HEXADECIMALNUM OCTALNUM BINARYNUM INTNUM APPROXNUM + IDENT UIDENT aTYPE ALIAS RANK MARGFUNC sqlINT OIDNUM HEXADECIMALNUM OCTALNUM BINARYNUM INTNUM APPROXNUM USING GLOBAL CAST CONVERT CHARACTER VARYING LARGE OBJECT VARCHAR CLOB sqlTEXT BINARY sqlBLOB @@ -664,7 +663,6 @@ int yydebug=1; %token <sval> COMMIT ROLLBACK SAVEPOINT RELEASE WORK CHAIN NO PRESERVE ROWS %token START TRANSACTION READ WRITE ONLY ISOLATION LEVEL %token UNCOMMITTED COMMITTED sqlREPEATABLE SERIALIZABLE DIAGNOSTICS sqlSIZE STORAGE SNAPSHOT -%token LEAST GREATEST %token <sval> ASYMMETRIC SYMMETRIC ORDER ORDERED BY IMPRINTS %token <operation> ESCAPE UESCAPE HAVING sqlGROUP ROLLUP CUBE sqlNULL @@ -5876,6 +5874,7 @@ calc_ident: | aTYPE { $$ = $1; } | ALIAS { $$ = $1; } | RANK { $$ = $1; } /* without '(' */ + | MARGFUNC { $$ = $1; } /* without '(' */ _______________________________________________ checkin-list mailing list -- checkin-list@monetdb.org To unsubscribe send an email to checkin-list-le...@monetdb.org