Changeset: 2b808c456eb8 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/2b808c456eb8
Modified Files:
        sql/server/rel_exp.c
        sql/server/rel_select.c
        sql/server/sql_semantic.c
Branch: cleanup_types
Log Message:

make sure we use the correct scale on division of decimals


diffs (116 lines):

diff --git a/sql/server/rel_exp.c b/sql/server/rel_exp.c
--- a/sql/server/rel_exp.c
+++ b/sql/server/rel_exp.c
@@ -2920,6 +2920,7 @@ exp_scale_algebra(mvc *sql, sql_subfunc 
                /* scale fixing may require a larger type ! */
                /* TODO make '3' setable by user (division_minimal_scale or so) 
*/
                scaleL = (lt->scale < 3) ? 3 : lt->scale;
+               scaleL += (scaleL < rt->scale)?(rt->scale - scaleL):0;
                scale = scaleL;
                scaleL += rt->scale;
                digL = lt->digits + (scaleL - lt->scale);
diff --git a/sql/server/rel_select.c b/sql/server/rel_select.c
--- a/sql/server/rel_select.c
+++ b/sql/server/rel_select.c
@@ -510,21 +510,22 @@ check_arguments_and_find_largest_any_typ
                        if (a->type.type->eclass == EC_ANY && atp)
                                ntp = sql_create_subtype(sql->sa, atp->type, 
atp->digits, atp->scale);
                        rel_set_type_param(sql, ntp, rel, e, 
sf->func->fix_scale != INOUT && !UDF_LANG(sf->func->lang));
-               } else if (a->type.type->eclass == EC_ANY && atp)
+               } else if (a->type.type->eclass == EC_ANY && atp) {
                        ntp = sql_create_subtype(sql->sa, atp->type, 
atp->digits, atp->scale);
-               else if (t && ntp->digits == 0 && 
EC_VARCHAR(a->type.type->eclass))
+               } else if (t && ntp->digits == 0 && 
EC_VARCHAR(a->type.type->eclass)) {
                        ntp = sql_create_subtype(sql->sa, a->type.type, 
type_digits_to_char_digits(t), 0);
-               else if (t && ntp->digits > 0 && a->type.type->eclass == EC_NUM 
&& t->type->eclass == EC_NUM)
+               } else if (t && ntp->digits > 0 && a->type.type->eclass == 
EC_NUM && t->type->eclass == EC_NUM) {
                        ntp = sql_create_subtype(sql->sa, a->type.type, 
t->digits, 0);
-               else if (t && ntp->scale == 0 && ntp->type->eclass == EC_DEC && 
EC_VARCHAR(t->type->eclass)) {
+               } else if (t && ntp->scale == 0 && ntp->type->eclass == EC_DEC 
&& EC_VARCHAR(t->type->eclass)) {
                        sql_subtype *res = SA_NEW(sql->sa, sql_subtype);
                        int digits = t->digits?t->digits+3:ntp->digits;
                        (void)sql_find_subtype(res, a->type.type->base.name, 
digits, 3);
                        ntp = res;
-               } else if (t && ntp->scale == 0 && ntp->type->eclass == EC_DEC)
+               } else if (t && ntp->scale == 0 && ntp->type->eclass == EC_DEC) 
{
                        ntp = sql_create_subtype(sql->sa, a->type.type, 
t->type->eclass == EC_NUM?bits2digits(t->digits):t->digits, t->scale);
-               else if (sf->func->fix_scale != SCALE_EQ && t->type == 
ntp->type)
+               } else if (sf->func->fix_scale != SCALE_EQ && t->type == 
ntp->type) {
                        ntp = t;
+               }
                if (!(e = exp_check_type(sql, ntp, rel, e, type_equal)))
                        return NULL;
                if (sf->func->fix_scale == SCALE_FIX) {
diff --git a/sql/server/sql_semantic.c b/sql/server/sql_semantic.c
--- a/sql/server/sql_semantic.c
+++ b/sql/server/sql_semantic.c
@@ -718,21 +718,41 @@ sql_bind_func_result_internal(mvc *sql, 
        int points = 0, npoints = 0;
 
        if (ff) {
-               node *n;
-               sql_base_loop( ff, n) {
-                       sql_func *f = n->data;
-                       sql_arg *firstres = NULL;
+               if (ff->ht) {
+                       int key = hash_key(fname);
+                       sql_hash_e *he = ff->ht->buckets[key&(ff->ht->size-1)];
+                       for (; he; he = he->chain) {
+                               sql_func *f = he->value;
+                               sql_arg *firstres = NULL;
+
+                               if ((!f->res && !IS_FILT(f)) || (f->private && 
!private))
+                                       continue;
+                               firstres = IS_FILT(f)?tp->type:f->res->h->data;
+                               if (strcmp(f->base.name, fname) == 0 && f->type 
== type && (is_subtype(&firstres->type, res) || firstres->type.type->eclass == 
EC_ANY) && list_cmp(f->ops, ops, (fcmp) &arg_subtype_cmp) == 0) {
+                                       npoints = next_cand_points(f->ops, ops);
 
-                       if ((!f->res && !IS_FILT(f)) || (f->private && 
!private))
-                               continue;
-                       firstres = IS_FILT(f)?tp->type:f->res->h->data;
-                       if (strcmp(f->base.name, fname) == 0 && f->type == type 
&& (is_subtype(&firstres->type, res) || firstres->type.type->eclass == EC_ANY) 
&& list_cmp(f->ops, ops, (fcmp) &arg_subtype_cmp) == 0) {
-                               if (!cand) {
-                                       cand = f;
-                                       points = next_cand_points(f->ops, ops);
-                               } else if ((npoints = next_cand_points(f->ops, 
ops)) > points) {
-                                       cand = f;
-                                       points = npoints;
+                                       if (!cand || npoints > points) {
+                                               cand = f;
+                                               points = npoints;
+                                       }
+                               }
+                       }
+               } else {
+                       node *n;
+                       sql_base_loop( ff, n) {
+                               sql_func *f = n->data;
+                               sql_arg *firstres = NULL;
+
+                               if ((!f->res && !IS_FILT(f)) || (f->private && 
!private))
+                                       continue;
+                               firstres = IS_FILT(f)?tp->type:f->res->h->data;
+                               if (strcmp(f->base.name, fname) == 0 && f->type 
== type && (is_subtype(&firstres->type, res) || firstres->type.type->eclass == 
EC_ANY) && list_cmp(f->ops, ops, (fcmp) &arg_subtype_cmp) == 0) {
+                                       npoints = next_cand_points(f->ops, ops);
+
+                                       if (!cand || npoints > points) {
+                                               cand = f;
+                                               points = npoints;
+                                       }
                                }
                        }
                }
@@ -760,10 +780,9 @@ os_bind_func_result_internal(mvc *sql, s
                                continue;
                        firstres = IS_FILT(f)?tp->type:f->res->h->data;
                        if (strcmp(f->base.name, fname) == 0 && f->type == type 
&& (is_subtype(&firstres->type, res) || firstres->type.type->eclass == EC_ANY) 
&& list_cmp(f->ops, ops, (fcmp) &arg_subtype_cmp) == 0) {
-                               if (!cand) {
-                                       cand = f;
-                                       points = next_cand_points(f->ops, ops);
-                               } else if ((npoints = next_cand_points(f->ops, 
ops)) > points) {
+                               npoints = next_cand_points(f->ops, ops);
+
+                               if (!cand || npoints > points) {
                                        cand = f;
                                        points = npoints;
                                }
_______________________________________________
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org

Reply via email to