MonetDB: default - small typo fix
Changeset: 2177fc38606f for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/2177fc38606f Modified Files: gdk/gdk_bat.c Branch: default Log Message: small typo fix diffs (12 lines): diff --git a/gdk/gdk_bat.c b/gdk/gdk_bat.c --- a/gdk/gdk_bat.c +++ b/gdk/gdk_bat.c @@ -2457,7 +2457,7 @@ BATmode(BAT *b, bool transient) #ifdef NDEBUG /* assertions are disabled, turn failing tests into a message */ #undef assert -#define assert(test) ((void) ((test) || (TRC_CRITICAL_ENDIF(CHECK, "Assertion `%s' failed\n", #test), 0))) +#define assert(test) ((void) ((test) || (TRC_CRITICAL_ENDIF(CHECK_, "Assertion `%s' failed\n", #test), 0))) #endif /* Assert that properties are set correctly. ___ checkin-list mailing list -- checkin-list@monetdb.org To unsubscribe send an email to checkin-list-le...@monetdb.org
MonetDB: default - Replace loop with GDK operator.
Changeset: 48ae3d12100f for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/48ae3d12100f Modified Files: sql/storage/bat/bat_storage.c Branch: default Log Message: Replace loop with GDK operator. diffs (26 lines): diff --git a/sql/storage/bat/bat_storage.c b/sql/storage/bat/bat_storage.c --- a/sql/storage/bat/bat_storage.c +++ b/sql/storage/bat/bat_storage.c @@ -2314,15 +2314,13 @@ delta_append_val(sql_trans *tr, sql_delt if (cnt) { if (BATcount(b) < offset) { /* add space */ const void *tv = ATOMnilptr(b->ttype); - lng j, d = offset - BATcount(b); - for(j=0;jstore, id); - return LOG_ERR; - } + lng d = offset - BATcount(b); + if (BUNappendmulti(b, tv, d, true) != GDK_SUCCEED) { + bat_destroy(b); + if (i != oi) + GDKfree(i); + unlock_column(tr->store, id); + return LOG_ERR; } } if (BUNappendmulti(b, i, cnt, true) != GDK_SUCCEED) { ___ checkin-list mailing list -- checkin-list@monetdb.org To unsubscribe send an email to checkin-list-le...@monetdb.org
MonetDB: properties - Merged with default
Changeset: 1fcc6b61b775 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/1fcc6b61b775 Modified Files: sql/backends/monet5/sql.c sql/storage/bat/bat_storage.c Branch: properties Log Message: Merged with default diffs (269 lines): diff --git a/clients/odbc/ChangeLog b/clients/odbc/ChangeLog --- a/clients/odbc/ChangeLog +++ b/clients/odbc/ChangeLog @@ -1,3 +1,9 @@ # ChangeLog file for odbc # This file is updated with Maddlog +* Thu Apr 21 2022 Martin van Dinther +- Corrected ODBC API functions SQLPrimaryKeys(), SQLSpecialColumns() and + SQLStatistics() for local temporary tables located in schema tmp. They did + not return any rows when the temp table had a primary or unique key or + index. Now they do return rows as expected. + diff --git a/clients/odbc/driver/SQLPrimaryKeys.c b/clients/odbc/driver/SQLPrimaryKeys.c --- a/clients/odbc/driver/SQLPrimaryKeys.c +++ b/clients/odbc/driver/SQLPrimaryKeys.c @@ -45,6 +45,7 @@ MNDBPrimaryKeys(ODBCStmt *stmt, size_t querylen; size_t pos = 0; char *sch = NULL, *tab = NULL; + char *sysORtmp = "sys"; /* deal with SQL_NTS and SQL_NULL_DATA */ fixODBCstring(CatalogName, NameLength1, SQLSMALLINT, @@ -60,6 +61,12 @@ MNDBPrimaryKeys(ODBCStmt *stmt, addStmtError(stmt, "HY009", NULL, 0); return SQL_ERROR; } + if (NameLength3 == 0) { + /* Invalid string or buffer length */ + addStmtError(stmt, "HY090", NULL, 0); + return SQL_ERROR; + } + #ifdef ODBCDEBUG ODBCLOG("\"%.*s\" \"%.*s\" \"%.*s\"\n", (int) NameLength1, CatalogName ? (char *) CatalogName : "", @@ -106,6 +113,9 @@ MNDBPrimaryKeys(ODBCStmt *stmt, if (query == NULL) goto nomem; + if (SchemaName != NULL && strcmp((const char *) SchemaName, "tmp") == 0) + sysORtmp = "tmp"; + /* SQLPrimaryKeys returns a table with the following columns: VARCHAR table_cat VARCHAR table_schem @@ -121,13 +131,14 @@ MNDBPrimaryKeys(ODBCStmt *stmt, "kc.name as column_name, " "cast(kc.nr + 1 as smallint) as key_seq, " "k.name as pk_name " - "from sys.schemas s, sys.tables t, " - "sys.keys k, sys.objects kc " + "from sys.schemas s, %s._tables t, " + "%s.keys k, %s.objects kc " "where k.id = kc.id and " "k.table_id = t.id and " "t.schema_id = s.id and " "k.type = 0", - stmt->Dbc->dbname); + stmt->Dbc->dbname, + sysORtmp, sysORtmp, sysORtmp); assert(pos < 800); /* Construct the selection condition query part */ diff --git a/clients/odbc/driver/SQLSpecialColumns.c b/clients/odbc/driver/SQLSpecialColumns.c --- a/clients/odbc/driver/SQLSpecialColumns.c +++ b/clients/odbc/driver/SQLSpecialColumns.c @@ -95,6 +95,7 @@ MNDBSpecialColumns(ODBCStmt *stmt, size_t querylen; size_t pos = 0; char *sch = NULL, *tab = NULL; + char *sysORtmp = "sys"; fixODBCstring(CatalogName, NameLength1, SQLSMALLINT, addStmtError, stmt, return SQL_ERROR); fixODBCstring(SchemaName, NameLength2, SQLSMALLINT, addStmtError, stmt, return SQL_ERROR); @@ -204,6 +205,9 @@ MNDBSpecialColumns(ODBCStmt *stmt, if (query == NULL) goto nomem; + if (SchemaName != NULL && strcmp((const char *) SchemaName, "tmp") == 0) + sysORtmp = "tmp"; + /* Note: SCOPE is SQL_SCOPE_TRANSACTION */ /* Note: PSEUDO_COLUMN is SQL_PC_NOT_PSEUDO */ pos += snprintf(query + pos, querylen - pos, @@ -218,10 +222,10 @@ MNDBSpecialColumns(ODBCStmt *stmt, DECIMAL_DIGITS(c) ", " "cast(%d as smallint) as pseudo_column " "from sys.schemas s, " - "sys.tables t, " - "sys.columns c, " - "sys.keys k, " - "sys.objects kc " + "%s._tables t, " + "%s._columns c, " + "%s.keys k, " + "%s.objects kc " "where s.id = t.schema_id and " "t.id = c.table_id and " "t.id = k.table_id and " @@ -246,7 +250,8 @@ MNDBSpecialColumns(ODBCStmt *stmt, DECIMAL_DIGITS_ARGS, #endif /* pseudo_column: */ - SQL_PC_NOT_PSEUDO); + SQL_PC_NOT_PSEUDO, + sysORtmp, sysORtmp, sysORtmp, sysORtmp); assert(pos < 4300); /* TO
MonetDB: properties - Use right macro for null availability chec...
Changeset: 614fae5d98d4 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/614fae5d98d4 Modified Files: sql/server/rel_statistics.c sql/test/BugTracker/Tests/explain.SF-1739353.test sql/test/BugTracker/Tests/jdbc_no_debug.SF-1739356.test Branch: properties Log Message: Use right macro for null availability check. Fix cmp_notequal case diffs (152 lines): 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 @@ -248,7 +248,7 @@ rel_setop_get_statistics(mvc *sql, sql_r *rval_min = find_prop_and_get(re->p, PROP_MIN), *rval_max = find_prop_and_get(re->p, PROP_MAX); /* for the intersection, if both expresssions don't overlap, it can be pruned */ - if (is_inter(rel->op) && exp_is_not_null(le) && exp_is_not_null(re) && + if (is_inter(rel->op) && !has_nil(le) && !has_nil(re) && ((rval_max && lval_min && atom_cmp(rval_max, lval_min) < 0) || (rval_min && lval_max && atom_cmp(rval_min, lval_max) > 0))) return true; @@ -469,53 +469,55 @@ rel_prune_predicates(visitor *v, sql_rel always_false |= not_int1 || not_int2 || not_int3; /* for anti the middle must be before the left or after the right or the right after the left, for the other the middle must be always between the left and right intervals */ - always_true |= exp_is_not_null(le) && exp_is_not_null(re) && exp_is_not_null(fe) && + always_true |= !has_nil(le) && !has_nil(re) && !has_nil(fe) && lval_min && lval_max && rval_min && rval_max && fval_min && fval_max && (is_anti(e) ? ((lower == cmp_gte ? atom_cmp(rval_min, lval_max) > 0 : atom_cmp(rval_min, lval_max) >= 0) || (higher == cmp_lte ? atom_cmp(lval_min, fval_max) > 0 : atom_cmp(lval_min, fval_max) >= 0) || atom_cmp(rval_min, fval_max) > 0) : ((lower == cmp_gte ? atom_cmp(lval_min, rval_max) >= 0 : atom_cmp(lval_min, rval_max) > 0) && (higher == cmp_lte ? atom_cmp(fval_min, lval_max) >= 0 : atom_cmp(fval_min, lval_max) > 0))); } else if (!fe) { + if (!is_semantics(e)) /* trival not null cmp null case */ + always_false |= !is_anti(e) && ((exp_is_not_null(le) && exp_is_null(re)) || (exp_is_null(le) && exp_is_not_null(re))); switch (e->flag) { case cmp_equal: if (lval_min && lval_max && rval_min && rval_max && (!is_semantics(e) || !has_nil(le) || !has_nil(re))) - always_false |= is_anti(e) ? (atom_cmp(lval_min, rval_min) == 0 && atom_cmp(lval_max, rval_max) <= 0) : (atom_cmp(rval_max, lval_min) < 0 || atom_cmp(rval_min, lval_max) > 0); + always_false |= (is_anti(e) ? (atom_cmp(lval_min, rval_min) == 0 && atom_cmp(lval_max, rval_max) <= 0) : (atom_cmp(rval_max, lval_min) < 0 || atom_cmp(rval_min, lval_max) > 0)); if (is_semantics(e)) { /* prune *= NULL cases */ - always_false |= is_anti(e) ? (exp_is_null(le) && exp_is_null(re)) : ((exp_is_not_null(le) && exp_is_null(re)) || (exp_is_null(le) && exp_is_not_null(re))); - always_true |= is_anti(e) ? ((exp_is_not_null(le) && exp_is_null(re)) || (exp_is_null(le) && exp_is_not_null(re))) : (exp_is_null(le) && exp_is_null(re)); + always_false |= (is_anti(e) ? (exp_is_null(le) && exp_is_null(re)) : ((exp_is_not_null(le) && exp_is_null(re)) || (exp_is_null(le) && exp_is_not_null(re; + always_true |= (is_anti(e) ? ((exp_is_not_null(le) && exp_is_null(re)) || (exp_is_null(le) && exp_is_not_null(re))) : (exp_is_null(le) && exp_is_null(re))); } break; case cmp_notequal: - if (lval_min && lval_max && rval_min && rval_max && (!is_semantics(e) || !has_nil(le) || !has_nil(re))) - always_true |= is_anti(e) ? (atom_cmp(lval_min, rval_min) == 0 && atom_cmp(lval_max, rval_max) <= 0) : (atom_cmp(rval_max, lval_min) < 0 || atom_cmp(rval_min, lval_max) > 0); + if (lval_min && lval_max && rval_min && rval_max) + always_true |= !has_nil(le) && !has_nil(re) && (is_anti(e) ? (atom_cmp(lval_min, rval_min) == 0 && atom_cmp(lval_max, rval_max) <= 0) :
MonetDB: properties - Backported properties from future branch
Changeset: 309f95e550b2 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/309f95e550b2 Modified Files: sql/backends/monet5/rel_bin.c sql/backends/monet5/sql_gencode.c sql/server/rel_basetable.c sql/server/rel_distribute.c sql/server/rel_dump.c sql/server/rel_exp.c sql/server/rel_exp.h sql/server/rel_optimize_proj.c sql/server/rel_optimize_sel.c sql/server/rel_optimizer_private.h sql/server/rel_prop.c sql/server/rel_prop.h sql/server/rel_rewriter.c sql/server/rel_rewriter.h sql/server/rel_select.c sql/server/rel_statistics.c sql/server/rel_statistics.h sql/server/rel_statistics_functions.c sql/server/rel_unnest.c sql/storage/bat/bat_storage.c sql/test/BugTracker-2017/Tests/sqlitelogictest-aggregation-having-avg.Bug-6428.test sql/test/BugTracker/Tests/explain.SF-1739353.test sql/test/merge-partitions/Tests/mergepart31.test Branch: properties Log Message: Backported properties from future branch diffs (truncated from 1968 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 @@ -2539,7 +2539,7 @@ rel2bin_join(backend *be, sql_rel *rel, /* handle possible index lookups, expressions are in index order! */ if (!join && (p=find_prop(e->p, PROP_HASHCOL)) != NULL) { - sql_idx *i = p->value; + sql_idx *i = p->value.pval; int oldvtop = be->mb->vtop, oldstop = be->mb->stop, oldvid = be->mb->vid; join = s = rel2bin_hash_lookup(be, rel, left, right, i, en); @@ -3642,7 +3642,7 @@ rel2bin_select(backend *be, sql_rel *rel prop *p; if ((p=find_prop(e->p, PROP_HASHCOL)) != NULL) { - sql_idx *i = p->value; + sql_idx *i = p->value.pval; int oldvtop = be->mb->vtop, oldstop = be->mb->stop, oldvid = be->mb->vid; if (!(sel = rel2bin_hash_lookup(be, rel, sub, NULL, i, en))) { 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 @@ -318,7 +318,7 @@ static int MalBlkPtr curBlk = 0; InstrPtr curInstr = 0, p, o; Symbol backup = NULL; - const char *local_tbl = prp->value; + const char *local_tbl = prp->value.pval; node *n; int i, q, v, res = 0, added_to_cache = 0, *lret, *rret; size_t len = 1024, nr; 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 @@ -156,10 +156,10 @@ bind_col_exp(mvc *sql, char *name, sql_c if (c->t->pkey && ((sql_kc*)c->t->pkey->k.columns->h->data)->c == c) { p = e->p = prop_create(sql->sa, PROP_HASHCOL, e->p); - p->value = c->t->pkey; + p->value.pval = c->t->pkey; } else if (c->unique == 2) { p = e->p = prop_create(sql->sa, PROP_HASHCOL, e->p); - p->value = NULL; + p->value.pval = NULL; } set_basecol(e); return e; @@ -267,11 +267,11 @@ rel_base_projection( mvc *sql, sql_rel * sql_exp *e = exp_column(sql->sa, name, iname, t, CARD_MULTI, has_nils, unique, 1); if (hash_index(i->type)) { p = e->p = prop_create(sql->sa, PROP_HASHIDX, e->p); - p->value = i; + p->value.pval = i; } if (i->type == join_idx) { p = e->p = prop_create(sql->sa, PROP_JOINIDX, e->p); - p->value = i; + p->value.pval = i; } append(exps, e); } @@ -324,10 +324,10 @@ rel_base_add_columns( mvc *sql, sql_rel } if (c->t->pkey && ((sql_kc*)c->t->pkey->k.columns->h->data)->c == c) { p = e->p = prop_create(sql->sa, PROP_HASHCOL, e->p); - p->value = c->t->pkey; + p->value.pval = c->t->pkey; } else if (c->unique == 2) { p = e->p = prop_create(sql->sa, PROP_HASHCOL, e->p); - p->value = NULL; + p->value.pval = NULL; } set_basecol(e); append(r->exps, e); @@ -37
MonetDB: properties - Make count property an unsigned number and...
Changeset: 61c0e7677763 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/61c0e7677763 Modified Files: sql/server/rel_prop.c sql/server/rel_prop.h sql/server/rel_rewriter.c sql/server/rel_rewriter.h sql/server/rel_statistics.c Branch: properties Log Message: Make count property an unsigned number and fix propagation diffs (295 lines): diff --git a/sql/server/rel_prop.c b/sql/server/rel_prop.c --- a/sql/server/rel_prop.c +++ b/sql/server/rel_prop.c @@ -118,7 +118,7 @@ propvalue2string(sql_allocator *sa, prop switch(p->kind) { case PROP_COUNT: { - snprintf(buf, BUFSIZ, LLFMT, p->value.lval); + snprintf(buf, BUFSIZ, BUNFMT, p->value.lval); return sa_strdup(sa, buf); } case PROP_NUNIQUES: { diff --git a/sql/server/rel_prop.h b/sql/server/rel_prop.h --- a/sql/server/rel_prop.h +++ b/sql/server/rel_prop.h @@ -25,7 +25,7 @@ typedef enum rel_prop { typedef struct prop { rel_prop kind; /* kind of property */ union { - lng lval; /* property with simple counts */ + BUN lval; /* property with simple counts */ dbl dval; /* property with estimate */ void *pval; /* property value */ } value; diff --git a/sql/server/rel_rewriter.c b/sql/server/rel_rewriter.c --- a/sql/server/rel_rewriter.c +++ b/sql/server/rel_rewriter.c @@ -499,16 +499,18 @@ exps_unique(mvc *sql, sql_rel *rel, list return 0; } -lng +BUN get_rel_count(sql_rel *rel) { prop *found = find_prop(rel->p, PROP_COUNT); - return found ? found->value.lval : -1; + return found ? found->value.lval : BUN_NONE; } void -set_count_prop(sql_allocator *sa, sql_rel *rel, lng val) +set_count_prop(sql_allocator *sa, sql_rel *rel, BUN val) { - prop *p = rel->p = prop_create(sa, PROP_COUNT, rel->p); - p->value.lval = val; + if (val != BUN_NONE) { + prop *p = rel->p = prop_create(sa, PROP_COUNT, rel->p); + p->value.lval = val; + } } diff --git a/sql/server/rel_rewriter.h b/sql/server/rel_rewriter.h --- a/sql/server/rel_rewriter.h +++ b/sql/server/rel_rewriter.h @@ -47,7 +47,7 @@ extern int exps_unique(mvc *sql, sql_rel extern sql_column *exp_find_column(sql_rel *rel, sql_exp *exp, int pnr); -extern lng get_rel_count(sql_rel *rel); -extern void set_count_prop(sql_allocator *sa, sql_rel *rel, lng val); +extern BUN get_rel_count(sql_rel *rel); +extern void set_count_prop(sql_allocator *sa, sql_rel *rel, BUN val); #endif /*_REL_REWRITER_H_*/ 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 @@ -596,12 +596,12 @@ set_setop_side(visitor *v, sql_rel *rel, return side; } -static lng +static BUN trivial_project_exp_card(sql_exp *e) { if (e->type == e_convert) return trivial_project_exp_card(e->l); - return e->type == e_atom && e->f ? list_length(e->f) : 1; + return e->type == e_atom && e->f ? (BUN) list_length(e->f) : 1; } static sql_rel * @@ -628,7 +628,8 @@ rel_get_statistics_(visitor *v, sql_rel } /* set table row count */ /* TODO look for remote/replica tables */ - set_count_prop(v->sql->sa, rel, isTable(t) ? (lng)store->storage_api.count_col(v->sql->session->tr, ol_first_node(t->columns)->data, 0) : 50); + if (isTable(t)) + set_count_prop(v->sql->sa, rel, (BUN)store->storage_api.count_col(v->sql->session->tr, ol_first_node(t->columns)->data, 0)); } break; case op_union: case op_inter: @@ -662,7 +663,7 @@ rel_get_statistics_(visitor *v, sql_rel r = rel->r; /* propagate row count */ if (is_union(rel->op)) { - lng lv = get_rel_count(l), rv = get_rel_count(r); + BUN lv = get_rel_count(l), rv = get_rel_count(r); if (lv == 0 && rv == 0) { /* both sides empty */ if (can_be_pruned) @@ -673,13 +674,15 @@ rel_get_statistics_(visitor *v, sql_rel rel = set_setop_side(v, rel, r); } else if (can_be_pruned && rv == 0 && !rel_is_ref(rel)) { /* right side empty */ rel = set_setop_side(v, rel, l); - } else if ((lv + rv) < lv) { - set_count_prop(v->sql->sa, rel, MAX(lv, rv)); - } else { - set_count_prop(v->sql->sa, rel, lv + rv); - } + } else if (lv != BUN_NONE && rv != BUN_NONE) { + if ((lv + rv) < lv) { + set_count_prop(v->sql->sa, rel, MAX(lv, rv)); +
MonetDB: properties - Do better overflow checks and fix count pr...
Changeset: a0fa73f02941 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/a0fa73f02941 Modified Files: sql/server/rel_statistics.c Branch: properties Log Message: Do better overflow checks and fix count propagation for trivial joins and selections diffs (108 lines): 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 @@ -675,11 +675,7 @@ rel_get_statistics_(visitor *v, sql_rel } else if (can_be_pruned && rv == 0 && !rel_is_ref(rel)) { /* right side empty */ rel = set_setop_side(v, rel, l); } else if (lv != BUN_NONE && rv != BUN_NONE) { - if ((lv + rv) < lv) { - set_count_prop(v->sql->sa, rel, MAX(lv, rv)); - } else { - set_count_prop(v->sql->sa, rel, lv + rv); - } + set_count_prop(v->sql->sa, rel, (rv > (BUN_MAX - lv)) ? BUN_MAX : (lv + rv)); /* overflow check */ } } else if (is_inter(rel->op) || is_except(rel->op)) { BUN lv = get_rel_count(l), rv = get_rel_count(r); @@ -750,7 +746,7 @@ rel_get_statistics_(visitor *v, sql_rel case op_left: case op_right: case op_full: { - BUN lv = get_rel_count(l), rv = get_rel_count(r), uniques_estimate = BUN_NONE, join_idx_estimate = BUN_NONE; + BUN lv = get_rel_count(l), rv = get_rel_count(r), uniques_estimate = BUN_MAX, join_idx_estimate = BUN_MAX; if (!list_empty(rel->exps)) { for (node *n = rel->exps->h ; n ; n = n->next) { @@ -770,8 +766,8 @@ rel_get_statistics_(visitor *v, sql_rel } } if ((p = find_prop(el->p, PROP_NUNIQUES)) && (p2 = find_prop(er->p, PROP_NUNIQUES))) { - BUN pv = (BUN) p->value.dval, pv2 = (BUN) p2->value.dval, mul = pv * pv2; - mul = mul < pv ? MAX(pv, pv2) : mul; /* check for overflows */ + BUN pv = (BUN) p->value.dval, pv2 = (BUN) p2->value.dval, + mul = (pv == 0 || pv2 == 0) ? 0 : ((pv2 > (BUN_MAX / pv)) ? BUN_MAX : (pv * pv2)); /* check for overflows */ if (is_left(rel->op)) mul = MAX(mul, lv); @@ -785,38 +781,42 @@ rel_get_statistics_(visitor *v, sql_rel } } } - if (join_idx_estimate != BUN_NONE) { + if (join_idx_estimate != BUN_MAX) { set_count_prop(v->sql->sa, rel, join_idx_estimate); - } else if (uniques_estimate != BUN_NONE) { + } else if (uniques_estimate != BUN_MAX) { set_count_prop(v->sql->sa, rel, uniques_estimate); } else if (lv != BUN_NONE && rv != BUN_NONE) { - if (list_empty(rel->exps) && is_outerjoin(rel->op)) { /* outer joins without conditions, sum cardinalities instead of multiply */ - if ((lv + rv) < lv) { - set_count_prop(v->sql->sa, rel, MAX(lv, rv)); + if (list_length(rel->exps) == 1 && (exp_is_false(rel->exps->h->data) || exp_is_null(rel->exps->h->data))) { + /* corner cases for outer joins */ + if (is_left(rel->op)) { + set_count_prop(v->sql->sa, rel, lv); + } else if (is_right(rel->op)) { + set_count_prop(v->sql->sa, rel, rv); + } else if (is_full(rel->op)) { + set_count_prop(v->sql->sa, rel, (rv > (BUN_MAX - lv)) ? BUN_MAX : (lv + rv)); /* overflow check */ } else { - set_count_prop(v->sql->sa, rel, lv + rv); + set_count_prop(v->sql->sa, rel, 0); } - } else if ((lv * rv) < lv) { - set_coun
MonetDB: properties - Cleanup and add defensive line
Changeset: 192d92d8509b for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/192d92d8509b Modified Files: sql/server/rel_rewriter.c sql/server/rel_statistics.c Branch: properties Log Message: Cleanup and add defensive line diffs (55 lines): diff --git a/sql/server/rel_rewriter.c b/sql/server/rel_rewriter.c --- a/sql/server/rel_rewriter.c +++ b/sql/server/rel_rewriter.c @@ -225,6 +225,7 @@ rewrite_simplify(visitor *v, uint8_t cyc /* make sure the single expression is false, so the generate NULL values won't match */ rel->exps->h->data = exp_atom_bool(v->sql->sa, 0); rel->l = rel_project(v->sql->sa, NULL, nexps); + set_count_prop(v->sql->sa, rel, 0); rel->card = CARD_ATOM; v->changes++; } @@ -510,7 +511,13 @@ void set_count_prop(sql_allocator *sa, sql_rel *rel, BUN val) { if (val != BUN_NONE) { - prop *p = rel->p = prop_create(sa, PROP_COUNT, rel->p); - p->value.lval = val; + prop *found = find_prop(rel->p, PROP_COUNT); + + if (found) { + found->value.lval = val; + } else { + prop *p = rel->p = prop_create(sa, PROP_COUNT, rel->p); + p->value.lval = val; + } } } 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 @@ -732,11 +732,8 @@ rel_get_statistics_(visitor *v, sql_rel if (can_be_pruned && (is_join(rel->op) || is_select(rel->op)) && !list_empty(rel->exps)) { int changes = v->changes; rel->exps = rel_prune_predicates(v, rel); - if (v->changes > changes) { + if (v->changes > changes) rel = rewrite_simplify(v, 0, v->value_based_opt, rel); - if (is_select(rel->op) && get_rel_count(rel->l) == BUN_NONE) /* hack, set generated projection count */ - set_count_prop(v->sql->sa, rel->l, 0); - } } /* propagate row count */ @@ -806,9 +803,9 @@ rel_get_statistics_(visitor *v, sql_rel } } } break; - case op_anti: + case op_anti: { set_count_prop(v->sql->sa, rel, get_rel_count(l)); - break; + } break; case op_semi: case op_select: { /* TODO calculate cardinalities using selectivities */ ___ checkin-list mailing list -- checkin-list@monetdb.org To unsubscribe send an email to checkin-list-le...@monetdb.org
MonetDB: default - small test to see if utf8test on windows if f...
Changeset: c710490589e2 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/c710490589e2 Modified Files: sql/test/mapi/Tests/All Branch: default Log Message: small test to see if utf8test on windows if failing.. diffs (12 lines): diff --git a/sql/test/mapi/Tests/All b/sql/test/mapi/Tests/All --- a/sql/test/mapi/Tests/All +++ b/sql/test/mapi/Tests/All @@ -4,7 +4,7 @@ sample4 smack00 smack01 python3_dbapi -utf8test +NOT_WIN32?utf8test HAVE_HGE?mal_int128 HAVE_HGE?sql_int128 HAVE_HGE?python3_int128 ___ checkin-list mailing list -- checkin-list@monetdb.org To unsubscribe send an email to checkin-list-le...@monetdb.org
MonetDB: properties - Read nuniques property if sent on remote p...
Changeset: 17e3d03cc29f for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/17e3d03cc29f Modified Files: sql/server/rel_dump.c Branch: properties Log Message: Read nuniques property if sent on remote plans. Be more restrict to dump properties on atom expressions diffs (51 lines): diff --git a/sql/server/rel_dump.c b/sql/server/rel_dump.c --- a/sql/server/rel_dump.c +++ b/sql/server/rel_dump.c @@ -323,7 +323,7 @@ exp_print(mvc *sql, stream *fout, sql_ex mnstr_printf(fout, " NOT NULL"); if (e->type != e_atom && e->type != e_cmp && is_unique(e)) mnstr_printf(fout, " UNIQUE"); - if (e->p && e->type != e_atom) { + if (e->p && !exp_is_atom(e)) { for (prop *p = e->p; p; p = p->p) { /* Don't show min/max/unique est on atoms, or when running tests with forcemito */ if ((GDKdebug & FORCEMITOMASK) == 0 || (p->kind != PROP_MIN && p->kind != PROP_MAX && p->kind != PROP_NUNIQUES)) { @@ -923,6 +923,28 @@ exp_read_min_or_max(mvc *sql, sql_exp *e skipWS(r, pos); } +static void +exp_read_nuniques(mvc *sql, sql_exp *exp, char *r, int *pos) +{ + void *ptr = NULL; + size_t nbytes = 0; + sql_subtype *tpe = sql_bind_localtype("dbl"); + + (*pos)+= (int) strlen("NUNIQUES"); + skipWS(r, pos); + + if (ATOMfromstr(tpe->type->localtype, &ptr, &nbytes, r + *pos, true) < 0) + return; + + if (!find_prop(exp->p, PROP_NUNIQUES)) { + prop *p = exp->p = prop_create(sql->sa, PROP_NUNIQUES, exp->p); + p->value.dval = *(dbl*)ptr; + } + (*pos) += nbytes; + GDKfree(ptr); + skipWS(r, pos); +} + static sql_exp* read_exp_properties(mvc *sql, sql_exp *exp, char *r, int *pos) { @@ -952,6 +974,9 @@ read_exp_properties(mvc *sql, sql_exp *e } else if (strncmp(r+*pos, "MAX", strlen("MAX")) == 0) { exp_read_min_or_max(sql, exp, r, pos, "MAX", PROP_MAX); found = true; + } else if (strncmp(r+*pos, "NUNIQUES", strlen("NUNIQUES")) == 0) { + exp_read_nuniques(sql, exp, r, pos); + found = true; } if (!read_prop(sql, exp, r, pos, &found)) return NULL; ___ checkin-list mailing list -- checkin-list@monetdb.org To unsubscribe send an email to checkin-list-le...@monetdb.org
MonetDB: properties - Set count property if sent to the remote s...
Changeset: 71cfb9713288 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/71cfb9713288 Modified Files: sql/server/rel_dump.c Branch: properties Log Message: Set count property if sent to the remote side. Cleanup diffs (65 lines): diff --git a/sql/server/rel_dump.c b/sql/server/rel_dump.c --- a/sql/server/rel_dump.c +++ b/sql/server/rel_dump.c @@ -17,6 +17,7 @@ #include "rel_updates.h" #include "rel_select.h" #include "rel_remote.h" +#include "rel_rewriter.h" #include "rel_optimizer.h" #include "sql_privileges.h" @@ -323,7 +324,7 @@ exp_print(mvc *sql, stream *fout, sql_ex mnstr_printf(fout, " NOT NULL"); if (e->type != e_atom && e->type != e_cmp && is_unique(e)) mnstr_printf(fout, " UNIQUE"); - if (e->p && !exp_is_atom(e)) { + if (e->p && e->type != e_atom && !exp_is_atom(e)) { /* don't show properties on value lists */ for (prop *p = e->p; p; p = p->p) { /* Don't show min/max/unique est on atoms, or when running tests with forcemito */ if ((GDKdebug & FORCEMITOMASK) == 0 || (p->kind != PROP_MIN && p->kind != PROP_MAX && p->kind != PROP_NUNIQUES)) { @@ -954,6 +955,8 @@ read_exp_properties(mvc *sql, sql_exp *e if (strncmp(r+*pos, "COUNT", strlen("COUNT")) == 0) { (*pos)+= (int) strlen("COUNT"); + if (!find_prop(exp->p, PROP_COUNT)) + exp->p = prop_create(sql->sa, PROP_COUNT, exp->p); skipWS(r,pos); found = true; } else if (strncmp(r+*pos, "HASHIDX", strlen("HASHIDX")) == 0) { @@ -1634,6 +1637,25 @@ rel_set_types(mvc *sql, sql_rel *rel) return 0; } +static void +rel_read_count(mvc *sql, sql_rel *rel, char *r, int *pos) +{ + void *ptr = NULL; + size_t nbytes = 0; + sql_subtype *tpe = sql_bind_localtype("oid"); + + (*pos)+= (int) strlen("COUNT"); + skipWS(r, pos); + + if (ATOMfromstr(tpe->type->localtype, &ptr, &nbytes, r + *pos, true) < 0) + return; + + set_count_prop(sql->sa, rel, *(BUN*)ptr); + (*pos) += nbytes; + GDKfree(ptr); + skipWS(r, pos); +} + static sql_rel* read_rel_properties(mvc *sql, sql_rel *rel, char *r, int *pos) { @@ -1642,8 +1664,7 @@ read_rel_properties(mvc *sql, sql_rel *r found = false; if (strncmp(r+*pos, "COUNT", strlen("COUNT")) == 0) { - (*pos)+= (int) strlen("COUNT"); - skipWS(r,pos); + rel_read_count(sql, rel, r, pos); found = true; } else if (strncmp(r+*pos, "REMOTE", strlen("REMOTE")) == 0) { /* Remote tables under remote tables not supported, so remove REMOTE property */ (*pos)+= (int) strlen("REMOTE"); ___ checkin-list mailing list -- checkin-list@monetdb.org To unsubscribe send an email to checkin-list-le...@monetdb.org
MonetDB: properties - Add right offset
Changeset: e0f43457ce94 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/e0f43457ce94 Modified Files: sql/server/rel_dump.c Branch: properties Log Message: Add right offset diffs (46 lines): diff --git a/sql/server/rel_dump.c b/sql/server/rel_dump.c --- a/sql/server/rel_dump.c +++ b/sql/server/rel_dump.c @@ -929,19 +929,20 @@ exp_read_nuniques(mvc *sql, sql_exp *exp { void *ptr = NULL; size_t nbytes = 0; + ssize_t res = 0; sql_subtype *tpe = sql_bind_localtype("dbl"); (*pos)+= (int) strlen("NUNIQUES"); skipWS(r, pos); - if (ATOMfromstr(tpe->type->localtype, &ptr, &nbytes, r + *pos, true) < 0) + if ((res = ATOMfromstr(tpe->type->localtype, &ptr, &nbytes, r + *pos, true)) < 0) return; if (!find_prop(exp->p, PROP_NUNIQUES)) { prop *p = exp->p = prop_create(sql->sa, PROP_NUNIQUES, exp->p); p->value.dval = *(dbl*)ptr; } - (*pos) += nbytes; + (*pos) += (int) res; /* it should always fit */ GDKfree(ptr); skipWS(r, pos); } @@ -1642,16 +1643,17 @@ rel_read_count(mvc *sql, sql_rel *rel, c { void *ptr = NULL; size_t nbytes = 0; + ssize_t res = 0; sql_subtype *tpe = sql_bind_localtype("oid"); (*pos)+= (int) strlen("COUNT"); skipWS(r, pos); - if (ATOMfromstr(tpe->type->localtype, &ptr, &nbytes, r + *pos, true) < 0) + if ((res = ATOMfromstr(tpe->type->localtype, &ptr, &nbytes, r + *pos, true)) < 0) return; set_count_prop(sql->sa, rel, *(BUN*)ptr); - (*pos) += nbytes; + (*pos) += (int) res; /* it should always fit */ GDKfree(ptr); skipWS(r, pos); } ___ checkin-list mailing list -- checkin-list@monetdb.org To unsubscribe send an email to checkin-list-le...@monetdb.org
MonetDB: properties - Throw error if input is invalid
Changeset: 860a5dab6d5a for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/860a5dab6d5a Modified Files: sql/server/rel_dump.c Branch: properties Log Message: Throw error if input is invalid diffs (132 lines): diff --git a/sql/server/rel_dump.c b/sql/server/rel_dump.c --- a/sql/server/rel_dump.c +++ b/sql/server/rel_dump.c @@ -898,7 +898,7 @@ read_exps(mvc *sql, sql_rel *lrel, sql_r return exps; } -static void +static sql_exp* exp_read_min_or_max(mvc *sql, sql_exp *exp, char *r, int *pos, const char *prop_str, rel_prop kind) { atom *a; @@ -913,7 +913,7 @@ exp_read_min_or_max(mvc *sql, sql_exp *e } else { void *ptr = readAtomString(tpe->type->localtype, r, pos); if (!ptr) - return ; + return sql_error(sql, -1, SQLSTATE(42000) "Invalid atom string\n"); a = atom_general_ptr(sql->sa, tpe, ptr); GDKfree(ptr); } @@ -922,9 +922,10 @@ exp_read_min_or_max(mvc *sql, sql_exp *e p->value.pval = a; } skipWS(r, pos); + return exp; } -static void +static sql_exp* exp_read_nuniques(mvc *sql, sql_exp *exp, char *r, int *pos) { void *ptr = NULL; @@ -935,8 +936,10 @@ exp_read_nuniques(mvc *sql, sql_exp *exp (*pos)+= (int) strlen("NUNIQUES"); skipWS(r, pos); - if ((res = ATOMfromstr(tpe->type->localtype, &ptr, &nbytes, r + *pos, true)) < 0) - return; + if ((res = ATOMfromstr(tpe->type->localtype, &ptr, &nbytes, r + *pos, true)) < 0) { + GDKfree(ptr); + return sql_error(sql, -1, SQLSTATE(42000) "Invalid atom string\n"); + } if (!find_prop(exp->p, PROP_NUNIQUES)) { prop *p = exp->p = prop_create(sql->sa, PROP_NUNIQUES, exp->p); @@ -945,6 +948,7 @@ exp_read_nuniques(mvc *sql, sql_exp *exp (*pos) += (int) res; /* it should always fit */ GDKfree(ptr); skipWS(r, pos); + return exp; } static sql_exp* @@ -973,13 +977,16 @@ read_exp_properties(mvc *sql, sql_exp *e skipWS(r,pos); found = true; } else if (strncmp(r+*pos, "MIN", strlen("MIN")) == 0) { - exp_read_min_or_max(sql, exp, r, pos, "MIN", PROP_MIN); + if (!exp_read_min_or_max(sql, exp, r, pos, "MIN", PROP_MIN)) + return NULL; found = true; } else if (strncmp(r+*pos, "MAX", strlen("MAX")) == 0) { - exp_read_min_or_max(sql, exp, r, pos, "MAX", PROP_MAX); + if (!exp_read_min_or_max(sql, exp, r, pos, "MAX", PROP_MAX)) + return NULL; found = true; } else if (strncmp(r+*pos, "NUNIQUES", strlen("NUNIQUES")) == 0) { - exp_read_nuniques(sql, exp, r, pos); + if (!exp_read_nuniques(sql, exp, r, pos)) + return NULL; found = true; } if (!read_prop(sql, exp, r, pos, &found)) @@ -1332,7 +1339,8 @@ exp_read(mvc *sql, sql_rel *lrel, sql_re skipWS(r, pos); exp = exp_convert(sql->sa, exp, exp_subtype(exp), &tpe); } else { - exp = parse_atom(sql, r, pos, &tpe); + if (!(exp = parse_atom(sql, r, pos, &tpe))) + return NULL; skipWS(r, pos); } } @@ -1348,7 +1356,8 @@ exp_read(mvc *sql, sql_rel *lrel, sql_re return sql_error(sql, ERR_NOTFOUND, SQLSTATE(42000) "SQL type %s not found\n", tname); sql_init_subtype(&tpe, t, 0, 0); } - exp = parse_atom(sql, r, pos, &tpe); + if (!(exp = parse_atom(sql, r, pos, &tpe))) + return NULL; skipWS(r, pos); } break; @@ -1638,7 +1647,7 @@ rel_set_types(mvc *sql, sql_rel *rel) return 0; } -static void +static sql_rel* rel_read_count(mvc *sql, sql_rel *rel, char *r, int *pos) { void *ptr = NULL; @@ -1649,13 +1658,16 @@ rel_read_count(mvc *sql, sql_rel *rel, c (*pos)+= (int) strlen("COUNT"); skipWS(r, pos); - if ((res = ATOMfromstr(tpe->type->localtype, &ptr, &nbytes, r + *pos, true)) < 0) - return; + if ((res = ATOMfromstr(tpe->type->localtype, &ptr, &nbytes, r + *pos, true)) < 0) { + GDKfree(ptr); + return sql_error(sql, -1, SQLSTATE(42000) "Invalid atom string\n"); + } set_count_prop(sql->sa, rel, *(BUN*)ptr);
MonetDB: properties - This estimation is wrong. Remove it
Changeset: ae4d897b9c50 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/ae4d897b9c50 Modified Files: sql/server/rel_statistics.c Branch: properties Log Message: This estimation is wrong. Remove it diffs (32 lines): 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 @@ -609,7 +609,7 @@ rel_get_statistics_(visitor *v, sql_rel { /* Don't prune updates as pruning will possibly result in removing the joins which therefore cannot be used for constraint checking */ uint8_t has_special_modify = *(uint8_t*) v->data; - prop *p, *p2; + prop *p; bool can_be_pruned = !has_special_modify && v->storage_based_opt; /* Don't look at the same relation twice */ @@ -762,19 +762,6 @@ rel_get_statistics_(visitor *v, sql_rel uniques_estimate = MIN(uniques_estimate, ncount); } } - if ((p = find_prop(el->p, PROP_NUNIQUES)) && (p2 = find_prop(er->p, PROP_NUNIQUES))) { - BUN pv = (BUN) p->value.dval, pv2 = (BUN) p2->value.dval, - mul = (pv == 0 || pv2 == 0) ? 0 : ((pv2 > (BUN_MAX / pv)) ? BUN_MAX : (pv * pv2)); /* check for overflows */ - - if (is_left(rel->op)) - mul = MAX(mul, lv); - else if (is_right(rel->op)) - mul = MAX(mul, rv); - else if (is_full(rel->op)) - mul = MAX(MAX(mul, lv), rv); - - uniques_estimate = MIN(uniques_estimate, mul); - } } } } ___ checkin-list mailing list -- checkin-list@monetdb.org To unsubscribe send an email to checkin-list-le...@monetdb.org
MonetDB: default - Next dict thetaselect issue
Changeset: 7c1c0f761999 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/7c1c0f761999 Modified Files: sql/test/dict/Tests/dict04.test Branch: default Log Message: Next dict thetaselect issue diffs (33 lines): diff --git a/sql/test/dict/Tests/dict04.test b/sql/test/dict/Tests/dict04.test --- a/sql/test/dict/Tests/dict04.test +++ b/sql/test/dict/Tests/dict04.test @@ -322,6 +322,29 @@ statement ok START TRANSACTION statement ok +CREATE TABLE t0 (c0 INT) + +statement ok rowcount 1 +INSERT INTO t0 VALUES (2) + +statement ok +COMMIT + +statement ok +CALL "sys"."dict_compress"('sys','t0','c0', true) + +query I nosort +SELECT * FROM t0 WHERE c0 > 1 + +2 + +statement ok +DROP TABLE t0 + +statement ok +START TRANSACTION + +statement ok DROP ALL PROCEDURE "sys"."dict_compress" statement ok ___ checkin-list mailing list -- checkin-list@monetdb.org To unsubscribe send an email to checkin-list-le...@monetdb.org
MonetDB: default - Compilation fix
Changeset: 16ef3ce087fe for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/16ef3ce087fe Modified Files: sql/storage/bat/bat_storage.c Branch: default Log Message: Compilation fix diffs (12 lines): diff --git a/sql/storage/bat/bat_storage.c b/sql/storage/bat/bat_storage.c --- a/sql/storage/bat/bat_storage.c +++ b/sql/storage/bat/bat_storage.c @@ -2314,7 +2314,7 @@ delta_append_val(sql_trans *tr, sql_delt if (cnt) { if (BATcount(b) < offset) { /* add space */ const void *tv = ATOMnilptr(b->ttype); - lng d = offset - BATcount(b); + BUN d = offset - BATcount(b); if (BUNappendmulti(b, tv, d, true) != GDK_SUCCEED) { bat_destroy(b); if (i != oi) ___ checkin-list mailing list -- checkin-list@monetdb.org To unsubscribe send an email to checkin-list-le...@monetdb.org