Update of /cvsroot/monetdb/sql/src/server
In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv4764/src/server
Modified Files:
rel_optimizer.mx rel_select.mx rel_subquery.mx
Log Message:
For avg we now always first change to doubles.
With this we can now rewrite all 'avg's into sum/cnt.
approved slight rounding changes
approved output after changes on the optimizers
approved tests which changed because of number of default functions changed
U rel_subquery.mx
Index: rel_subquery.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/rel_subquery.mx,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- rel_subquery.mx 7 Jan 2009 14:19:29 -0000 1.9
+++ rel_subquery.mx 4 Jun 2009 20:27:54 -0000 1.10
@@ -117,9 +117,9 @@
if (f->func->fix_scale == SCALE_FIX) {
ls = fix_scale(sql, t2, ls, 0, 0);
rs = fix_scale(sql, t1, rs, 0, 0);
- } else if (f->func->fix_scale == SCALE_SUB) {
+ } else if (f->func->fix_scale == SCALE_DIV) {
ls = scale_algebra(sql, f, ls, rs);
- } else if (f->func->fix_scale == SCALE_ADD) {
+ } else if (f->func->fix_scale == SCALE_MUL) {
ls = sum_scales(sql, f, ls, rs);
} else if (f->func->fix_scale == DIGITS_ADD) {
f->res.digits = t1->digits + t2->digits;
@@ -167,9 +167,9 @@
if (f->func->fix_scale == SCALE_FIX) {
ls = fix_scale(sql, t2, ls, 0, 0);
rs = fix_scale(sql, t1, rs, 0, 0);
- } else if (f->func->fix_scale == SCALE_SUB) {
+ } else if (f->func->fix_scale == SCALE_DIV) {
ls = scale_algebra(sql, f, ls, rs);
- } else if (f->func->fix_scale == SCALE_ADD) {
+ } else if (f->func->fix_scale == SCALE_MUL) {
ls = sum_scales(sql, f, ls, rs);
} else if (f->func->fix_scale == DIGITS_ADD) {
f->res.digits = digits;
U rel_select.mx
Index: rel_select.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/rel_select.mx,v
retrieving revision 1.145
retrieving revision 1.146
diff -u -d -r1.145 -r1.146
--- rel_select.mx 1 Jun 2009 13:37:33 -0000 1.145
+++ rel_select.mx 4 Jun 2009 20:27:54 -0000 1.146
@@ -1670,11 +1670,13 @@
f->res.scale = lt->scale + rt->scale;
f->res.digits = lt->digits + rt->digits;
+
/* HACK alert: digits should be less then max */
if (f->res.type->radix == 10 && f->res.digits > 19)
f->res.digits = 19;
if (f->res.type->radix == 2 && f->res.digits > 53)
f->res.digits = 53;
+
/* sum of digits may mean we need a bigger result type
* as the function don't support this we need to
* make bigger input types!
@@ -1707,38 +1709,28 @@
sql_subtype *lt = exp_subtype(l);
sql_subtype *rt = exp_subtype(r);
- /*
- * Decimals are mapped on plain integers. This has impact on the
- * implemantion of division. First the 'dividend' should be large
- * enough to prevent rounding errors. This is solved by a
- * multiplication with the 'scale' of the divisor.
- * Second the result type of the division should be equal to the
- * 'dividend', with the maximum scale of the dividend and divisor.
- *
- * Example 1.0/0.1 mapped (int 1 dec(1,0) and int 1 dec(2,1))
- * 1 * 10 = 10 (scale of divisor)
- * 10/1 = 1 dec(1)
- */
-
if (lt->type->scale == SCALE_FIX && rt->scale &&
strcmp(f->func->imp, "/") == 0) {
- int digits = rt->scale + lt->digits;
+ int scale, digits, digL, scaleL;
sql_subtype nlt;
+ /* scale fixing may require a larger type ! */
+ scaleL = (lt->scale < 3) ? 3 : lt->scale;
+ scale = scaleL;
+ scaleL += rt->scale;
+ digL = lt->digits + (scaleL - lt->scale);
+ digits = (digL > (int)rt->digits) ? digL : (int)rt->digits;
+
/* HACK alert: digits should be less then max */
if (f->res.type->radix == 10 && digits > 19)
digits = 19;
if (f->res.type->radix == 2 && digits > 53)
digits = 53;
- /* scale fixing may require a larger type ! */
- sql_find_subtype(&nlt, lt->type->sqlname, digits,
lt->scale+rt->scale);
- f->res.digits = digits;
- f->res.scale = lt->scale;
-
+ sql_find_subtype(&nlt, lt->type->sqlname, digL, scaleL);
l = rel_check_type( sql, &nlt, l, type_equal );
- sql_find_subtype(&f->res, lt->type->sqlname, f->res.digits,
f->res.scale);
+ sql_find_subtype(&f->res, lt->type->sqlname, digits, scale);
}
return l;
}
@@ -2955,9 +2947,9 @@
if (f->func->fix_scale == SCALE_FIX) {
l = exp_fix_scale(sql, t2, l, 0, 0);
r = exp_fix_scale(sql, t1, r, 0, 0);
- } else if (f->func->fix_scale == SCALE_SUB) {
+ } else if (f->func->fix_scale == SCALE_DIV) {
l = exp_scale_algebra(sql, f, l, r);
- } else if (f->func->fix_scale == SCALE_ADD) {
+ } else if (f->func->fix_scale == SCALE_MUL) {
l = exp_sum_scales(sql, f, l, r);
} else if (f->func->fix_scale == DIGITS_ADD) {
f->res.digits = t1->digits + t2->digits;
@@ -3006,9 +2998,9 @@
if (f->func->fix_scale == SCALE_FIX) {
l = exp_fix_scale(sql, t2, l, 0, 0);
r = exp_fix_scale(sql, t1, r, 0, 0);
- } else if (f->func->fix_scale == SCALE_SUB) {
+ } else if (f->func->fix_scale == SCALE_DIV) {
l = exp_scale_algebra(sql, f, l, r);
- } else if (f->func->fix_scale == SCALE_ADD) {
+ } else if (f->func->fix_scale == SCALE_MUL) {
l = exp_sum_scales(sql, f, l, r);
} else if (f->func->fix_scale == DIGITS_ADD) {
f->res.digits = digits;
@@ -3272,6 +3264,17 @@
if (!e)
return NULL;
a = sql_bind_aggr(sql->session->schema, aggrstr, exp_subtype(e));
+ if (!a) { /* find aggr + convert */
+
+ a = sql_find_aggr(sql->session->schema, aggrstr);
+ if (a) {
+ sql_arg *arg = a->aggr->ops->h->data;
+
+ e = rel_check_type(sql, &arg->type, e, type_equal);
+ if (!e)
+ a = NULL;
+ }
+ }
if (a) {
/* type may have changed, ie. need to fix_scale */
sql_subtype *t = exp_subtype(e);
U rel_optimizer.mx
Index: rel_optimizer.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/rel_optimizer.mx,v
retrieving revision 1.60
retrieving revision 1.61
diff -u -d -r1.60 -r1.61
--- rel_optimizer.mx 14 Apr 2009 14:01:33 -0000 1.60
+++ rel_optimizer.mx 4 Jun 2009 20:27:54 -0000 1.61
@@ -1820,16 +1820,6 @@
sql_subaggr *a = e->f;
if (strcmp(a->aggr->base.name, "avg") == 0) {
- list *exps = e->l;
- sql_exp *ae = exps->h->data;
-
- /*
- FOR NOW ESCAPE ON AVG ON DECIMALS,
- we need a rewrite or DEC's in
- the optimizer to solve this problem
- */
- if (exp_subtype(ae)->type->eclass ==
EC_DEC)
- return rel;
append(avgs, e);
continue;
}
------------------------------------------------------------------------------
OpenSolaris 2009.06 is a cutting edge operating system for enterprises
looking to deploy the next generation of Solaris that includes the latest
innovations from Sun and the OpenSource community. Download a copy and
enjoy capabilities such as Networking, Storage and Virtualization.
Go to: http://p.sf.net/sfu/opensolaris-get
_______________________________________________
Monetdb-sql-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-sql-checkins