Changeset: 524b3deabf60 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=524b3deabf60
Added Files:
        sql/test/BugTracker-2020/Tests/ifthenelse-crash.Bug-6815.sql
        sql/test/BugTracker-2020/Tests/ifthenelse-crash.Bug-6815.stable.err
        sql/test/BugTracker-2020/Tests/ifthenelse-crash.Bug-6815.stable.out
Modified Files:
        gdk/gdk_hash.h
        sql/server/rel_dump.c
        sql/server/rel_optimizer.c
        sql/server/rel_propagate.c
        sql/server/rel_select.c
        sql/server/rel_unnest.c
        sql/test/BugTracker-2020/Tests/All
        sql/test/miscellaneous/Tests/groupby_error.sql
        sql/test/miscellaneous/Tests/groupby_error.stable.out
Branch: default
Log Message:

Merged with linear-hashing


diffs (289 lines):

diff --git a/gdk/gdk_hash.h b/gdk/gdk_hash.h
--- a/gdk/gdk_hash.h
+++ b/gdk/gdk_hash.h
@@ -9,7 +9,7 @@
 #ifndef _GDK_SEARCH_H_
 #define _GDK_SEARCH_H_
 
-typedef struct Hash {
+struct Hash {
        int type;               /* type of index entity */
        uint8_t width;          /* width of hash entries */
        BUN mask1;              /* .mask1 < .nbucket <= .mask2 */
@@ -22,7 +22,7 @@ typedef struct Hash {
        void *Link;             /* collision list, points into .heaplink */
        Heap heaplink;          /* heap where the hash links are stored */
        Heap heapbckt;          /* heap where the hash buckets are stored */
-} Hash;
+};
 
 static inline BUN
 HASHbucket(const Hash *h, BUN v)
diff --git a/sql/server/rel_dump.c b/sql/server/rel_dump.c
--- a/sql/server/rel_dump.c
+++ b/sql/server/rel_dump.c
@@ -118,7 +118,7 @@ exp_print(mvc *sql, stream *fout, sql_ex
                break;
        }
        case e_convert: {
-               char *to_type = sql_subtype_string(&e->tpe);
+               char *to_type = sql_subtype_string(exp_subtype(e));
                mnstr_printf(fout, "%s[", to_type);
                exp_print(sql, fout, e->l, depth, refs, 0, 0);
                mnstr_printf(fout, "]");
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
@@ -5889,10 +5889,21 @@ rel_groupby_distinct(int *changes, mvc *
                for (n=rel->exps->h; n; n = n->next) {
                        sql_exp *e = n->data;
                        if (e != distinct) {
-                               e = exp_ref(sql->sa, e);
-                               append(ngbe, e);
-                               append(exps, e);
-                               e = exp_ref(sql->sa, e);
+                               if (e->type == e_aggr) { /* copy the arguments 
to the aggregate */
+                                       list *args = e->l;
+                                       sql_exp *dargs = args->h->data;
+
+                                       list_append(ngbe, exp_copy(sql, dargs));
+                                       list_append(exps, exp_copy(sql, dargs));
+                               } else {
+                                       e = exp_ref(sql->sa, e);
+                                       append(ngbe, e);
+                                       append(exps, e);
+                               }
+                               if (e->type == e_aggr) /* aggregates must be 
copied */
+                                       e = exp_copy(sql, e);
+                               else
+                                       e = exp_ref(sql->sa, e);
                                append(nexps, e);
                        }
                }
diff --git a/sql/server/rel_propagate.c b/sql/server/rel_propagate.c
--- a/sql/server/rel_propagate.c
+++ b/sql/server/rel_propagate.c
@@ -187,11 +187,11 @@ create_range_partition_anti_rel(sql_quer
                sql_exp *range1, *range2;
                e1 = exp_copy(sql, pmin);
                if (subtype_cmp(exp_subtype(pmin), &tpe) != 0)
-                       e1 = exp_convert(sql->sa, e1, &e1->tpe, &tpe);
+                       e1 = exp_convert(sql->sa, e1, exp_subtype(e1), &tpe);
 
                e2 = exp_copy(sql, pmax);
                if (subtype_cmp(exp_subtype(e2), &tpe) != 0)
-                       e2 = exp_convert(sql->sa, e2, &e2->tpe, &tpe);
+                       e2 = exp_convert(sql->sa, e2, exp_subtype(e2), &tpe);
 
                range1 = exp_compare(sql->sa, exp_copy(sql, anti_le), e1, 3);
                range2 = exp_compare(sql->sa, exp_copy(sql, anti_le), e2, 1);
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,14 +510,15 @@ find_table_function_type(mvc *sql, sql_s
                        for (n = exps->h, m = (*sf)->func->ops->h; n && m; n = 
n->next, m = m->next) {
                                sql_arg *a = m->data;
                                sql_exp *e = n->data;
+                               sql_subtype *t = exp_subtype(e);
 
                                if (!aa && a->type.type->eclass == EC_ANY) {
-                                       atp = &e->tpe;
+                                       atp = t;
                                        aa = a;
                                }
                                if (aa && a->type.type->eclass == EC_ANY &&
-                                   e->tpe.type->localtype > 
atp->type->localtype){
-                                       atp = &e->tpe;
+                                   t->type->localtype > atp->type->localtype){
+                                       atp = t;
                                        aa = a;
                                }
                        }
@@ -1855,14 +1856,15 @@ static sql_exp*
                        for (n = exps->h, m = f->func->ops->h; n && m; n = 
n->next, m = m->next) {
                                sql_arg *a = m->data;
                                sql_exp *e = n->data;
+                               sql_subtype *t = exp_subtype(e);
 
                                if (!aa && a->type.type->eclass == EC_ANY) {
-                                       atp = &e->tpe;
+                                       atp = t;
                                        aa = a;
                                }
                                if (aa && a->type.type->eclass == EC_ANY &&
-                                   e->tpe.type->localtype > 
atp->type->localtype){
-                                       atp = &e->tpe;
+                                   t->type->localtype > atp->type->localtype){
+                                       atp = t;
                                        aa = a;
                                }
                        }
@@ -4165,7 +4167,7 @@ rel_order_by(sql_query *query, sql_rel *
                                e = rel_value_exp2(query, &rel, col, f, ek);
 
                                if (e && e->card <= CARD_ATOM) {
-                                       sql_subtype *tpe = &e->tpe;
+                                       sql_subtype *tpe = exp_subtype(e);
                                        /* integer atom on the stack */
                                        if (e->type == e_atom &&
                                            tpe->type->eclass == EC_NUM) {
@@ -4590,11 +4592,11 @@ rel_rankop(sql_query *query, sql_rel **r
                                        return NULL;
 
                                /* corner case, if the argument is null convert 
it into something countable such as bte */
-                               if (subtype_cmp(&(in->tpe), empty) == 0)
+                               if (subtype_cmp(exp_subtype(in), empty) == 0)
                                        in = exp_convert(sql->sa, in, empty, 
bte);
                                if ((is_lag || is_lead) && nfargs == 2) { /* 
lag and lead 3rd arg must have same type as 1st arg */
                                        sql_exp *first = (sql_exp*) 
fargs->h->data;
-                                       if (!(in = rel_check_type(sql, 
&first->tpe, p, in, type_equal)))
+                                       if (!(in = rel_check_type(sql, 
exp_subtype(first), p, in, type_equal)))
                                                return NULL;
                                }
                                if (!in)
@@ -4615,7 +4617,7 @@ rel_rankop(sql_query *query, sql_rel **r
                                return NULL;
 
                        /* corner case, if the argument is null convert it into 
something countable such as bte */
-                       if (subtype_cmp(&(in->tpe), empty) == 0)
+                       if (subtype_cmp(exp_subtype(in), empty) == 0)
                                in = exp_convert(sql->sa, in, empty, bte);
                        if (!in)
                                return NULL;
diff --git a/sql/server/rel_unnest.c b/sql/server/rel_unnest.c
--- a/sql/server/rel_unnest.c
+++ b/sql/server/rel_unnest.c
@@ -2717,7 +2717,7 @@ rewrite_groupings(mvc *sql, sql_rel *rel
                                                exp_setname(sql->sa, ne, 
e->alias.rname, e->alias.name);
                                        } else if (e->type == e_column && 
!exps_find_exp(l, e) && !has_label(e)) { 
                                                /* do not include in the output 
of the group by, but add to the project as null */
-                                               ne = exp_atom(sql->sa, 
atom_null_value(sql->sa, &(e->tpe)));
+                                               ne = exp_atom(sql->sa, 
atom_null_value(sql->sa, exp_subtype(e)));
                                                exp_setname(sql->sa, ne, 
e->alias.rname, e->alias.name);
                                        } else {
                                                ne = exp_ref(sql->sa, e);
diff --git a/sql/test/BugTracker-2020/Tests/All 
b/sql/test/BugTracker-2020/Tests/All
--- a/sql/test/BugTracker-2020/Tests/All
+++ b/sql/test/BugTracker-2020/Tests/All
@@ -1,1 +1,2 @@
 median_avg-nulls.Bug-6807
+ifthenelse-crash.Bug-6815
diff --git a/sql/test/BugTracker-2020/Tests/ifthenelse-crash.Bug-6815.sql 
b/sql/test/BugTracker-2020/Tests/ifthenelse-crash.Bug-6815.sql
new file mode 100644
--- /dev/null
+++ b/sql/test/BugTracker-2020/Tests/ifthenelse-crash.Bug-6815.sql
@@ -0,0 +1,4 @@
+start transaction;
+create table t6815 (type_digits int);
+select ifthenelse((type_digits > 0), '('||type_digits||')', '') as opt_len 
from t6815;
+rollback;
diff --git 
a/sql/test/BugTracker-2020/Tests/ifthenelse-crash.Bug-6815.stable.err 
b/sql/test/BugTracker-2020/Tests/ifthenelse-crash.Bug-6815.stable.err
new file mode 100644
--- /dev/null
+++ b/sql/test/BugTracker-2020/Tests/ifthenelse-crash.Bug-6815.stable.err
@@ -0,0 +1,30 @@
+stderr of test 'ifthenelse-crash.Bug-6815` in directory 
'sql/test/BugTracker-2020` itself:
+
+
+# 15:58:03 >  
+# 15:58:03 >  "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set" 
"mapi_open=true" "--set" "mapi_port=36500" "--set" 
"mapi_usock=/var/tmp/mtest-377911/.s.monetdb.36500" "--forcemito" 
"--dbpath=/home/ferreira/repositories/MonetDB-Nov2019/BUILD/var/MonetDB/mTests_sql_test_BugTracker-2020"
 "--set" "embedded_c=true"
+# 15:58:03 >  
+
+# builtin opt  gdk_dbpath = 
/home/ferreira/repositories/MonetDB-Nov2019/BUILD/var/monetdb5/dbfarm/demo
+# builtin opt  mapi_port = 50000
+# builtin opt  mapi_open = false
+# builtin opt  mapi_ipv6 = 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 = 36500
+# cmdline opt  mapi_usock = /var/tmp/mtest-377911/.s.monetdb.36500
+# cmdline opt  gdk_dbpath = 
/home/ferreira/repositories/MonetDB-Nov2019/BUILD/var/MonetDB/mTests_sql_test_BugTracker-2020
+# cmdline opt  embedded_c = true
+
+# 15:58:03 >  
+# 15:58:03 >  "mclient" "-lsql" "-ftest" "-tnone" "-Eutf-8" "-i" "-e" 
"--host=/var/tmp/mtest-377911" "--port=36500"
+# 15:58:03 >  
+
+
+# 15:58:04 >  
+# 15:58:04 >  "Done."
+# 15:58:04 >  
+
diff --git 
a/sql/test/BugTracker-2020/Tests/ifthenelse-crash.Bug-6815.stable.out 
b/sql/test/BugTracker-2020/Tests/ifthenelse-crash.Bug-6815.stable.out
new file mode 100644
--- /dev/null
+++ b/sql/test/BugTracker-2020/Tests/ifthenelse-crash.Bug-6815.stable.out
@@ -0,0 +1,37 @@
+stdout of test 'ifthenelse-crash.Bug-6815` in directory 
'sql/test/BugTracker-2020` itself:
+
+
+# 15:58:03 >  
+# 15:58:03 >  "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set" 
"mapi_open=true" "--set" "mapi_port=36500" "--set" 
"mapi_usock=/var/tmp/mtest-377911/.s.monetdb.36500" "--forcemito" 
"--dbpath=/home/ferreira/repositories/MonetDB-Nov2019/BUILD/var/MonetDB/mTests_sql_test_BugTracker-2020"
 "--set" "embedded_c=true"
+# 15:58:03 >  
+
+# MonetDB 5 server v11.35.6 (hg id: 4c25f517a2d8)
+# This is an unreleased version
+# Serving database 'mTests_sql_test_BugTracker-2020', using 8 threads
+# Compiled for x86_64-pc-linux-gnu/64bit with 128bit integers
+# Found 15.496 GiB available main-memory of which we use 12.630 GiB
+# Copyright (c) 1993 - July 2008 CWI.
+# Copyright (c) August 2008 - 2020 MonetDB B.V., all rights reserved
+# Visit https://www.monetdb.org/ for further information
+# Listening for connection requests on 
mapi:monetdb://localhost.localdomain:36500/
+# Listening for UNIX domain connection requests on 
mapi:monetdb:///var/tmp/mtest-377911/.s.monetdb.36500
+# MonetDB/GIS module loaded
+# MonetDB/SQL module loaded
+
+# 15:58:03 >  
+# 15:58:03 >  "mclient" "-lsql" "-ftest" "-tnone" "-Eutf-8" "-i" "-e" 
"--host=/var/tmp/mtest-377911" "--port=36500"
+# 15:58:03 >  
+
+#start transaction;
+#create table t6815 (type_digits int);
+#select ifthenelse((type_digits > 0), '('||type_digits||')', '') as opt_len 
from t6815;
+% sys. # table_name
+% opt_len # name
+% varchar # type
+% 0 # length
+#rollback;
+
+# 15:58:04 >  
+# 15:58:04 >  "Done."
+# 15:58:04 >  
+
diff --git a/sql/test/miscellaneous/Tests/groupby_error.sql 
b/sql/test/miscellaneous/Tests/groupby_error.sql
--- a/sql/test/miscellaneous/Tests/groupby_error.sql
+++ b/sql/test/miscellaneous/Tests/groupby_error.sql
@@ -5,3 +5,9 @@ INSERT INTO "kagami_dump".test_task(sys_
 SELECT parent."sys_id" FROM "kagami_dump"."test_task" parent INNER JOIN 
"kagami_dump"."test_task" child ON child."parent" = parent."sys_id" GROUP BY 
parent."sys_id" HAVING count(child."sys_id") >= 1 ORDER BY parent."number"; 
--error, parent."number" requires an aggregate function
 
 DROP SCHEMA "kagami_dump" CASCADE;
+
+START TRANSACTION;
+CREATE TABLE tab0(col0 INTEGER, col1 INTEGER, col2 INTEGER);
+INSERT INTO tab0 VALUES(97,1,99), (15,81,47), (87,21,10);
+SELECT CAST(+ col1 * - col1 AS BIGINT) AS col2 FROM tab0 GROUP BY col2, col0, 
col1 HAVING + - col0 / - AVG ( ALL + col2 ) - - - AVG ( DISTINCT + col0 ) + 
col0 IS NULL;
+ROLLBACK;
diff --git a/sql/test/miscellaneous/Tests/groupby_error.stable.out 
b/sql/test/miscellaneous/Tests/groupby_error.stable.out
--- a/sql/test/miscellaneous/Tests/groupby_error.stable.out
+++ b/sql/test/miscellaneous/Tests/groupby_error.stable.out
@@ -67,6 +67,16 @@ stdout of test 'groupby_error` in direct
 #INSERT INTO "kagami_dump".test_task(sys_id, number, parent) VALUES ('aaa', 
'T0001', null),('bbb','T0002','aaa');
 [ 2    ]
 #DROP SCHEMA "kagami_dump" CASCADE;
+#START TRANSACTION;
+#CREATE TABLE tab0(col0 INTEGER, col1 INTEGER, col2 INTEGER);
+#INSERT INTO tab0 VALUES(97,1,99), (15,81,47), (87,21,10);
+[ 3    ]
+#SELECT CAST(+ col1 * - col1 AS BIGINT) AS col2 FROM tab0 GROUP BY col2, col0, 
col1 HAVING + - col0 / - AVG ( ALL + col2 ) - - - AVG ( DISTINCT + col0 ) + 
col0 IS NULL;
+% sys. # table_name
+% col2 # name
+% bigint # type
+% 1 # length
+#ROLLBACK;
 
 # 10:56:47 >  
 # 10:56:47 >  "Done."
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to