Changeset: bd50c650a7fd for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=bd50c650a7fd
Modified Files:
sql/server/rel_statistics_functions.c
Branch: properties
Log Message:
Propagation for div and sub functions
diffs (84 lines):
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
@@ -94,8 +94,53 @@ sql_add_propagate_statistics(mvc *sql, s
}
}
+#define mul_and_sub_propagate(FUNC) \
+static void \
+sql_##FUNC##_propagate_statistics(mvc *sql, sql_exp *e) \
+{ \
+ list *l = e->l; \
+ sql_exp *first = l->h->data, *second = l->h->next->data; \
+ ValPtr lmax, rmax, lmin, rmin; \
+ \
+ if ((lmax = find_prop_and_get(first->p, PROP_MAX)) && (rmax =
find_prop_and_get(second->p, PROP_MAX)) && \
+ (lmin = find_prop_and_get(first->p, PROP_MIN)) && (rmin =
find_prop_and_get(second->p, PROP_MIN))) { \
+ ValPtr res1 = (ValPtr) sa_zalloc(sql->sa, sizeof(ValRecord)),
res2 = (ValPtr) sa_zalloc(sql->sa, sizeof(ValRecord)); \
+ gdk_return code1, code2; \
+ \
+ res1->vtype = res2->vtype = lmax->vtype > rmax->vtype ?
lmax->vtype : rmax->vtype; \
+ code1 = VARcalc##FUNC(res1, lmax, rmax, true); \
+ GDKclrerr(); \
+ code2 = VARcalc##FUNC(res2, lmin, rmin, true); \
+ 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; \
+ \
+ 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 */ \
+ copy_property(sql, e, PROP_MAX, res1); \
+ copy_property(sql, e, PROP_MIN, res2); \
+ } else if (verify1.val.btval == 0 && verify2.val.btval
== 0 && verify3.val.btval == 0 && verify4.val.btval == 0) { /* if all negative
propagate by swapping min and max */ \
+ copy_property(sql, e, PROP_MIN, res1); \
+ copy_property(sql, e, PROP_MAX, res2); \
+ } \
+ } \
+ } \
+}
+
+mul_and_sub_propagate(sub)
+mul_and_sub_propagate(mul)
+
static void
-sql_mul_propagate_statistics(mvc *sql, sql_exp *e)
+sql_div_propagate_statistics(mvc *sql, sql_exp *e)
{
list *l = e->l;
sql_exp *first = l->h->data, *second = l->h->next->data;
@@ -107,9 +152,9 @@ sql_mul_propagate_statistics(mvc *sql, s
gdk_return code1, code2;
res1->vtype = res2->vtype = lmax->vtype > rmax->vtype ?
lmax->vtype : rmax->vtype;
- code1 = VARcalcmul(res1, lmax, rmax, true);
+ code1 = VARcalcdiv(res1, lmax, rmin, true);
GDKclrerr();
- code2 = VARcalcmul(res2, lmin, rmin, true);
+ code2 = VARcalcdiv(res2, lmin, rmax, true);
GDKclrerr();
if (code1 == GDK_SUCCEED && code2 == GDK_SUCCEED) { /* if the
min/max pair overflows, then don't propagate */
@@ -135,9 +180,11 @@ sql_mul_propagate_statistics(mvc *sql, s
}
}
-static struct function_properties functions_list[2] = {
+static struct function_properties functions_list[4] = {
{"sql_add", &sql_add_propagate_statistics},
- {"sql_mul", &sql_mul_propagate_statistics}
+ {"sql_sub", &sql_sub_propagate_statistics},
+ {"sql_mul", &sql_mul_propagate_statistics},
+ {"sql_div", &sql_div_propagate_statistics}
};
void
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list