Changeset: 515b9461bd13 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/515b9461bd13
Modified Files:
sql/backends/monet5/bin_partition_by_slice.c
sql/server/rel_statistics.c
sql/server/rel_statistics_functions.c
Branch: pp_hashjoin
Log Message:
add improved statistics function for case statements
diffs (87 lines):
diff --git a/sql/backends/monet5/bin_partition_by_slice.c
b/sql/backends/monet5/bin_partition_by_slice.c
--- a/sql/backends/monet5/bin_partition_by_slice.c
+++ b/sql/backends/monet5/bin_partition_by_slice.c
@@ -828,7 +828,7 @@ rel_groupby_partition(mvc *sql, sql_rel
if (list_empty(rel->r))
return false;
/* check size */
- BUN est = get_rel_count(rel);
+ BUN est = get_rel_count(rel->l);
lng estimate, card = 1;
if (est == BUN_NONE
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
@@ -1160,6 +1160,8 @@ rel_get_statistics_(visitor *v, sql_rel
set_count_prop(v->sql->sa, rel, 1000 /* TODO
get size of querylog */);
} else if (f->func->lang == FUNC_LANG_MAL &&
strncmp(f->func->base.name, "generate_series", 15) == 0) {
set_count_prop(v->sql->sa, rel, 1000 /* TODO
get size of (limit - start + 1) */);
+ } else if (f->func->lang == FUNC_LANG_INT &&
strncmp(f->func->base.name, "file_loader", 11) == 0) {
+ set_count_prop(v->sql->sa, rel, 1000) /* get
size from file loader */;
} else if (f->func->lang == FUNC_LANG_MAL &&
(strcmp(f->func->base.name, "env")
== 0 ||
strcmp(f->func->base.name,
"keywords") == 0 ||
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
@@ -368,6 +368,50 @@ sql_casewhen_propagate_statistics(mvc *s
}
static void
+sql_case_propagate_statistics(mvc *sql, sql_exp *e)
+{
+ list *l = e->l;
+ int len = list_length(l);
+ sql_exp *first = (len>=2) ? l->h->next->data : NULL;
+ atom *curmin = NULL, *curmax = NULL, *lval;
+
+ assert(list_length(l) >= 3);
+ if (first && (lval = find_prop_and_get(first->p, PROP_MAX)))
+ curmax = lval;
+ if (first && (lval = find_prop_and_get(first->p, PROP_MIN)))
+ curmin = lval;
+
+ prop *p = first ? find_prop(first->p, PROP_NUNIQUES) : NULL;
+ dbl nuniques = p ? p->value.dval : 1;
+ if (len >= 2) {
+ for (node *n = l->h->next->next ; n && curmin && curmax ; n =
n->next) {
+ sql_exp *next = n->data;
+ if ((lval = find_prop_and_get(next->p, PROP_MAX))) {
+ curmax = atom_cmp(lval, curmax) > 0 ? lval :
curmax;
+ } else {
+ curmax = NULL;
+ }
+ if ((lval = find_prop_and_get(next->p, PROP_MIN))) {
+ curmin = atom_cmp(lval, curmin) > 0 ? curmin :
lval;
+ } else {
+ curmin = NULL;
+ }
+ prop *p = next ? find_prop(next->p, PROP_NUNIQUES) :
NULL;
+ nuniques *= p ? p->value.dval : 1;
+ }
+ }
+
+ if (curmin && curmax) {
+ set_minmax_property(sql, e, PROP_MAX, curmax);
+ set_minmax_property(sql, e, PROP_MIN, curmin);
+ }
+ if (!find_prop(e->p, PROP_NUNIQUES)) {
+ prop *p = e->p = prop_create(sql->sa, PROP_NUNIQUES, e->p);
+ p->value.dval = nuniques;
+ }
+}
+
+static void
sql_nullif_propagate_statistics(mvc *sql, sql_exp *e)
{
list *l = e->l;
@@ -804,7 +848,7 @@ static struct function_properties functi
{"nullif", &sql_nullif_propagate_statistics},
{"coalesce", &sql_coalesce_propagate_statistics},
{"casewhen", &sql_casewhen_propagate_statistics},
- {"case", &sql_casewhen_propagate_statistics},
+ {"case", &sql_case_propagate_statistics},
/* time functions */
{"century", &sql_century_propagate_statistics},
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]