Changeset: 0321c072c1ff for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/0321c072c1ff
Modified Files:
        sql/server/rel_statistics.c
Branch: properties
Log Message:

Two fixes. Make sure max is set before min (alignment on the plan). Also don't 
call storage function for declared table because it won't be cleared and it's 
not meaningful


diffs (94 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
@@ -82,16 +82,16 @@ rel_propagate_column_ref_statistics(mvc 
                                                                        if 
(symmetric) {
                                                                                
prop *p1 = find_prop(e->p, PROP_MIN), *p2 = find_prop(e->p, PROP_MAX);
                                                                                
atom *nmin = statistics_atom_min(sql, rval_min, fval_min), *nmax = 
statistics_atom_max(sql, rval_max, fval_max);
-                                                                               
/* min is max from le and (min from re and fe min) */
-                                                                               
set_minmax_property(sql, e, PROP_MIN, p1 ? statistics_atom_max(sql, nmin, 
p1->value.pval) : nmin);
                                                                                
/* max is min from le and (max from re and fe max) */
                                                                                
set_minmax_property(sql, e, PROP_MAX, p2 ? statistics_atom_min(sql, nmax, 
p2->value.pval) : nmax);
+                                                                               
/* min is max from le and (min from re and fe min) */
+                                                                               
set_minmax_property(sql, e, PROP_MIN, p1 ? statistics_atom_max(sql, nmin, 
p1->value.pval) : nmin);
                                                                        } else {
                                                                                
prop *p1 = find_prop(e->p, PROP_MIN), *p2 = find_prop(e->p, PROP_MAX);
+                                                                               
/* max is min from le and fe max */
+                                                                               
set_minmax_property(sql, e, PROP_MAX, p2 ? statistics_atom_min(sql, fval_max, 
p2->value.pval) : fval_max);
                                                                                
/* min is max from le and re min */
                                                                                
set_minmax_property(sql, e, PROP_MIN, p1 ? statistics_atom_max(sql, rval_min, 
p1->value.pval) : rval_min);
-                                                                               
/* max is min from le and fe max */
-                                                                               
set_minmax_property(sql, e, PROP_MAX, p2 ? statistics_atom_min(sql, fval_max, 
p2->value.pval) : fval_max);
                                                                        }
                                                                } else if (rne) 
{
                                                                        if 
(symmetric && int1 && int2) { /* min is max from le and (min from re and fe 
min) */
@@ -240,6 +240,13 @@ rel_basetable_column_get_statistics(mvc 
                        prop *p = e->p = prop_create(sql->sa, PROP_NUNIQUES, 
e->p);
                        p->value.dval = unique_est;
                }
+               if ((ok & 2) == 2) {
+                       if (!VALisnil(&max)) {
+                               prop *p = e->p = prop_create(sql->sa, PROP_MAX, 
e->p);
+                               p->value.pval = atom_from_valptr(sql->sa, 
&c->type, &max);
+                       }
+                       VALclear(&max);
+               }
                if ((ok & 1) == 1) {
                        if (!VALisnil(&min)) {
                                prop *p = e->p = prop_create(sql->sa, PROP_MIN, 
e->p);
@@ -247,13 +254,6 @@ rel_basetable_column_get_statistics(mvc 
                        }
                        VALclear(&min);
                }
-               if ((ok & 2) == 2) {
-                       if (!VALisnil(&max)) {
-                               prop *p = e->p = prop_create(sql->sa, PROP_MAX, 
e->p);
-                               p->value.pval = atom_from_valptr(sql->sa, 
&c->type, &max);
-                       }
-                       VALclear(&max);
-               }
        }
 }
 
@@ -270,6 +270,14 @@ rel_setop_get_statistics(mvc *sql, sql_r
                ((rval_max && lval_min && atom_cmp(rval_max, lval_min) < 0) || 
(rval_min && lval_max && atom_cmp(rval_min, lval_max) > 0)))
                return true;
 
+       if (lval_max && rval_max) {
+               if (is_union(rel->op))
+                       set_minmax_property(sql, e, PROP_MAX, 
statistics_atom_max(sql, lval_max, rval_max)); /* for union the new max will be 
the max of the two */
+               else if (is_inter(rel->op))
+                       set_minmax_property(sql, e, PROP_MAX, 
statistics_atom_min(sql, lval_max, rval_max)); /* for intersect the new max 
will be the min of the two */
+               else /* except */
+                       set_minmax_property(sql, e, PROP_MAX, lval_max);
+       }
        if (lval_min && rval_min) {
                if (is_union(rel->op))
                        set_minmax_property(sql, e, PROP_MIN, 
statistics_atom_min(sql, lval_min, rval_min)); /* for union the new min will be 
the min of the two */
@@ -278,14 +286,6 @@ rel_setop_get_statistics(mvc *sql, sql_r
                else /* except */
                        set_minmax_property(sql, e, PROP_MIN, lval_min);
        }
-       if (lval_max && rval_max) {
-               if (is_union(rel->op))
-                       set_minmax_property(sql, e, PROP_MAX, 
statistics_atom_max(sql, lval_max, rval_max)); /* for union the new max will be 
the max of the two */
-               else if (is_inter(rel->op))
-                       set_minmax_property(sql, e, PROP_MAX, 
statistics_atom_min(sql, lval_max, rval_max)); /* for intersect the new max 
will be the min of the two */
-               else /* except */
-                       set_minmax_property(sql, e, PROP_MAX, lval_max);
-       }
 
        if (is_union(rel->op)) {
                if (!has_nil(le) && !has_nil(re))
@@ -626,9 +626,8 @@ rel_get_statistics_(visitor *v, sql_rel 
                        for (node *n = rel->exps->h ; n ; n = n->next)
                                rel_basetable_column_get_statistics(v->sql, 
rel, n->data);
                }
-               /* set table row count */
-               /* TODO look for remote/replica tables */
-               if (isTable(t))
+               /* Set table row count. TODO? look for remote/replica tables. 
Don't look at storage for declared tables, because it won't be cleaned */
+               if (isTable(t) && t->s && !isDeclaredTable(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:
_______________________________________________
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org

Reply via email to