Changeset: 94cc1d6f4f27 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=94cc1d6f4f27 Modified Files: sql/server/rel_statistics.c sql/server/rel_statistics.h sql/server/rel_statistics_functions.c Branch: properties Log Message:
Propagate statistics of trivial functions and cleanup diffs (truncated from 416 to 300 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 @@ -66,9 +66,9 @@ rel_propagate_column_ref_statistics(mvc if ((ne = comparison_find_column(le, e)) || (rne = comparison_find_column(re, e))) { if (is_outerjoin(rel->op)) { if ((lval = find_prop_and_get(le ? le->p : re->p, PROP_MAX))) - copy_property(sql, e, PROP_MAX, lval); + set_property(sql, e, PROP_MAX, lval); if ((lval = find_prop_and_get(le ? le->p : re->p, PROP_MIN))) - copy_property(sql, e, PROP_MIN, lval); + set_property(sql, e, PROP_MIN, lval); } else { if ((lval = find_prop_and_get(le->p, PROP_MAX)) && (rval = find_prop_and_get(re->p, PROP_MAX))) set_min_of_values(sql, e, PROP_MAX, lval, rval); /* for equality reduce */ @@ -84,9 +84,9 @@ rel_propagate_column_ref_statistics(mvc if ((ne = comparison_find_column(le, e)) || (rne = comparison_find_column(re, e))) { if (is_outerjoin(rel->op)) { if ((lval = find_prop_and_get(le ? le->p : re->p, PROP_MAX))) - copy_property(sql, e, PROP_MAX, lval); + set_property(sql, e, PROP_MAX, lval); if ((lval = find_prop_and_get(le ? le->p : re->p, PROP_MIN))) - copy_property(sql, e, PROP_MIN, lval); + set_property(sql, e, PROP_MIN, lval); } else { if ((lval = find_prop_and_get(le->p, PROP_MAX)) && (rval = find_prop_and_get(re->p, PROP_MAX))) set_max_of_values(sql, e, PROP_MAX, lval, rval); /* for inequality expand */ @@ -104,19 +104,19 @@ rel_propagate_column_ref_statistics(mvc if ((ne = comparison_find_column(le, e)) || (rne = comparison_find_column(re, e))) { if (is_outerjoin(rel->op)) { if ((lval = find_prop_and_get(le ? le->p : re->p, PROP_MAX))) - copy_property(sql, e, PROP_MAX, lval); + set_property(sql, e, PROP_MAX, lval); if ((lval = find_prop_and_get(le ? le->p : re->p, PROP_MIN))) - copy_property(sql, e, PROP_MIN, lval); + set_property(sql, e, PROP_MIN, lval); } else if (ne) { if ((lval = find_prop_and_get(le->p, PROP_MAX))) - copy_property(sql, e, PROP_MAX, lval); + set_property(sql, e, PROP_MAX, lval); if ((rval = find_prop_and_get(re->p, PROP_MAX))) - copy_property(sql, e, PROP_MIN, rval); + set_property(sql, e, PROP_MIN, rval); } else { if ((lval = find_prop_and_get(le->p, PROP_MIN))) - copy_property(sql, e, PROP_MAX, lval); + set_property(sql, e, PROP_MAX, lval); if ((rval = find_prop_and_get(re->p, PROP_MIN))) - copy_property(sql, e, PROP_MIN, rval); + set_property(sql, e, PROP_MIN, rval); } } ne = ne ? ne : rne; @@ -128,38 +128,38 @@ rel_propagate_column_ref_statistics(mvc if ((ne = comparison_find_column(le, e)) || (rne = comparison_find_column(re, e)) || (fe && (fne = comparison_find_column(fe, e)))) { if (is_outerjoin(rel->op)) { if ((lval = find_prop_and_get(le ? le->p : re ? re->p : fe->p, PROP_MAX))) - copy_property(sql, e, PROP_MAX, lval); + set_property(sql, e, PROP_MAX, lval); if ((lval = find_prop_and_get(le ? le->p : re ? re->p : fe->p, PROP_MIN))) - copy_property(sql, e, PROP_MIN, lval); + set_property(sql, e, PROP_MIN, lval); } else if (ne) { if (fe) { /* range case */ if ((lval = find_prop_and_get(fe->p, PROP_MIN))) - copy_property(sql, e, PROP_MAX, lval); + set_property(sql, e, PROP_MAX, lval); if ((rval = find_prop_and_get(re->p, PROP_MAX))) - copy_property(sql, e, PROP_MIN, rval); + set_property(sql, e, PROP_MIN, rval); } else { if ((lval = find_prop_and_get(re->p, PROP_MIN))) - copy_property(sql, e, PROP_MAX, lval); + set_property(sql, e, PROP_MAX, lval); if ((rval = find_prop_and_get(le->p, PROP_MIN))) - copy_property(sql, e, PROP_MIN, rval); + set_property(sql, e, PROP_MIN, rval); } } else if (rne) { if (fe) { /* range case */ if ((lval = find_prop_and_get(re->p, PROP_MIN))) - copy_property(sql, e, PROP_MAX, lval); + set_property(sql, e, PROP_MAX, lval); if ((rval = find_prop_and_get(le->p, PROP_MIN))) - copy_property(sql, e, PROP_MIN, rval); + set_property(sql, e, PROP_MIN, rval); } else { if ((lval = find_prop_and_get(re->p, PROP_MAX))) - copy_property(sql, e, PROP_MAX, lval); + set_property(sql, e, PROP_MAX, lval); if ((rval = find_prop_and_get(le->p, PROP_MAX))) - copy_property(sql, e, PROP_MIN, rval); + set_property(sql, e, PROP_MIN, rval); } } else { /* range case */ if ((lval = find_prop_and_get(fe->p, PROP_MAX))) - copy_property(sql, e, PROP_MAX, lval); + set_property(sql, e, PROP_MAX, lval); if ((rval = find_prop_and_get(le->p, PROP_MAX))) - copy_property(sql, e, PROP_MIN, rval); + set_property(sql, e, PROP_MIN, rval); } } ne = ne ? ne : rne ? rne : fne; @@ -180,9 +180,9 @@ rel_propagate_column_ref_statistics(mvc case op_basetable: { if (e->l && (ne = exps_bind_column2(rel->exps, e->l, e->r, NULL))) { if ((lval = find_prop_and_get(ne->p, PROP_MAX))) - copy_property(sql, e, PROP_MAX, lval); + set_property(sql, e, PROP_MAX, lval); if ((lval = find_prop_and_get(ne->p, PROP_MIN))) - copy_property(sql, e, PROP_MIN, lval); + set_property(sql, e, PROP_MIN, lval); } } break; case op_union: @@ -193,9 +193,9 @@ rel_propagate_column_ref_statistics(mvc ne = e->l ? exps_bind_column2(rel->exps, e->l, e->r, NULL) : exps_bind_column(rel->exps, e->r, NULL, NULL, 1); if (ne) { if ((lval = find_prop_and_get(ne->p, PROP_MAX))) - copy_property(sql, e, PROP_MAX, lval); + set_property(sql, e, PROP_MAX, lval); if ((lval = find_prop_and_get(ne->p, PROP_MIN))) - copy_property(sql, e, PROP_MIN, lval); + set_property(sql, e, PROP_MIN, lval); } } break; default: /* if there is a topN or sample relation in between, then the MIN and MAX values are lost */ @@ -244,7 +244,7 @@ rel_set_get_statistics(mvc *sql, sql_rel else if (rel->op == op_inter) set_min_of_values(sql, e, PROP_MAX, lval, rval); /* for intersect the new max will be the min of the two */ else - copy_property(sql, e, PROP_MAX, lval); + set_property(sql, e, PROP_MAX, lval); } if ((lval = find_prop_and_get(le->p, PROP_MIN)) && (rval = find_prop_and_get(re->p, PROP_MIN))) { if (rel->op == op_union) @@ -252,7 +252,7 @@ rel_set_get_statistics(mvc *sql, sql_rel else if (rel->op == op_inter) set_max_of_values(sql, e, PROP_MIN, lval, rval); /* for intersect the new min will be the max of the two */ else - copy_property(sql, e, PROP_MIN, lval); + set_property(sql, e, PROP_MIN, lval); } } @@ -301,9 +301,9 @@ rel_propagate_statistics(visitor *v, sql ValPtr res = (ValPtr) sa_zalloc(sql->sa, sizeof(ValRecord)); VALcopy(res, lval); if (VALconvert(to->type->localtype, res)) - copy_property(sql, e, PROP_MAX, res); + set_property(sql, e, PROP_MAX, res); } else { - copy_property(sql, e, PROP_MAX, lval); + set_property(sql, e, PROP_MAX, lval); } } if ((lval = find_prop_and_get(l->p, PROP_MIN))) { @@ -311,9 +311,9 @@ rel_propagate_statistics(visitor *v, sql ValPtr res = (ValPtr) sa_zalloc(sql->sa, sizeof(ValRecord)); VALcopy(res, lval); if (VALconvert(to->type->localtype, res)) - copy_property(sql, e, PROP_MIN, res); + set_property(sql, e, PROP_MIN, res); } else { - copy_property(sql, e, PROP_MIN, lval); + set_property(sql, e, PROP_MIN, lval); } } } @@ -341,8 +341,8 @@ rel_propagate_statistics(visitor *v, sql if (e->l) { atom *a = (atom*) e->l; if (!a->isnull) { - copy_property(sql, e, PROP_MAX, &a->data); - copy_property(sql, e, PROP_MIN, &a->data); + set_property(sql, e, PROP_MAX, &a->data); + set_property(sql, e, PROP_MIN, &a->data); } } else if (e->f) { list *vals = (list *) e->f; @@ -377,9 +377,9 @@ rel_propagate_statistics(visitor *v, sql } if (max) - copy_property(sql, e, PROP_MAX, max); + set_property(sql, e, PROP_MAX, max); if (min) - copy_property(sql, e, PROP_MIN, min); + set_property(sql, e, PROP_MIN, min); } } break; case e_cmp: /* propagating min and max of booleans is not very worth it */ diff --git a/sql/server/rel_statistics.h b/sql/server/rel_statistics.h --- a/sql/server/rel_statistics.h +++ b/sql/server/rel_statistics.h @@ -45,7 +45,7 @@ set_min_of_values(mvc *sql, sql_exp *e, } static inline void -copy_property(mvc *sql, sql_exp *e, rel_prop kind, ValPtr val) +set_property(mvc *sql, sql_exp *e, rel_prop kind, ValPtr val) { prop *p = e->p = prop_create(sql->sa, kind, e->p); p->value = val; 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 @@ -19,55 +19,6 @@ sql_hash *sql_functions_lookup = NULL; static void -VALzero_value(ValPtr input, int localtype) -{ - void *ret = NULL; - - bte bval = 0; - sht sval = 0; - int ival = 0; - lng lval = 0; -#ifdef HAVE_HGE - hge hval = 0; -#endif - flt fval = 0; - dbl dval = 0; - - if (ATOMlinear(localtype)) { - switch (ATOMstorage(localtype)) { - case TYPE_bte: - ret = &bval; - break; - case TYPE_sht: - ret = &sval; - break; - case TYPE_int: - ret = &ival; - break; - case TYPE_lng: - ret = &lval; - break; -#ifdef HAVE_HGE - case TYPE_hge: - ret = &hval; - break; -#endif - case TYPE_flt: - ret = &fval; - break; - case TYPE_dbl: - ret = &dval; - break; - default: - break; - } - } - - VALset(input, localtype, ret); -} - - -static void sql_add_propagate_statistics(mvc *sql, sql_exp *e) { list *l = e->l; @@ -78,7 +29,7 @@ sql_add_propagate_statistics(mvc *sql, s ValPtr res = (ValPtr) sa_zalloc(sql->sa, sizeof(ValRecord)); res->vtype = lval->vtype > rval->vtype ? lval->vtype : rval->vtype; if (VARcalcadd(res, lval, rval, true) == GDK_SUCCEED) { - copy_property(sql, e, PROP_MAX, res); + set_property(sql, e, PROP_MAX, res); } else { GDKclrerr(); /* if the min/max pair overflows, then don't propagate */ } @@ -87,7 +38,7 @@ sql_add_propagate_statistics(mvc *sql, s ValPtr res = (ValPtr) sa_zalloc(sql->sa, sizeof(ValRecord)); res->vtype = lval->vtype > rval->vtype ? lval->vtype : rval->vtype; if (VARcalcadd(res, lval, rval, true) == GDK_SUCCEED) { - copy_property(sql, e, PROP_MIN, res); + set_property(sql, e, PROP_MIN, res); } else { GDKclrerr(); } @@ -114,23 +65,20 @@ sql_##FUNC##_propagate_statistics(mvc *s GDKclrerr(); \ \ if (code1 == GDK_SUCCEED && code2 == GDK_SUCCEED) { /* if the min/max pair overflows, then don't propagate */ \ - ValRecord zero1, zero2, zero3, zero4, verify1, verify2, verify3, verify4; \ + ValRecord zero1 = (ValRecord) {.vtype = lmax->vtype,}, zero2 = (ValRecord) {.vtype = rmax->vtype,}, zero3 = (ValRecord) {.vtype = lmin->vtype,}, \ + zero4 = (ValRecord) {.vtype = rmin->vtype,}, verify1, verify2, verify3, verify4; \ \ - VALzero_value(&zero1, lmax->vtype); \ VARcalcge(&verify1, lmax, &zero1); \ - VALzero_value(&zero2, rmax->vtype); \ VARcalcge(&verify2, rmax, &zero2); \ - VALzero_value(&zero3, lmin->vtype); \ VARcalcge(&verify3, lmin, &zero3); \ - VALzero_value(&zero4, rmin->vtype); \ VARcalcge(&verify4, rmin, &zero4); \ \ if (verify1.val.btval == 1 && verify2.val.btval == 1 && verify3.val.btval == 1 && verify4.val.btval == 1) { /* if all positive then propagate */ \ _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list