Changeset: ad3e7db083e1 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=ad3e7db083e1 Added Files: sql/test/BugTracker-2018/Tests/sqlitelogictest-undefined-calc.Bug-6570.stable.err sql/test/BugTracker-2018/Tests/sqlitelogictest-undefined-calc.Bug-6570.stable.out Modified Files: sql/server/rel_exp.c sql/server/rel_exp.h sql/server/rel_optimizer.c sql/server/rel_select.c sql/test/bugs/Tests/create_insert_select_aggr-bug-00001.stable.out sql/test/mergetables/Tests/part-elim.stable.out Branch: Mar2018 Log Message:
fixes for bug 6570, ie properly lookup the sql_mul function (and return type) after rewriting math expressions diffs (284 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 @@ -1977,3 +1977,43 @@ exp_flatten(mvc *sql, sql_exp *e) return NULL; } +void +exp_sum_scales(sql_subfunc *f, sql_exp *l, sql_exp *r) +{ + sql_arg *ares = f->func->res->h->data; + + if (strcmp(f->func->imp, "*") == 0 && ares->type.type->scale == SCALE_FIX) { + sql_subtype t; + sql_subtype *lt = exp_subtype(l); + sql_subtype *rt = exp_subtype(r); + sql_subtype *res = f->res->h->data; + + res->scale = lt->scale + rt->scale; + res->digits = lt->digits + rt->digits; + + /* HACK alert: digits should be less than max */ +#ifdef HAVE_HGE + if (have_hge) { + if (ares->type.type->radix == 10 && res->digits > 39) + res->digits = 39; + if (ares->type.type->radix == 2 && res->digits > 128) + res->digits = 128; + } else +#endif + { + + if (ares->type.type->radix == 10 && res->digits > 19) + res->digits = 19; + if (ares->type.type->radix == 2 && res->digits > 64) + res->digits = 64; + } + + /* numeric types are fixed length */ + if (ares->type.type->eclass == EC_NUM) { + sql_find_numeric(&t, ares->type.type->localtype, res->digits); + } else { + sql_find_subtype(&t, ares->type.type->sqlname, res->digits, res->scale); + } + *res = t; + } +} diff --git a/sql/server/rel_exp.h b/sql/server/rel_exp.h --- a/sql/server/rel_exp.h +++ b/sql/server/rel_exp.h @@ -150,4 +150,6 @@ extern int is_identity( sql_exp *e, sql_ extern atom *exp_flatten(mvc *sql, sql_exp *e); +extern void exp_sum_scales(sql_subfunc *f, sql_exp *l, sql_exp *r); + #endif /* _REL_EXP_H_ */ 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 @@ -2874,10 +2874,11 @@ exp_simplify_math( mvc *sql, sql_exp *e, } } /* move constants to the right, ie c*A = A*c */ - /* TODO beware of overflow, */ else if (exp_is_atom(le)) { l->h->data = re; l->h->next->data = le; + e->f = sql_bind_func(sql->sa, NULL, "sql_mul", exp_subtype(re), exp_subtype(le), F_FUNC); + exp_sum_scales(e->f, re, le); (*changes)++; return e; } @@ -2925,9 +2926,13 @@ exp_simplify_math( mvc *sql, sql_exp *e, append(l, lre); append(l, re); le->l = l; + le->f = sql_bind_func(sql->sa, NULL, "sql_mul", exp_subtype(lre), exp_subtype(re), F_FUNC); + exp_sum_scales(le->f, lre, re); l = e->l; l->h->data = lle; l->h->next->data = le; + e->f = sql_bind_func(sql->sa, NULL, "sql_mul", exp_subtype(lle), exp_subtype(le), F_FUNC); + exp_sum_scales(e->f, lle, le); (*changes)++; return e; } 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 @@ -1341,63 +1341,6 @@ rel_check_type(mvc *sql, sql_subtype *t, } static sql_exp * -exp_sum_scales(mvc *sql, sql_subfunc *f, sql_exp *l, sql_exp *r) -{ - sql_arg *ares = f->func->res->h->data; - - if (strcmp(f->func->imp, "*") == 0 && ares->type.type->scale == SCALE_FIX) { - sql_subtype t; - sql_subtype *lt = exp_subtype(l); - sql_subtype *rt = exp_subtype(r); - sql_subtype *res = f->res->h->data; - - res->scale = lt->scale + rt->scale; - res->digits = lt->digits + rt->digits; - - /* HACK alert: digits should be less than max */ -#ifdef HAVE_HGE - if (have_hge) { - if (ares->type.type->radix == 10 && res->digits > 39) - res->digits = 39; - if (ares->type.type->radix == 2 && res->digits > 128) - res->digits = 128; - } else -#endif - { - - if (ares->type.type->radix == 10 && res->digits > 19) - res->digits = 19; - if (ares->type.type->radix == 2 && res->digits > 64) - res->digits = 64; - } - - /* 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! - */ - - /* numeric types are fixed length */ - if (ares->type.type->eclass == EC_NUM) { - sql_find_numeric(&t, ares->type.type->localtype, res->digits); - } else { - sql_find_subtype(&t, ares->type.type->sqlname, res->digits, res->scale); - } - if (type_cmp(t.type, ares->type.type) != 0) { - /* do we need to convert to the a larger localtype - int * int may not fit in an int, so we need to - convert to lng * int. - */ - sql_subtype nlt; - - sql_init_subtype(&nlt, t.type, res->digits, lt->scale); - l = rel_check_type( sql, &nlt, l, type_equal ); - } - *res = t; - } - return l; -} - -static sql_exp * exp_scale_algebra(mvc *sql, sql_subfunc *f, sql_exp *l, sql_exp *r) { sql_subtype *lt = exp_subtype(l); @@ -3276,7 +3219,7 @@ rel_binop_(mvc *sql, sql_exp *l, sql_exp } else if (f->func->fix_scale == SCALE_DIV) { l = exp_scale_algebra(sql, f, l, r); } else if (f->func->fix_scale == SCALE_MUL) { - l = exp_sum_scales(sql, f, l, r); + exp_sum_scales(f, l, r); } else if (f->func->fix_scale == DIGITS_ADD) { sql_subtype *res = f->res->h->data; res->digits = (t1->digits && t2->digits)?t1->digits + t2->digits:0; @@ -3370,7 +3313,7 @@ rel_binop_(mvc *sql, sql_exp *l, sql_exp } else if (f->func->fix_scale == SCALE_DIV) { l = exp_scale_algebra(sql, f, l, r); } else if (f->func->fix_scale == SCALE_MUL) { - l = exp_sum_scales(sql, f, l, r); + exp_sum_scales(f, l, r); } else if (f->func->fix_scale == DIGITS_ADD) { sql_subtype *res = f->res->h->data; res->digits = (t1->digits && t2->digits)?t1->digits + t2->digits:0; diff --git a/sql/test/BugTracker-2018/Tests/sqlitelogictest-undefined-calc.Bug-6570.stable.err b/sql/test/BugTracker-2018/Tests/sqlitelogictest-undefined-calc.Bug-6570.stable.err new file mode 100644 --- /dev/null +++ b/sql/test/BugTracker-2018/Tests/sqlitelogictest-undefined-calc.Bug-6570.stable.err @@ -0,0 +1,35 @@ +stderr of test 'sqlitelogictest-undefined-calc.Bug-6570` in directory 'sql/test/BugTracker-2018` itself: + + +# 12:55:14 > +# 12:55:14 > "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set" "mapi_open=true" "--set" "mapi_port=38816" "--set" "mapi_usock=/var/tmp/mtest-3299/.s.monetdb.38816" "--set" "monet_prompt=" "--forcemito" "--dbpath=/home/niels/scratch/rc-old/Linux-x86_64/var/MonetDB/mTests_sql_test_BugTracker-2018" "--set" "embedded_c=true" +# 12:55:14 > + +# builtin opt gdk_dbpath = /home/niels/scratch/rc-old/Linux-x86_64/var/monetdb5/dbfarm/demo +# builtin opt gdk_debug = 0 +# builtin opt gdk_vmtrim = no +# builtin opt monet_prompt = > +# builtin opt monet_daemon = no +# builtin opt mapi_port = 50000 +# builtin opt mapi_open = false +# builtin opt mapi_autosense = false +# builtin opt sql_optimizer = default_pipe +# builtin opt sql_debug = 0 +# cmdline opt gdk_nr_threads = 0 +# cmdline opt mapi_open = true +# cmdline opt mapi_port = 38816 +# cmdline opt mapi_usock = /var/tmp/mtest-3299/.s.monetdb.38816 +# cmdline opt monet_prompt = +# cmdline opt gdk_dbpath = /home/niels/scratch/rc-old/Linux-x86_64/var/MonetDB/mTests_sql_test_BugTracker-2018 +# cmdline opt embedded_c = true +# cmdline opt gdk_debug = 553648138 + +# 12:55:14 > +# 12:55:14 > "mclient" "-lsql" "-ftest" "-tnone" "-Eutf-8" "-i" "-e" "--host=/var/tmp/mtest-3299" "--port=38816" +# 12:55:14 > + + +# 12:55:14 > +# 12:55:14 > "Done." +# 12:55:14 > + diff --git a/sql/test/BugTracker-2018/Tests/sqlitelogictest-undefined-calc.Bug-6570.stable.out b/sql/test/BugTracker-2018/Tests/sqlitelogictest-undefined-calc.Bug-6570.stable.out new file mode 100644 --- /dev/null +++ b/sql/test/BugTracker-2018/Tests/sqlitelogictest-undefined-calc.Bug-6570.stable.out @@ -0,0 +1,37 @@ +stdout of test 'sqlitelogictest-undefined-calc.Bug-6570` in directory 'sql/test/BugTracker-2018` itself: + + +# 12:55:14 > +# 12:55:14 > "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set" "mapi_open=true" "--set" "mapi_port=38816" "--set" "mapi_usock=/var/tmp/mtest-3299/.s.monetdb.38816" "--set" "monet_prompt=" "--forcemito" "--dbpath=/home/niels/scratch/rc-old/Linux-x86_64/var/MonetDB/mTests_sql_test_BugTracker-2018" "--set" "embedded_c=true" +# 12:55:14 > + +# MonetDB 5 server v11.29.2 +# This is an unreleased version +# Serving database 'mTests_sql_test_BugTracker-2018', using 8 threads +# Compiled for x86_64-unknown-linux-gnu/64bit +# Found 15.387 GiB available main-memory. +# Copyright (c) 1993 - July 2008 CWI. +# Copyright (c) August 2008 - 2018 MonetDB B.V., all rights reserved +# Visit https://www.monetdb.org/ for further information +# Listening for connection requests on mapi:monetdb://xps13:38816/ +# Listening for UNIX domain connection requests on mapi:monetdb:///var/tmp/mtest-3299/.s.monetdb.38816 +# MonetDB/GIS module loaded +# MonetDB/SQL module loaded + +Ready. + +# 12:55:14 > +# 12:55:14 > "mclient" "-lsql" "-ftest" "-tnone" "-Eutf-8" "-i" "-e" "--host=/var/tmp/mtest-3299" "--port=38816" +# 12:55:14 > + +#SELECT ALL 37 * + COALESCE ( - 65, 81 ) * - 36 / + - 36 AS col1; +% .L2 # table_name +% col1 # name +% int # type +% 5 # length +[ -2405 ] + +# 12:55:14 > +# 12:55:14 > "Done." +# 12:55:14 > + diff --git a/sql/test/bugs/Tests/create_insert_select_aggr-bug-00001.stable.out b/sql/test/bugs/Tests/create_insert_select_aggr-bug-00001.stable.out --- a/sql/test/bugs/Tests/create_insert_select_aggr-bug-00001.stable.out +++ b/sql/test/bugs/Tests/create_insert_select_aggr-bug-00001.stable.out @@ -73,7 +73,7 @@ Ready. #select (4-1)*5; % .L2 # table_name % L2 # name -% smallint # type +% tinyint # type % 2 # length [ 15 ] % sys._tables, sys._tables, sys._tables, sys._tables, sys._tables # table_name diff --git a/sql/test/mergetables/Tests/part-elim.stable.out b/sql/test/mergetables/Tests/part-elim.stable.out --- a/sql/test/mergetables/Tests/part-elim.stable.out +++ b/sql/test/mergetables/Tests/part-elim.stable.out @@ -137,12 +137,12 @@ union ( | project ( | | select ( | | | table(sys.mt1) [ "mt1"."id" as "test"."id", "mt1"."posx" as "test"."posx" ] COUNT -| | ) [ bigint "1" <= "test"."id" <= bigint[sys.sql_mul(smallint "100", tinyint "10")] ] +| | ) [ bigint "1" <= "test"."id" <= bigint[sys.sql_mul(tinyint "100", tinyint "10")] ] | ) [ "test"."id", "test"."posx" ], | project ( | | select ( | | | table(sys.mt2) [ "mt2"."id" as "test"."id", "mt2"."posx" as "test"."posx" ] COUNT -| | ) [ bigint "1" <= "test"."id" <= bigint[sys.sql_mul(smallint "100", tinyint "10")] ] +| | ) [ bigint "1" <= "test"."id" <= bigint[sys.sql_mul(tinyint "100", tinyint "10")] ] | ) [ "test"."id", "test"."posx" ] ) [ "test"."id", "test"."posx" ] #plan select * from test where id in (1, 1022); _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list