Changeset: 5fd6413b6476 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/5fd6413b6476
Modified Files:
        sql/server/rel_optimizer.c
        sql/test/SQLancer/Tests/sqlancer19.SQL.py
Branch: Jul2021
Log Message:

Update atom's scale after reducing it


diffs (83 lines):

diff --git a/sql/server/rel_optimizer.c b/sql/server/rel_optimizer.c
--- a/sql/server/rel_optimizer.c
+++ b/sql/server/rel_optimizer.c
@@ -8272,10 +8272,11 @@ exp_merge_range(visitor *v, sql_rel *rel
 static int
 reduce_scale(atom *a)
 {
+       int i = 0;
+
 #ifdef HAVE_HGE
        if (a->data.vtype == TYPE_hge) {
                hge v = a->data.val.hval;
-               int i = 0;
 
                if (v != 0)
                        while( (v/10)*10 == v ) {
@@ -8283,12 +8284,10 @@ reduce_scale(atom *a)
                                v /= 10;
                        }
                a->data.val.hval = v;
-               return i;
-       }
+       } else
 #endif
        if (a->data.vtype == TYPE_lng) {
                lng v = a->data.val.lval;
-               int i = 0;
 
                if (v != 0)
                        while( (v/10)*10 == v ) {
@@ -8296,11 +8295,8 @@ reduce_scale(atom *a)
                                v /= 10;
                        }
                a->data.val.lval = v;
-               return i;
-       }
-       if (a->data.vtype == TYPE_int) {
+       } else if (a->data.vtype == TYPE_int) {
                int v = a->data.val.ival;
-               int i = 0;
 
                if (v != 0)
                        while( (v/10)*10 == v ) {
@@ -8308,11 +8304,8 @@ reduce_scale(atom *a)
                                v /= 10;
                        }
                a->data.val.ival = v;
-               return i;
-       }
-       if (a->data.vtype == TYPE_sht) {
+       } else if (a->data.vtype == TYPE_sht) {
                sht v = a->data.val.shval;
-               int i = 0;
 
                if (v != 0)
                        while( (v/10)*10 == v ) {
@@ -8320,9 +8313,9 @@ reduce_scale(atom *a)
                                v /= 10;
                        }
                a->data.val.shval = v;
-               return i;
-       }
-       return 0;
+       }
+       a->tpe.scale -= i;
+       return i;
 }
 
 static sql_rel *
diff --git a/sql/test/SQLancer/Tests/sqlancer19.SQL.py 
b/sql/test/SQLancer/Tests/sqlancer19.SQL.py
--- a/sql/test/SQLancer/Tests/sqlancer19.SQL.py
+++ b/sql/test/SQLancer/Tests/sqlancer19.SQL.py
@@ -88,6 +88,10 @@ with SQLTestCase() as cli:
         .assertSucceeded().assertDataResultMatch([(Decimal('3.571'),)])
     cli.execute("SELECT 3 / 0.84 FROM rt3 where rt3.c0 = 1;") \
         .assertSucceeded().assertDataResultMatch([(Decimal('3.571'),)])
+    cli.execute("SELECT CAST(2 AS DECIMAL) * 0.010 FROM t3 where t3.c0 = 1;") \
+        .assertSucceeded().assertDataResultMatch([(Decimal('0.02000'),)])
+    cli.execute("SELECT CAST(2 AS DECIMAL) * 0.010 FROM rt3 where rt3.c0 = 
1;") \
+        .assertSucceeded().assertDataResultMatch([(Decimal('0.02000'),)])
     cli.execute("SELECT t3.c0 FROM t3 INNER JOIN t3 myx ON t3.c0 = myx.c0 
ORDER BY t3.c0;") \
         
.assertSucceeded().assertDataResultMatch([(1,),(2,),(2,),(2,),(2,),(5,),(5,),(5,),(5,),(7,)])
     cli.execute("SELECT rt3.c0 FROM rt3 INNER JOIN rt3 myx ON rt3.c0 = myx.c0 
ORDER BY rt3.c0;") \
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to