MonetDB: default - Merged with Oct2020

2021-04-29 Thread Pedro Ferreira
Changeset: cc547f6accc7 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/cc547f6accc7
Modified Files:
gdk/gdk_atoms.c
monetdb5/modules/atoms/uuid.c
Branch: default
Log Message:

Merged with Oct2020

___
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list


MonetDB: default - Merged with Oct2020

2021-04-28 Thread Pedro Ferreira
Changeset: 2e1268f95684 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/2e1268f95684
Modified Files:
monetdb5/modules/atoms/json.c
Branch: default
Log Message:

Merged with Oct2020


diffs (13 lines):

diff --git a/monetdb5/modules/atoms/json.c b/monetdb5/modules/atoms/json.c
--- a/monetdb5/modules/atoms/json.c
+++ b/monetdb5/modules/atoms/json.c
@@ -186,7 +186,8 @@ JSONtoString(str *s, size_t *len, const 
}
if (external) {
assert(*len >= strlen("nil") + 1);
-   return (ssize_t) strcpy(*s, "nil");
+   strcpy(*s, "nil");
+   return 3;
}
assert(*len >= strlen(str_nil) + 1);
strcpy(*s, str_nil);
___
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list


MonetDB: default - merged with oct2020

2021-04-28 Thread Niels Nes
Changeset: dc3c550a6acf for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/dc3c550a6acf
Modified Files:
common/stream/Tests/urlstream.py
common/utils/mstring.h
gdk/gdk_project.c
Branch: default
Log Message:

merged with oct2020


diffs (12 lines):

diff --git a/common/stream/Tests/urlstream.py b/common/stream/Tests/urlstream.py
--- a/common/stream/Tests/urlstream.py
+++ b/common/stream/Tests/urlstream.py
@@ -94,7 +94,7 @@ def run_tests():
 
 (code, out, err) = streamcat('/xyzzy')
 assert code != 0
-assert b'hollow voice' in err
+assert b'404' in err
 
 try:
 run_tests()
___
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list


MonetDB: default - Merged with Oct2020

2021-04-28 Thread Pedro Ferreira
Changeset: caa84a73805b for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/caa84a73805b
Modified Files:
gdk/gdk_atoms.c
monetdb5/modules/atoms/json.c
monetdb5/modules/atoms/uuid.c
monetdb5/modules/mal/mal_mapi.c
Branch: default
Log Message:

Merged with Oct2020


diffs (57 lines):

diff --git a/gdk/gdk_atoms.c b/gdk/gdk_atoms.c
--- a/gdk/gdk_atoms.c
+++ b/gdk/gdk_atoms.c
@@ -955,8 +955,10 @@ hgeToStr(char **dst, size_t *len, const 
atommem(hgeStrlen);
if (is_hge_nil(*src)) {
if (external) {
-   return (ssize_t) strcpy_len(*dst, "nil", 4);
+   assert(*len >= strlen("nil") + 1);
+   return (ssize_t) strcpy(*dst, "nil");
}
+   assert(*len >= strlen(str_nil) + 1);
strcpy(*dst, str_nil);
return 1;
}
@@ -1360,9 +1362,11 @@ UUIDtoString(str *retval, size_t *len, c
}
if (is_uuid_nil(*value)) {
if (external) {
-   return (ssize_t) strcpy_len(*retval, "nil", 4);
-   }
-   return (ssize_t) strcpy_len(*retval, str_nil, 2);
+   assert(*len >= strlen("nil") + 1);
+   return (ssize_t) strcpy(*retval, "nil");
+   }
+   assert(*len >= strlen(str_nil) + 1);
+   return (ssize_t) strcpy(*retval, str_nil);
}
 #ifdef HAVE_UUID
uuid_unparse_lower(value->u, *retval);
diff --git a/monetdb5/modules/atoms/json.c b/monetdb5/modules/atoms/json.c
--- a/monetdb5/modules/atoms/json.c
+++ b/monetdb5/modules/atoms/json.c
@@ -185,8 +185,10 @@ JSONtoString(str *s, size_t *len, const 
return -1;
}
if (external) {
-   return (ssize_t) strcpy_len(*s, "nil", 4);
+   assert(*len >= strlen("nil") + 1);
+   return (ssize_t) strcpy(*s, "nil");
}
+   assert(*len >= strlen(str_nil) + 1);
strcpy(*s, str_nil);
return 1;
}
diff --git a/monetdb5/modules/mal/mal_mapi.c b/monetdb5/modules/mal/mal_mapi.c
--- a/monetdb5/modules/mal/mal_mapi.c
+++ b/monetdb5/modules/mal/mal_mapi.c
@@ -640,7 +640,7 @@ SERVERlisten(int port, const char *usock
 
const char *listenaddr = port < 0 ? "none" : 
GDKgetenv("mapi_listenaddr");
 
-   if (strNil(usockfile)) {
+   if (strNil(usockfile) || *usockfile == '\0') {
usockfile = NULL;
 #ifndef HAVE_SYS_UN_H
} else {
___
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list


MonetDB: default - merged with oct2020

2021-04-23 Thread Niels Nes
Changeset: 215e3cc4ff9d for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/215e3cc4ff9d
Modified Files:
tools/monetdbe/monetdbe.c
Branch: default
Log Message:

merged with oct2020


diffs (153 lines):

diff --git a/tools/monetdbe/monetdbe.c b/tools/monetdbe/monetdbe.c
--- a/tools/monetdbe/monetdbe.c
+++ b/tools/monetdbe/monetdbe.c
@@ -125,6 +125,43 @@ static daytime time_from_data(monetdbe_d
 
 static char* monetdbe_cleanup_result_internal(monetdbe_database_internal 
*mdbe, monetdbe_result_internal* res);
 
+static int
+date_is_null(monetdbe_data_date *value)
+{
+   monetdbe_data_date null_value;
+   data_from_date(date_nil, &null_value);
+   return value->year == null_value.year && value->month == 
null_value.month &&
+  value->day == null_value.day;
+}
+
+static int
+time_is_null(monetdbe_data_time *value)
+{
+   monetdbe_data_time null_value;
+   data_from_time(daytime_nil, &null_value);
+   return value->hours == null_value.hours &&
+  value->minutes == null_value.minutes &&
+  value->seconds == null_value.seconds && value->ms == 
null_value.ms;
+}
+
+static int
+timestamp_is_null(monetdbe_data_timestamp *value)
+{
+   return is_timestamp_nil(timestamp_from_data(value));
+}
+
+static int
+str_is_null(char **value)
+{
+   return !value || *value == NULL;
+}
+
+static int
+blob_is_null(monetdbe_data_blob *value)
+{
+   return !value || value->data == NULL;
+}
+
 const char *
 monetdbe_version(void)
 {
@@ -1420,14 +1457,52 @@ monetdbe_bind(monetdbe_statement *stmt, 
 {
monetdbe_stmt_internal *stmt_internal = (monetdbe_stmt_internal*)stmt;
 
-   /* TODO !data treat as NULL value (add nil mask) ? */
if (i >= stmt->nparam)
return createException(MAL, "monetdbe.monetdbe_bind", 
"Parameter %zu not bound to a value", i);
sql_arg *a = (sql_arg*)list_fetch(stmt_internal->q->f->ops, (int) i);
assert(a);
-   stmt_internal->data[i].vtype = a->type.type->localtype;
-   /* TODO handle conversion from NULL and special types */
-   VALset(&stmt_internal->data[i], a->type.type->localtype, data);
+   int tpe = a->type.type->localtype;
+   stmt_internal->data[i].vtype = tpe;
+
+   const void* nil = (tpe>=0)?ATOMnilptr(tpe):NULL;
+   if (!data) {
+   VALset(&stmt_internal->data[i], tpe, (ptr)nil);
+   } else if (tpe == TYPE_timestamp) {
+   monetdbe_data_timestamp* ts = (monetdbe_data_timestamp*)data;
+   timestamp t = *(timestamp*) nil;
+   if(!timestamp_is_null(ts))
+   t = timestamp_from_data(ts);
+   VALset(&stmt_internal->data[i], tpe, &t);
+   } else if (tpe == TYPE_date) {
+   monetdbe_data_date* de = (monetdbe_data_date*)data;
+   date d = *(date*) nil;
+   if(!date_is_null(de))
+   d = date_from_data(de);
+   VALset(&stmt_internal->data[i], tpe, &d);
+   } else if (tpe == TYPE_daytime) {
+   monetdbe_data_time* t = (monetdbe_data_time*)data;
+   daytime dt = *(daytime*) nil;
+
+   if(!time_is_null(t))
+   dt = time_from_data(t);
+   VALset(&stmt_internal->data[i], tpe, &dt);
+   } else if (tpe == TYPE_blob) {
+   monetdbe_data_blob *be = (monetdbe_data_blob*)data;
+   blob *b = (blob*)nil;
+   if (!blob_is_null(be)) {
+   size_t len = be->size;
+   b = (blob*) GDKmalloc(blobsize(len));
+   if (b == NULL) {
+   stmt_internal->mdbe->msg = createException(MAL, 
"monetdbe.monetdbe_bind", MAL_MALLOC_FAIL);
+   return stmt_internal->mdbe->msg;
+   }
+   b->nitems = len;
+   memcpy(b->data, be->data, len);
+   }
+   VALset(&stmt_internal->data[i], tpe, b);
+   } else {
+   VALset(&stmt_internal->data[i], tpe, data);
+   }
return MAL_SUCCEED;
 }
 
@@ -1465,6 +1540,7 @@ monetdbe_execute(monetdbe_statement *stm
}
 
(*(monetdbe_result_internal**) result)->type = (b->results) ? 
Q_TABLE : Q_UPDATE;
+   res_internal = *(monetdbe_result_internal**)result;
}
 cleanup:
return commit_action(m, stmt_internal->mdbe, result, res_internal);
@@ -2504,40 +2580,3 @@ timestamp_from_data(monetdbe_data_timest
date_create(ptr->date.year, ptr->date.month, ptr->date.day),
daytime_create(ptr->time.hours, ptr->time.minutes, 
ptr->time.seconds, ptr->time.ms * 1000));
 }
-
-static int
-date_is_null(monetdbe_data_date *value)
-{
-   monetdbe_data_date null_value;
-   data_from_date(date_nil, &null_value);
-   return value->year == null_value.year && value->month == 
null_value.month &&
-

MonetDB: default - merged with oct2020

2021-04-23 Thread Niels Nes
Changeset: 88de31cd8491 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/88de31cd8491
Modified Files:
sql/server/rel_optimizer.c
Branch: default
Log Message:

merged with oct2020


diffs (truncated from 465 to 300 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
@@ -4198,10 +4198,6 @@ rel_push_aggr_down(visitor *v, sql_rel *
}
}
 
-   u = rel_setop(v->sql->sa, ul, ur, op_union);
-   rel_setop_set_exps(v->sql, u, rel_projections(v->sql, ul, NULL, 
1, 1));
-   set_processed(u);
-
if (rel->r) {
list *ogbe = rel->r;
 
@@ -4209,15 +4205,27 @@ rel_push_aggr_down(visitor *v, sql_rel *
for (n = ogbe->h; n; n = n->next) {
sql_exp *e = n->data, *ne;
 
+   /* group by in aggreation list */
ne = exps_uses_exp( rel->exps, e);
-   if (!ne)
-   continue;
-   ne = list_find_exp( u->exps, ne);
+   if (ne)
+   ne = list_find_exp( ul->exps, ne);
+   if (!ne) {
+   /* e only in the ul/ur->r (group by 
list) */
+   ne = exp_ref(v->sql, e);
+   list_append(ul->exps, ne);
+   ne = exp_ref(v->sql, e);
+   list_append(ur->exps, ne);
+   }
assert(ne);
ne = exp_ref(v->sql, ne);
append(gbe, ne);
}
}
+
+   u = rel_setop(v->sql->sa, ul, ur, op_union);
+   rel_setop_set_exps(v->sql, u, rel_projections(v->sql, ul, NULL, 
1, 1));
+   set_processed(u);
+
exps = new_exp_list(v->sql->sa);
for (n = u->exps->h, m = rel->exps->h; n && m; n = n->next, m = 
m->next) {
sql_exp *ne, *e = n->data, *oa = m->data;
diff --git a/sql/test/BugTracker-2021/Tests/All 
b/sql/test/BugTracker-2021/Tests/All
--- a/sql/test/BugTracker-2021/Tests/All
+++ b/sql/test/BugTracker-2021/Tests/All
@@ -2,5 +2,6 @@ update-from-count.Bug-7079
 HAVE_PYMONETDB?remote-table-ranges.Bug-7089
 KNOWNFAIL?query-too-complex.Bug-7092
 ntile-wrong-result.Bug-7104
+union-groupby.Bug-7108
 merge-stmt.wrong-error.Bug-7109
 remote-table-groupby.Bug-7110
diff --git a/sql/test/BugTracker-2021/Tests/union-groupby.Bug-7108.sql 
b/sql/test/BugTracker-2021/Tests/union-groupby.Bug-7108.sql
new file mode 100644
--- /dev/null
+++ b/sql/test/BugTracker-2021/Tests/union-groupby.Bug-7108.sql
@@ -0,0 +1,330 @@
+START TRANSACTION;
+CREATE TABLE "sys"."lineitem_denormalized_first1k_sanitised" (
+   "Customer_Gender"VARCHAR(255),
+   "Customer_Region"VARCHAR(255),
+   "Customer_Country"   VARCHAR(255),
+   "Customer_State" VARCHAR(255),
+   "Customer_City"  VARCHAR(255),
+   "Customer_Date_Of_Birth" TIMESTAMP,
+   "Customer_Id"BIGINT,
+   "Product_Family" VARCHAR(255),
+   "Product_Category"   VARCHAR(255),
+   "Product_Subcategory"VARCHAR(255),
+   "Product_Name"   VARCHAR(255),
+   "Product_Id" BIGINT,
+   "Store_Id"   BIGINT,
+   "Store_Longitude"DOUBLE,
+   "Store_Latitude" DOUBLE,
+   "Store_Name" VARCHAR(255),
+   "Store_Manager"  VARCHAR(255),
+   "Store_Phone_Number" VARCHAR(255),
+   "Store_Region"   VARCHAR(255),
+   "Store_Country"  VARCHAR(255),
+   "Store_State"VARCHAR(255),
+   "Store_City" VARCHAR(255),
+   "Order_Date" TIMESTAMP,
+   "Year_Begin_Date"TIMESTAMP,
+   "Quarter_Begin_Date" TIMESTAMP,
+   "Month_Begin_Date"   TIMESTAMP,
+   "Yyyymm" BIGINT,
+   "Yyyymmdd"   BIGINT,
+   "Ddmon"  VARCHAR(255),
+   "Line_Price" DOUBLE,
+   "Line_Cost"  DOUBLE,
+   "Line_Margin"DOUBLE,
+   "Line_Margin_Percent"DOUBLE
+);
+COPY 200 RECORDS INTO "sys"."lineitem_denormalized_first1k_sanitised" FROM 
stdin USING DELIMITERS E'\t',E'\n','"';
+"f""APAC"  "People's Republic of China""Sichuan"   "Yibin" 
"1957-09-19 00:00:00.00"99425   "Non-consumables"   "Clothing"  
"Clothing"  "Croft & Barrow Velour Separates"   175730  -3.2
55.95   "Edinburgh, United Kingdom" "Melody J. Hambard" 
"+44-875-77

MonetDB: default - Merged with Oct2020

2021-04-21 Thread Pedro Ferreira
Changeset: 5f168c6a79e6 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/5f168c6a79e6
Modified Files:
sql/server/sql_atom.c
Branch: default
Log Message:

Merged with Oct2020


diffs (17 lines):

diff --git a/sql/server/sql_atom.c b/sql/server/sql_atom.c
--- a/sql/server/sql_atom.c
+++ b/sql/server/sql_atom.c
@@ -1278,12 +1278,7 @@ atom_cast(sql_allocator *sa, atom *a, sq
int tpe = tp->type->localtype;
size_t len = (tpe == TYPE_dbl) ? 
sizeof(dbl) : sizeof(flt);
ssize_t res;
-   ptr p;
-
-   if (tpe == TYPE_dbl)
-   p = &(a->data.val.dval);
-   else
-   p = &(a->data.val.fval);
+   ptr p = &(a->data.val);
if ((res = ATOMfromstr(tpe, &p, &len, 
s, false)) < 0) {
GDKclrerr();
return 0;
___
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list


MonetDB: default - Merged with Oct2020

2021-04-16 Thread Pedro Ferreira
Changeset: 8a64aa8e8050 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/8a64aa8e8050
Added Files:
sql/test/BugTracker-2021/Tests/ntile-wrong-result.Bug-7104.test
Removed Files:
sql/test/BugTracker-2021/Tests/ntile-wrong-result.Bug-7104.sql
sql/test/BugTracker-2021/Tests/ntile-wrong-result.Bug-7104.stable.err
sql/test/BugTracker-2021/Tests/ntile-wrong-result.Bug-7104.stable.out
Modified Files:
gdk/gdk_analytic_func.c
Branch: default
Log Message:

Merged with Oct2020


diffs (214 lines):

diff --git a/gdk/gdk_analytic_func.c b/gdk/gdk_analytic_func.c
--- a/gdk/gdk_analytic_func.c
+++ b/gdk/gdk_analytic_func.c
@@ -44,8 +44,7 @@ GDKrebuild_segment_tree(oid ncount, oid 
 
 #define NTILE_CALC(TPE, NEXT_VALUE, LNG_HGE, UPCAST, VALIDATION)   \
do {\
-   TPE j = 0; \
-   UPCAST ncnt = (UPCAST) (i - k); \
+   UPCAST j = 0, ncnt = (UPCAST) (i - k); \
for (; k < i; k++, j++) {   \
TPE val = NEXT_VALUE; \
if (is_##TPE##_nil(val)) {  \
@@ -55,7 +54,7 @@ GDKrebuild_segment_tree(oid ncount, oid 
UPCAST nval = (UPCAST) LNG_HGE; \
VALIDATION /* validation must come after null 
check */  \
if (nval >= ncnt) { \
-   rb[k] = j + 1;  \
+   rb[k] = (TPE)(j + 1);  \
} else { \
UPCAST bsize = ncnt / nval; \
UPCAST top = ncnt - nval * bsize; \
diff --git a/sql/test/BugTracker-2021/Tests/All 
b/sql/test/BugTracker-2021/Tests/All
--- a/sql/test/BugTracker-2021/Tests/All
+++ b/sql/test/BugTracker-2021/Tests/All
@@ -1,3 +1,4 @@
 update-from-count.Bug-7079
 HAVE_PYMONETDB?remote-table-ranges.Bug-7089
 KNOWNFAIL?query-too-complex.Bug-7092
+ntile-wrong-result.Bug-7104
diff --git a/sql/test/BugTracker-2021/Tests/ntile-wrong-result.Bug-7104.test 
b/sql/test/BugTracker-2021/Tests/ntile-wrong-result.Bug-7104.test
new file mode 100644
--- /dev/null
+++ b/sql/test/BugTracker-2021/Tests/ntile-wrong-result.Bug-7104.test
@@ -0,0 +1,179 @@
+statement ok
+START TRANSACTION
+
+statement ok
+CREATE TABLE stringpower(kw INTEGER)
+
+statement ok
+COPY 160 RECORDS INTO stringpower FROM STDIN USING DELIMITERS E' ',E'\n','"'
+
+25
+12
+23
+34
+23
+24
+34
+23
+21
+45
+23
+232
+4
+32
+324
+321
+23
+234
+46
+34
+34
+32
+53
+423
+34
+53
+23
+12
+35
+45
+78
+68
+85
+56
+78
+58
+8
+5
+934
+48
+65
+445
+656
+63
+34
+65
+32
+32
+44
+55
+34
+67
+8
+64
+544
+3
+8
+987
+344
+5
+73
+78
+789
+9
+8
+7
+779
+977
+25
+78
+35
+5
+8
+9
+67
+9
+7
+78
+54
+435
+30
+14
+27
+40
+27
+28
+40
+27
+25
+54
+27
+278
+4
+38
+388
+385
+27
+280
+55
+40
+40
+38
+63
+507
+40
+63
+27
+14
+42
+54
+93
+81
+102
+67
+93
+69
+9
+6
+1120
+57
+78
+534
+787
+75
+40
+78
+38
+38
+52
+66
+40
+80
+9
+76
+652
+3
+9
+1184
+412
+6
+87
+93
+946
+10
+9
+8
+934
+1172
+30
+93
+42
+6
+9
+10
+80
+10
+8
+93
+64
+522
+
+query II rowsort
+SELECT NTILE(2) OVER(ORDER BY kw) as tile, NTILE(CAST(2 AS BIGINT)) OVER(ORDER 
BY kw) as tile2 from stringpower
+
+320 values hashing to fa967d46913adf240bb90d0b98419dfb
+
+statement ok
+ROLLBACK
+
+
___
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list


MonetDB: default - Merged with Oct2020

2021-03-31 Thread Pedro Ferreira
Changeset: bf735b295425 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/bf735b295425
Removed Files:
sql/test/sys-schema/Tests/webExamplesCastFunctionsOperators.sql
sql/test/sys-schema/Tests/webExamplesComparisonFunctionsOperators.sql
sql/test/sys-schema/Tests/webExamplesLogicalFunctionsOperators.sql
sql/test/sys-schema/Tests/webExamplesMathematicalFunctionsOperators.sql
Modified Files:
sql/test/sys-schema/Tests/webExamplesCastFunctionsOperators.test
sql/test/sys-schema/Tests/webExamplesMathematicalFunctionsOperators.test
Branch: default
Log Message:

Merged with Oct2020


diffs (truncated from 830 to 300 lines):

diff --git a/clients/odbc/ChangeLog b/clients/odbc/ChangeLog
--- a/clients/odbc/ChangeLog
+++ b/clients/odbc/ChangeLog
@@ -1,13 +1,3 @@
 # ChangeLog file for odbc
 # This file is updated with Maddlog
 
-* Thu Mar 25 2021 Sjoerd Mullender 
-- The ODBC driver now only passes on information about HUGEINT columns
-  as HUGEINT when the application has indicated interest by querying
-  about the SQL_HUGEINT extension type using the SQLGetTypeInfo
-  function or by specifying the type in a call to SQLSetDescField.
-  Otherwise the driver silently translates the HUGEINT type to BIGINT.
-  This means that most application will see BIGINT columns when the
-  server produced a HUGEINT column and only give an error if the value
-  in the HUGEINT column didn't fit into a BIGINT.
-
diff --git a/clients/odbc/ChangeLog.Oct2020 b/clients/odbc/ChangeLog.Oct2020
new file mode 100644
--- /dev/null
+++ b/clients/odbc/ChangeLog.Oct2020
@@ -0,0 +1,20 @@
+# ChangeLog file for odbc
+# This file is updated with Maddlog
+
+* Wed Mar 31 2021 Sjoerd Mullender 
+- When connecting using a DSN (Data Source Name), information about the
+  data source is retrieved from the ODBC.INI file.  Now we also get the
+  location of the LOGFILE from this file.  The logfile can be used to
+  log all calls to the MonetDB ODBC driver to a file which can be used
+  for debugging.
+
+* Thu Mar 25 2021 Sjoerd Mullender 
+- The ODBC driver now only passes on information about HUGEINT columns
+  as HUGEINT when the application has indicated interest by querying
+  about the SQL_HUGEINT extension type using the SQLGetTypeInfo
+  function or by specifying the type in a call to SQLSetDescField.
+  Otherwise the driver silently translates the HUGEINT type to BIGINT.
+  This means that most application will see BIGINT columns when the
+  server produced a HUGEINT column and only give an error if the value
+  in the HUGEINT column didn't fit into a BIGINT.
+
diff --git a/clients/odbc/driver/SQLConnect.c b/clients/odbc/driver/SQLConnect.c
--- a/clients/odbc/driver/SQLConnect.c
+++ b/clients/odbc/driver/SQLConnect.c
@@ -141,6 +141,20 @@ MNDBConnect(ODBCDbc *dbc,
}
}
 
+#ifdef ODBCDEBUG
+   if ((ODBCdebug == NULL || *ODBCdebug == 0) && dsn && *dsn) {
+   char logfile[2048];
+   n = SQLGetPrivateProfileString(dsn, "logfile", "",
+  logfile, sizeof(logfile),
+  "odbc.ini");
+   if (n > 0) {
+   if (ODBCdebug)
+   free((void *) ODBCdebug); /* discard const */
+   ODBCdebug = strdup(logfile);
+   }
+   }
+#endif
+
if (dsn && *dsn)
n = SQLGetPrivateProfileString(dsn, "uid", "monetdb",
   uid, sizeof(uid), "odbc.ini");
diff --git a/sql/test/sys-schema/Tests/webExamplesCastFunctionsOperators.sql 
b/sql/test/sys-schema/Tests/webExamplesCastFunctionsOperators.sql
deleted file mode 100644
--- a/sql/test/sys-schema/Tests/webExamplesCastFunctionsOperators.sql
+++ /dev/null
@@ -1,49 +0,0 @@
-select cast(123 as varchar(10));
-select convert(123, decimal(10,3));
-
-select cast(true as smallint);
-select cast(42 as int);
-select cast(123.45 as real);
-select cast('123.45' as double precision);
-select cast(23.45 as decimal(5,2));-- precision of 5 digits of which 2 
decimal digits
-
-select cast('2020-07-29' as date);
-select cast('17:44:59' as time);
-select cast('17:44:59.123456' as time);
-select cast('2020-07-29 17:44:59' as timestamp);
-select cast('2020-07-29T17:44:59' as timestamp);
-select cast('2020-07-29 17:44:59.123456' as timestamp);
-select cast('17:44:59.321+01:30' as timetz);
-select cast('2020-07-29 17:44:59.321+01:30' as timestamptz);   -- produces 
wrong TZ +1:00 instead of +1:30
-select cast('1234' as interval month);
-select cast('86400.123' as interval second);
-
-select cast('abcd' as blob);
-select cast('abcde' as clob);
-select cast('192.168.1.5/24' as inet);
-select cast(r'{"a":[1,2,4]}' as json);
-select cast('https://www.monetdb.org/Home' as url);
-select cast('e31960fb-dc8b-452d-ab30-b342723e756a' as uuid);
-
--- or using convert instead of cast:
-select convert('a4cd' , blob);
-select co

MonetDB: default - Merged with Oct2020

2021-03-30 Thread Ying Zhang
Changeset: 31c205a51f5c for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/31c205a51f5c
Branch: default
Log Message:

Merged with Oct2020


diffs (8 lines):

diff --git a/sql/test/BugTracker-2021/Tests/All 
b/sql/test/BugTracker-2021/Tests/All
--- a/sql/test/BugTracker-2021/Tests/All
+++ b/sql/test/BugTracker-2021/Tests/All
@@ -1,3 +1,3 @@
 update-from-count.Bug-7079
 HAVE_PYMONETDB?remote-table-ranges.Bug-7089
-query-too-complex.Bug-7092
+KNOWNFAIL?query-too-complex.Bug-7092
___
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list


MonetDB: default - Merged with Oct2020

2021-03-30 Thread Ying Zhang
Changeset: 3d9056d0975a for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/3d9056d0975a
Branch: default
Log Message:

Merged with Oct2020


diffs (truncated from 87089 to 300 lines):

diff --git a/sql/test/BugTracker-2021/Tests/All 
b/sql/test/BugTracker-2021/Tests/All
--- a/sql/test/BugTracker-2021/Tests/All
+++ b/sql/test/BugTracker-2021/Tests/All
@@ -1,2 +1,3 @@
 update-from-count.Bug-7079
 HAVE_PYMONETDB?remote-table-ranges.Bug-7089
+query-too-complex.Bug-7092
diff --git a/sql/test/BugTracker-2021/Tests/query-too-complex.Bug-7092.sql 
b/sql/test/BugTracker-2021/Tests/query-too-complex.Bug-7092.sql
new file mode 100644
--- /dev/null
+++ b/sql/test/BugTracker-2021/Tests/query-too-complex.Bug-7092.sql
@@ -0,0 +1,86989 @@
+create table test (
+  dkey int,
+  col1 int,
+  col2 int,
+  col3 int,
+  col4 int,
+  col5 int,
+  col6 int,
+  col7 int
+);
+
+SELECT SUM(test.dkey), test.dkey
+  FROM test
+ WHERE ((test.col4 NOT IN (13))
+   AND (test.col3 NOT IN (86, 552))
+   AND (test.col4 NOT IN (9))
+   AND (test.col4 NOT IN (6))
+   AND (test.col4 NOT IN (7))
+   AND (test.col5 NOT IN (3))
+   AND (test.col2 NOT IN (5))
+   AND (((test.col1 = 1)
+ AND (test.col4 = 20)
+ AND (test.col2 = 51)
+ AND (test.col3 = 23)
+ AND (test.col5 = 56))
+OR ((test.col1 = 1)
+AND (test.col4 = 20)
+AND (test.col2 = 51)
+AND (test.col3 = 23)
+AND (test.col5 = 58))
+OR ((test.col1 = 1)
+AND (test.col4 = 20)
+AND (test.col2 = 51)
+AND (test.col3 = 23)
+AND (test.col5 = 60))
+OR ((test.col1 = 1)
+AND (test.col4 = 20)
+AND (test.col2 = 51)
+AND (test.col3 = 23)
+AND (test.col5 = 2307))
+OR ((test.col1 = 1)
+AND (test.col4 = 20)
+AND (test.col2 = 51)
+AND (test.col3 = 23)
+AND (test.col5 = 2305)
+AND (test.col6 = 3283960))
+OR ((test.col1 = 1)
+AND (test.col4 = 20)
+AND (test.col2 = 51)
+AND (test.col3 = 23)
+AND (test.col5 = 2305)
+AND (test.col6 = 6134135))
+OR ((test.col1 = 1)
+AND (test.col4 = 20)
+AND (test.col2 = 51)
+AND (test.col3 = 23)
+AND (test.col5 = 2305)
+AND (test.col6 = 3294265))
+OR ((test.col1 = 1)
+AND (test.col4 = 20)
+AND (test.col2 = 51)
+AND (test.col3 = 23)
+AND (test.col5 = 2305)
+AND (test.col6 = 6146546))
+OR ((test.col1 = 1)
+AND (test.col4 = 20)
+AND (test.col2 = 51)
+AND (test.col3 = 23)
+AND (test.col5 = 2305)
+AND (test.col6 = 3311810))
+OR ((test.col1 = 1)
+AND (test.col4 = 20)
+AND (test.col2 = 51)
+AND (test.col3 = 23)
+AND (test.col5 = 2305)
+AND (test.col6 = 6150213))
+OR ((test.col1 = 1)
+AND (test.col4 = 20)
+AND (test.col2 = 51)
+AND (test.col3 = 23)
+AND (test.col5 = 2305)
+AND (test.col6 = 3311816))
+OR ((test.col1 = 1)
+AND (test.col4 = 20)
+AND (test.col2 = 51)
+AND (test.col3 = 23)
+AND (test.col5 = 2305)
+AND (test.col6 = 3311817))
+OR ((test.col1 = 1)
+AND (test.col4 = 20)
+AND (test.col2 = 51)
+AND (test.col3 = 23)
+AND (test.col5 = 2305)
+AND (test.col6 = 6150223))
+OR ((test.col1 = 1)
+AND (test.col4 = 20)
+AND (test.col2 = 51)
+AND (test.col3 = 23)
+AND (test.col5 = 2305)
+AND (test.col6 = 6150225))
+OR ((test.col1 = 1)
+AND (test.col4 = 20)
+AND (test.col2 = 51)
+AND (test.col3 = 23)
+AND (test.col5 = 2305)
+AND (test.col6 = 6150226))
+OR ((test.col1 = 1)
+AND (test.col4 = 20)
+AND (test.col2 = 51)
+AND (test.col3 = 23)
+AND (test.col5 = 2305)
+AND (test.col6 = 3311824))
+OR ((test.col1 = 1)
+AND (test.col4 = 20)
+AND (test.col2 = 51)
+AND (test.col3 = 23)
+AND (test.col5 = 2305)
+AND (test.col6 = 3311854))
+OR ((test.col1 = 1)
+AND (test.col4 = 20)
+AND (test.

MonetDB: default - Merged with Oct2020

2021-03-30 Thread Pedro Ferreira
Changeset: ae7bcc22e7ce for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/ae7bcc22e7ce
Removed Files:
sql/test/copy/Tests/crlf_normalization.stable.err
sql/test/copy/Tests/crlf_normalization.stable.out
Modified Files:
MonetDB.spec
sql/server/rel_select.c
sql/server/rel_updates.c
sql/test/copy/Tests/All
Branch: default
Log Message:

Merged with Oct2020


diffs (115 lines):

diff --git a/MonetDB.spec b/MonetDB.spec
--- a/MonetDB.spec
+++ b/MonetDB.spec
@@ -302,8 +302,8 @@ This package contains the files needed t
 Summary: MonetDB ODBC driver
 Group: Applications/Databases
 Requires: %{name}-client%{?_isa} = %{version}-%{release}
-Requires(post): unixODBC
-Requires(postun): unixODBC
+Requires(post): %{_bindir}/odbcinst
+Requires(postun): %{_bindir}/odbcinst
 
 %description client-odbc
 MonetDB is a database management system that is developed from a
diff --git a/sql/server/rel_updates.c b/sql/server/rel_updates.c
--- a/sql/server/rel_updates.c
+++ b/sql/server/rel_updates.c
@@ -1496,7 +1496,7 @@ copyfrom(sql_query *query, dlist *qname,
char *tname = qname_schema_object(qname);
sql_table *t = NULL, *nt = NULL;
const char *tsep = seps->h->data.sval;
-   const char *rsep = seps->h->next->data.sval;
+   char *rsep = seps->h->next->data.sval; // not const, might need 
adjusting
const char *ssep = 
(seps->h->next->next)?seps->h->next->next->data.sval:NULL;
const char *ns = (null_string)?null_string:"null";
lng nr = (nr_offset)?nr_offset->h->data.l_val:-1;
@@ -1506,10 +1506,15 @@ copyfrom(sql_query *query, dlist *qname,
assert(!nr_offset || nr_offset->h->type == type_lng);
assert(!nr_offset || nr_offset->h->next->type == type_lng);
 
-   if (strstr(rsep, "\r\n") != NULL)
+   if (strcmp(rsep, "\r\n") == 0) {
+   // silently fix it
+   rsep[0] = '\n';
+   rsep[1] = '\0';
+   } else if (strstr(rsep, "\r\n") != NULL) {
return sql_error(sql, 02, SQLSTATE(42000)
"COPY INTO: record separator contains '\\r\\n' 
but "
-   "in the input stream, '\\r\\n' is being 
normalized into '\\n'");
+   "that will never match, use '\\n' instead");
+   }
 
t = find_table_or_view_on_scope(sql, NULL, sname, tname, "COPY INTO", 
false);
if (insert_allowed(sql, t, tname, "COPY INTO", "copy into") == NULL)
diff --git a/sql/test/copy/Tests/All b/sql/test/copy/Tests/All
--- a/sql/test/copy/Tests/All
+++ b/sql/test/copy/Tests/All
@@ -15,3 +15,4 @@ incorrect_columns
 columns
 no_escape
 no_escape2
+crlf_normalization
diff --git a/sql/test/copy/Tests/crlf_normalization.SQL.py 
b/sql/test/copy/Tests/crlf_normalization.SQL.py
new file mode 100644
--- /dev/null
+++ b/sql/test/copy/Tests/crlf_normalization.SQL.py
@@ -0,0 +1,58 @@
+import os, re, sys, tempfile
+try:
+from MonetDBtesting import process
+except ImportError:
+import process
+
+# Use a Python test because we're testing LF / CR LF handling and we don't
+# want editors or version control systems messing with our line endings
+
+def r_escape(s):
+return "r'" + s.replace("'", "''") + "' "
+
+def testdata(prefix,line_sep):
+prefix = "crlf_test_" + prefix + "_"
+lines = [ b"1,one", b"3,two", b"5,three" ]
+text = bytes(line_sep, "ascii").join([*lines, b''])
+f = tempfile.NamedTemporaryFile(delete=False, prefix=prefix, suffix=".csv")
+name = f.name
+f.write(text)
+f.close()
+return name, text
+
+def run_test(name, data_delimiter, copy_delimiter):
+file_name, test_data = testdata(name, data_delimiter)
+script = f"""
+DROP TABLE IF EXISTS foo;
+CREATE TABLE foo(i INT, t TEXT);
+COPY INTO foo FROM {r_escape(file_name)}
+USING DELIMITERS ',', '{copy_delimiter}';
+SELECT i, LENGTH(t) FROM foo;
+"""
+with process.client('sql', stdin=process.PIPE, stdout=process.PIPE, 
stderr=process.PIPE) as c:
+out, err = c.communicate(script)
+reduced = "\n".join(re.sub(r"\s+", "", line) for line in 
out.splitlines() if line.startswith("["))
+expected = "[3]\n[1,3]\n[3,3]\n[5,5]"
+if reduced != expected:
+print("TEST: ", name, file=sys.stderr)
+print("\nLINE DELIMITER: ", repr(data_delimiter), sep='', 
file=sys.stderr)
+print("\nFILE CONTENTS: ", repr(test_data), sep='', 
file=sys.stderr)
+print("\nSCRIPT:\n", script, sep='', file=sys.stderr)
+print("\nEXPECTED:\n", expected, sep='', file=sys.stderr)
+print("\nGOT:\n", reduced, sep='', file=sys.stderr)
+print("\nFULL STDERR:\n", err, sep='', file=sys.stderr)
+print("\nFULL OUTPUT:\n", out, sep='', file=sys.stderr)
+raise SystemExit("Test failed")
+os.remove(file_name)
+
+# Load unix endings while asking for Unix endings.
+run_test("unix", "\n", r"\n

MonetDB: default - Merged with Oct2020. I am going to convert te...

2021-03-26 Thread Pedro Ferreira
Changeset: 78b8581fcffc for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/78b8581fcffc
Modified Files:
gdk/gdk_bbp.c
sql/backends/monet5/rel_bin.c
sql/server/rel_dump.c
sql/test/sys-schema/Tests/All
Branch: default
Log Message:

Merged with Oct2020. I am going to convert tests next


diffs (truncated from 3375 to 300 lines):

diff --git a/clients/odbc/ChangeLog b/clients/odbc/ChangeLog
new file mode 100644
--- /dev/null
+++ b/clients/odbc/ChangeLog
@@ -0,0 +1,13 @@
+# ChangeLog file for odbc
+# This file is updated with Maddlog
+
+* Thu Mar 25 2021 Sjoerd Mullender 
+- The ODBC driver now only passes on information about HUGEINT columns
+  as HUGEINT when the application has indicated interest by querying
+  about the SQL_HUGEINT extension type using the SQLGetTypeInfo
+  function or by specifying the type in a call to SQLSetDescField.
+  Otherwise the driver silently translates the HUGEINT type to BIGINT.
+  This means that most application will see BIGINT columns when the
+  server produced a HUGEINT column and only give an error if the value
+  in the HUGEINT column didn't fit into a BIGINT.
+
diff --git a/clients/odbc/driver/ODBCDbc.c b/clients/odbc/driver/ODBCDbc.c
--- a/clients/odbc/driver/ODBCDbc.c
+++ b/clients/odbc/driver/ODBCDbc.c
@@ -53,40 +53,16 @@ newODBCDbc(ODBCEnv *env)
addEnvError(env, "HY001", NULL, 0);
return NULL;
}
-   assert(dbc);
 
-   dbc->Env = env;
-   dbc->Error = NULL;
-   dbc->RetrievedErrors = 0;
-
-   dbc->dsn = NULL;
-   dbc->uid = NULL;
-   dbc->pwd = NULL;
-   dbc->host = NULL;
-   dbc->port = 0;
-   dbc->dbname = NULL;
-
-   dbc->Connected = false;
-   dbc->has_comment = false;
-   dbc->sql_attr_autocommit = SQL_AUTOCOMMIT_ON;   /* default is 
autocommit */
-   dbc->sql_attr_metadata_id = SQL_FALSE;
-   dbc->sql_attr_connection_timeout = 0;
-   dbc->mid = NULL;
-   dbc->major = 0;
-   dbc->minor = 0;
-   dbc->patch = 0;
-   dbc->cachelimit = 0;
-   dbc->qtimeout = 0;
-   dbc->Mdebug = 0;
-
-   dbc->FirstStmt = NULL;
-
-   /* add this dbc to start of the administrative linked dbc list */
-   dbc->next = env->FirstDbc;
+   *dbc = (ODBCDbc) {
+   .Env = env,
+   .sql_attr_autocommit = SQL_AUTOCOMMIT_ON,   /* default is 
autocommit */
+   .sql_attr_metadata_id = SQL_FALSE,
+   /* add this dbc to start of the administrative linked dbc list 
*/
+   .next = env->FirstDbc,
+   .Type = ODBC_DBC_MAGIC_NR,  /* set it valid */
+   };
env->FirstDbc = dbc;
-
-   dbc->Type = ODBC_DBC_MAGIC_NR;  /* set it valid */
-
return dbc;
 }
 
diff --git a/clients/odbc/driver/ODBCDbc.h b/clients/odbc/driver/ODBCDbc.h
--- a/clients/odbc/driver/ODBCDbc.h
+++ b/clients/odbc/driver/ODBCDbc.h
@@ -55,6 +55,7 @@ typedef struct tODBCDRIVERDBC {
char *dbname;   /* Database Name or NULL */
bool Connected; /* whether we are connecte to a server */
bool has_comment;   /* whether the server has sys.comments */
+   bool allow_hugeint; /* whether the application deals with HUGEINT */
SQLUINTEGER sql_attr_autocommit;
SQLUINTEGER sql_attr_metadata_id;
SQLUINTEGER sql_attr_connection_timeout;
diff --git a/clients/odbc/driver/ODBCDesc.c b/clients/odbc/driver/ODBCDesc.c
--- a/clients/odbc/driver/ODBCDesc.c
+++ b/clients/odbc/driver/ODBCDesc.c
@@ -30,22 +30,14 @@ newODBCDesc(ODBCDbc *dbc)
addDbcError(dbc, "HY001", NULL, 0);
return NULL;
}
-   assert(desc);
 
-   desc->Dbc = dbc;
-   desc->Error = NULL;
-   desc->RetrievedErrors = 0;
-   desc->Stmt = NULL;
-   desc->descRec = NULL;
-   desc->sql_desc_alloc_type = SQL_DESC_ALLOC_USER;
-   desc->sql_desc_array_size = 1;
-   desc->sql_desc_array_status_ptr = NULL;
-   desc->sql_desc_bind_offset_ptr = NULL;
-   desc->sql_desc_bind_type = SQL_BIND_TYPE_DEFAULT;
-   desc->sql_desc_count = 0;
-   desc->sql_desc_rows_processed_ptr = NULL;
-
-   desc->Type = ODBC_DESC_MAGIC_NR;/* set it valid */
+   *desc = (ODBCDesc) {
+   .Dbc = dbc,
+   .sql_desc_alloc_type = SQL_DESC_ALLOC_USER,
+   .sql_desc_array_size = 1,
+   .sql_desc_bind_type = SQL_BIND_TYPE_DEFAULT,
+   .Type = ODBC_DESC_MAGIC_NR, /* set it valid */
+   };
return desc;
 }
 
diff --git a/clients/odbc/driver/ODBCEnv.c b/clients/odbc/driver/ODBCEnv.c
--- a/clients/odbc/driver/ODBCEnv.c
+++ b/clients/odbc/driver/ODBCEnv.c
@@ -48,11 +48,9 @@ newODBCEnv(void)
if (env == NULL)
return NULL;
 
-   env->Error = NULL;
-   env->RetrievedErrors = 0;
-   env->FirstDbc = NULL;
-   env->Type = ODBC_ENV_MAGIC_NR;
-   env->sql_attr_odbc_version = 0;
+   

MonetDB: default - Merged with Oct2020

2021-03-23 Thread Pedro Ferreira
Changeset: acc9093acf74 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/acc9093acf74
Modified Files:
monetdb5/optimizer/opt_mergetable.c
monetdb5/optimizer/opt_support.c
Branch: default
Log Message:

Merged with Oct2020


diffs (59 lines):

diff --git a/monetdb5/optimizer/opt_mergetable.c 
b/monetdb5/optimizer/opt_mergetable.c
--- a/monetdb5/optimizer/opt_mergetable.c
+++ b/monetdb5/optimizer/opt_mergetable.c
@@ -2051,6 +2051,22 @@ OPTmergetableImplementation(Client cntxt
bats = nr_of_bats(mb, p);
nilbats = nr_of_nilbats(mb, p);
 
+   /* left joins can match at isMatJoinOp, so run this check 
beforehand */
+   if (match > 0 && isMatLeftJoinOp(p) && p->argc >= 5 && p->retc 
== 2 &&
+   (match == 1 || match == 2) && bats+nilbats == 4) {
+   m = is_a_mat(getArg(p,p->retc), &ml);
+   o = is_a_mat(getArg(p,p->retc+2), &ml);
+
+   if ((match == 1 && m >= 0) || (match == 2 && m >= 0 && 
o >= 0)) {
+   if(mat_join2(mb, p, &ml, m, -1, o, -1)) {
+   msg = 
createException(MAL,"optimizer.mergetable",SQLSTATE(HY013) MAL_MALLOC_FAIL);
+   goto cleanup;
+   }
+   actions++;
+   continue;
+   }
+   }
+
/* (l,r) Join (L, R, ..)
 * 2 -> (l,r) equi/theta joins (l,r)
 * 3 -> (l,r) range-joins (l,r1,r2)
@@ -2076,20 +2092,6 @@ OPTmergetableImplementation(Client cntxt
actions++;
continue;
}
-   if (match > 0 && isMatLeftJoinOp(p) && p->argc >= 5 && p->retc 
== 2 &&
-   (match == 1 || match == 2) && bats+nilbats == 
4) {
-   m = is_a_mat(getArg(p,p->retc), &ml);
-   o = is_a_mat(getArg(p,p->retc+2), &ml);
-
-   if ((match == 1 && m >= 0) || (match == 2 && m >= 0 && 
o >= 0)) {
-   if(mat_join2(mb, p, &ml, m, -1, o, -1)) {
-   msg = 
createException(MAL,"optimizer.mergetable",SQLSTATE(HY013) MAL_MALLOC_FAIL);
-   goto cleanup;
-   }
-   actions++;
-   continue;
-   }
-   }
/*
 * Aggregate handling is a prime target for optimization.
 * The simple cases are dealt with first.
diff --git a/monetdb5/optimizer/opt_support.c b/monetdb5/optimizer/opt_support.c
--- a/monetdb5/optimizer/opt_support.c
+++ b/monetdb5/optimizer/opt_support.c
@@ -674,7 +674,7 @@ inline int isSubJoin(InstrPtr p)
const char *func = getFunctionId(p);
size_t l = func?strlen(func):0;
 
-   return (l >= 7 && strcmp(func+l-7,"join") == 0);
+   return (l >= 4 && strcmp(func+l-4,"join") == 0);
 }
 
 inline int isMultiplex(InstrPtr p)
___
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list


MonetDB: default - Merged with Oct2020

2021-03-22 Thread Pedro Ferreira
Changeset: 0b90695c32a5 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/0b90695c32a5
Modified Files:
gdk/gdk_imprints.c
monetdb_config.h.in
Branch: default
Log Message:

Merged with Oct2020


diffs (32 lines):

diff --git a/gdk/gdk_imprints.c b/gdk/gdk_imprints.c
--- a/gdk/gdk_imprints.c
+++ b/gdk/gdk_imprints.c
@@ -53,7 +53,7 @@
  * one mask per "page" of the input BAT indicating in which bins the values
  * in that page fall.  The size of the mask is given by imprints->bits.
  * The list of masks may be run-length compressed, see the dict area.  A
- * “page” is 64 bytes worth of values, so the number of values depends on
+ * "page" is 64 bytes worth of values, so the number of values depends on
  * the type of the value.
  *
  * The dict area starts immediately after the imps area.  It consists of
diff --git a/monetdb_config.h.in b/monetdb_config.h.in
--- a/monetdb_config.h.in
+++ b/monetdb_config.h.in
@@ -324,11 +324,14 @@ typedef __uint128_t uhge;
 #define __attribute__(a)
 #endif
 
+#if !defined(__cplusplus) || __cplusplus < 201103L
 #ifndef static_assert
-/* static_assert is a C11 feature, defined in assert.h which also exists
- * in many other compilers we ignore it if the compiler doesn't support it */
+/* static_assert is a C11/C++11 feature, defined in assert.h which also exists
+ * in many other compilers we ignore it if the compiler doesn't support it
+ * However in C11 static_assert is a macro, while on C++11 is a keyword */
 #define static_assert(expr, mesg)  ((void) 0)
 #endif
+#endif
 
 #ifdef HAVE_STRINGS_H
 #include/* strcasecmp */
___
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list


MonetDB: default - merged with oct2020

2021-03-18 Thread Niels Nes
Changeset: c34557a9a866 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=c34557a9a866
Modified Files:
monetdb5/optimizer/opt_mergetable.c
Branch: default
Log Message:

merged with oct2020


diffs (61 lines):

diff --git a/monetdb5/optimizer/opt_mergetable.c 
b/monetdb5/optimizer/opt_mergetable.c
--- a/monetdb5/optimizer/opt_mergetable.c
+++ b/monetdb5/optimizer/opt_mergetable.c
@@ -375,6 +375,32 @@ mat_delta(matlist_t *ml, MalBlkPtr mb, I
return r;
 }
 
+static InstrPtr
+mat_assign(MalBlkPtr mb, InstrPtr p, matlist_t *ml)
+{
+   InstrPtr r = NULL;
+   mat_t *mat = ml->v;
+
+   for(int i = 0; iretc; i++) {
+   int res = is_a_mat(getArg(p,i), ml);
+   int m = is_a_mat(getArg(p,p->retc+i), ml);
+   assert(res<0 && m >= 0);
+
+   if((r = newInstructionArgs(mb, matRef, packRef, 
mat[m].mi->argc)) == NULL)
+   return NULL;
+   getArg(r, 0) = getArg(p,i);
+   for(int k=1; k < mat[m].mi->argc; k++) {
+   /* reuse inputs of old mat */
+   r = addArgument(mb, r, getArg(mat[m].mi, k));
+   (void)setPartnr(ml, -1, getArg(mat[m].mi, k), k);
+   }
+   if (mat_add(ml, r, mat_none, getFunctionId(p))) {
+   freeInstruction(r);
+   return NULL;
+   }
+   }
+   return r;
+}
 
 static InstrPtr
 mat_apply1(MalBlkPtr mb, InstrPtr p, matlist_t *ml, int m, int var)
@@ -385,6 +411,8 @@ mat_apply1(MalBlkPtr mb, InstrPtr p, mat
InstrPtr r = NULL, q;
mat_t *mat = ml->v;
 
+   assert(!is_assign);
+
assert (p->retc == 1);
 
/* Find the mat we overwrite */
@@ -2240,6 +2268,15 @@ OPTmergetableImplementation(Client cntxt
continue;
}
 
+   if (match == p->retc && p->argc == (p->retc*2) && 
getFunctionId(p) == NULL) {
+   if ((r = mat_assign(mb, p, &ml)) == NULL) {
+   msg = 
createException(MAL,"optimizer.mergetable",SQLSTATE(HY013) MAL_MALLOC_FAIL);
+   goto cleanup;
+   }
+   actions++;
+   continue;
+   }
+
m = n = o = e = -1;
for( fm= p->argc-1; fm>=p->retc ; fm--)
if ((m=is_a_mat(getArg(p,fm), &ml)) >= 0)
___
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list


MonetDB: default - Merged with Oct2020 and converted

2021-03-17 Thread Pedro Ferreira
Changeset: 76572b0e4e67 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=76572b0e4e67
Added Files:
sql/test/BugTracker-2021/Tests/update-from-count.Bug-7079.test
Removed Files:
sql/test/BugTracker-2021/Tests/update-from-count.Bug-7079.sql
sql/test/BugTracker-2021/Tests/update-from-count.Bug-7079.stable.err
sql/test/BugTracker-2021/Tests/update-from-count.Bug-7079.stable.out
Modified Files:
sql/server/rel_updates.c
Branch: default
Log Message:

Merged with Oct2020 and converted


diffs (104 lines):

diff --git a/sql/test/BugTracker-2021/Tests/update-from-count.Bug-7079.sql 
b/sql/test/BugTracker-2021/Tests/update-from-count.Bug-7079.sql
deleted file mode 100644
--- a/sql/test/BugTracker-2021/Tests/update-from-count.Bug-7079.sql
+++ /dev/null
@@ -1,5 +0,0 @@
-START TRANSACTION;
-CREATE TABLE testme (a int, b varchar(32));
-insert into testme values (1, 'a'), (2, 'b'), (3, 'c');
-update testme set a = "y".a from testme "y", testme "z";
-ROLLBACK;
diff --git 
a/sql/test/BugTracker-2021/Tests/update-from-count.Bug-7079.stable.err 
b/sql/test/BugTracker-2021/Tests/update-from-count.Bug-7079.stable.err
deleted file mode 100644
--- a/sql/test/BugTracker-2021/Tests/update-from-count.Bug-7079.stable.err
+++ /dev/null
@@ -1,28 +0,0 @@
-stderr of test 'update-from-count.Bug-7079` in directory 
'sql/test/BugTracker-2021` itself:
-
-
-# 10:42:13 >  
-# 10:42:13 >  "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set" 
"mapi_listenaddr=all" "--set" "mapi_port=36380" "--set" 
"mapi_usock=/var/tmp/mtest-72939/.s.monetdb.36380" "--forcemito" 
"--dbpath=/home/ferreira/repositories/MonetDB-Oct2020/BUILD/var/MonetDB/mTests_sql_test_BugTracker-2021"
 "--set" "embedded_c=true"
-# 10:42:13 >  
-
-# builtin opt  gdk_dbpath = 
/home/ferreira/repositories/MonetDB-Oct2020/BUILD/var/monetdb5/dbfarm/demo
-# builtin opt  mapi_port = 5
-# builtin opt  sql_optimizer = default_pipe
-# builtin opt  sql_debug = 0
-# builtin opt  raw_strings = false
-# cmdline opt  gdk_nr_threads = 0
-# cmdline opt  mapi_listenaddr = all
-# cmdline opt  mapi_port = 36380
-# cmdline opt  mapi_usock = /var/tmp/mtest-72939/.s.monetdb.36380
-# cmdline opt  gdk_dbpath = 
/home/ferreira/repositories/MonetDB-Oct2020/BUILD/var/MonetDB/mTests_sql_test_BugTracker-2021
-# cmdline opt  embedded_c = true
-
-# 10:42:14 >  
-# 10:42:14 >  "mclient" "-lsql" "-ftest" "-tnone" "-Eutf-8" "-i" "-e" 
"--host=/var/tmp/mtest-72939" "--port=36380"
-# 10:42:14 >  
-
-
-# 10:42:14 >  
-# 10:42:14 >  "Done."
-# 10:42:14 >  
-
diff --git 
a/sql/test/BugTracker-2021/Tests/update-from-count.Bug-7079.stable.out 
b/sql/test/BugTracker-2021/Tests/update-from-count.Bug-7079.stable.out
deleted file mode 100644
--- a/sql/test/BugTracker-2021/Tests/update-from-count.Bug-7079.stable.out
+++ /dev/null
@@ -1,36 +0,0 @@
-stdout of test 'update-from-count.Bug-7079` in directory 
'sql/test/BugTracker-2021` itself:
-
-
-# 10:42:13 >  
-# 10:42:13 >  "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set" 
"mapi_listenaddr=all" "--set" "mapi_port=36380" "--set" 
"mapi_usock=/var/tmp/mtest-72939/.s.monetdb.36380" "--forcemito" 
"--dbpath=/home/ferreira/repositories/MonetDB-Oct2020/BUILD/var/MonetDB/mTests_sql_test_BugTracker-2021"
 "--set" "embedded_c=true"
-# 10:42:13 >  
-
-# MonetDB 5 server v11.39.14 (hg id: 6f2834d3a3a1)
-# This is an unreleased version
-# Serving database 'mTests_sql_test_BugTracker-2021', using 8 threads
-# Compiled for x86_64-pc-linux-gnu/64bit with 128bit integers
-# Found 15.493 GiB available main-memory of which we use 12.627 GiB
-# Copyright (c) 1993 - July 2008 CWI.
-# Copyright (c) August 2008 - 2021 MonetDB B.V., all rights reserved
-# Visit https://www.monetdb.org/ for further information
-# Listening for connection requests on 
mapi:monetdb://localhost.localdomain:36380/
-# Listening for UNIX domain connection requests on 
mapi:monetdb:///var/tmp/mtest-72939/.s.monetdb.36380
-# MonetDB/GIS module loaded
-# MonetDB/SQL module loaded
-
-# 10:42:14 >  
-# 10:42:14 >  "mclient" "-lsql" "-ftest" "-tnone" "-Eutf-8" "-i" "-e" 
"--host=/var/tmp/mtest-72939" "--port=36380"
-# 10:42:14 >  
-
-#START TRANSACTION;
-#CREATE TABLE testme (a int, b varchar(32));
-#insert into testme values (1, 'a'), (2, 'b'), (3, 'c');
-[ 3]
-#update testme set a = "y".a from testme "y", testme "z";
-[ 3]
-#ROLLBACK;
-
-# 10:42:14 >  
-# 10:42:14 >  "Done."
-# 10:42:14 >  
-
diff --git a/sql/test/BugTracker-2021/Tests/update-from-count.Bug-7079.test 
b/sql/test/BugTracker-2021/Tests/update-from-count.Bug-7079.test
new file mode 100644
--- /dev/null
+++ b/sql/test/BugTracker-2021/Tests/update-from-count.Bug-7079.test
@@ -0,0 +1,15 @@
+statement ok
+START TRANSACTION
+
+statement ok
+CREATE TABLE testme (a int, b varchar(32))
+
+statement ok
+insert into testme values (1, 'a'), (2, 'b'), (3, 'c')
+
+statement error
+update testme set a = "y".a from testme "y", testme "z"
+
+statement ok
+ROLLBACK
+
_

MonetDB: default - Merged with Oct2020

2021-03-16 Thread Pedro Ferreira
Changeset: dd4daa59bbf3 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=dd4daa59bbf3
Modified Files:
sql/server/rel_select.c
Branch: default
Log Message:

Merged with Oct2020


diffs (104 lines):

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
@@ -552,14 +552,16 @@ find_table_function(mvc *sql, char *snam
 found ? "insufficient 
privileges for" : "no such", type == F_UNION ? "table returning" : "loader", 
sname ? "'":"", sname ? sname : "",
 sname ? "'.":"", 
fname, arg_list ? arg_list : "");
}
-   found = true;
-   for (node *n = ff->h; n ; ) { /* Reduce on privileges */
-   sql_subfunc *sf = n->data;
-   node *nn = n->next;
-
-   if (!execute_priv(sql, sf->func))
-   list_remove_node(funcs, NULL, n);
-   n = nn;
+   if (!list_empty(ff)) {
+   found = true;
+   for (node *n = ff->h; n ; ) { /* Reduce on privileges */
+   sql_subfunc *sf = n->data;
+   node *nn = n->next;
+
+   if (!execute_priv(sql, sf->func))
+   list_remove_node(funcs, NULL, n);
+   n = nn;
+   }
}
len = list_length(ff);
if (len > 1) {
@@ -1788,16 +1790,17 @@ static sql_exp*
return sql_error(sql, ERR_NOTFOUND, SQLSTATE(42000) 
"SELECT: %s operator %s%s%s'%s'(%s)",
 found ? "insufficient 
privileges for" : "no such", sname ? "'":"", sname ? sname : "", sname ? 
"'.":"", fname, arg_list ? arg_list : "");
}
-   found = true;
-   for (node *n = ff->h; n ; ) { /* Reduce on privileges */
-   sql_subfunc *sf = n->data;
-   node *nn = n->next;
-
-   if (!execute_priv(sql, sf->func))
-   list_remove_node(funcs, NULL, n);
-   n = nn;
-   }
-
+   if (!list_empty(ff)) {
+   found = true;
+   for (node *n = ff->h; n ; ) { /* Reduce on privileges */
+   sql_subfunc *sf = n->data;
+   node *nn = n->next;
+
+   if (!execute_priv(sql, sf->func))
+   list_remove_node(funcs, NULL, n);
+   n = nn;
+   }
+   }
len = list_length(ff);
if (len > 1) {
int i, score = 0;
@@ -3712,8 +3715,10 @@ static sql_exp *
if (!a) {
list *aggrs = sql_find_funcs(sql, sname, aname, 
list_length(exps), F_AGGR);
 
-   if (aggrs) {
+   if (!list_empty(aggrs)) {
found = true;
+   int type_misses = 0;
+
for (node *m = aggrs->h ; m; m = m->next) {
list *nexps = sa_list(sql->sa);
node *n, *op;
@@ -3727,8 +3732,10 @@ static sql_exp *
sql_exp *e = n->data;
 
e = exp_check_type(sql, 
&arg->type, *rel, e, type_equal); /* rel is a valid pointer */
-   if (!e)
+   if (!e) {
a = NULL;
+   type_misses++;
+   }
list_append(nexps, e);
}
if (a) {
@@ -3740,6 +3747,7 @@ static sql_exp *
break;
}
}
+   found &= !type_misses; /* if 'a' was found but 
the types didn't match don't give permission error */
}
}
}
@@ -4912,12 +4920,13 @@ rel_rankop(sql_query *query, sql_rel **r
if (!(wf = bind_func_(sql, sname, aname, types, F_ANALYTIC, &found))) {
sql->session->status = 0; /* if the function was not found 
clean the error */
sql->errstr[0] = '\0';
-   wf = find_func(sql, sname, aname, list_length(types), 
F_ANALYTIC, 

MonetDB: default - Merged with Oct2020

2021-03-16 Thread Pedro Ferreira
Changeset: eb4dc8bf9ff2 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=eb4dc8bf9ff2
Modified Files:
sql/server/rel_select.c
sql/test/Users/Tests/userCallFunction.SQL.py
Branch: default
Log Message:

Merged with Oct2020


diffs (truncated from 689 to 300 lines):

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
@@ -346,7 +346,7 @@ query_exp_optname(sql_query *query, sql_
 }
 
 static sql_subfunc *
-bind_func_(mvc *sql, char *sname, char *fname, list *ops, sql_ftype type)
+bind_func_(mvc *sql, char *sname, char *fname, list *ops, sql_ftype type, bool 
*found)
 {
sql_subfunc *sf = NULL;
 
@@ -355,13 +355,15 @@ bind_func_(mvc *sql, char *sname, char *
execute_priv(sql, sql->forward) && type == sql->forward->type)
return sql_dup_subfunc(sql->sa, sql->forward, NULL, NULL);
sf = sql_bind_func_(sql, sname, fname, ops, type);
+   if (found)
+   *found |= sf != NULL;
if (sf && execute_priv(sql, sf->func))
return sf;
return NULL;
 }
 
 static sql_subfunc *
-bind_func(mvc *sql, char *sname, char *fname, sql_subtype *t1, sql_subtype 
*t2, sql_ftype type)
+bind_func(mvc *sql, char *sname, char *fname, sql_subtype *t1, sql_subtype 
*t2, sql_ftype type, bool *found)
 {
sql_subfunc *sf = NULL;
 
@@ -379,13 +381,15 @@ bind_func(mvc *sql, char *sname, char *f
}
}
sf = sql_bind_func(sql, sname, fname, t1, t2, type);
+   if (found)
+   *found |= sf != NULL;
if (sf && execute_priv(sql, sf->func))
return sf;
return NULL;
 }
 
 static sql_subfunc *
-bind_member_func(mvc *sql, char *sname, char *fname, sql_subtype *t, int 
nrargs, sql_ftype type, sql_subfunc *prev)
+bind_member_func(mvc *sql, char *sname, char *fname, sql_subtype *t, int 
nrargs, sql_ftype type, sql_subfunc *prev, bool *found)
 {
sql_subfunc *sf = NULL;
 
@@ -393,19 +397,23 @@ bind_member_func(mvc *sql, char *sname, 
is_subtype(t, &((sql_arg *) sql->forward->ops->h->data)->type) 
&& execute_priv(sql, sql->forward) && type == sql->forward->type)
return sql_dup_subfunc(sql->sa, sql->forward, NULL, t);
sf = sql_bind_member(sql, sname, fname, t, type, nrargs, prev);
+   if (found)
+   *found |= sf != NULL;
if (sf && execute_priv(sql, sf->func))
return sf;
return NULL;
 }
 
 static sql_subfunc *
-find_func(mvc *sql, char *sname, char *fname, int len, sql_ftype type, 
sql_subfunc *prev )
+find_func(mvc *sql, char *sname, char *fname, int len, sql_ftype type, 
sql_subfunc *prev, bool *found)
 {
sql_subfunc *sf = NULL;
 
if (sql->forward && strcmp(fname, sql->forward->base.name) == 0 && 
list_length(sql->forward->ops) == len && execute_priv(sql, sql->forward) && 
type == sql->forward->type)
return sql_dup_subfunc(sql->sa, sql->forward, NULL, NULL);
sf = sql_find_func(sql, sname, fname, len, type, prev);
+   if (found)
+   *found |= sf != NULL;
if (sf && execute_priv(sql, sf->func))
return sf;
return NULL;
@@ -528,10 +536,11 @@ nary_function_arg_types_2str(mvc *sql, l
 sql_exp *
 find_table_function(mvc *sql, char *sname, char *fname, list *exps, list *tl, 
sql_ftype type)
 {
+   bool found = false;
sql_subfunc *f = NULL;
 
assert(type == F_UNION || type == F_LOADER);
-   if (!(f = bind_func_(sql, sname, fname, tl, type)) && list_length(tl)) {
+   if (!(f = bind_func_(sql, sname, fname, tl, type, &found)) && 
list_length(tl)) {
int len, match = 0;
list *ff;
 
@@ -539,9 +548,11 @@ find_table_function(mvc *sql, char *snam
sql->errstr[0] = '\0';
if (!(ff = sql_find_funcs(sql, sname, fname, list_length(tl), 
type))) {
char *arg_list = list_length(tl) ? 
nary_function_arg_types_2str(sql, tl, list_length(tl)) : NULL;
-   return sql_error(sql, ERR_NOTFOUND, SQLSTATE(42000) 
"SELECT: no such %s function %s%s%s'%s'(%s)",
-type == F_UNION ? 
"table returning" : "loader", sname ? "'":"", sname ? sname : "", sname ? 
"'.":"", fname, arg_list ? arg_list : "");
-   }
+   return sql_error(sql, ERR_NOTFOUND, SQLSTATE(42000) 
"SELECT: %s %s function %s%s%s'%s'(%s)",
+found ? "insufficient 
privileges for" : "no such", type == F_UNION ? "table returning" : "loader", 
sname ? "'":"", sname ? sname : "",
+sname ? "'.":"", 
fname, arg_list ? arg_list : "");
+   }
+   found = true;
for (node *n = ff->h; n ; ) { /* Reduce on privileges */
   

MonetDB: default - merged with Oct2020

2021-03-13 Thread Niels Nes
Changeset: c3f06ac64f73 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=c3f06ac64f73
Removed Files:
sql/jdbc/tests/Tests/bogus-auto-generated-keys.SQL.bat
sql/jdbc/tests/Tests/bogus-auto-generated-keys.SQL.sh
sql/jdbc/tests/Tests/bogus-auto-generated-keys.stable.err
sql/jdbc/tests/Tests/bogus-auto-generated-keys.stable.out
Modified Files:
sql/server/rel_optimizer.c
Branch: default
Log Message:

merged with Oct2020


diffs (174 lines):

diff --git a/sql/jdbc/tests/Tests/All b/sql/jdbc/tests/Tests/All
--- a/sql/jdbc/tests/Tests/All
+++ b/sql/jdbc/tests/Tests/All
@@ -1,7 +1,6 @@
 HAVE_JDBCTESTS?JDBC_API_Tester
 #HAVE_JDBCTESTS?Test_Csendthread  # unfortunately has runtime-dependant output
-HAVE_JDBCCLIENT_JAR?Test_JdbcClient
-HAVE_JDBCCLIENT_JAR?bogus-auto-generated-keys
 #HAVE_JDBCTESTS?Test_PSlargeamount # scalabity test which is disabled by 
default (it takes a long time to run and does not need to be run everytime, 
only before a new release)
 # next test should be done AFTER all the other tests have completed
+HAVE_JDBCCLIENT_JAR?Test_JdbcClient
 HAVE_JDBCCLIENT_JAR?ValidateSystemCatalogTables
diff --git a/sql/jdbc/tests/Tests/bogus-auto-generated-keys.SQL.bat 
b/sql/jdbc/tests/Tests/bogus-auto-generated-keys.SQL.bat
deleted file mode 100755
--- a/sql/jdbc/tests/Tests/bogus-auto-generated-keys.SQL.bat
+++ /dev/null
@@ -1,10 +0,0 @@
-@echo off
-
-echo user=monetdb> .monetdb
-echo password=monetdb>>.monetdb
-
-prompt # $t $g  
-
-call java org.monetdb.client.JdbcClient -h %HOST% -p %MAPIPORT% -d %TSTDB% -e 
-f "%TSTSRCBASE%\%TSTDIR%\Tests\bogus-auto-generated-keys.sql"
-
-@del .monetdb
diff --git a/sql/jdbc/tests/Tests/bogus-auto-generated-keys.SQL.sh 
b/sql/jdbc/tests/Tests/bogus-auto-generated-keys.SQL.sh
deleted file mode 100755
--- a/sql/jdbc/tests/Tests/bogus-auto-generated-keys.SQL.sh
+++ /dev/null
@@ -1,10 +0,0 @@
-#!/bin/sh
-
-cat << EOF > .monetdb
-user=monetdb
-password=monetdb
-EOF
-
-java org.monetdb.client.JdbcClient -h $HOST -p $MAPIPORT -d ${TSTDB} -e -f 
$TSTSRCBASE/$TSTDIR/Tests/bogus-auto-generated-keys.sql
-
-rm -f .monetdb
diff --git a/sql/jdbc/tests/Tests/bogus-auto-generated-keys.sql 
b/sql/jdbc/tests/Tests/bogus-auto-generated-keys.sql
deleted file mode 100644
--- a/sql/jdbc/tests/Tests/bogus-auto-generated-keys.sql
+++ /dev/null
@@ -1,21 +0,0 @@
-START TRANSACTION;
--- generate a simple table with an auto-generated key (id)
-CREATE TABLE gen_keys (
-   "id" serial,
-   "x" varchar(12)
-);
-
--- perform an update, useless, but illustrates the bug, this time no
--- generated key is reported, which is correct
-UPDATE gen_keys SET "x" = 'bla' WHERE "id" = 12;
-
--- insert some value, should get a generated key
-INSERT INTO gen_keys ("x") VALUES ('boe');
-
--- update again, we expect NO generated key, but we DO get one
-UPDATE gen_keys SET "x" = 'bla' WHERE "id" = 1;
-UPDATE gen_keys SET "x" = 'bla' WHERE "id" = 12;
-
--- ok, cleanup a bit
-DROP TABLE gen_keys;
-ROLLBACK;
diff --git a/sql/jdbc/tests/Tests/bogus-auto-generated-keys.stable.err 
b/sql/jdbc/tests/Tests/bogus-auto-generated-keys.stable.err
deleted file mode 100644
--- a/sql/jdbc/tests/Tests/bogus-auto-generated-keys.stable.err
+++ /dev/null
@@ -1,17 +0,0 @@
-stderr of test 'bogus-auto-generated-keys` in directory 'sql/jdbc/tests` 
itself:
-
-
-# 19:33:44 >  
-# 19:33:44 >  "./bogus-auto-generated-keys.SQL.sh" "bogus-auto-generated-keys"
-# 19:33:44 >  
-
-
-# 19:33:44 >  
-# 19:33:44 >  java org.monetdb.client.JdbcClient -h monetdb-nuc2 -p 30491 -d 
mTests_sql_jdbc_tests -e -f 
"/home/dinther/dev/dev/MonetDB/sql/jdbc/tests/Tests/bogus-auto-generated-keys.sql"
-# 19:33:44 >  
-
-
-# 19:33:44 >  
-# 19:33:44 >  "Done."
-# 19:33:44 >  
-
diff --git a/sql/jdbc/tests/Tests/bogus-auto-generated-keys.stable.out 
b/sql/jdbc/tests/Tests/bogus-auto-generated-keys.stable.out
deleted file mode 100644
--- a/sql/jdbc/tests/Tests/bogus-auto-generated-keys.stable.out
+++ /dev/null
@@ -1,46 +0,0 @@
-stdout of test 'bogus-auto-generated-keys` in directory 'sql/jdbc/tests` 
itself:
-
-
-# 19:33:44 >  
-# 19:33:44 >  "./bogus-auto-generated-keys.SQL.sh" "bogus-auto-generated-keys"
-# 19:33:44 >  
-
-
-# 19:33:44 >  
-# 19:33:44 >  java org.monetdb.client.JdbcClient -h monetdb-nuc2 -p 30491 -d 
mTests_sql_jdbc_tests -e -f 
"/home/dinther/dev/dev/MonetDB/sql/jdbc/tests/Tests/bogus-auto-generated-keys.sql"
-# 19:33:44 >  
-
-START TRANSACTION;
-Operation successful
--- generate a simple table with an auto-generated key (id)
-CREATE TABLE gen_keys (
-   "id" serial,
-   "x" varchar(12)
-);
-Operation successful
-
--- perform an update, useless, but illustrates the bug, this time no
--- generated key is reported, which is correct
-UPDATE gen_keys SET "x" = 'bla' WHERE "id" = 12;
-0 affected rows
-
--- insert some value, should get a generated key
-INSERT INTO gen_keys ("x") VALUES ('boe');
-1 affected row, last generated key: 1
-
--- update again, we expect NO 

MonetDB: default - Merged with Oct2020

2021-03-12 Thread Pedro Ferreira
Changeset: 4f85e95ff098 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=4f85e95ff098
Modified Files:
gdk/gdk_utils.c
sql/server/rel_optimizer.c
Branch: default
Log Message:

Merged with Oct2020


diffs (63 lines):

diff --git a/gdk/gdk_utils.c b/gdk/gdk_utils.c
--- a/gdk/gdk_utils.c
+++ b/gdk/gdk_utils.c
@@ -599,7 +599,7 @@ MT_init(void)
/* assume "max" if not a number */
fclose(f);
}
-   /* soft limit */
+   /* soft high limit */
strcpy(pth + l, "memory.high");
f = fopen(pth, "r");
if (f != NULL) {
@@ -610,6 +610,17 @@ MT_init(void)
/* assume "max" if not a number */
fclose(f);
}
+   /* soft low limit */
+   strcpy(pth + l, "memory.low");
+   f = fopen(pth, "r");
+   if (f != NULL) {
+   if (fscanf(f, "%" SCNu64, &mem) == 1 && 
mem > 0 && mem < (uint64_t) _MT_pagesize * _MT_npages) {
+   _MT_npages = (size_t) (mem / 
_MT_pagesize);
+   }
+   success = true;
+   /* assume "max" if not a number */
+   fclose(f);
+   }
/* limit of memory+swap usage
 * we use this as maximum virtual memory size */
strcpy(pth + l, "memory.swap.max");
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
@@ -5364,19 +5364,6 @@ find_projection_for_join2semi(sql_rel *r
if (is_project(rel->op) && !is_union(rel->op)) {
if (rel->card < CARD_AGGR) /* const or groupby without group by 
exps */
return true;
-
-   if (is_groupby(rel->op)) { /* if just groupby columns are 
projected, it will be distinct */
-   bool all_groupby_columns = true;
-
-   if (list_empty(rel->r)) /* global aggregate */
-   return true;
-   for (node *n = rel->exps->h; n && all_groupby_columns; 
n = n->next) {
-   sql_exp *e = n->data;
-   all_groupby_columns &= (e->type == e_column && 
(find_prop(e->p, PROP_HASHCOL) || exps_find_exp(rel->r, e)));
-   }
-   if (all_groupby_columns)
-   return true;
-   }
if (list_length(rel->exps) == 1) {
sql_exp *e = rel->exps->h->data;
/* a single group by column in the projection list from 
a group by relation is guaranteed to be unique, but not an aggregate */
@@ -5385,7 +5372,8 @@ find_projection_for_join2semi(sql_rel *r
sql_exp *found = NULL;
bool underjoin = false;
 
-   if (is_groupby(rel->op) || need_distinct(rel) 
|| find_prop(e->p, PROP_HASHCOL))
+   /* if just one groupby column is projected, it 
will be distinct */
+   if ((is_groupby(rel->op) && list_length(rel->r) 
== 1 && exps_find_exp(rel->r, e)) || need_distinct(rel) || find_prop(e->p, 
PROP_HASHCOL))
return true;
 
if ((found = 
rel_find_exp_and_corresponding_rel(rel->l, e, &res, &underjoin)) && !underjoin) 
{ /* grouping column on inner relation */
___
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list


MonetDB: default - Merged with Oct2020

2021-03-11 Thread Pedro Ferreira
Changeset: 85e9226abd1f for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=85e9226abd1f
Removed Files:

sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-prologue.sql
Modified Files:
sql/server/rel_optimizer.c

sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-prologue.test
Branch: default
Log Message:

Merged with Oct2020


diffs (182 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
@@ -1659,13 +1659,32 @@ rel_push_count_down(visitor *v, sql_rel 
return rel;
 }
 
+static bool
+check_projection_on_foreignside(sql_rel *r, list *pexps, int fk_left) 
+{
+   /* projection columns from the foreign side */
+   if (list_empty(pexps))
+   return true;
+   for (node *n = pexps->h; n; n = n->next) {
+   sql_exp *pe = n->data;
+
+   if (pe && is_atom(pe->type))
+   continue;
+   if (pe && !is_alias(pe->type))
+   return false;
+   /* check for columns from the pk side, then keep the join with 
the pk */
+   if ((fk_left && rel_find_exp(r->r, pe)) || (!fk_left && 
rel_find_exp(r->l, pe)))
+   return false;
+   }
+   return true;
+}
+
 static sql_rel *
-rel_simplify_project_fk_join(mvc *sql, sql_rel *r, list *pexps, int *changes)
+rel_simplify_project_fk_join(mvc *sql, sql_rel *r, list *pexps, list 
*orderexps, int *changes)
 {
sql_rel *rl = r->l;
sql_rel *rr = r->r;
sql_exp *je, *le, *nje, *re;
-   node *n;
int fk_left = 1;
 
/* check for foreign key join */
@@ -1695,22 +1714,11 @@ rel_simplify_project_fk_join(mvc *sql, s
 #endif
/* primary side must be a full table */
if ((fk_left && (!is_left(r->op) && !is_full(r->op)) && 
!is_basetable(rr->op)) ||
-   (!fk_left && (!is_right(r->op) && !is_full(r->op)) && 
!is_basetable(rl->op)))
+   (!fk_left && (!is_right(r->op) && !is_full(r->op)) && 
!is_basetable(rl->op)))
return r;
 
-   /* projection columns from the foreign side */
-   for (n = pexps->h; n; n = n->next) {
-   sql_exp *pe = n->data;
-
-   if (pe && is_atom(pe->type))
-   continue;
-   if (pe && !is_alias(pe->type))
-   return r;
-   /* check for columns from the pk side, then keep the join with 
the pk */
-   if ((fk_left && rel_find_exp(r->r, pe)) ||
-   (!fk_left && rel_find_exp(r->l, pe)))
-   return r;
-   }
+   if (!check_projection_on_foreignside(r, pexps, fk_left) || 
!check_projection_on_foreignside(r, orderexps, fk_left))
+   return r;
 
/* rewrite, ie remove pkey side if possible */
le = (sql_exp*)je->l, re = (sql_exp*)je->l;
@@ -1733,7 +1741,7 @@ rel_simplify_project_fk_join(mvc *sql, s
 }
 
 static sql_rel *
-rel_simplify_count_fk_join(mvc *sql, sql_rel *r, list *gexps, int *changes)
+rel_simplify_count_fk_join(mvc *sql, sql_rel *r, list *gexps, list *gcols, int 
*changes)
 {
sql_rel *rl = r->l;
sql_rel *rr = r->r;
@@ -1760,18 +1768,21 @@ rel_simplify_count_fk_join(mvc *sql, sql
 
/* primary side must be a full table */
if ((fk_left && (!is_left(r->op) && !is_full(r->op)) && 
!is_basetable(rr->op)) ||
-   (!fk_left && (!is_right(r->op) && !is_full(r->op)) && 
!is_basetable(rl->op)))
+   (!fk_left && (!is_right(r->op) && !is_full(r->op)) && 
!is_basetable(rl->op)))
return r;
 
if (fk_left && is_join(rl->op) && !rel_is_ref(rl)) {
-   rl = rel_simplify_count_fk_join(sql, rl, gexps, changes);
+   rl = rel_simplify_count_fk_join(sql, rl, gexps, gcols, changes);
r->l = rl;
}
if (!fk_left && is_join(rr->op) && !rel_is_ref(rr)) {
-   rr = rel_simplify_count_fk_join(sql, rr, gexps, changes);
+   rr = rel_simplify_count_fk_join(sql, rr, gexps, gcols, changes);
r->r = rr;
}
 
+   if (!check_projection_on_foreignside(r, gcols, fk_left))
+   return r;
+
/* rewrite, ie remove pkey side if possible */
le = (sql_exp*)je->l, re = (sql_exp*)je->l;
 
@@ -1794,7 +1805,7 @@ rel_simplify_count_fk_join(mvc *sql, sql
 
 /*
  * Handle (left/right/outer/natural) join fk-pk rewrites
- *   1 group by ( fk-pk-join () ) [ count(*) ] -> groub py ( fk )
+ *   1 group by ( fk-pk-join () ) [ count(*) ] -> group by ( fk )
  *   2 project ( fk-pk-join () ) [ fk-column ] -> project (fk table)[ 
fk-column ]
  *   3 project ( fk1-pk1-join( fk2-pk2-join()) [ fk-column, pk1 column ] -> 
project (fk1-pk1-join)[ fk-column, pk1 column ]
  */
@@ -1803,13 +1814,13 @@ rel_simplify_fk_joins(visitor *v, sql_re
 {
s

MonetDB: default - Merged with Oct2020

2021-03-10 Thread Pedro Ferreira
Changeset: e9fc7b085ccc for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=e9fc7b085ccc
Removed Files:
sql/test/miscellaneous/Tests/view-mul-digits.sql
Modified Files:
sql/server/rel_select.c
sql/test/miscellaneous/Tests/view-mul-digits.test
Branch: default
Log Message:

Merged with Oct2020


diffs (109 lines):

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
@@ -5524,8 +5524,7 @@ rel_select_exp(sql_query *query, sql_rel
 */
pexps = list_merge(pexps, te, (fdup)NULL);
}
-   if (rel && is_groupby(rel->op) && !sn->groupby) {
-   set_processed(rel);
+   if (rel && is_groupby(rel->op) && !sn->groupby && !is_processed(rel)) {
for (node *n=pexps->h; n; n = n->next) {
sql_exp *ce = n->data;
if (rel->card < ce->card) {
@@ -5536,6 +5535,7 @@ rel_select_exp(sql_query *query, sql_rel
}
}
}
+   set_processed(rel);
}
rel = rel_project(sql->sa, rel, pexps);
 
diff --git a/sql/test/miscellaneous/Tests/view-mul-digits.test 
b/sql/test/miscellaneous/Tests/view-mul-digits.test
--- a/sql/test/miscellaneous/Tests/view-mul-digits.test
+++ b/sql/test/miscellaneous/Tests/view-mul-digits.test
@@ -23,3 +23,72 @@ 0
 statement ok
 ROLLBACK
 
+statement ok
+create schema myschema
+
+statement ok
+create table myschema.mygroyp(code varchar(10),amount int)
+
+statement ok
+insert into myschema.mygroyp(code,amount)values('a',1),('a',2),('b',3),('b',4)
+
+query TI rowsort
+select code, cast(sum(amount) as bigint) as eind from myschema.mygroyp group 
by code
+
+a
+3
+b
+7
+
+statement ok
+create view myschema.mygroypview as select code, cast(sum(amount) as bigint) 
as eind from myschema.mygroyp group by code
+
+query TI rowsort
+select * from myschema.mygroypview
+
+a
+3
+b
+7
+
+query TI rowsort
+select code, eind from myschema.mygroypview
+
+a
+3
+b
+7
+
+query T rowsort
+select code from myschema.mygroypview
+
+a
+b
+
+query I rowsort
+select eind from myschema.mygroypview
+
+3
+7
+
+query TI rowsort
+select code, cast(sum(eind) as bigint) from myschema.mygroypview group by code
+
+a
+3
+b
+7
+
+statement error
+select code, cast(sum(eind) as bigint) from myschema.mygroypview
+
+statement error
+create view myschema.ups as select code, sum(amount) as eind from 
myschema.mygroyp
+
+statement error
+create view myschema.ups as select code, amount as eind from myschema.mygroyp 
group by code
+
+statement ok
+drop schema myschema cascade
+
+
diff --git a/tools/merovingian/utils/utils.c b/tools/merovingian/utils/utils.c
--- a/tools/merovingian/utils/utils.c
+++ b/tools/merovingian/utils/utils.c
@@ -59,6 +59,8 @@ readConfFile(confkeyval *list, FILE *cnf
 
while (fgets(buf, 1024, cnf) != NULL) {
/* eliminate fgets' newline */
+   if (buf[0] == '\n' || buf[0] == '#')
+   continue;
buf[strlen(buf) - 1] = '\0';
for (t = list; t->key != NULL; t++) {
len = strlen(t->key);
___
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list


MonetDB: default - merged with Oct2020

2021-03-05 Thread Niels Nes
Changeset: 94ac77cf1fd6 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=94ac77cf1fd6
Branch: default
Log Message:

merged with Oct2020


diffs (24 lines):

diff --git a/sql/jdbc/tests/Tests/All b/sql/jdbc/tests/Tests/All
--- a/sql/jdbc/tests/Tests/All
+++ b/sql/jdbc/tests/Tests/All
@@ -1,6 +1,5 @@
 HAVE_JDBCTESTS?JDBC_API_Tester
 #HAVE_JDBCTESTS?Test_Csendthread  # unfortunately has runtime-dependant output
-HAVE_JDBCTESTS&HAVE_HGE?Test_Int128
 HAVE_JDBCCLIENT_JAR?Test_JdbcClient
 HAVE_JDBCCLIENT_JAR?bogus-auto-generated-keys
 #HAVE_JDBCTESTS?Test_PSlargeamount # scalabity test which is disabled by 
default (it takes a long time to run and does not need to be run everytime, 
only before a new release)
diff --git a/sql/jdbc/tests/Tests/Test_Int128.SQL.bat 
b/sql/jdbc/tests/Tests/Test_Int128.SQL.bat
deleted file mode 100755
--- a/sql/jdbc/tests/Tests/Test_Int128.SQL.bat
+++ /dev/null
@@ -1,1 +0,0 @@
-@call "%TSTSRCDIR%\Test.SQL.bat" %*
diff --git a/sql/jdbc/tests/Tests/Test_Int128.SQL.sh 
b/sql/jdbc/tests/Tests/Test_Int128.SQL.sh
deleted file mode 100755
--- a/sql/jdbc/tests/Tests/Test_Int128.SQL.sh
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/bin/sh
-
-$TSTSRCDIR/Test.SQL.sh $*
___
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list


MonetDB: default - Merged with Oct2020

2021-03-04 Thread Pedro Ferreira
Changeset: 55872aff17d0 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=55872aff17d0
Modified Files:
sql/test/emptydb/Tests/check.stable.out
sql/test/emptydb/Tests/check.stable.out.32bit
sql/test/emptydb/Tests/check.stable.out.int128
Branch: default
Log Message:

Merged with Oct2020


diffs (32 lines):

diff --git a/sql/backends/monet5/UDF/pyapi3/connection3.c 
b/sql/backends/monet5/UDF/pyapi3/connection3.c
--- a/sql/backends/monet5/UDF/pyapi3/connection3.c
+++ b/sql/backends/monet5/UDF/pyapi3/connection3.c
@@ -41,6 +41,7 @@ static PyObject *_connection_execute(Py_
if (res != MAL_SUCCEED) {
PyErr_Format(PyExc_Exception, "SQL Query Failed: %s",
 (res ? 
getExceptionMessage(res) : ""));
+   freeException(res);
return NULL;
}
 
diff --git a/sql/backends/monet5/UDF/pyapi3/emit3.c 
b/sql/backends/monet5/UDF/pyapi3/emit3.c
--- a/sql/backends/monet5/UDF/pyapi3/emit3.c
+++ b/sql/backends/monet5/UDF/pyapi3/emit3.c
@@ -204,7 +204,7 @@ PyObject *PyEmit_Emit(PyEmitObject *self
// insert NULL values up until the 
current entry
for (ai = 0; ai < self->nvals; ai++) {
if 
(BUNappend(self->cols[self->ncols].b,
- 
ATOMnil(self->cols[self->ncols].b->ttype),
+ 
ATOMnilptr(self->cols[self->ncols].b->ttype),
  
false) != GDK_SUCCEED) {
msg = 
GDKstrdup("BUNappend failed.");
goto wrapup;
@@ -368,7 +368,7 @@ PyObject *PyEmit_Emit(PyEmitObject *self
}
for (ai = 0; ai < (size_t)el_count; ai++) {
if (BUNappend(self->cols[i].b,
- 
ATOMnil(self->cols[i].b->ttype),
+ 
ATOMnilptr(self->cols[i].b->ttype),
  false) != 
GDK_SUCCEED) {
goto wrapup;
}
___
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list


MonetDB: default - Merged with Oct2020

2021-03-03 Thread Pedro Ferreira
Changeset: 701eb0e24417 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=701eb0e24417
Modified Files:
gdk/gdk_logger.c
gdk/gdk_string.c
sql/server/rel_optimizer.c
sql/server/rel_rel.c
sql/server/rel_unnest.c

sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-plan-0join-query.test

sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-plan-1join-query.test

sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-plan-1join-view.test

sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-plan-2join-query.test

sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-plan-2join-view.test

sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-prologue.test
Branch: default
Log Message:

Merged with Oct2020


diffs (truncated from 836 to 300 lines):

diff --git a/gdk/gdk_string.c b/gdk/gdk_string.c
--- a/gdk/gdk_string.c
+++ b/gdk/gdk_string.c
@@ -176,6 +176,46 @@ strLocate(Heap *h, const char *v)
return 0;
 }
 
+static inline gdk_return
+checkUTF8(const char *v)
+{
+   if (v[0] != '\200' || v[1] != '\0') {
+   /* check that string is correctly encoded UTF-8; there
+* was no need to do this earlier: if the string was
+* found above, it must have gone through here in the
+* past */
+   int nutf8 = 0;
+   int m = 0;
+   for (size_t i = 0; v[i]; i++) {
+   if (nutf8 > 0) {
+   if ((v[i] & 0xC0) != 0x80 ||
+   (m != 0 && (v[i] & m) == 0))
+   goto badutf8;
+   m = 0;
+   nutf8--;
+   } else if ((v[i] & 0xE0) == 0xC0) {
+   nutf8 = 1;
+   if ((v[i] & 0x1E) == 0)
+   goto badutf8;
+   } else if ((v[i] & 0xF0) == 0xE0) {
+   nutf8 = 2;
+   if ((v[i] & 0x0F) == 0)
+   m = 0x20;
+   } else if ((v[i] & 0xF8) == 0xF0) {
+   nutf8 = 3;
+   if ((v[i] & 0x07) == 0)
+   m = 0x30;
+   } else if ((v[i] & 0x80) != 0) {
+   goto badutf8;
+   }
+   }
+   }
+   return GDK_SUCCEED;
+
+  badutf8:
+   return GDK_FAIL;
+}
+
 var_t
 strPut(BAT *b, var_t *dst, const void *V)
 {
@@ -221,39 +261,9 @@ strPut(BAT *b, var_t *dst, const void *V
}
/* the string was not found in the heap, we need to enter it */
 
-   if (v[0] != '\200' || v[1] != '\0') {
-   /* check that string is correctly encoded UTF-8; there
-* was no need to do this earlier: if the string was
-* found above, it must have gone through here in the
-* past */
-   int nutf8 = 0;
-   int m = 0;
-   for (size_t i = 0; v[i]; i++) {
-   if (nutf8 > 0) {
-   if ((v[i] & 0xC0) != 0x80 ||
-   (m != 0 && (v[i] & m) == 0)) {
- badutf8:
-   GDKerror("incorrectly encoded UTF-8");
-   return 0;
-   }
-   m = 0;
-   nutf8--;
-   } else if ((v[i] & 0xE0) == 0xC0) {
-   nutf8 = 1;
-   if ((v[i] & 0x1E) == 0)
-   goto badutf8;
-   } else if ((v[i] & 0xF0) == 0xE0) {
-   nutf8 = 2;
-   if ((v[i] & 0x0F) == 0)
-   m = 0x20;
-   } else if ((v[i] & 0xF8) == 0xF0) {
-   nutf8 = 3;
-   if ((v[i] & 0x07) == 0)
-   m = 0x30;
-   } else if ((v[i] & 0x80) != 0) {
-   goto badutf8;
-   }
-   }
+   if (checkUTF8(v) != GDK_SUCCEED) {
+   GDKerror("incorrectly encoded UTF-8\n");
+   return 0;
}
 
pad = GDK_VARALIGN - (h->free & (GDK_VARALIGN - 1));
@@ -789,6 +799,10 @@ strWrite(const char *a, stream *s, size_
 
(void) cnt;
assert(cnt == 1);
+   if (checkUTF8(a) != GDK_SUCCEED) {
+   GDKerror("incorrectly encoded UTF-8\

MonetDB: default - merged with oct2020

2021-03-02 Thread Niels Nes
Changeset: b208db26102d for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=b208db26102d
Modified Files:
gdk/gdk_storage.c
gdk/gdk_utils.c
Branch: default
Log Message:

merged with oct2020


diffs (33 lines):

diff --git a/gdk/gdk_storage.c b/gdk/gdk_storage.c
--- a/gdk/gdk_storage.c
+++ b/gdk/gdk_storage.c
@@ -62,7 +62,7 @@ GDKfilepath(int farmid, const char *dir,
assert(dir == NULL || *dir != DIR_SEP);
assert(farmid == NOFARM ||
   (farmid >= 0 && farmid < MAXFARMS && BBPfarms[farmid].dirname));
-   if (MT_path_absolute(name)) {
+   if (!GDKembedded() && MT_path_absolute(name)) {
GDKerror("name should not be absolute\n");
return NULL;
}
@@ -103,7 +103,7 @@ GDKcreatedir(const char *dir)
 
TRC_DEBUG(IO_, "GDKcreatedir(%s)\n", dir);
assert(!GDKinmemory(0));
-   if (!MT_path_absolute(dir)) {
+   if (!GDKembedded() && !MT_path_absolute(dir)) {
GDKerror("directory '%s' is not absolute\n", dir);
return GDK_FAIL;
}
diff --git a/gdk/gdk_utils.c b/gdk/gdk_utils.c
--- a/gdk/gdk_utils.c
+++ b/gdk/gdk_utils.c
@@ -83,7 +83,7 @@ GDKenvironment(const char *dbpath)
TRC_CRITICAL(GDK, "Database name too long.\n");
return false;
}
-   if (!MT_path_absolute(dbpath)) {
+   if (!GDKembedded() && !MT_path_absolute(dbpath)) {
TRC_CRITICAL(GDK, "Directory not an absolute path: %s.\n", 
dbpath);
return false;
}
___
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list


MonetDB: default - Merged with Oct2020

2021-02-24 Thread Pedro Ferreira
Changeset: ba1fe8e44d87 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=ba1fe8e44d87
Modified Files:
sql/server/sql_semantic.c
Branch: default
Log Message:

Merged with Oct2020


diffs (41 lines):

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
@@ -1199,7 +1199,7 @@ char *
concat = stpcpy(concat, ")");
}
return res;
-   } break;
+   }
case SQL_BINOP: {
dnode *lst = se->data.lval->h;
const char *op = symbol_escape_ident(sql->ta, 
qname_schema_object(lst->data.lval)),
@@ -1217,7 +1217,7 @@ char *

stpcpy(stpcpy(stpcpy(stpcpy(stpcpy(stpcpy(stpcpy(concat, "\""), op), "\"("), 
l), ","), r), ")");
}
return res;
-   } break;
+   }
case SQL_OP: {
dnode *lst = se->data.lval->h;
const char *op = symbol_escape_ident(sql->ta, 
qname_schema_object(lst->data.lval)),
@@ -1232,7 +1232,7 @@ char *
stpcpy(stpcpy(stpcpy(concat, "\""), op), "\"()");
}
return res;
-   } break;
+   }
case SQL_UNOP: {
dnode *lst = se->data.lval->h;
const char *op = symbol_escape_ident(sql->ta, 
qname_schema_object(lst->data.lval)),
@@ -1309,9 +1309,8 @@ char *
dlist *dl = se->data.lval;
char *val = NULL, *tpe = NULL, *res;
 
-   if (!(val = _symbol2string(sql, dl->h->data.sym, expression, 
err)) || !(tpe = subtype2string2(sql->ta, &dl->h->next->data.typeval))) {
+   if (!(val = _symbol2string(sql, dl->h->data.sym, expression, 
err)) || !(tpe = subtype2string2(sql->ta, &dl->h->next->data.typeval)))
return NULL;
-   }
if ((res = SA_NEW_ARRAY(sql->ta, char, strlen(val) + 
strlen(tpe) + 11)))
stpcpy(stpcpy(stpcpy(stpcpy(stpcpy(res, "cast("), val), 
" as "), tpe), ")");
return res;
___
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list


MonetDB: default - Merged with Oct2020

2021-02-24 Thread Pedro Ferreira
Changeset: 103c27da7d60 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=103c27da7d60
Modified Files:
sql/include/sql_relation.h
sql/server/rel_unnest.c
Branch: default
Log Message:

Merged with Oct2020


diffs (71 lines):

diff --git a/sql/include/sql_relation.h b/sql/include/sql_relation.h
--- a/sql/include/sql_relation.h
+++ b/sql/include/sql_relation.h
@@ -277,7 +277,7 @@ typedef struct relation {
 outer:1,   /* used as outer (ungrouped) */
 grouped:1, /* groupby processed all the group by exps */
 single:1,
-used:1;/* used by rewrite_fix_count at rel_unnest, so a 
relation is not modified twice */
+used:2;/* used by rewriters at rel_unnest and rel_dce, so a 
relation is not modified twice */
void *p;/* properties for the optimizer, distribution */
 } sql_rel;
 
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
@@ -20,6 +20,13 @@
 #include "sql_query.h"
 #include "mal_errors.h" /* for SQLSTATE() */
 
+/* some unnesting steps use the 'used' flag to avoid further rewrites. List 
them here, so only one reset flag iteration will be used */
+#define rewrite_fix_count_used (1 << 0)
+#define rewrite_values_used(1 << 1)
+
+#define is_rewrite_fix_count_used(X) ((X & rewrite_fix_count_used) == 
rewrite_fix_count_used)
+#define is_rewrite_values_used(X)((X & rewrite_values_used) == 
rewrite_values_used)
+
 static void
 exp_set_freevar(mvc *sql, sql_exp *e, sql_rel *r)
 {
@@ -3173,7 +3180,7 @@ rewrite_fix_count(visitor *v, sql_rel *r
int rel_changes = 0;
sql_rel *r = rel->r;
 
-   if (!r->used) {
+   if (!is_rewrite_fix_count_used(r->used)) {
/* TODO create an exp iterator */
list *rexps = rel_projections(v->sql, r, NULL, 1, 1), 
*exps;
 
@@ -3207,7 +3214,7 @@ rewrite_fix_count(visitor *v, sql_rel *r
exps = list_merge(rel_projections(v->sql, 
rel->l, NULL, 1, 1), rexps, (fdup)NULL);
rel = rel_project(v->sql->sa, rel, exps);
set_processed(rel);
-   r->used = 1;
+   r->used |= rewrite_fix_count_used;
v->changes++;
}
}
@@ -3468,11 +3475,12 @@ rewrite_values(visitor *v, sql_rel *rel)
if (!is_simple_project(rel->op) || list_empty(rel->exps))
return rel;
 
-   if (rel_is_ref(rel)) { /* need extra project */
+   if (rel_is_ref(rel) && !is_rewrite_values_used(rel->used)) { /* need 
extra project */
rel->l = rel_project(v->sql->sa, rel->l, rel->exps);
rel->exps = rel_projections(v->sql, rel->l, NULL, 1, 1);
((sql_rel*)rel->l)->r = rel->r; /* propagate order by exps */
rel->r = NULL;
+   rel->used |= rewrite_values_used;
return rel;
}
sql_exp *e = rel->exps->h->data;
@@ -3545,7 +3553,8 @@ rel_unnest(mvc *sql, sql_rel *rel)
rel = rel_visitor_bottomup(&v, rel, &rel_remove_empty_select);
rel = rel_visitor_bottomup(&v, rel, &_rel_unnest);
rel = rel_visitor_bottomup(&v, rel, &rewrite_fix_count);/* fix 
count inside a left join (adds a project (if (cnt IS null) then (0) else (cnt)) 
*/
-   rel = rel_visitor_bottomup(&v, rel, &rewrite_reset_used);   /* 
rewrite_fix_count uses 'used' property from sql_rel, reset it after it's done */
+   /* both rewrite_values and rewrite_fix_count use 'used' property from 
sql_rel, reset it */
+   rel = rel_visitor_bottomup(&v, rel, &rewrite_reset_used);
rel = rel_visitor_bottomup(&v, rel, &rewrite_remove_xp);/* 
remove crossproducts with project [ atom ] */
rel = rel_visitor_bottomup(&v, rel, &rewrite_groupings);/* 
transform group combinations into union of group relations */
rel = rel_visitor_bottomup(&v, rel, &rewrite_empty_project);
___
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list


MonetDB: default - Merged with Oct2020

2021-02-23 Thread Pedro Ferreira
Changeset: add5b4ca1e6d for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=add5b4ca1e6d
Removed Files:
sql/test/analytics/Tests/analytics01.sql
Modified Files:
sql/backends/monet5/sql_rank.c
sql/test/BugTracker/Tests/rank_over.SF-1691098.test
sql/test/Tests/rank.test
sql/test/analytics/Tests/analytics01.test
Branch: default
Log Message:

Merged with Oct2020


diffs (truncated from 1253 to 300 lines):

diff --git a/sql/backends/monet5/sql_rank.c b/sql/backends/monet5/sql_rank.c
--- a/sql/backends/monet5/sql_rank.c
+++ b/sql/backends/monet5/sql_rank.c
@@ -315,9 +315,9 @@ SQLrank(Client cntxt, MalBlkPtr mb, MalS
goto bailout;
}
np = (bit*)Tloc(p, 0);
-   for(j=1,k=1; rptsorted = true;
-   r->tkey = true;
+   r->trevsorted = true;
}
}
BATsetcount(r, cnt);
@@ -432,11 +431,10 @@ SQLdense_rank(Client cntxt, MalBlkPtr mb
*rp = j;
}
} else { /* single value, ie no ordering */
-   int icnt = (int) cnt;
-   for(j=1; j<=icnt; j++, rp++)
-   *rp = j;
+   for(; rptsorted = true;
-   r->tkey = true;
+   r->trevsorted = true;
}
}
BATsetcount(r, cnt);
@@ -472,10 +470,10 @@ SQLpercent_rank(Client cntxt, MalBlkPtr 
}
(void)cntxt;
if (isaBatType(getArgType(mb, pci, 1))) {
-   BUN cnt;
+   BUN ncnt, cnt;
int j, k;
dbl *rp, *end, cnt_cast;
-   bit *np, *no;
+   bit *np, *np2, *no, *no2;
 
res = getArgReference_bat(stk, pci, 0);
if (!(b = BATdescriptor(*getArgReference_bat(stk, pci, 1 {
@@ -489,7 +487,6 @@ SQLpercent_rank(Client cntxt, MalBlkPtr 
r->tsorted = r->trevsorted = BATcount(b) <= 1;
 
cnt = BATcount(b);
-   cnt_cast = (dbl) (cnt - 1);
rp = (dbl*)Tloc(r, 0);
end = rp + cnt;
if (isaBatType(getArgType(mb, pci, 2))) {
@@ -499,25 +496,46 @@ SQLpercent_rank(Client cntxt, MalBlkPtr 
goto bailout;
}
np = (bit*)Tloc(p, 0);
-   no = (bit*)Tloc(o, 0);
-   for(j=0,k=0; rptsorted = true;
+   r->trevsorted = true;
}
} else { /* single value, ie no partitions */
if (isaBatType(getArgType(mb, pci, 3))) {
@@ -526,14 +544,23 @@ SQLpercent_rank(Client cntxt, MalBlkPtr 
goto bailout;
}
no = (bit*)Tloc(o, 0);
-   for(j=0,k=0; rptsorted = true;
+   r->trevsorted = true;
+   } else {
+   cnt_cast = (dbl) (cnt - 1);
+   for(j=0,k=0; rptsorted = true;
r->trevsorted = true;
}
@@ -544,7 +571,7 @@ SQLpercent_rank(Client cntxt, MalBlkPtr 
} else {
dbl *res = getArgReference_dbl(stk, pci, 0);
 
-   *res = 1;
+   *res = 0.0;
}
 
 bailout:
@@ -611,7 +638,7 @@ SQLcume_dist(Client cntxt, MalBlkPtr mb,
}
}
for (; bo1 < bo2; bo1++, rb++)
-   *rb = 1;
+   *rb = 1.0;
}
}
j = 0;
@@ -626,11 +653,11 @@ SQLcume_dist(Client cntxt, MalBlkPtr mb,
}
}
for (; bo1 < bo2; bo1++, rb++)
-   *rb = 1;
+   *rb = 1.0;
} else { /* single value, ie no ordering */
rp = rb + BATcount(b);
for (; rbtsorted = true;
r->trevsorted = true;
}
@@ -652,11 +679,11 @@ SQLcume_dist(Client cntxt, MalBlkPtr mb,
}

MonetDB: default - merged with oct2020

2021-02-22 Thread Niels Nes
Changeset: ee668f067ef7 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=ee668f067ef7
Modified Files:
gdk/gdk_join.c
monetdb5/optimizer/opt_mergetable.c
Branch: default
Log Message:

merged with oct2020


diffs (56 lines):

diff --git a/gdk/gdk_join.c b/gdk/gdk_join.c
--- a/gdk/gdk_join.c
+++ b/gdk/gdk_join.c
@@ -2994,7 +2994,9 @@ count_unique(BAT *b, BAT *s, BUN *cnt1, 
mask = HASHmask(ci.ncand);
if (mask < ((BUN) 1 << 16))
mask = (BUN) 1 << 16;
-   if (snprintf(hs.heaplink.filename, 
sizeof(hs.heaplink.filename), "%s.thshunil%x", nme, (unsigned) THRgettid()) >= 
(int) sizeof(hs.heaplink.filename) ||
+   if ((hs.heaplink.farmid = BBPselectfarm(TRANSIENT, b->ttype, 
hashheap)) < 0 ||
+   (hs.heapbckt.farmid = BBPselectfarm(TRANSIENT, b->ttype, 
hashheap)) < 0 ||
+   snprintf(hs.heaplink.filename, 
sizeof(hs.heaplink.filename), "%s.thshunil%x", nme, (unsigned) THRgettid()) >= 
(int) sizeof(hs.heaplink.filename) ||
snprintf(hs.heapbckt.filename, 
sizeof(hs.heapbckt.filename), "%s.thshunib%x", nme, (unsigned) THRgettid()) >= 
(int) sizeof(hs.heapbckt.filename) ||
HASHnew(&hs, b->ttype, BUNlast(b), mask, BUN_NONE, false) 
!= GDK_SUCCEED) {
GDKerror("cannot allocate hash table\n");
diff --git a/gdk/gdk_unique.c b/gdk/gdk_unique.c
--- a/gdk/gdk_unique.c
+++ b/gdk/gdk_unique.c
@@ -220,7 +220,9 @@ BATunique(BAT *b, BAT *s)
GDKerror("cannot allocate hash table\n");
goto bunins_failed;
}
-   if (snprintf(hs->heaplink.filename, 
sizeof(hs->heaplink.filename), "%s.thshunil%x", nme, (unsigned) THRgettid()) >= 
(int) sizeof(hs->heaplink.filename) ||
+   if ((hs->heaplink.farmid = BBPselectfarm(TRANSIENT, b->ttype, 
hashheap)) < 0 ||
+   (hs->heapbckt.farmid = BBPselectfarm(TRANSIENT, b->ttype, 
hashheap)) < 0 ||
+   snprintf(hs->heaplink.filename, 
sizeof(hs->heaplink.filename), "%s.thshunil%x", nme, (unsigned) THRgettid()) >= 
(int) sizeof(hs->heaplink.filename) ||
snprintf(hs->heapbckt.filename, 
sizeof(hs->heapbckt.filename), "%s.thshunib%x", nme, (unsigned) THRgettid()) >= 
(int) sizeof(hs->heapbckt.filename) ||
HASHnew(hs, b->ttype, BUNlast(b), mask, BUN_NONE, false) != 
GDK_SUCCEED) {
GDKfree(hs);
diff --git a/monetdb5/optimizer/opt_mergetable.c 
b/monetdb5/optimizer/opt_mergetable.c
--- a/monetdb5/optimizer/opt_mergetable.c
+++ b/monetdb5/optimizer/opt_mergetable.c
@@ -492,8 +492,7 @@ mat_apply(MalBlkPtr mb, InstrPtr p, matl
}
}
 
-   InstrPtr *r = NULL;
-   r = (InstrPtr*) GDKmalloc(sizeof(InstrPtr)* p->retc);
+   InstrPtr *r = (InstrPtr*) GDKmalloc(sizeof(InstrPtr)* p->retc);
if(!r)
return -1;
for(k=0; k < p->retc; k++) {
@@ -532,13 +531,12 @@ mat_apply(MalBlkPtr mb, InstrPtr p, matl
}
}
for(k=0; k < p->retc; k++) {
-   if(mat_add_var(ml, r[k], NULL, getArg(r[k], 0), mat_type(ml->v, 
matvar[0]),  -1, -1, 1)) {
+   if(mat_add_var(ml, r[k], NULL, getArg(r[k], 0), mat_type(ml->v, 
matvar[0]),  -1, -1, 0)) {
for(l=0; l < k; l++)
freeInstruction(r[l]);
GDKfree(r);
return -1;
}
-   pushInstruction(mb, r[k]);
}
GDKfree(r);
return 0;
___
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list


MonetDB: default - merged with Oct2020

2021-02-22 Thread Niels Nes
Changeset: c3a9dbb758fe for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=c3a9dbb758fe
Modified Files:
sql/jdbc/tests/Tests/Test_JdbcClient.SQL.bat
sql/jdbc/tests/Tests/Test_JdbcClient.SQL.sh
sql/jdbc/tests/Tests/ValidateSystemCatalogTables.SQL.bat
sql/jdbc/tests/Tests/ValidateSystemCatalogTables.SQL.sh
sql/jdbc/tests/Tests/bogus-auto-generated-keys.SQL.bat
sql/jdbc/tests/Tests/bogus-auto-generated-keys.SQL.sh
Branch: default
Log Message:

merged with Oct2020


diffs (67 lines):

diff --git a/sql/jdbc/tests/Tests/All b/sql/jdbc/tests/Tests/All
--- a/sql/jdbc/tests/Tests/All
+++ b/sql/jdbc/tests/Tests/All
@@ -14,7 +14,6 @@ HAVE_JDBCTESTS?BugDecimalRound_Bug_3561
 HAVE_JDBCTESTS?BugResultSetMetaData_Bug_6183
 HAVE_JDBCTESTS?Bug_PrepStmtSetObject_CLOB_6349
 HAVE_JDBCTESTS?Bug_Connect_as_voc_getMetaData_Failure_Bug_6388
-HAVE_JDBCTESTS?Bug_PrepStmtSetString_6382
 HAVE_JDBCTESTS?Bug_LargeQueries_6571_6693
 HAVE_JDBCTESTS?Bug_IsValid_Timeout_Bug_6782
 HAVE_JDBCTESTS?Bug_PrepStmt_With_Errors_Jira292
diff --git a/sql/jdbc/tests/Tests/Bug_PrepStmtSetString_6382.SQL.bat 
b/sql/jdbc/tests/Tests/Bug_PrepStmtSetString_6382.SQL.bat
deleted file mode 100755
--- a/sql/jdbc/tests/Tests/Bug_PrepStmtSetString_6382.SQL.bat
+++ /dev/null
@@ -1,1 +0,0 @@
-@call "%TSTSRCDIR%\Test.SQL.bat" %*
diff --git a/sql/jdbc/tests/Tests/Bug_PrepStmtSetString_6382.SQL.sh 
b/sql/jdbc/tests/Tests/Bug_PrepStmtSetString_6382.SQL.sh
deleted file mode 100755
--- a/sql/jdbc/tests/Tests/Bug_PrepStmtSetString_6382.SQL.sh
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/bin/sh
-
-$TSTSRCDIR/Test.SQL.sh $*
diff --git a/sql/jdbc/tests/Tests/Test_JdbcClient.SQL.bat 
b/sql/jdbc/tests/Tests/Test_JdbcClient.SQL.bat
--- a/sql/jdbc/tests/Tests/Test_JdbcClient.SQL.bat
+++ b/sql/jdbc/tests/Tests/Test_JdbcClient.SQL.bat
@@ -5,11 +5,11 @@ echo password=monetdb>>   .monetdb
 
 prompt # $t $g  
 
-java nl.cwi.monetdb.client.JdbcClient -h %HOST% -p %MAPIPORT% -d "%TSTDB%" 
--help
+java org.monetdb.client.JdbcClient -h %HOST% -p %MAPIPORT% -d "%TSTDB%" --help
 
-java nl.cwi.monetdb.client.JdbcClient -h %HOST% -p %MAPIPORT% -d "%TSTDB%" -f 
"%TSTSRCBASE%\%TSTDIR%\Tests\JdbcClient_create_tables.sql"
-java nl.cwi.monetdb.client.JdbcClient -h %HOST% -p %MAPIPORT% -d "%TSTDB%" -f 
"%TSTSRCBASE%\%TSTDIR%\Tests\JdbcClient_inserts_selects.sql"
-java nl.cwi.monetdb.client.JdbcClient -h %HOST% -p %MAPIPORT% -d "%TSTDB%" -D
-java nl.cwi.monetdb.client.JdbcClient -h %HOST% -p %MAPIPORT% -d "%TSTDB%" -f 
"%TSTSRCBASE%\%TSTDIR%\Tests\JdbcClient_drop_tables.sql"
+java org.monetdb.client.JdbcClient -h %HOST% -p %MAPIPORT% -d "%TSTDB%" -f 
"%TSTSRCBASE%\%TSTDIR%\Tests\JdbcClient_create_tables.sql"
+java org.monetdb.client.JdbcClient -h %HOST% -p %MAPIPORT% -d "%TSTDB%" -f 
"%TSTSRCBASE%\%TSTDIR%\Tests\JdbcClient_inserts_selects.sql"
+java org.monetdb.client.JdbcClient -h %HOST% -p %MAPIPORT% -d "%TSTDB%" -D
+java org.monetdb.client.JdbcClient -h %HOST% -p %MAPIPORT% -d "%TSTDB%" -f 
"%TSTSRCBASE%\%TSTDIR%\Tests\JdbcClient_drop_tables.sql"
 
 @del .monetdb
diff --git a/sql/jdbc/tests/Tests/ValidateSystemCatalogTables.SQL.bat 
b/sql/jdbc/tests/Tests/ValidateSystemCatalogTables.SQL.bat
--- a/sql/jdbc/tests/Tests/ValidateSystemCatalogTables.SQL.bat
+++ b/sql/jdbc/tests/Tests/ValidateSystemCatalogTables.SQL.bat
@@ -5,6 +5,6 @@ echo password=monetdb>> .monetdb
 
 prompt # $t $g  
 
-call java nl.cwi.monetdb.client.JdbcClient -h %HOST% -p %MAPIPORT% -d %TSTDB% 
-e -f "%TSTSRCBASE%\%TSTDIR%\Tests\ValidateSystemCatalogTables.sql"
+call java org.monetdb.client.JdbcClient -h %HOST% -p %MAPIPORT% -d %TSTDB% -e 
-f "%TSTSRCBASE%\%TSTDIR%\Tests\ValidateSystemCatalogTables.sql"
 
 @del .monetdb
diff --git a/sql/jdbc/tests/Tests/bogus-auto-generated-keys.SQL.bat 
b/sql/jdbc/tests/Tests/bogus-auto-generated-keys.SQL.bat
--- a/sql/jdbc/tests/Tests/bogus-auto-generated-keys.SQL.bat
+++ b/sql/jdbc/tests/Tests/bogus-auto-generated-keys.SQL.bat
@@ -5,6 +5,6 @@ echo password=monetdb>> .monetdb
 
 prompt # $t $g  
 
-call java nl.cwi.monetdb.client.JdbcClient -h %HOST% -p %MAPIPORT% -d %TSTDB% 
-e -f "%TSTSRCBASE%\%TSTDIR%\Tests\bogus-auto-generated-keys.sql"
+call java org.monetdb.client.JdbcClient -h %HOST% -p %MAPIPORT% -d %TSTDB% -e 
-f "%TSTSRCBASE%\%TSTDIR%\Tests\bogus-auto-generated-keys.sql"
 
 @del .monetdb
___
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list


MonetDB: default - Merged with Oct2020

2021-02-11 Thread Pedro Ferreira
Changeset: 1c33bc4ce55c for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=1c33bc4ce55c
Removed Files:
sql/test/SQLancer/Tests/sqlancer10.sql
sql/test/SQLancer/Tests/sqlancer11.sql
Modified Files:
sql/server/rel_unnest.c
sql/test/SQLancer/Tests/sqlancer10.test
sql/test/SQLancer/Tests/sqlancer11.test
Branch: default
Log Message:

Merged with Oct2020


diffs (truncated from 443 to 300 lines):

diff --git a/gdk/gdk_project.c b/gdk/gdk_project.c
--- a/gdk/gdk_project.c
+++ b/gdk/gdk_project.c
@@ -612,7 +612,7 @@ BATproject2(BAT *restrict l, BAT *restri
}
 
if (!stringtrick && tpe != TYPE_oid)
-   tpe = ATOMstorage(tpe);
+   tpe = ATOMbasetype(tpe);
switch (tpe) {
case TYPE_bte:
res = project_bte(bn, l, lci, r1, r2);
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
@@ -1995,7 +1995,7 @@ rewrite_or_exp(visitor *v, sql_rel *rel)
if (exps_have_rel_exp(e->l) || 
exps_have_rel_exp(e->r)) {
/* rewrite into setop */
list_remove_node(rel->exps, NULL, n); 
/* remove or expression */
-   if (is_select(rel->op) && 
list_empty(rel->exps)) { /* remove empty select if that's the case */
+   if (is_select(rel->op) && 
list_empty(rel->exps) && !(rel_is_ref(rel))) { /* remove empty select if that's 
the case */
sql_rel *l = rel->l;
rel->l = NULL;
rel_destroy(rel);
diff --git a/sql/test/SQLancer/Tests/sqlancer10.test 
b/sql/test/SQLancer/Tests/sqlancer10.test
--- a/sql/test/SQLancer/Tests/sqlancer10.test
+++ b/sql/test/SQLancer/Tests/sqlancer10.test
@@ -138,6 +138,26 @@ 1
 statement ok
 ROLLBACK
 
+statement ok
+START TRANSACTION
+
+statement ok
+CREATE TABLE "t0" ("c0" TINYINT NOT NULL,"c1" TINYINT NOT NULL,"c3" 
BOOLEAN,"c4" INT,"c5" BIGINT)
+
+statement ok
+CREATE TABLE "t1" ("c0" INT,"c3" VARCHAR(32))
+
+statement ok
+INSERT INTO "t1" VALUES (NULL, ''),(NULL, 'E5E0'),(NULL, '396B34AC'),(NULL, 
'68AB5D04'),(NULL, ''),(0, NULL),(NULL, 'D5E5'),(NULL, '4E')
+
+query T rowsort
+select case t0.c1 = any(select 2 from t1) when false then 'a' when true then 
'b' end from t0
+
+
+
+statement ok
+ROLLBACK
+
 query I rowsort
 select case 3 <> any(select 4) when true then 2 when false then 8 end;
 
diff --git a/sql/test/SQLancer/Tests/sqlancer11.test 
b/sql/test/SQLancer/Tests/sqlancer11.test
--- a/sql/test/SQLancer/Tests/sqlancer11.test
+++ b/sql/test/SQLancer/Tests/sqlancer11.test
@@ -118,14 +118,14 @@ INSERT INTO "t2" VALUES (4, 0, 6, NULL),
 (0.39272912837466945, 8, NULL, NULL),(NULL, NULL, 4, NULL),(2, 0, 6, 
NULL),(-1596101049, 0, 6, NULL),(-1951243968, 0, 6, NULL),(NULL, 0, 6, NULL),
 (NULL, 0, 6, NULL),(NULL, 0, 6, NULL),(NULL, 0, 6, NULL)
 
-query I rowsort
+query T rowsort
 SELECT 4 = ANY(SELECT t2.c2 FROM t2) FROM t0
 
-1
-1
-1
-1
-1
+True
+True
+True
+True
+True
 
 statement ok
 ROLLBACK
@@ -158,12 +158,12 @@ NULL
 NULL
 NULL
 
-query I rowsort
+query T rowsort
 SELECT FALSE BETWEEN t0.c3 = ANY(SELECT t0.c0 FROM t0 WHERE t0.c1) AND TRUE 
FROM t2, t0
 
-1
-1
-1
+True
+True
+True
 
 statement ok
 ROLLBACK
@@ -212,33 +212,33 @@ F4BECB7E
 F4BECB7E
 F4BECB7E
 
-query I rowsort
+query T rowsort
 SELECT 4 NOT IN (6, 1.7976931348623157E308, 0) FROM t1, t0
 
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
+True
+True
+True
+True
+True
+True
+True
+True
+True
+True
+True
+True
+True
+True
+True
+True
+True
+True
+True
+True
+True
+True
+True
+True
 
 statement ok
 ROLLBACK
@@ -263,16 +263,16 @@ cTR' Abp
 cTR' Abp
 cTR' Abp
 
-query I rowsort
+query T rowsort
 SELECT CASE 3 WHEN ((SELECT 0.48) INTERSECT DISTINCT (SELECT -1.2)) THEN FALSE 
ELSE TRUE END FROM t1
 
-1
-1
-1
-1
-1
-1
-1
+True
+True
+True
+True
+True
+True
+True
 
 statement ok
 ROLLBACK
@@ -387,102 +387,102 @@ 9
 9
 9
 
-query I rowsort
+query T rowsort
 SELECT (EXISTS (SELECT 1)) OR greatest(TRUE, FALSE) FROM t1 FULL OUTER JOIN 
(SELECT 3.3 FROM t2) AS sub0 ON true
 
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
+True
+True
+True
+True
+True
+True
+True
+True
+True
+True
+True
+True
+True
+True
+True
+True
+True
+True
+True
+True
+True
+True
+True
___
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list


MonetDB: default - Merged with Oct2020

2021-02-11 Thread Pedro Ferreira
Changeset: e1feb741fa00 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=e1feb741fa00
Removed Files:
sql/test/subquery/Tests/subquery6.sql
Modified Files:
sql/server/rel_exp.c
sql/server/rel_optimizer.c
sql/server/rel_rel.c
sql/server/rel_unnest.c
sql/test/subquery/Tests/subquery6.test
Branch: default
Log Message:

Merged with Oct2020


diffs (199 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
@@ -2589,7 +2589,7 @@ is_identity( sql_exp *e, sql_rel *r)
return 0;
case e_func: {
sql_subfunc *f = e->f;
-   return (strcmp(f->func->base.name, "identity") == 0);
+   return !f->func->s && strcmp(f->func->base.name, "identity") == 
0;
}
default:
return 0;
@@ -2750,12 +2750,12 @@ exp_flatten(mvc *sql, sql_exp *e)
sql_arg *res = (f->func->res)?(f->func->res->h->data):NULL;
 
/* TODO handle date + x months */
-   if (strcmp(f->func->base.name, "sql_add") == 0 && 
list_length(l) == 2 && res && EC_NUMBER(res->type.type->eclass)) {
+   if (!f->func->s && strcmp(f->func->base.name, "sql_add") == 0 
&& list_length(l) == 2 && res && EC_NUMBER(res->type.type->eclass)) {
atom *l1 = exp_flatten(sql, l->h->data);
atom *l2 = exp_flatten(sql, l->h->next->data);
if (l1 && l2)
return atom_add(l1,l2);
-   } else if (strcmp(f->func->base.name, "sql_sub") == 0 && 
list_length(l) == 2 && res && EC_NUMBER(res->type.type->eclass)) {
+   } else if (!f->func->s && strcmp(f->func->base.name, "sql_sub") 
== 0 && list_length(l) == 2 && res && EC_NUMBER(res->type.type->eclass)) {
atom *l1 = exp_flatten(sql, l->h->data);
atom *l2 = exp_flatten(sql, l->h->next->data);
if (l1 && l2)
@@ -2821,7 +2821,7 @@ exp_sum_scales(sql_subfunc *f, sql_exp *
 int
 exp_aggr_is_count(sql_exp *e)
 {
-   if (e->type == e_aggr && strcmp(((sql_subfunc *)e->f)->func->base.name, 
"count") == 0)
+   if (e->type == e_aggr && !((sql_subfunc *)e->f)->func->s && 
strcmp(((sql_subfunc *)e->f)->func->base.name, "count") == 0)
return 1;
return 0;
 }
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
@@ -4039,7 +4039,7 @@ rel_push_aggr_down(visitor *v, sql_rel *
if (u->op == op_project)
u = u->l;
 
-   if (!u || !is_union(u->op) || need_distinct(u) || !u->exps || 
rel_is_ref(u))
+   if (!u || !is_union(u->op) || need_distinct(u) || is_single(u) 
|| !u->exps || rel_is_ref(u))
return rel;
 
ul = u->l;
@@ -4845,7 +4845,7 @@ rel_push_semijoin_down_or_up(visitor *v,
l = l->l;
*/
 
-   if (!is_join(l->op) || is_full(l->op) || rel_is_ref(l))
+   if (!is_join(l->op) || is_full(l->op) || rel_is_ref(l) || 
is_single(l))
return rel;
 
lop = l->op;
@@ -5055,7 +5055,7 @@ rel_push_join_down_union(visitor *v, sql
if (is_semi(rel->op) && is_union(l->op) && je && 
!find_prop(je->p, PROP_JOINIDX))
return rel;
 
-   if ((is_union(l->op) && !need_distinct(l)) && !is_union(r->op)){
+   if ((is_union(l->op) && !need_distinct(l) && !is_single(l)) && 
!is_union(r->op)){
sql_rel *nl, *nr;
sql_rel *ll = rel_dup(l->l), *lr = rel_dup(l->r);
 
@@ -5082,8 +5082,8 @@ rel_push_join_down_union(visitor *v, sql
nr = rel_project(v->sql->sa, nr, 
rel_projections(v->sql, nr, NULL, 1, 1));
v->changes++;
return rel_inplace_setop(v->sql, rel, nl, nr, op_union, 
rel_projections(v->sql, rel, NULL, 1, 1));
-   } else if (is_union(l->op) && !need_distinct(l) &&
-  is_union(r->op) && !need_distinct(r)) {
+   } else if (is_union(l->op) && !need_distinct(l) && 
!is_single(l) &&
+  is_union(r->op) && !need_distinct(r) && 
!is_single(r)) {
sql_rel *nl, *nr;
sql_rel *ll = rel_dup(l->l), *lr = rel_dup(l->r);
sql_rel *rl = rel_dup(r->l), *rr = rel_dup(r->r);
@@ -5126,7 +5126,7 @@ rel_push_join_down_union(visitor *v, sql
v->changes++;
return rel_inplace_setop(v->sql, rel, nl, nr, op_union, 
rel_projections(v->sql, rel, NULL, 1, 1));
} else if (!is_union(l->op) &&
-  is_union(r->op) && !need_distinct(r) &&
+

MonetDB: default - Merged with Oct2020

2021-02-10 Thread Pedro Ferreira
Changeset: 22e26f2548f2 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=22e26f2548f2
Removed Files:
sql/test/BugTracker-2020/Tests/integers-intervals.Bug-6979.sql
sql/test/SQLancer/Tests/sqlancer11.sql
Modified Files:
clients/mapiclient/dump.c
gdk/gdk_subquery.c
sql/server/rel_exp.c
sql/server/rel_exp.h
sql/server/rel_select.c
sql/test/BugTracker-2020/Tests/integers-intervals.Bug-6979.test
sql/test/SQLancer/Tests/sqlancer11.test
sql/test/testdb-upgrade-hge/Tests/dump.stable.out
sql/test/testdb-upgrade/Tests/dump.stable.out
sql/test/testdb/Tests/dump-nogeom.stable.out
sql/test/testdb/Tests/dump.stable.out
Branch: default
Log Message:

Merged with Oct2020


diffs (truncated from 495 to 300 lines):

diff --git a/clients/mapiclient/dump.c b/clients/mapiclient/dump.c
--- a/clients/mapiclient/dump.c
+++ b/clients/mapiclient/dump.c
@@ -1256,7 +1256,11 @@ describe_table(Mapi mid, const char *sch
goto bailout;
while (mapi_fetch_row(hdl) != 0)
expr = mapi_fetch_field(hdl, 0);
-   mnstr_printf(toConsole, " PARTITION BY %s %s 
(%s)", phow, pusing, expr);
+   mnstr_printf(toConsole, " PARTITION BY %s %s 
(", phow, pusing);
+   if (column)
+   dquoted_print(toConsole, expr, ")");
+   else
+   mnstr_printf(toConsole, "%s)", expr);
mapi_close_handle(hdl);
}
}
diff --git a/gdk/gdk_subquery.c b/gdk/gdk_subquery.c
--- a/gdk/gdk_subquery.c
+++ b/gdk/gdk_subquery.c
@@ -574,7 +574,6 @@ alloc_fail:
ret[gid] = VAL2; \
} else if (is_##TYPE##_nil(vals1[i]) || 
is_##TYPE##_nil(vals2[i])) { \
ret[gid] = bit_nil; \
-   hasnil = 1; \
} else if (vals1[i] == vals2[i]) { \
ret[gid] = VAL1; \
} \
@@ -671,7 +670,6 @@ BATanyequal_grp2(BAT *l, BAT *r, BAT *ri
const void *rv = 
BUNtail(ri, i);
if (ocmp(lv, nilp) == 0 
|| ocmp(rv, nilp) == 0) {
ret[gid] = 
bit_nil;
-   hasnil = 1;
} else if (ocmp(lv, rv) 
== 0)
ret[gid] = TRUE;
}
@@ -680,6 +678,8 @@ BATanyequal_grp2(BAT *l, BAT *r, BAT *ri
}
}
}
+   for (BUN i = 0 ; i < ngrp ; i++)
+   hasnil |= ret[i] == bit_nil;
BATsetcount(res, ngrp);
res->tkey = BATcount(res) <= 1;
res->tsorted = BATcount(res) <= 1;
@@ -790,7 +790,6 @@ BATallnotequal_grp2(BAT *l, BAT *r, BAT 
const void *rv = 
BUNtail(ri, i);
if (ocmp(lv, nilp) == 0 
|| ocmp(rv, nilp) == 0) {
ret[gid] = 
bit_nil;
-   hasnil = 1;
} else if (ocmp(lv, rv) 
== 0)
ret[gid] = 
FALSE;
}
@@ -799,6 +798,8 @@ BATallnotequal_grp2(BAT *l, BAT *r, BAT 
}
}
}
+   for (BUN i = 0 ; i < ngrp ; i++)
+   hasnil |= ret[i] == bit_nil;
BATsetcount(res, ngrp);
res->tkey = BATcount(res) <= 1;
res->tsorted = BATcount(res) <= 1;
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
@@ -228,26 +228,6 @@ exp_or(sql_allocator *sa, list *l, list 
return e;
 }
 
-static int /* if the quantifier has to be upcasted, ignore the upper 
conversion for the cardinalilty */
-quantifier_has_rel(sql_exp *e)
-{
-   if (!e)
-   return 0;
-   switch(e->type){
-   case e_convert:
-   return quantifier_has_rel(e->l);
-   case e_psm:
-   return exp_is_rel(e);
-   case e_atom:
-   case e_column:
-   case e_func:
- 

MonetDB: default - Merged with Oct2020

2021-02-09 Thread Pedro Ferreira
Changeset: b5191e96a368 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=b5191e96a368
Removed Files:
sql/test/SQLancer/Tests/sqlancer07.sql
sql/test/SQLancer/Tests/sqlancer07.stable.err
sql/test/SQLancer/Tests/sqlancer07.stable.err.int128
sql/test/SQLancer/Tests/sqlancer10.sql
Modified Files:
monetdb5/mal/mal_embedded.c
sql/server/rel_select.c
sql/test/prepare/Tests/sqlancer_prepare.sql
sql/test/prepare/Tests/sqlancer_prepare.stable.err
sql/test/prepare/Tests/sqlancer_prepare.stable.err.int128
Branch: default
Log Message:

Merged with Oct2020


diffs (99 lines):

diff --git a/monetdb5/mal/mal_embedded.c b/monetdb5/mal/mal_embedded.c
--- a/monetdb5/mal/mal_embedded.c
+++ b/monetdb5/mal/mal_embedded.c
@@ -120,7 +120,7 @@ malEmbeddedBoot(int workerlimit, int mem
MCcloseClient(c);
return msg;
}
-   char *modules[3] = { "embedded", "sql" };
+   char *modules[5] = { "embedded", "sql", "generator", "udf" };
if ((msg = malIncludeModules(c, modules, 0, !with_mapi_server)) != 
MAL_SUCCEED) {
MCcloseClient(c);
return msg;
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
@@ -1798,7 +1798,7 @@ exp_exist(sql_query *query, sql_rel *rel
return NULL;
} else if (exp_is_rel(le)) { /* for the subquery case, propagate to the 
inner query */
sql_rel *r = exp_rel_get_rel(sql->sa, le);
-   if (is_simple_project(r->op) || is_groupby(r->op)) {
+   if ((is_simple_project(r->op) || is_groupby(r->op)) && 
!list_empty(r->exps)) {
for (node *n = r->exps->h; n; n = n->next)
if (!exp_subtype(n->data) && 
rel_set_type_param(sql, sql_bind_localtype("bit"), r, n->data, 0) < 0) /* 
workaround */
return NULL;
@@ -4069,6 +4069,8 @@ rel_group_column(sql_query *query, sql_r
return NULL;
}
}
+   if (!exp_subtype(e))
+   return sql_error(sql, 01, SQLSTATE(42000) "Cannot have a 
parameter (?) for group by column");
return e;
 }
 
@@ -4421,6 +4423,8 @@ rel_order_by(sql_query *query, sql_rel *
}
if (!e)
return NULL;
+   if (!exp_subtype(e))
+   return sql_error(sql, 01, SQLSTATE(42000) 
"Cannot have a parameter (?) for order by column");
set_direction(e, direction);
list_append(exps, e);
} else {
diff --git a/sql/test/prepare/Tests/sqlancer_prepare.sql 
b/sql/test/prepare/Tests/sqlancer_prepare.sql
--- a/sql/test/prepare/Tests/sqlancer_prepare.sql
+++ b/sql/test/prepare/Tests/sqlancer_prepare.sql
@@ -54,3 +54,7 @@ prepare values (0.34, (values ((select ?
 prepare with cte0(c0) as (select 1), cte1(c0,c1,c2) as (select distinct 1, 2, 
false)
 select distinct least('y', (values (''), (''))), 1, (select ? from (select 1) 
as l1v0(x))
 from cte0 as l0cte0, cte1 as l0cte1 order by l0cte0.c0 desc nulls last, 
l0cte1.c2 desc nulls first; -- ? can't be defined, so error
+
+prepare with cte0(c0) as (select 2) select 1 <> all(select 2 from (values 
(1),(2)) as t1) from cte0 as l0cte0 group by ?; --error, cannot have a 
parameter for group by column
+
+prepare with cte0(c0) as (select 2) select 1 <> all(select 2 from (values 
(1),(2)) as t1) from cte0 as l0cte0 order by ?; --error, cannot have a 
parameter for order by column
diff --git a/sql/test/prepare/Tests/sqlancer_prepare.stable.err 
b/sql/test/prepare/Tests/sqlancer_prepare.stable.err
--- a/sql/test/prepare/Tests/sqlancer_prepare.stable.err
+++ b/sql/test/prepare/Tests/sqlancer_prepare.stable.err
@@ -1,6 +1,6 @@
 MAPI  = (monetdb) /var/tmp/mtest-918314/.s.monetdb.35583
 QUERY = PREPARE SELECT DISTINCT (SELECT DISTINCT r'|m all(select 2 from 
(values (1),(2)) as t1) from cte0 as l0cte0 group by ?; --error, cannot have a 
parameter for group by column
+ERROR = !Cannot have a parameter (?) for group by column
+CODE  = 42000
+MAPI  = (monetdb) /var/tmp/mtest-185783/.s.monetdb.32587
+QUERY = prepare with cte0(c0) as (select 2) select 1 <> all(select 2 from 
(values (1),(2)) as t1) from cte0 as l0cte0 order by ?; --error, cannot have a 
parameter for order by column
+ERROR = !Cannot have a parameter (?) for order by column
+CODE  = 42000
diff --git a/sql/test/prepare/Tests/sqlancer_prepare.stable.err.int128 
b/sql/test/prepare/Tests/sqlancer_prepare.stable.err.int128
--- a/sql/test/prepare/Tests/sqlancer_prepare.stable.err.int128
+++ b/sql/test/prepare/Tests/sqlancer_prepare.stable.err.int128
@@ -1,6 +1,6 @@
 MAPI  = (monetdb) /var/tmp/mtest-918314/.s.monetdb.35583
 QUERY = PREPARE SELECT DISTINCT (SELECT DISTINCT r'|m all(select 2 from 
(values

MonetDB: default - Merged with Oct2020

2021-02-08 Thread Pedro Ferreira
Changeset: 0b72d54e38a2 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=0b72d54e38a2
Removed Files:
sql/test/SQLancer/Tests/sqlancer07.sql
sql/test/SQLancer/Tests/sqlancer07.stable.err
sql/test/SQLancer/Tests/sqlancer07.stable.err.int128
sql/test/SQLancer/Tests/sqlancer07.stable.out
sql/test/SQLancer/Tests/sqlancer07.stable.out.int128
sql/test/SQLancer/Tests/sqlancer10.sql
Modified Files:
sql/server/rel_exp.c
sql/server/rel_optimizer.c
sql/server/rel_select.c
sql/server/rel_unnest.c
sql/test/SQLancer/Tests/sqlancer07.test
sql/test/prepare/Tests/sqlancer_prepare.sql
sql/test/prepare/Tests/sqlancer_prepare.stable.err
sql/test/prepare/Tests/sqlancer_prepare.stable.err.int128
sql/test/prepare/Tests/sqlancer_prepare.stable.out
sql/test/prepare/Tests/sqlancer_prepare.stable.out.int128
Branch: default
Log Message:

Merged with Oct2020


diffs (204 lines):

diff --git a/NT/mkodbcwxs.py b/NT/mkodbcwxs.py
--- a/NT/mkodbcwxs.py
+++ b/NT/mkodbcwxs.py
@@ -84,6 +84,8 @@ def main():
vcpkg.format(r'bin\bz2.dll'),
vcpkg.format(r'bin\charset-1.dll'), # for iconv-2.dll
vcpkg.format(r'bin\libcrypto-1_1{}.dll'.format(libcrypto)),
+   vcpkg.format(r'bin\lz4.dll'),
+   vcpkg.format(r'bin\lzma.dll'),
vcpkg.format(r'bin\zlib1.dll')])
 print(r'')
 id = comp(features, id, 12,
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
@@ -3048,21 +3048,30 @@ exp_set_list_recurse(mvc *sql, sql_subty
if (!e)
return 0;
 
-   assert(e->type == e_atom);
-   if (e->f) {
-   const char *next_rel = exp_relname(e), *next_exp = exp_name(e);
-   if (next_rel && next_exp && !strcmp(next_rel, *relname) && 
!strcmp(next_exp, *expname))
-   for (node *n = ((list *) e->f)->h; n; n = n->next)
+   if (exp_is_rel(e)) {
+   /* Try to set parameters on the list of projections of the 
subquery. For now I won't go any further, ugh */
+   sql_rel *r = exp_rel_get_rel(sql->sa, e);
+   if ((is_simple_project(r->op) || is_groupby(r->op)) && 
list_length(r->exps) == 1) {
+   for (node *n = r->exps->h; n; n = n->next)
if (exp_set_list_recurse(sql, type, (sql_exp *) 
n->data, relname, expname) < 0)
return -1;
-   }
-   if (e->f && !e->tpe.type) {
-   e->tpe = *type;
-   } else if (!e->l && !e->r && !e->f && !e->tpe.type) {
-   if (set_type_param(sql, type, e->flag) == 0)
+   }
+   } else if (e->type == e_atom) {
+   if (e->f) {
+   const char *next_rel = exp_relname(e), *next_exp = 
exp_name(e);
+   if (next_rel && next_exp && !strcmp(next_rel, *relname) 
&& !strcmp(next_exp, *expname))
+   for (node *n = ((list *) e->f)->h; n; n = 
n->next)
+   if (exp_set_list_recurse(sql, type, 
(sql_exp *) n->data, relname, expname) < 0)
+   return -1;
+   }
+   if (e->f && !e->tpe.type) {
e->tpe = *type;
-   else
-   return -1;
+   } else if (!e->l && !e->r && !e->f && !e->tpe.type) {
+   if (set_type_param(sql, type, e->flag) == 0)
+   e->tpe = *type;
+   else
+   return -1;
+   }
}
return 0;
 }
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
@@ -5711,7 +5711,7 @@ rel_groupby_order(visitor *v, sql_rel *r
if (ngbe - i > 1) {
for (int j = i; j < ngbe; j++) {
sql_subtype *t = exp_subtype(exps[j]);
-   scores[j] = t->digits;
+   scores[j] = t ? t->digits : 0;
}
/* the less number of digits the better, order 
ascending */
GDKqsort(scores + i, exps + i, NULL, ngbe - i, 
sizeof(int), sizeof(void *), TYPE_int, false, true);
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
@@ -1794,8 +1794,16 @@ exp_exist(sql_query *query, sql_rel *rel
 
if (!exp_name(le))
exp_label(sql->sa, le, ++sql->label);
-   if (!exp_subtype(le) && rel_set_type_param(sql, 
sql_bind_localtype("bit"), rel, le, 0) < 0) /* workaround */
+   if (!exp_subtype(le) && rel_set_type_param(sql, 
sql_bind_lo

MonetDB: default - merged with oct2020

2021-02-06 Thread Niels Nes
Changeset: 7aa66655a794 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=7aa66655a794
Modified Files:
monetdb5/optimizer/opt_mergetable.c
Branch: default
Log Message:

merged with oct2020


diffs (259 lines):

diff --git a/monetdb5/optimizer/opt_mergetable.c 
b/monetdb5/optimizer/opt_mergetable.c
--- a/monetdb5/optimizer/opt_mergetable.c
+++ b/monetdb5/optimizer/opt_mergetable.c
@@ -473,15 +473,31 @@ mat_apply1(MalBlkPtr mb, InstrPtr p, mat
 }
 
 static int
-mat_apply2(matlist_t *ml, MalBlkPtr mb, InstrPtr p, mat_t *mat, int m, int n, 
int mvar, int nvar)
+mat_apply(MalBlkPtr mb, InstrPtr p, matlist_t *ml, int nrmats)
 {
-   int k, l, is_select = isSelect(p);
+   int matvar[8], fargument[8], k, l, parts = 0;
+
+   assert(nrmats <= 8);
+
+   for(k=p->retc, l=0; k < p->argc; k++) {
+   int mv = is_a_mat(getArg(p,k), ml);
+   if (mv >=0) {
+   matvar[l] = mv;
+   fargument[l] = k;
+   l++;
+   if (parts==0)
+   parts = ml->v[mv].mi->argc;
+   if (parts != ml->v[mv].mi->argc)
+   return -1;
+   }
+   }
+
InstrPtr *r = NULL;
r = (InstrPtr*) GDKmalloc(sizeof(InstrPtr)* p->retc);
if(!r)
return -1;
for(k=0; k < p->retc; k++) {
-   if((r[k] = newInstructionArgs(mb, matRef, packRef, 
mat[m].mi->argc)) == NULL) {
+   if((r[k] = newInstructionArgs(mb, matRef, packRef, parts)) == 
NULL) {
for(l=0; l < k; l++)
freeInstruction(r[l]);
GDKfree(r);
@@ -490,7 +506,7 @@ mat_apply2(matlist_t *ml, MalBlkPtr mb, 
getArg(r[k],0) = getArg(p,k);
}
 
-   for(k=1; k < mat[m].mi->argc; k++) {
+   for(k = 1; k < ml->v[matvar[0]].mi->argc; k++) {
int tpe;
InstrPtr q = copyInstruction(p);
if(!q) {
@@ -502,70 +518,8 @@ mat_apply2(matlist_t *ml, MalBlkPtr mb, 
tpe = getArgType(mb,p,l);
getArg(q, l) = newTmpVariable(mb, tpe);
}
-   getArg(q, mvar) = getArg(mat[m].mi, k);
-   getArg(q, nvar) = getArg(mat[n].mi, k);
-   pushInstruction(mb, q);
-   for(l=0; l < p->retc; l++) {
-   int res = 0;
-   if (is_select)
-   res = propagatePartnr(ml, getArg(q,p->retc+1), 
getArg(q,l), k);
-   else
-   res = propagatePartnr(ml, -1, getArg(q,l), k);
-   if(res) {
-   for(l=0; l < k; l++)
-   freeInstruction(r[l]);
-   GDKfree(r);
-   return -1;
-   }
-   r[l] = addArgument(mb, r[l], getArg(q, l));
-   }
-   }
-
-   for(k=0; k < p->retc; k++) {
-   if(mat_add_var(ml, r[k], NULL, getArg(r[k], 0), mat_type(ml->v, 
m),  -1, -1, 0)) {
-   for(l=0; l < k; l++)
-   freeInstruction(r[l]);
-   GDKfree(r);
-   return -1;
-   }
-   }
-   GDKfree(r);
-   return 0;
-}
-
-static int
-mat_apply3(MalBlkPtr mb, InstrPtr p, matlist_t *ml, int m, int n, int o, int 
mvar, int nvar, int ovar)
-{
-   int k, l;
-   InstrPtr *r = NULL;
-   r = (InstrPtr*) GDKmalloc(sizeof(InstrPtr)* p->retc);
-   if(!r)
-   return -1;
-   for(k=0; k < p->retc; k++) {
-   if((r[k] = newInstructionArgs(mb, matRef, packRef, 
ml->v[m].mi->argc)) == NULL) {
-   for(l=0; l < k; l++)
-   freeInstruction(r[l]);
-   GDKfree(r);
-   return -1;
-   }
-   getArg(r[k],0) = getArg(p,k);
-   }
-
-   for(k = 1; k < ml->v[m].mi->argc; k++) {
-   int tpe;
-   InstrPtr q = copyInstruction(p);
-   if(!q) {
-   GDKfree(r);
-   return -1;
-   }
-
-   for(l=0; l < p->retc; l++) {
-   tpe = getArgType(mb,p,l);
-   getArg(q, l) = newTmpVariable(mb, tpe);
-   }
-   getArg(q, mvar) = getArg(ml->v[m].mi, k);
-   getArg(q, nvar) = getArg(ml->v[n].mi, k);
-   getArg(q, ovar) = getArg(ml->v[o].mi, k);
+   for (l = 0; lv[matvar[l]].mi, 
k);
pushInstruction(mb, q);
for(l=0; l < p->retc; l++) {
if(setPartnr(ml, -1, getArg(q,l), k)) {
@@ -578,7 +532,7 @@ mat_apply3(MalBlkPtr mb, InstrPtr p, mat

MonetDB: default - Merged with Oct2020

2021-02-05 Thread Pedro Ferreira
Changeset: c08c6c533e87 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=c08c6c533e87
Modified Files:
sql/server/rel_unnest.c
Branch: default
Log Message:

Merged with Oct2020


diffs (29 lines):

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
@@ -3409,6 +3409,25 @@ rewrite_values(visitor *v, sql_rel *rel)
if (rel_is_ref(rel)) { /* need extra project */
rel->l = rel_project(v->sql->sa, rel->l, rel->exps);
rel->exps = rel_projections(v->sql, rel->l, NULL, 1, 1);
+   if (!list_empty(rel->r)) { /* propagate order by exps */
+   list *nexps = sa_list(v->sql->sa);
+   for (node *en = ((list*)rel->r)->h; en; en = en->next) {
+   sql_exp *e = en->data, *ne = 
exps_find_exp(((sql_rel*)rel->l)->exps, e);
+
+   assert(ne);
+   ne = exp_ref(v->sql, ne);
+   if (is_ascending(e))
+   set_ascending(ne);
+   else
+   set_descending(ne);
+   if (nulls_last(e))
+   set_nulls_last(ne);
+   else
+   set_nulls_first(ne);
+   list_append(nexps, ne);
+   }
+   rel->r = nexps;
+   }
return rel;
}
sql_exp *e = rel->exps->h->data;
___
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list


MonetDB: default - Merged with Oct2020

2021-02-05 Thread Pedro Ferreira
Changeset: afbe79587c5b for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=afbe79587c5b
Removed Files:
sql/test/SQLancer/Tests/sqlancer09.sql
sql/test/SQLancer/Tests/sqlancer10.sql
Modified Files:
sql/common/sql_types.c
sql/server/sql_semantic.c
sql/test/BugTracker-2019/Tests/outer-join-varchar.Bug-6776.test
sql/test/SQLancer/Tests/sqlancer09.test
sql/test/SQLancer/Tests/sqlancer10.test
sql/test/subquery/Tests/subquery6.test
Branch: default
Log Message:

Merged with Oct2020


diffs (truncated from 364 to 300 lines):

diff --git a/sql/common/sql_types.c b/sql/common/sql_types.c
--- a/sql/common/sql_types.c
+++ b/sql/common/sql_types.c
@@ -505,7 +505,7 @@ sql_dup_subfunc(sql_allocator *sa, sql_f
} else if (r->scale)
scale = r->scale;
}
-   if (member && f->fix_scale == INOUT)
+   if (member && (f->fix_scale == INOUT || 
r->type->eclass == EC_ANY))
digits = member->digits;
if (IS_ANALYTIC(f) && mscale)
scale = mscale;
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
@@ -266,8 +266,10 @@ static sql_subfunc *
scale = member->scale;
}
/* same type as the input */
-   if (r->type->eclass == EC_ANY && member)
+   if (r->type->eclass == EC_ANY && member) {
r = member;
+   digits = member->digits;
+   }
if (!EC_SCALE(r->type->eclass))
scale = 0;
res = sql_create_subtype(sa, r->type, digits, scale);
@@ -955,14 +957,14 @@ result_datatype(sql_subtype *super, sql_
char *tpe = "varchar";
unsigned int digits = 0;
if (!EC_VARCHAR(lclass)) {
-   tpe = r->type->sqlname;
-   digits = (!l->digits)?0:r->digits;
+   tpe = r->type->sqlname;
+   digits = (!l->digits)?0:r->digits;
} else if (!EC_VARCHAR(rclass)) {
-   tpe = l->type->sqlname;
-   digits = (!r->digits)?0:l->digits;
+   tpe = l->type->sqlname;
+   digits = (!r->digits)?0:l->digits;
} else { /* both */
-   tpe = (l->type->base.id > 
r->type->base.id)?l->type->sqlname:r->type->sqlname;
-   digits = 
(!l->digits||!r->digits)?0:sql_max(l->digits, r->digits);
+   tpe = (l->type->base.id > 
r->type->base.id)?l->type->sqlname:r->type->sqlname;
+   digits = (!l->digits||!r->digits)?0:sql_max(l->digits, 
r->digits);
}
sql_find_subtype(super, tpe, digits, 0);
/* case b blob */
@@ -976,30 +978,38 @@ result_datatype(sql_subtype *super, sql_
char *tpe = (l->type->base.id > 
r->type->base.id)?l->type->sqlname:r->type->sqlname;
unsigned int digits = sql_max(l->digits, r->digits);
unsigned int scale = sql_max(l->scale, r->scale);
-   if (l->type->radix == 10 || r->type->radix == 10) {
-   digits = 0;
-   /* change to radix 10 */
-   if (l->type->radix == 2 && r->type->radix == 10) {
-   digits = bits2digits(l->type->digits);
-   digits = sql_max(r->digits, digits);
-   scale = r->scale;
-   } else if (l->type->radix == 10 && r->type->radix == 2) 
{
-   digits = bits2digits(r->type->digits);
-   digits = sql_max(l->digits, digits);
-   scale = l->scale;
+
+   if (l->type->radix == 10 && r->type->radix == 10) {
+   digits = scale + (sql_max(l->digits - l->scale, 
r->digits - r->scale));
+#ifdef HAVE_HGE
+   if (digits > 39) {
+   digits = 39;
+#else
+   if (digits > 19) {
+   digits = 19;
+#endif
+   scale = MIN(scale, digits - 1);
}
+   } else if (l->type->radix == 2 && r->type->radix == 10) { /* 
change to radix 10 */
+   digits = bits2digits(l->type->digits);
+   digits = sql_max(r->digits, digits);
+   scale = r->scale;
+   } else if (l->type->radix == 10 && r->type->radix == 2) { /* 
ch

MonetDB: default - Merged with Oct2020

2021-02-04 Thread Pedro Ferreira
Changeset: bf49a29af207 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=bf49a29af207
Removed Files:
sql/test/SQLancer/Tests/sqlancer11.sql
Modified Files:
gdk/gdk_utils.c
sql/backends/monet5/rel_bin.c
sql/server/rel_dump.c
sql/server/rel_unnest.c
sql/test/SQLancer/Tests/sqlancer04.test
sql/test/SQLancer/Tests/sqlancer11.test
Branch: default
Log Message:

Merged with Oct2020


diffs (truncated from 432 to 300 lines):

diff --git a/gdk/gdk_utils.c b/gdk/gdk_utils.c
--- a/gdk/gdk_utils.c
+++ b/gdk/gdk_utils.c
@@ -851,13 +851,19 @@ gdk_return
 GDKinit(opt *set, int setlen, bool embedded)
 {
static bool first = true;
-   const char *dbpath = mo_find_option(set, setlen, "gdk_dbpath");
-   const char *dbtrace = mo_find_option(set, setlen, "gdk_dbtrace");
+   const char *dbpath;
+   const char *dbtrace;
const char *p;
opt *n;
int i, nlen = 0;
char buf[16];
 
+   if (GDKinmemory(0)) {
+   dbpath = dbtrace = NULL;
+   } else {
+   dbpath = mo_find_option(set, setlen, "gdk_dbpath");
+   dbtrace = mo_find_option(set, setlen, "gdk_dbtrace");
+   }
Mbedded = embedded;
/* some sanity checks (should also find if symbols are not defined) */
static_assert(sizeof(int) == sizeof(int32_t),
diff --git a/sql/backends/monet5/rel_bin.c b/sql/backends/monet5/rel_bin.c
--- a/sql/backends/monet5/rel_bin.c
+++ b/sql/backends/monet5/rel_bin.c
@@ -4060,7 +4060,7 @@ first_updated_col(stmt **updates, int cn
 }
 
 static stmt *
-update_check_ukey(backend *be, stmt **updates, sql_key *k, stmt *tids, stmt 
*idx_updates, int updcol)
+update_check_ukey(backend *be, stmt **updates, sql_key *k, stmt *u_tids, stmt 
*idx_updates, int updcol)
 {
mvc *sql = be->mvc;
char *msg = NULL;
@@ -4071,7 +4071,6 @@ update_check_ukey(backend *be, stmt **up
sql_subtype *bt = sql_bind_localtype("bit");
sql_subfunc *ne;
 
-   (void)tids;
ne = sql_bind_func_result(sql, "sys", "<>", F_FUNC, bt, 2, lng, lng);
if (list_length(k->columns) > 1) {
stmt *dels = stmt_tid(be, k->t, 0);
@@ -4084,7 +4083,7 @@ update_check_ukey(backend *be, stmt **up
should be zero)
*/
if (!isNew(k)) {
-   stmt *nu_tids = stmt_tdiff(be, dels, tids, NULL); /* 
not updated ids */
+   stmt *nu_tids = stmt_tdiff(be, dels, u_tids, NULL); /* 
not updated ids */
list *lje = sa_list(sql->sa);
list *rje = sa_list(sql->sa);
 
@@ -4100,7 +4099,7 @@ update_check_ukey(backend *be, stmt **up
if (updates[c->c->colnr]) {
upd = updates[c->c->colnr];
} else {
-   upd = stmt_project(be, tids, 
stmt_col(be, c->c, dels, dels->partition));
+   upd = stmt_col(be, c->c, u_tids, 
u_tids->partition);
}
list_append(lje, stmt_col(be, c->c, nu_tids, 
nu_tids->partition));
list_append(rje, upd);
@@ -4197,7 +4196,7 @@ update_check_ukey(backend *be, stmt **up
 
/* s should be empty */
if (!isNew(k)) {
-   stmt *nu_tids = stmt_tdiff(be, dels, tids, NULL); /* 
not updated ids */
+   stmt *nu_tids = stmt_tdiff(be, dels, u_tids, NULL); /* 
not updated ids */
assert (updates);
 
h = updates[c->c->colnr];
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
@@ -731,7 +731,7 @@ convertIdent(char *r)
r[j++] = r[i++];
}
}
-   r[i] = '\0';
+   r[j] = '\0';
 }
 
 static void
@@ -786,8 +786,8 @@ readString( char *r, int *pos)
 
 static sql_exp* exp_read(mvc *sql, sql_rel *lrel, sql_rel *rrel, list 
*top_exps, char *r, int *pos, int grp) ;
 
-static void *
-read_prop( mvc *sql, sql_exp *exp, char *r, int *pos)
+static sql_exp*
+read_prop(mvc *sql, sql_exp *exp, char *r, int *pos, bool *found)
 {
/* PROPs */
if (strncmp(r+*pos, "JOINIDX",  strlen("JOINIDX")) == 0) {
@@ -825,6 +825,8 @@ read_prop( mvc *sql, sql_exp *exp, char 
return sql_error(sql, -1, SQLSTATE(42000) 
"Index %s missing\n", iname);
}
skipWS(r,pos);
+   if (found)
+   *found = true;
}
return exp;
 }
@@ -851,7 +853,7 @@ read_exps(mvc *sql, sql_rel *lrel, sql_r
}
append(exps, e);
skipWS( r, pos);
-   if (!read_prop(sql, e, r, pos))
+   if (!read_prop(sql, e, r, pos, N

MonetDB: default - Merged with Oct2020

2021-02-04 Thread Pedro Ferreira
Changeset: 838a69a96c86 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=838a69a96c86
Removed Files:
sql/test/BugTracker-2013/Tests/duplicate_column_name.Bug-3349.sql

sql/test/BugTracker-2019/Tests/disallow_duplicate_column_aliases.Bug-6723.sql
sql/test/miscellaneous/Tests/simple_selects.sql
Modified Files:
sql/backends/monet5/rel_bin.c
sql/backends/monet5/sql_cat.c
sql/backends/monet5/sql_gencode.c
sql/backends/monet5/sql_scenario.c
sql/server/rel_select.c
sql/test/BugTracker-2013/Tests/duplicate_column_name.Bug-3349.test

sql/test/BugTracker-2019/Tests/disallow_duplicate_column_aliases.Bug-6723.test
sql/test/miscellaneous/Tests/simple_selects.test
Branch: default
Log Message:

Merged with Oct2020


diffs (truncated from 324 to 300 lines):

diff --git a/sql/backends/monet5/rel_bin.c b/sql/backends/monet5/rel_bin.c
--- a/sql/backends/monet5/rel_bin.c
+++ b/sql/backends/monet5/rel_bin.c
@@ -2740,7 +2740,7 @@ rel2bin_semijoin(backend *be, sql_rel *r
const char *rnme = table_name(sql->sa, c);
const char *nme = column_name(sql->sa, c);
 
-   if (l_is_base && nme[0] == '%' && strcmp(nme, TID) == 0)
+   if (semijoin_only && l_is_base && nme[0] == '%' && strcmp(nme, 
TID) == 0)
s = join;
else
s = stmt_project(be, join, column(be, c));
diff --git a/sql/backends/monet5/sql_cat.c b/sql/backends/monet5/sql_cat.c
--- a/sql/backends/monet5/sql_cat.c
+++ b/sql/backends/monet5/sql_cat.c
@@ -788,12 +788,13 @@ create_func(mvc *sql, char *sname, char 
 
FUNC_TYPE_STR(f->type, F, fn)
 
-   (void) fname;
(void) fn;
if (!(s = mvc_bind_schema(sql, sname)))
throw(SQL,"sql.create_func", SQLSTATE(3F000) "CREATE %s: no 
such schema '%s'", F, sname);
if (!mvc_schema_privs(sql, s))
throw(SQL,"sql.create_func", SQLSTATE(42000) "CREATE %s: access 
denied for %s to schema '%s'", F, get_string_global_var(sql, "current_user"), 
s->base.name);
+   if (strlen(fname) >= IDLENGTH)
+   throw(SQL,"sql.create_func", SQLSTATE(42000) "CREATE %s: name 
'%s' too large for the backend", F, fname);
nf = mvc_create_func(sql, NULL, s, f->base.name, f->ops, f->res, 
f->type, f->lang, f->mod, f->imp, f->query, f->varres, f->vararg, f->system);
assert(nf);
switch (nf->lang) {
diff --git a/sql/backends/monet5/sql_gencode.c 
b/sql/backends/monet5/sql_gencode.c
--- a/sql/backends/monet5/sql_gencode.c
+++ b/sql/backends/monet5/sql_gencode.c
@@ -141,6 +141,14 @@ static int
int res = 0;
str msg = MAL_SUCCEED;
 
+   if (strlen(mod) >= IDLENGTH) {
+   (void) sql_error(m, 02, SQLSTATE(42000) "Module name '%s' too 
large for the backend", mod);
+   return -1;
+   }
+   if (strlen(name) >= IDLENGTH) {
+   (void) sql_error(m, 02, SQLSTATE(42000) "Function name '%s' too 
large for the backend", name);
+   return -1;
+   }
backup = c->curprg;
curPrg = c->curprg = newFunction(putName(mod), putName(name), 
FUNCTIONsymbol);
if( curPrg == NULL) {
@@ -181,7 +189,10 @@ static int
sql_error(m, 001, SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
return -1;
}
-   varid = newVariable(curBlk, buf, strlen(buf), type);
+   if ((varid = newVariable(curBlk, buf, strlen(buf), 
type)) < 0) {
+   sql_error(m, 003, SQLSTATE(42000) "Internal 
error while compiling statement: variable id too long");
+   return -1;
+   }
curInstr = pushArgument(curBlk, curInstr, varid);
setVarType(curBlk, varid, type);
}
@@ -209,7 +220,10 @@ static int
sql_error(m, 001, SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
return -1;
}
-   varid = newVariable(curBlk, (char *)buf, strlen(buf), 
type);
+   if ((varid = newVariable(curBlk, (char *)buf, 
strlen(buf), type)) < 0) {
+   sql_error(m, 003, SQLSTATE(42000) "Internal 
error while compiling statement: variable id too long");
+   return -1;
+   }
curInstr = pushArgument(curBlk, curInstr, varid);
setVarType(curBlk, varid, type);
}
@@ -306,6 +320,14 @@ static int
sql_error(m, 003, SQLSTATE(42000) "Missing property on the 
input relation");
return -1;
}
+   if (strlen(mod) >= IDLENGTH) {
+   sql_error(m, 003, SQLSTATE(42000) "Module name '%s' too large 
for the backend", 

MonetDB: default - Merged with Oct2020

2021-02-03 Thread Pedro Ferreira
Changeset: 553eb6be7d4b for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=553eb6be7d4b
Removed Files:
sql/test/SQLancer/Tests/sqlancer07.sql
sql/test/SQLancer/Tests/sqlancer10.sql
sql/test/SQLancer/Tests/sqlancer11.sql
Modified Files:
sql/server/rel_optimizer.c
sql/server/rel_updates.c
sql/test/SQLancer/Tests/sqlancer07.test
sql/test/SQLancer/Tests/sqlancer10.test
sql/test/SQLancer/Tests/sqlancer11.test
Branch: default
Log Message:

Merged with Oct2020


diffs (269 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
@@ -1365,10 +1365,8 @@ can_push_func(sql_exp *e, sql_rel *rel, 
} else {
int mustl = 0, mustr = 0, mustf = 0;
return ((l->type == e_column || can_push_func(l, rel, 
&mustl, depth + 1)) && (*must = mustl)) ||
-   (!f && (r->type == e_column || 
can_push_func(r, rel, &mustr, depth + 1)) && (*must = mustr)) ||
-   (f &&
-   (r->type == e_column || 
can_push_func(r, rel, &mustr, depth + 1)) &&
-   (f->type == e_column || can_push_func(f, rel, 
&mustf, depth + 1)) && (*must = (mustr || mustf)));
+   ((r->type == e_column || 
can_push_func(r, rel, &mustr, depth + 1)) && (*must = mustr)) ||
+   ((f && (f->type == e_column || 
can_push_func(f, rel, &mustf, depth + 1)) && (*must = mustf)));
}
}
case e_convert:
diff --git a/sql/server/rel_updates.c b/sql/server/rel_updates.c
--- a/sql/server/rel_updates.c
+++ b/sql/server/rel_updates.c
@@ -68,15 +68,6 @@ get_table(sql_rel *t)
return tab;
 }
 
-static list *
-get_inserts( sql_rel *ins )
-{
-   sql_rel *r = ins->r;
-
-   assert(is_project(r->op) || r->op == op_table);
-   return r->exps;
-}
-
 static sql_rel *
 rel_insert_hash_idx(mvc *sql, const char* alias, sql_idx *i, sql_rel *inserts)
 {
@@ -85,10 +76,13 @@ rel_insert_hash_idx(mvc *sql, const char
sql_subtype *it, *lng;
int bits = 1 + ((sizeof(lng)*8)-1)/(list_length(i->columns)+1);
sql_exp *h = NULL;
+   sql_rel *ins = inserts->r;
 
+   assert(is_project(ins->op) || ins->op == op_table);
if (list_length(i->columns) <= 1 || i->type == no_idx) {
/* dummy append */
-   append(get_inserts(inserts), exp_label(sql->sa, 
exp_atom_lng(sql->sa, 0), ++sql->label));
+   inserts->r = ins = rel_project(sql->sa, ins, 
rel_projections(sql, ins, NULL, 1, 1));
+   list_append(ins->exps, exp_label(sql->sa, exp_atom_lng(sql->sa, 
0), ++sql->label));
return inserts;
}
 
@@ -96,7 +90,7 @@ rel_insert_hash_idx(mvc *sql, const char
lng = sql_bind_localtype("lng");
for (m = i->columns->h; m; m = m->next) {
sql_kc *c = m->data;
-   sql_exp *e = list_fetch(get_inserts(inserts), c->c->colnr);
+   sql_exp *e = list_fetch(ins->exps, c->c->colnr);
e = exp_ref(sql, e);
 
if (h && i->type == hash_idx)  {
@@ -124,7 +118,8 @@ rel_insert_hash_idx(mvc *sql, const char
}
}
/* append inserts to hash */
-   append(get_inserts(inserts), h);
+   inserts->r = ins = rel_project(sql->sa, ins, rel_projections(sql, ins, 
NULL, 1, 1));
+   list_append(ins->exps, h);
exp_setname(sql->sa, h, alias, iname);
return inserts;
 }
@@ -145,6 +140,7 @@ rel_insert_join_idx(mvc *sql, const char
sql_exp *lnll_exps = NULL, *rnll_exps = NULL, *e;
list *join_exps = new_exp_list(sql->sa), *pexps;
 
+   assert(is_project(ins->op) || ins->op == op_table);
for (m = i->columns->h; m; m = m->next) {
sql_kc *c = m->data;
 
@@ -218,7 +214,6 @@ static sql_rel *
 rel_insert_idxs(mvc *sql, sql_table *t, const char* alias, sql_rel *inserts)
 {
sql_rel *p = inserts->r;
-   bool need_proj = true, special_insert = false;
 
if (!t->idxs.set)
return inserts;
@@ -226,23 +221,14 @@ rel_insert_idxs(mvc *sql, sql_table *t, 
inserts->r = rel_label(sql, inserts->r, 1);
for (node *n = t->idxs.set->h; n; n = n->next) {
sql_idx *i = n->data;
-   sql_rel *ins = inserts->r;
 
-   if (is_union(ins->op))
-   inserts->r = rel_project(sql->sa, ins, 
rel_projections(sql, ins, NULL, 0, 1));
if (hash_index(i->type) || i->type == no_idx) {
-   /* needs projection for hash functions */
-   if (list_length(i->columns) > 1 && hash_index(i->type) 
&& need_proj) {
-   inserts->r = rel_project(sql->sa, inserts->r, 
rel_projecti

MonetDB: default - Merged with Oct2020

2021-02-02 Thread Pedro Ferreira
Changeset: a4fc114bb5f7 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=a4fc114bb5f7
Modified Files:
monetdb5/mal/mal_authorize.c
sql/backends/monet5/rel_bin.c
sql/server/rel_exp.c
sql/server/rel_optimizer.c
sql/server/sql_atom.c
tools/mserver/mserver5.c
Branch: default
Log Message:

Merged with Oct2020


diffs (truncated from 419 to 300 lines):

diff --git a/monetdb5/optimizer/opt_pushselect.c 
b/monetdb5/optimizer/opt_pushselect.c
--- a/monetdb5/optimizer/opt_pushselect.c
+++ b/monetdb5/optimizer/opt_pushselect.c
@@ -132,6 +132,8 @@ no_updates(InstrPtr *old, int *vars, int
return 1;
 }
 
+#define isIntersect(p) (getModuleId(p) == algebraRef && getFunctionId(p) == 
intersectRef)
+
 str
 OPTpushselectImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, 
InstrPtr pci)
 {
@@ -169,7 +171,7 @@ OPTpushselectImplementation(Client cntxt
}
 
if (getModuleId(p) == algebraRef &&
-   (getFunctionId(p) == intersectRef ||
+   ((!no_mito && getFunctionId(p) == intersectRef) ||
 getFunctionId(p) == differenceRef)) {
GDKfree(vars);
goto wrapup;
@@ -181,6 +183,9 @@ OPTpushselectImplementation(Client cntxt
if (isLikeOp(p))
nr_likes++;
 
+   if (no_mito && isIntersect(p))
+   push_down_delta++;
+
if ((getModuleId(p) == sqlRef && getFunctionId(p) == deltaRef) 
||
(no_mito && getModuleId(p) == matRef && 
getFunctionId(p) == packRef && p->argc == (p->retc+2)))
push_down_delta++;
@@ -804,6 +809,74 @@ OPTpushselectImplementation(Client cntxt
oclean[i] = 1;
actions++;
}
+   } else if (isIntersect(p) && p->retc == 1 && lastbat == 4) {
+   /* c = delta(b, uid, uvl, ins)
+* s = intersect(l, r, li, ..)
+*
+* nc = intersect(b, r, li..)
+* ni = intersect(ins, r, li..)
+* nu = intersect(uvl, r, ..)
+* s = subdelta(nc, uid, nu, ni);
+*/
+   int var = getArg(p, 1);
+   InstrPtr q = old[vars[var]];
+
+   if (q && q->token == ASSIGNsymbol) {
+   var = getArg(q, 1);
+   q = old[vars[var]];
+   }
+   if (q && getModuleId(q) == sqlRef && getFunctionId(q) 
== deltaRef) {
+   InstrPtr r = copyInstruction(p);
+   InstrPtr s = copyInstruction(p);
+   InstrPtr t = copyInstruction(p);
+   InstrPtr u = copyInstruction(q);
+
+   if( r == NULL || s == NULL || t== NULL ||u == 
NULL){
+   freeInstruction(r);
+   freeInstruction(s);
+   freeInstruction(t);
+   freeInstruction(u);
+   GDKfree(vars);
+   GDKfree(nvars);
+   GDKfree(slices);
+   GDKfree(rslices);
+   GDKfree(oclean);
+   GDKfree(old);
+   throw(MAL,"optimizer.pushselect", 
SQLSTATE(HY013) MAL_MALLOC_FAIL);
+   }
+   getArg(r, 0) = newTmpVariable(mb, 
newBatType(TYPE_oid));
+   setVarCList(mb,getArg(r,0));
+   getArg(r, 1) = getArg(q, 1); /* column */
+   r->typechk = TYPE_UNKNOWN;
+   pushInstruction(mb,r);
+   getArg(s, 0) = newTmpVariable(mb, 
newBatType(TYPE_oid));
+   setVarCList(mb,getArg(s,0));
+   getArg(s, 1) = getArg(q, 3); /* updates */
+   s = ReplaceWithNil(mb, s, 3, TYPE_bat); /* no 
candidate list */
+   setArgType(mb, s, 3, newBatType(TYPE_oid));
+   /* make sure to resolve again */
+   s->token = ASSIGNsymbol;
+   s->typechk = TYPE_UNKNOWN;
+   s->fcn = NULL;
+   s->blk = NULL;
+   pushInstruction(mb,s);
+   getArg(t, 0) = newTmpVariable(mb, 
newBatType(TYPE_oid));
+   setVarCList(mb,getArg(t,0));
+ 

MonetDB: default - Merged with Oct2020

2021-01-27 Thread Pedro Ferreira
Changeset: 71da2e9b2bfb for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=71da2e9b2bfb
Added Files:
sql/test/SQLancer/Tests/sqlancer11.test
Removed Files:
sql/test/SQLancer/Tests/sqlancer01.sql
sql/test/SQLancer/Tests/sqlancer10.sql
sql/test/SQLancer/Tests/sqlancer11.sql
sql/test/SQLancer/Tests/sqlancer11.stable.err
sql/test/SQLancer/Tests/sqlancer11.stable.out
Modified Files:
sql/backends/monet5/rel_bin.c
sql/server/rel_optimizer.c
sql/server/rel_select.c
sql/test/SQLancer/Tests/sqlancer01.test
sql/test/SQLancer/Tests/sqlancer10.test
Branch: default
Log Message:

Merged with Oct2020


diffs (truncated from 539 to 300 lines):

diff --git a/sql/backends/monet5/rel_bin.c b/sql/backends/monet5/rel_bin.c
--- a/sql/backends/monet5/rel_bin.c
+++ b/sql/backends/monet5/rel_bin.c
@@ -3312,7 +3312,6 @@ rel2bin_select(backend *be, sql_rel *rel
if ((p=find_prop(e->p, PROP_HASHCOL)) != NULL) {
sql_idx *i = p->value;
 
-   assert(0);
sel = rel2bin_hash_lookup(be, rel, sub, NULL, i, en);
}
}
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
@@ -591,10 +591,10 @@ matching_joins(sql_allocator *sa, list *
 }
 
 static int
-sql_kc_column_cmp(sql_kc *kc, sql_column *c)
+sql_column_kc_cmp(sql_column *c, sql_kc *kc)
 {
/* return on equality */
-   return (kc->c->colnr - c->colnr);
+   return (c->colnr - kc->c->colnr);
 }
 
 static sql_idx *
@@ -606,11 +606,11 @@ find_fk_index(sql_table *l, list *lcols,
sql_idx *li = in->data;
if (li->type == join_idx) {
sql_key *rk = &((sql_fkey*)li->key)->rkey->k;
-   fcmp cmp = (fcmp)&sql_kc_column_cmp;
+   fcmp cmp = (fcmp)&sql_column_kc_cmp;
 
if (rk->t == r &&
-   list_match(li->columns, lcols, cmp) == 
0 &&
-   list_match(rk->columns, rcols, cmp) == 
0) {
+   list_match(lcols, li->columns, cmp) == 
0 &&
+   list_match(rcols, rk->columns, cmp) == 
0) {
return li;
}
}
@@ -1346,23 +1346,33 @@ exp_rename(mvc *sql, sql_exp *e, sql_rel
 }
 
 static int
-can_push_func(sql_exp *e, sql_rel *rel, int *must)
+can_push_func(sql_exp *e, sql_rel *rel, int *must, int depth)
 {
switch(e->type) {
case e_cmp: {
-   int mustl = 0, mustr = 0, mustf = 0;
sql_exp *l = e->l, *r = e->r, *f = e->f;
 
-   if ((is_project(rel->op) && e->f) || e->flag == cmp_or || 
e->flag == cmp_in || e->flag == cmp_notin || e->flag == cmp_filter)
+   if (e->flag == cmp_or || e->flag == cmp_in || e->flag == 
cmp_notin || e->flag == cmp_filter)
return 0;
-   return ((l->type == e_column || can_push_func(l, rel, &mustl)) 
&& (*must = mustl)) ||
-   (!f && (r->type == e_column || can_push_func(r, 
rel, &mustr)) && (*must = mustr)) ||
-   (f &&
-   (r->type == e_column || can_push_func(r, rel, 
&mustr)) &&
-   (f->type == e_column || can_push_func(f, rel, &mustf)) 
&& (*must = (mustr || mustf)));
+   if (depth > 0) { /* for comparisons under the top ones, they 
become functions */
+   int lmust = 0;
+   int res = can_push_func(l, rel, &lmust, depth + 1) && 
can_push_func(r, rel, &lmust, depth + 1) &&
+   (!f || can_push_func(f, rel, &lmust, 
depth + 1));
+   if (res && !lmust)
+   return 1;
+   (*must) |= lmust;
+   return res;
+   } else {
+   int mustl = 0, mustr = 0, mustf = 0;
+   return ((l->type == e_column || can_push_func(l, rel, 
&mustl, depth + 1)) && (*must = mustl)) ||
+   (!f && (r->type == e_column || 
can_push_func(r, rel, &mustr, depth + 1)) && (*must = mustr)) ||
+   (f &&
+   (r->type == e_column || 
can_push_func(r, rel, &mustr, depth + 1)) &&
+   (f->type == e_column || can_push_func(f, rel, 
&mustf, depth + 1)) && (*must = (mustr || mustf)));
+   }
}
case e_convert:
-   return can_push_func(e->l, rel, must);
+   return can_push_func(e->l, rel, must, depth + 1);
case e_aggr:
case e_func: {
  

MonetDB: default - Merged with Oct2020

2021-01-26 Thread Pedro Ferreira
Changeset: 8ba85c5ddbb2 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=8ba85c5ddbb2
Removed Files:

sql/test/BugTracker-2009/Tests/alter_table_drop_constraint.SF-2803477.sql
sql/test/miscellaneous/Tests/simple_selects.sql
Modified Files:
clients/Tests/MAL-signatures.stable.out
clients/Tests/MAL-signatures.stable.out.int128
monetdb5/modules/mal/wlc.c
sql/backends/monet5/rel_bin.c
sql/backends/monet5/sql.c
sql/backends/monet5/sql_cat.c
sql/server/rel_schema.c

sql/test/BugTracker-2009/Tests/alter_table_drop_constraint.SF-2803477.test
sql/test/miscellaneous/Tests/simple_selects.test
Branch: default
Log Message:

Merged with Oct2020


diffs (truncated from 479 to 300 lines):

diff --git a/clients/Tests/MAL-signatures.stable.out 
b/clients/Tests/MAL-signatures.stable.out
--- a/clients/Tests/MAL-signatures.stable.out
+++ b/clients/Tests/MAL-signatures.stable.out
@@ -9514,19 +9514,19 @@ stdout of test 'MAL-signatures` in direc
 [ "sqlcatalog","comment_on",   "pattern sqlcatalog.comment_on(X_1:int, 
X_2:str):void ","SQLcomment_on;",   ""  ]
 [ "sqlcatalog","create_function",  "pattern 
sqlcatalog.create_function(X_1:str, X_2:str, X_3:ptr):void ",  
"SQLcreate_function;",  ""  ]
 [ "sqlcatalog","create_role",  "pattern 
sqlcatalog.create_role(X_1:str, X_2:str, X_3:int):void ",  
"SQLcreate_role;",  ""  ]
-[ "sqlcatalog","create_schema","pattern 
sqlcatalog.create_schema(X_1:str, X_2:str, X_3:int, X_4:int):void ",   
"SQLcreate_schema;",""  ]
+[ "sqlcatalog","create_schema","pattern 
sqlcatalog.create_schema(X_1:str, X_2:str, X_3:int):void ",
"SQLcreate_schema;",""  ]
 [ "sqlcatalog","create_seq",   "pattern sqlcatalog.create_seq(X_1:str, 
X_2:str, X_3:ptr, X_4:int):void ",  "SQLcreate_seq;",   ""  ]
 [ "sqlcatalog","create_table", "pattern 
sqlcatalog.create_table(X_1:str, X_2:str, X_3:ptr, X_4:int):void ",
"SQLcreate_table;", ""  ]
 [ "sqlcatalog","create_trigger",   "pattern 
sqlcatalog.create_trigger(X_1:str, X_2:str, X_3:str, X_4:int, X_5:int, X_6:int, 
X_7:str, X_8:str, X_9:str, X_10:str):void ",   "SQLcreate_trigger;",   ""  ]
 [ "sqlcatalog","create_type",  "pattern 
sqlcatalog.create_type(X_1:str, X_2:str, X_3:str):void ",  
"SQLcreate_type;",  ""  ]
 [ "sqlcatalog","create_user",  "pattern 
sqlcatalog.create_user(X_1:str, X_2:str, X_3:int, X_4:str, X_5:str, 
X_6:str):void ",   "SQLcreate_user;",  ""  ]
 [ "sqlcatalog","create_view",  "pattern 
sqlcatalog.create_view(X_1:str, X_2:str, X_3:ptr, X_4:int):void ", 
"SQLcreate_view;",  ""  ]
-[ "sqlcatalog","drop_constraint",  "pattern 
sqlcatalog.drop_constraint(X_1:str, X_2:str, X_3:int, X_4:int):void ", 
"SQLdrop_constraint;",  ""  ]
+[ "sqlcatalog","drop_constraint",  "pattern 
sqlcatalog.drop_constraint(X_1:str, X_2:str, X_3:str, X_4:int, X_5:int):void ", 
   "SQLdrop_constraint;",  ""  ]
 [ "sqlcatalog","drop_function","pattern 
sqlcatalog.drop_function(X_1:str, X_2:str, X_3:int, X_4:int, X_5:int):void ",  
"SQLdrop_function;",""  ]
 [ "sqlcatalog","drop_index",   "pattern sqlcatalog.drop_index(X_1:str, 
X_2:str, X_3:int):void ",   "SQLdrop_index;",   ""  ]
 [ "sqlcatalog","drop_role","pattern sqlcatalog.drop_role(X_1:str, 
X_2:int):void ", "SQLdrop_role;",""  ]
 [ "sqlcatalog","drop_role","pattern sqlcatalog.drop_role(X_1:str, 
X_2:str, X_3:int):void ","SQLdrop_role;",""  ]
-[ "sqlcatalog","drop_schema",  "pattern 
sqlcatalog.drop_schema(X_1:str, X_2:str, X_3:int, X_4:int):void ", 
"SQLdrop_schema;",  ""  ]
+[ "sqlcatalog","drop_schema",  "pattern 
sqlcatalog.drop_schema(X_1:str, X_2:int, X_3:int):void ",  
"SQLdrop_schema;",  ""  ]
 [ "sqlcatalog","drop_seq", "pattern sqlcatalog.drop_seq(X_1:str, 
X_2:str, X_3:int):void ", "SQLdrop_seq;", ""  ]
 [ "sqlcatalog","drop_table",   "pattern sqlcatalog.drop_table(X_1:str, 
X_2:str, X_3:int, X_4:int):void ",  "SQLdrop_table;",   ""  ]
 [ "sqlcatalog","drop_trigger", "pattern 
sqlcatalog.drop_trigger(X_1:str, X_2:str, X_3:int):void ", 
"SQLdrop_trigger;", ""  ]
@@ -9693,7 +9693,7 @@ stdout of test 'MAL-signatures` in direc
 [ "wlc",   "commit",   "pattern wlc.commit():void ",   
"WLCcommitCmd;",""  ]
 [ "wlc",   "create_function",  "pattern wlc.create_function(X_1:str, 
X_2:str):void ",  "WLCgeneric;",  ""  ]
 [ "wlc",   "create_role",  "pattern wlc.create_role(X_1:str, X_2:str, 
X_3:int):void ", "WLCgeneric;",  ""  ]
-[ "wlc",   "create_schema","pattern wlc.create_schema(X_1:str, 
X_2:str, X_3:int, X

MonetDB: default - Merged with Oct2020

2021-01-26 Thread Pedro Ferreira
Changeset: 3cac25ae0132 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=3cac25ae0132
Removed Files:
sql/test/LSST/Tests/schema_3_1_88.sql
sql/test/SQLancer/Tests/sqlancer01.sql
sql/test/SQLancer/Tests/sqlancer02.sql
sql/test/SQLancer/Tests/sqlancer03.sql
sql/test/SQLancer/Tests/sqlancer07.sql
sql/test/SQLancer/Tests/sqlancer08.sql
Modified Files:
sql/server/rel_optimizer.c
sql/server/rel_schema.c
sql/test/BugTracker-2009/Tests/copy_multiple_files.SF-2902320.stable.out

sql/test/BugTracker-2009/Tests/copy_multiple_files.SF-2902320.stable.out.Windows
sql/test/LSST/Tests/schema_3_1_88.test
sql/test/SQLancer/Tests/sqlancer01.test
sql/test/SQLancer/Tests/sqlancer02.test
sql/test/SQLancer/Tests/sqlancer03.test
sql/test/SQLancer/Tests/sqlancer07.test
sql/test/SQLancer/Tests/sqlancer08.test
Branch: default
Log Message:

Merged with Oct2020


diffs (truncated from 1373 to 300 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
@@ -591,10 +591,10 @@ matching_joins(sql_allocator *sa, list *
 }
 
 static int
-sql_column_kc_cmp(sql_column *c, sql_kc *kc)
+sql_kc_column_cmp(sql_kc *kc, sql_column *c)
 {
/* return on equality */
-   return (c->colnr - kc->c->colnr);
+   return (kc->c->colnr - c->colnr);
 }
 
 static sql_idx *
@@ -606,11 +606,11 @@ find_fk_index(sql_table *l, list *lcols,
sql_idx *li = in->data;
if (li->type == join_idx) {
sql_key *rk = &((sql_fkey*)li->key)->rkey->k;
-   fcmp cmp = (fcmp)&sql_column_kc_cmp;
+   fcmp cmp = (fcmp)&sql_kc_column_cmp;
 
if (rk->t == r &&
-   list_match(lcols, li->columns, cmp) == 
0 &&
-   list_match(rcols, rk->columns, cmp) == 
0) {
+   list_match(li->columns, lcols, cmp) == 
0 &&
+   list_match(rk->columns, rcols, cmp) == 
0) {
return li;
}
}
@@ -1553,9 +1553,9 @@ rel_push_func_down(visitor *v, sql_rel *
sql_rel *l = pl->l, *r = pl->r;
list *nexps = new_exp_list(v->sql->sa);
 
-   if (push_left && !is_simple_project(l->op))
+   if (push_left && (!is_simple_project(l->op) || !l->l))
pl->l = l = rel_project(v->sql->sa, l, 
rel_projections(v->sql, l, NULL, 1, 1));
-   if (push_right && !is_simple_project(r->op))
+   if (push_right && (!is_simple_project(r->op)|| !r->l))
pl->r = r = rel_project(v->sql->sa, r, 
rel_projections(v->sql, r, NULL, 1, 1));
for (node *n = rel->exps->h; n; n = n->next) {
sql_exp *e = n->data;
@@ -4730,10 +4730,11 @@ rel_push_join_down(visitor *v, sql_rel *
if (!re || 
(list_length(jes) == 0 && !find_prop(le->p, PROP_HASHCOL))) {
fnd = 0;
} else {
-   int anti = 
is_anti(je);
+   int anti = 
is_anti(je), semantics = is_semantics(je);
 
je = 
exp_compare(v->sql->sa, le, re, je->flag);
if (anti) 
set_anti(je);
+   if (semantics) 
set_semantics(je);

list_append(jes, je);
}
}
@@ -6711,8 +6712,32 @@ exp_used(sql_exp *e)
 {
if (e) {
e->used = 1;
-   if ((e->type == e_func || e->type == e_aggr) && e->l)
+
+   switch (e->type) {
+   case e_convert:
+   exp_used(e->l);
+   break;
+   case e_func:
+   case e_aggr:
exps_used(e->l);
+   break;
+   case e_cmp:
+   if (e->flag == cmp_or || e->flag == cmp_filter) {
+   exps_used(e->l);
+   exps_used(e->r);
+   } else if (e->flag == cmp_in || e->flag == cmp_notin) {
+   exp_used(e->

MonetDB: default - Merged with Oct2020

2021-01-22 Thread Pedro Ferreira
Changeset: b44902c141d5 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=b44902c141d5
Modified Files:
sql/server/rel_optimizer.c
Branch: default
Log Message:

Merged with Oct2020


diffs (87 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
@@ -1353,7 +1353,7 @@ can_push_func(sql_exp *e, sql_rel *rel, 
int mustl = 0, mustr = 0, mustf = 0;
sql_exp *l = e->l, *r = e->r, *f = e->f;
 
-   if (is_project(rel->op) || e->flag == cmp_or || e->flag == 
cmp_in || e->flag == cmp_notin || e->flag == cmp_filter)
+   if ((is_project(rel->op) && e->f) || e->flag == cmp_or || 
e->flag == cmp_in || e->flag == cmp_notin || e->flag == cmp_filter)
return 0;
return ((l->type == e_column || can_push_func(l, rel, &mustl)) 
&& (*must = mustl)) ||
(!f && (r->type == e_column || can_push_func(r, 
rel, &mustr)) && (*must = mustr)) ||
@@ -1388,17 +1388,20 @@ can_push_func(sql_exp *e, sql_rel *rel, 
 }
 
 static int
-exps_can_push_func(list *exps, sql_rel *rel)
-{
-   for(node *n = exps->h; n; n = n->next) {
+exps_can_push_func(list *exps, sql_rel *rel, bool *push_left, bool *push_right)
+{
+   for(node *n = exps->h; n && !*push_left && !*push_right; n = n->next) {
sql_exp *e = n->data;
-   int must = 0, mustl = 0, mustr = 0;
-
-   if (is_joinop(rel->op) && ((can_push_func(e, rel->l, &mustl) && 
mustl) || (can_push_func(e, rel->r, &mustr) && mustr)))
-   return 1;
-   else if (is_select(rel->op) && can_push_func(e, rel->l, &must) 
&& must)
-   return 1;
-   }
+   int mustl = 0, mustr = 0;
+
+   if ((is_joinop(rel->op) || is_select(rel->op)) && 
((can_push_func(e, rel->l, &mustl) && mustl)))
+   *push_left = true;
+   
+   if (is_joinop(rel->op) && can_push_func(e, rel->r, &mustr) && 
mustr)
+   *push_right = true;
+   }
+   if (*push_left || *push_right)
+   return 1;
return 0;
 }
 
@@ -1512,19 +1515,20 @@ rel_push_func_down(visitor *v, sql_rel *
if ((is_select(rel->op) || is_joinop(rel->op)) && rel->l && rel->exps 
&& !(rel_is_ref(rel))) {
list *exps = rel->exps;
sql_rel *l = rel->l, *r = rel->r;
+   bool push_left = false, push_right = false;
 
/* only push down when is useful */
if ((is_select(rel->op) && list_length(rel->exps) <= 1) || 
rel_is_ref(l) || (is_joinop(rel->op) && rel_is_ref(r)))
return rel;
-   if (exps_can_push_func(exps, rel) && exps_need_push_down(exps)) 
{
+   if (exps_can_push_func(exps, rel, &push_left, &push_right) && 
exps_need_push_down(exps)) {
sql_rel *nrel, *ol = l, *or = r;
visitor nv = { .sql = v->sql, .parent = v->parent, 
.value_based_opt = v->value_based_opt, .storage_based_opt = 
v->storage_based_opt };
 
/* we need a full projection, group by's and unions 
cannot be extended
 * with more expressions */
-   if (!is_simple_project(l->op) || !l->l)
+   if (push_left && (!is_simple_project(l->op) || !l->l))
rel->l = l = rel_project(v->sql->sa, l, 
rel_projections(v->sql, l, NULL, 1, 1));
-   if (is_joinop(rel->op) && (!is_simple_project(r->op) || 
!r->l))
+   if (push_right && (!is_simple_project(r->op)|| !r->l))
rel->r = r = rel_project(v->sql->sa, r, 
rel_projections(v->sql, r, NULL, 1, 1));
nrel = rel_project(v->sql->sa, rel, 
rel_projections(v->sql, rel, NULL, 1, 1));
 
@@ -1543,14 +1547,15 @@ rel_push_func_down(visitor *v, sql_rel *
}
if (is_simple_project(rel->op) && rel->l && rel->exps) {
sql_rel *pl = rel->l;
-
-   if (is_joinop(pl->op) && exps_can_push_func(rel->exps, rel)) {
+   bool push_left = false, push_right = false;
+
+   if (is_joinop(pl->op) && exps_can_push_func(rel->exps, rel, 
&push_left, &push_right)) {
sql_rel *l = pl->l, *r = pl->r;
list *nexps = new_exp_list(v->sql->sa);
 
-   if (!is_simple_project(l->op) || !l->l)
+   if (push_left && !is_simple_project(l->op))
pl->l = l = rel_project(v->sql->sa, l, 
rel_projections(v->sql, l, NULL, 1, 1));
-   if (is_joinop(rel->op) && (!is_simple_project(r->op) || 
!r->l))
+   if (push_right && !is_simple_project(r->op))
pl->r = r = re

MonetDB: default - Merged with Oct2020 and converted tests

2021-01-22 Thread Pedro Ferreira
Changeset: 5d454d2623a0 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=5d454d2623a0
Removed Files:
sql/test/SQLancer/Tests/sqlancer02.sql
Modified Files:
sql/include/sql_relation.h
sql/server/rel_optimizer.c
sql/server/rel_rel.c
sql/server/rel_rel.h
sql/server/rel_select.c
sql/server/rel_unnest.c
sql/server/rel_updates.c
sql/test/SQLancer/Tests/sqlancer02.test
sql/test/merge-partitions/Tests/mergepart31.test
Branch: default
Log Message:

Merged with Oct2020 and converted tests


diffs (truncated from 645 to 300 lines):

diff --git a/sql/include/sql_relation.h b/sql/include/sql_relation.h
--- a/sql/include/sql_relation.h
+++ b/sql/include/sql_relation.h
@@ -197,7 +197,6 @@ typedef enum operator_type {
 #define is_simple_project(op)  (op == op_project)
 #define is_project(op) (op == op_project || op == op_groupby 
|| is_set(op))
 #define is_groupby(op) (op == op_groupby)
-#define is_sort(rel)   (((rel)->op == op_project && (rel)->r) || 
(rel)->op == op_topn)
 #define is_topn(op)(op == op_topn)
 #define is_modify(op)  (op == op_insert || op == op_update || op == 
op_delete || op == op_truncate)
 #define is_sample(op)  (op == op_sample)
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
@@ -2077,6 +2077,7 @@ rel_push_topn_and_sample_down(visitor *v
ur = func(v->sql->sa, ur, sum_limit_offset(v->sql, 
rel));
 
u = rel_setop(v->sql->sa, ul, ur, op_union);
+   /* TODO the list of expressions of u don't match ul and 
ur */
u->exps = exps_alias(v->sql, r->exps);
u->nrcols = list_length(u->exps);
set_processed(u);
@@ -4100,7 +4101,7 @@ rel_push_aggr_down(visitor *v, sql_rel *
sql_table *mt = (bt)?bt->r:NULL;
if (c && mt && 
list_find(c->t->pkey->k.columns, c, cmp) != NULL) {
v->changes++;
-   return rel_inplace_setop(rel, 
ul, ur, op_union,
+   return 
rel_inplace_setop(v->sql, rel, ul, ur, op_union,
   rel_projections(v->sql, 
rel, NULL, 1, 1));
}
}
@@ -5058,7 +5059,7 @@ rel_push_join_down_union(visitor *v, sql
nl = rel_project(v->sql->sa, nl, 
rel_projections(v->sql, nl, NULL, 1, 1));
nr = rel_project(v->sql->sa, nr, 
rel_projections(v->sql, nr, NULL, 1, 1));
v->changes++;
-   return rel_inplace_setop(rel, nl, nr, op_union, 
rel_projections(v->sql, rel, NULL, 1, 1));
+   return rel_inplace_setop(v->sql, rel, nl, nr, op_union, 
rel_projections(v->sql, rel, NULL, 1, 1));
} else if (is_union(l->op) && !need_distinct(l) &&
   is_union(r->op) && !need_distinct(r)) {
sql_rel *nl, *nr;
@@ -5101,7 +5102,7 @@ rel_push_join_down_union(visitor *v, sql
nl = rel_project(v->sql->sa, nl, 
rel_projections(v->sql, nl, NULL, 1, 1));
nr = rel_project(v->sql->sa, nr, 
rel_projections(v->sql, nr, NULL, 1, 1));
v->changes++;
-   return rel_inplace_setop(rel, nl, nr, op_union, 
rel_projections(v->sql, rel, NULL, 1, 1));
+   return rel_inplace_setop(v->sql, rel, nl, nr, op_union, 
rel_projections(v->sql, rel, NULL, 1, 1));
} else if (!is_union(l->op) &&
   is_union(r->op) && !need_distinct(r) &&
   !is_semi(rel->op)) {
@@ -5130,7 +5131,7 @@ rel_push_join_down_union(visitor *v, sql
nl = rel_project(v->sql->sa, nl, 
rel_projections(v->sql, nl, NULL, 1, 1));
nr = rel_project(v->sql->sa, nr, 
rel_projections(v->sql, nr, NULL, 1, 1));
v->changes++;
-   return rel_inplace_setop(rel, nl, nr, op_union, 
rel_projections(v->sql, rel, NULL, 1, 1));
+   return rel_inplace_setop(v->sql, rel, nl, nr, op_union, 
rel_projections(v->sql, rel, NULL, 1, 1));
/* {semi}join ( A1, union (A2, B)) [A1.partkey = A2.partkey] ->
 * {semi}join ( A1, A2 )
 * and
@@ -5460,7 +5461,7 @@ rel_push_select_down_union(visitor *v, s
ul->exps = exps_copy(v->sql, s->exps);
ur->exps = exps_copy(v->sql, s->exps);
 
-   rel = rel_inplace_setop(rel, ul, ur, op_union, 
rel_projections(v->sql, rel, NULL, 1, 1));
+   

MonetDB: default - Merged with Oct2020 and converted tests

2021-01-21 Thread Pedro Ferreira
Changeset: 43ad3ab454ad for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=43ad3ab454ad
Added Files:
sql/test/bugs/Tests/rtrim_bug.test
Modified Files:
sql/backends/monet5/rel_bin.c
sql/server/rel_optimizer.c
sql/test/miscellaneous/Tests/simple_plans.stable.out
sql/test/miscellaneous/Tests/simple_selects.test
Branch: default
Log Message:

Merged with Oct2020 and converted tests


diffs (294 lines):

diff --git a/sql/backends/monet5/rel_bin.c b/sql/backends/monet5/rel_bin.c
--- a/sql/backends/monet5/rel_bin.c
+++ b/sql/backends/monet5/rel_bin.c
@@ -2519,8 +2519,6 @@ rel2bin_antijoin(backend *be, sql_rel *r
return stmt_list(be, l);
 }
 
-#define complex_join_expression(e) (exp_has_func(e) && (e)->flag != 
cmp_filter) || (e)->flag == cmp_or || ((e)->f && (e)->anti)
-
 static stmt *
 rel2bin_semijoin(backend *be, sql_rel *rel, list *refs)
 {
@@ -2565,7 +2563,7 @@ rel2bin_semijoin(backend *be, sql_rel *r
int idx = 0, equality_only = 1;
 
jexps = get_equi_joins_first(sql, jexps, 
&equality_only);
-   if (!equality_only || list_length(jexps) > 1 || 
complex_join_expression((sql_exp*)jexps->h->data))
+   if (!equality_only || list_length(jexps) > 1 || 
exp_has_func((sql_exp*)jexps->h->data))
left = subrel_project(be, left, refs, rel->l);
right = subrel_project(be, right, refs, rel->r);
 
@@ -2575,7 +2573,7 @@ rel2bin_semijoin(backend *be, sql_rel *r
stmt *s = NULL;
 
/* only handle simple joins here */
-   if (complex_join_expression(e)) {
+   if ((exp_has_func(e) && e->flag != cmp_filter) 
|| e->flag == cmp_or || (e->f && e->anti)) {
if (!join && !list_length(lje)) {
stmt *l = bin_first_column(be, 
left);
stmt *r = bin_first_column(be, 
right);
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
@@ -1350,16 +1350,16 @@ can_push_func(sql_exp *e, sql_rel *rel, 
 {
switch(e->type) {
case e_cmp: {
+   int mustl = 0, mustr = 0, mustf = 0;
sql_exp *l = e->l, *r = e->r, *f = e->f;
-   int res = 1, lmust = 0;
-
-   if (e->flag == cmp_or || e->flag == cmp_in || e->flag == 
cmp_notin || e->flag == cmp_filter)
+
+   if (is_project(rel->op) || e->flag == cmp_or || e->flag == 
cmp_in || e->flag == cmp_notin || e->flag == cmp_filter)
return 0;
-   res = can_push_func(l, rel, &lmust) && can_push_func(r, rel, 
&lmust) && (!f || can_push_func(f, rel, &lmust));
-   if (res && !lmust)
-   return 1;
-   (*must) |= lmust;
-   return res;
+   return ((l->type == e_column || can_push_func(l, rel, &mustl)) 
&& (*must = mustl)) ||
+   (!f && (r->type == e_column || can_push_func(r, 
rel, &mustr)) && (*must = mustr)) ||
+   (f &&
+   (r->type == e_column || can_push_func(r, rel, 
&mustr)) &&
+   (f->type == e_column || can_push_func(f, rel, &mustf)) 
&& (*must = (mustr || mustf)));
}
case e_convert:
return can_push_func(e->l, rel, must);
@@ -1378,8 +1378,7 @@ can_push_func(sql_exp *e, sql_rel *rel, 
return res;
}
case e_column:
-/* aliases cannot be bound on the same level, ie same 
projection */
-   if ((exp_name(e) && !has_label(e)) || (rel && 
!rel_find_exp(rel, e)))
+   if (rel && !rel_find_exp(rel, e))
return 0;
(*must) = 1;
/* fall through */
diff --git a/sql/test/bugs/Tests/rtrim_bug.sql 
b/sql/test/bugs/Tests/rtrim_bug.sql
--- a/sql/test/bugs/Tests/rtrim_bug.sql
+++ b/sql/test/bugs/Tests/rtrim_bug.sql
@@ -12,6 +12,24 @@ SELECT length("m") as data_length, "m" a
 
 CREATE VIEW v2 as select "m" from t1 where rtrim(m) in (select rtrim(m) from 
sys.t1);
 SELECT * FROM v2;
+
+PLAN SELECT length("m") as data_length, "m" as data_value FROM "sys"."v2" 
WHERE "m" IS NOT NULL AND length("m") > 1;
+
+set optimizer = 'sequential_pipe';
+create procedure profiler.starttrace() external name profiler."starttrace";
+create procedure profiler.stoptrace() external name profiler.stoptrace;
+
+call profiler."starttrace"();
+SELECT length("m") as data_length, "m" as data_value FROM "sys"."v2" WHERE "m" 
IS NOT NULL AND length("m") > 1;
+call profiler.stoptrace();
+
+select count(*) from sys.tracelog() where stmt like '% algebra.crossproduct%'; 
-- don't do crossjoin
+select count(

MonetDB: default - Merged with Oct2020

2021-01-20 Thread Pedro Ferreira
Changeset: d6791fc37829 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=d6791fc37829
Modified Files:
sql/backends/monet5/sql.c
sql/server/rel_exp.c
sql/server/rel_rel.c
sql/test/SQLancer/Tests/sqlancer02.sql
sql/test/SQLancer/Tests/sqlancer02.stable.out
sql/test/SQLancer/Tests/sqlancer02.test
sql/test/merge-partitions/Tests/mergepart21.stable.err
sql/test/merge-partitions/Tests/mergepart23.SQL.py
sql/test/merge-partitions/Tests/mergepart23.stable.err
sql/test/orderidx/Tests/simpletable.sql
sql/test/orderidx/Tests/simpletable.stable.out
sql/test/orderidx/Tests/simpletable.test
sql/test/orderidx/Tests/smalltable.sql
sql/test/orderidx/Tests/smalltable.stable.out
sql/test/orderidx/Tests/smalltable.test
testing/Mconvert.py.in
testing/Mz.py.in
Branch: default
Log Message:

Merged with Oct2020


diffs (truncated from 1763 to 300 lines):

diff --git a/sql/backends/monet5/sql.c b/sql/backends/monet5/sql.c
--- a/sql/backends/monet5/sql.c
+++ b/sql/backends/monet5/sql.c
@@ -337,8 +337,9 @@ create_table_or_view(mvc *sql, char* sna
sql_column *c = n->data;
 
if (c->def) {
+   /* TODO please don't place an auto incremented sequence 
in the default value */
+   const char *next_value_for = "next value for 
\"sys\".\"seq_";
sql_rel *r = NULL;
-   list *id_l;
 
sql->sa = sql->ta;
r = rel_parse(sql, s, sa_message(sql->ta, "select %s;", 
c->def), m_deps);
@@ -353,8 +354,12 @@ create_table_or_view(mvc *sql, char* sna
else
throw(SQL, "sql.catalog", 
SQLSTATE(42000) "%s", sql->errstr);
}
-   id_l = rel_dependencies(sql, r);
-   mvc_create_dependencies(sql, id_l, nt->base.id, 
FUNC_DEPENDENCY);
+   /* For a self incremented column, it's sequence will 
get a BEDROPPED_DEPENDENCY,
+   so no additional dependencies are needed */
+   if (strncmp(c->def, next_value_for, 
strlen(next_value_for)) != 0) {
+   list *id_l = rel_dependencies(sql, r);
+   mvc_create_dependencies(sql, id_l, nt->base.id, 
FUNC_DEPENDENCY);
+   }
rel_destroy(r);
sa_reset(sql->sa);
}
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
@@ -2963,6 +2963,7 @@ exp_check_type(mvc *sql, sql_subtype *t,
}
}
if (err) {
+   const char *name = (exp->type == e_column && !has_label(exp)) ? 
exp_name(exp) : "%";
sql_exp *res = sql_error( sql, 03, SQLSTATE(42000) "types 
%s(%u,%u) and %s(%u,%u) are not equal%s%s%s",
fromtype->type->sqlname,
fromtype->digits,
@@ -2970,9 +2971,9 @@ exp_check_type(mvc *sql, sql_subtype *t,
t->type->sqlname,
t->digits,
t->scale,
-   (exp->type == e_column && !has_label(exp) ? " for 
column '" : ""),
-   (exp->type == e_column && !has_label(exp) ? 
exp_name(exp) : ""),
-   (exp->type == e_column && !has_label(exp) ? "'" : "")
+   (name[0] != '%' ? " for column '" : ""),
+   (name[0] != '%' ? name : ""),
+   (name[0] != '%' ? "'" : "")
);
return res;
}
diff --git a/sql/server/rel_rel.c b/sql/server/rel_rel.c
--- a/sql/server/rel_rel.c
+++ b/sql/server/rel_rel.c
@@ -1682,12 +1682,10 @@ static int exp_deps(mvc *sql, sql_exp *e
 static int
 exps_deps(mvc *sql, list *exps, list *refs, list *l)
 {
-   node *n;
 
-   for(n = exps->h; n; n = n->next) {
+   for(node *n = exps->h; n; n = n->next)
if (exp_deps(sql, n->data, refs, l) != 0)
return -1;
-   }
return 0;
 }
 
@@ -1724,8 +1722,7 @@ exp_deps(mvc *sql, sql_exp *e, list *ref
} else if (e->flag & PSM_VAR) {
return 0;
} else if (e->flag & PSM_WHILE || e->flag & PSM_IF) {
-   if (exp_deps(sql, e->l, refs, l) != 0 ||
-   exps_deps(sql, e->r, refs, l) != 0)
+   if (exp_deps(sql, e->l, refs, l) != 0 || exps_deps(sql, 
e->r, refs, l) != 0)
return -1;
if (e->flag & PSM_IF && e->f)
return exps_deps(sql, e->f, refs, l);
@@ -1739,54 +1736,56 @@ exp_deps(mvc *sql, sql_exp *e, list *ref
case e

MonetDB: default - Merged with Oct2020

2021-01-19 Thread Pedro Ferreira
Changeset: a96e9a08f10a for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=a96e9a08f10a
Modified Files:
sql/server/rel_optimizer.c
sql/test/Tests/keys.test
Branch: default
Log Message:

Merged with Oct2020


diffs (truncated from 309 to 300 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
@@ -9381,14 +9381,13 @@ replace_column_references_with_nulls_2(m
 static sql_rel *
 out2inner(visitor *v, sql_rel* sel, sql_rel* join, sql_rel* inner_join_side, 
operator_type new_type) {
 
-list* select_predicates = exps_copy(v->sql, sel->exps);
-
 if (!is_base(inner_join_side->op) && 
!is_simple_project(inner_join_side->op)) {
 // Nothing to do here.
 return sel;
 }
 
 list* inner_join_column_references = inner_join_side->exps;
+list* select_predicates = exps_copy(v->sql, sel->exps);
 
 for(node* n = select_predicates->h; n; n=n->next) {
 sql_exp* e = n->data;
@@ -9532,6 +9531,8 @@ rel_remove_union_partitions(visitor *v, 
return rel;
if (exp_is_zero_rows(v->sql, rel->l, NULL)) {
sql_rel *r = rel->r;
+   if (!is_project(r->op))
+   r = rel_project(v->sql->sa, r, rel_projections(v->sql, 
r, NULL, 1, 1));
rel_rename_exps(v->sql, rel->exps, r->exps);
rel->r = NULL;
rel_destroy(rel);
@@ -9540,6 +9541,8 @@ rel_remove_union_partitions(visitor *v, 
}
if (exp_is_zero_rows(v->sql, rel->r, NULL)) {
sql_rel *l = rel->l;
+   if (!is_project(l->op))
+   l = rel_project(v->sql->sa, l, rel_projections(v->sql, 
l, NULL, 1, 1));
rel_rename_exps(v->sql, rel->exps, l->exps);
rel->l = NULL;
rel_destroy(rel);
diff --git a/sql/test/Tests/keys.sql b/sql/test/Tests/keys.sql
--- a/sql/test/Tests/keys.sql
+++ b/sql/test/Tests/keys.sql
@@ -7,9 +7,11 @@ CREATE INDEX allnewtriples_predicate_idx
 CREATE INDEX allnewtriples_object_idx ON allnewtriples ("object");
 
 SELECT idxs.name, idxs."type", keys.name, keys."type" 
-FROM sys.idxs LEFT JOIN sys.keys on idxs.name = keys.name;
+FROM sys.idxs LEFT JOIN sys.keys on idxs.name = keys.name
+ORDER BY idxs.name, keys.name;
 SELECT idxs.name, idxs."type", keys.name, keys."type" 
-FROM sys.idxs JOIN sys.keys on idxs.name = keys.name;
+FROM sys.idxs JOIN sys.keys on idxs.name = keys.name
+ORDER BY idxs.name, keys.name;
 
 /* test elimination of distinct restriction on aggregates */
 create table dummyme (a int primary key, b int);
diff --git a/sql/test/Tests/keys.stable.out b/sql/test/Tests/keys.stable.out
--- a/sql/test/Tests/keys.stable.out
+++ b/sql/test/Tests/keys.stable.out
@@ -60,27 +60,27 @@ stdout of test 'keys` in directory 'sql/
 % name,type,   name,   type # name
 % varchar, int,varchar,int # type
 % 44,  1,  44, 1 # length
+[ "allnewtriples_object_idx",  0,  NULL,   NULL]
+[ "allnewtriples_predicate_idx",   0,  NULL,   NULL]
+[ "allnewtriples_subject_idx", 0,  NULL,   NULL]
 [ "comments_id_pkey",  0,  "comments_id_pkey", 0   ]
 [ "dependency_types_dependency_type_id_pkey",  0,  
"dependency_types_dependency_type_id_pkey", 0   ]
 [ "dependency_types_dependency_type_name_unique",  0,  
"dependency_types_dependency_type_name_unique", 1   ]
-[ "spatial_ref_sys_srid_pkey", 0,  "spatial_ref_sys_srid_pkey",0   
]
-[ "keywords_keyword_pkey", 0,  "keywords_keyword_pkey",0   
]
-[ "table_types_table_type_id_pkey",0,  
"table_types_table_type_id_pkey",   0   ]
-[ "table_types_table_type_name_unique",0,  
"table_types_table_type_name_unique",   1   ]
-[ "function_types_function_type_id_pkey",  0,  
"function_types_function_type_id_pkey", 0   ]
-[ "function_types_function_type_name_unique",  0,  
"function_types_function_type_name_unique", 1   ]
 [ "function_languages_language_id_pkey",   0,  
"function_languages_language_id_pkey",  0   ]
 [ "function_languages_language_name_unique",   0,  
"function_languages_language_name_unique",  1   ]
-[ "key_types_key_type_id_pkey",0,  "key_types_key_type_id_pkey",   
0   ]
-[ "key_types_key_type_name_unique",0,  
"key_types_key_type_name_unique",   1   ]
+[ "function_types_function_type_id_pkey",  0,  
"function_types_function_type_id_pkey", 0   ]
+[ "function_types_function_type_name_unique",  0,  
"function_types_function_type_name_unique", 1   ]
 [ "index_types_index_type_id_pkey",0,  
"index_types_index_type_id_pkey",   0   ]
 [ "index_types_index_type_name_unique",0,  
"index_types_index_type_name_unique",   1   ]
+[ "key_types_key_type_id_pkey",0,  "key_types

MonetDB: default - Merged with Oct2020

2021-01-18 Thread Pedro Ferreira
Changeset: e03189d2bebe for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=e03189d2bebe
Modified Files:
sql/backends/monet5/UDF/udf/Tests/udf-fuse.stable.out
sql/backends/monet5/UDF/udf/Tests/udf-reverse.stable.out
sql/backends/monet5/rel_bin.c
sql/test/BugTracker-2010/Tests/LIMIT_OFFSET_big-endian.Bug-2622.test

sql/test/BugTracker-2012/Tests/rewrite_like_into_likesubselect.Bug-3179.stable.out
sql/test/BugTracker-2014/Tests/manifold.Bug-3556.stable.out
sql/test/BugTracker-2016/Tests/decimal_vs_integer.Bug-3941.sql
sql/test/BugTracker-2016/Tests/decimal_vs_integer.Bug-3941.stable.out

sql/test/BugTracker-2019/Tests/duplicates-not-eliminated-long-CASE-stmt.Bug-6697.sql

sql/test/BugTracker-2019/Tests/duplicates-not-eliminated-long-CASE-stmt.Bug-6697.stable.out
sql/test/BugTracker/Tests/explain.SF-1739353.stable.out
sql/test/BugTracker/Tests/jdbc_no_debug.SF-1739356.stable.out
sql/test/mapi/Tests/sql_int128.stable.out.int128
sql/test/miscellaneous/Tests/simple_plans.stable.out
sql/test/remote/Tests/partition_elim.stable.out
Branch: default
Log Message:

Merged with Oct2020


diffs (truncated from 1628 to 300 lines):

diff --git a/sql/backends/monet5/rel_bin.c b/sql/backends/monet5/rel_bin.c
--- a/sql/backends/monet5/rel_bin.c
+++ b/sql/backends/monet5/rel_bin.c
@@ -1515,16 +1515,12 @@ rel2bin_basetable(backend *be, sql_rel *
 {
mvc *sql = be->mvc;
sql_table *t = rel->l;
-   sql_column *c = rel->r;
+   sql_column *fcol = NULL;
+   sql_idx *fi = NULL;
list *l = sa_list(sql->sa);
-   stmt *dels, *col = NULL;
+   stmt *dels = stmt_tid(be, t, rel->flag == REL_PARTITION), *col = NULL;
node *en;
 
-   if (!t && c)
-   t = c->t;
-
-   dels = stmt_tid(be, t, rel->flag == REL_PARTITION);
-
/* add aliases */
assert(rel->exps);
for( en = rel->exps->h; en && !col; en = en->next ) {
@@ -1539,10 +1535,12 @@ rel2bin_basetable(backend *be, sql_rel *
/* do not include empty indices in the plan */
if ((hash_index(i->type) && list_length(i->columns) <= 
1) || !idx_has_column(i->type))
continue;
+   fi = i;
col = stmt_idx(be, i, NULL/*dels*/, dels->partition);
} else {
sql_column *c = find_sql_column(t, oname);
 
+   fcol = c;
col = stmt_col(be, c, NULL/*dels*/, dels->partition);
}
}
@@ -1552,26 +1550,8 @@ rel2bin_basetable(backend *be, sql_rel *
const char *oname = exp->r;
stmt *s = NULL;
 
-   if (is_func(exp->type)) {
-   assert(0);
-   list *exps = exp->l;
-   sql_exp *cexp = exps->h->data;
-   const char *cname = cexp->r;
-   list *l = sa_list(sql->sa);
-
-   c = find_sql_column(t, cname);
-   s = stmt_col(be, c, NULL/*dels*/, dels->partition);
-   append(l, s);
-   if (exps->h->next) {
-   sql_exp *at = exps->h->next->data;
-   stmt *u = exp_bin(be, at, NULL, NULL, NULL, 
NULL, NULL, NULL, 0, 0, 0);
-   if(!u)
-   return NULL;
-
-   append(l, u);
-   }
-   s = stmt_Nop(be, stmt_list(be, l), NULL, exp->f);
-   } else if (oname[0] == '%' && strcmp(oname, TID) == 0) {
+   assert(!is_func(exp->type));
+   if (oname[0] == '%' && strcmp(oname, TID) == 0) {
/* tid function  sql.tid(t) */
const char *rnme = t->base.name;
 
@@ -1588,11 +1568,11 @@ rel2bin_basetable(backend *be, sql_rel *
/* do not include empty indices in the plan */
if ((hash_index(i->type) && list_length(i->columns) <= 
1) || !idx_has_column(i->type))
continue;
-   s = stmt_idx(be, i, NULL/*dels*/, dels->partition);
+   s = (i == fi) ? col : stmt_idx(be, i, NULL/*dels*/, 
dels->partition);
} else {
sql_column *c = find_sql_column(t, oname);
 
-   s = stmt_col(be, c, NULL/*dels*/, dels->partition);
+   s = (c == fcol) ? col : stmt_col(be, c, NULL/*dels*/, 
dels->partition);
}
s->tname = rname;
s->cname = exp_name(exp);
diff --git 
a/sql/test/BugTracker-2010/Tests/LIMIT_OFFSET_big-endian.Bug-2622.stable.out 
b/sql/test/BugTracker-2010/Tests/LIMIT_OFFSET_big-endian.Bug-2622.sta

MonetDB: default - Merged with Oct2020

2021-01-18 Thread Pedro Ferreira
Changeset: fb54d2a518b9 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=fb54d2a518b9
Modified Files:
clients/mapiclient/mclient.c
gdk/gdk_group.c
sql/backends/monet5/CMakeLists.txt
sql/backends/monet5/sql_scenario.c
sql/scripts/CMakeLists.txt
sql/server/rel_optimizer.c
sql/test/SQLancer/Tests/sqlancer04.test
sql/test/SQLancer/Tests/sqlancer05.test
sql/test/SQLancer/Tests/sqlancer09.test
Branch: default
Log Message:

Merged with Oct2020


diffs (297 lines):

diff --git a/clients/mapiclient/mclient.c b/clients/mapiclient/mclient.c
--- a/clients/mapiclient/mclient.c
+++ b/clients/mapiclient/mclient.c
@@ -1893,6 +1893,7 @@ format_result(Mapi mid, MapiHdl hdl, boo
 
switch (formatter) {
case TRASHformatter:
+   mapi_finish(hdl);
break;
case XMLformatter:
XMLrenderer(hdl);
@@ -1917,6 +1918,7 @@ format_result(Mapi mid, MapiHdl hdl, boo
rows = mapi_get_row_count(hdl);
mnstr_printf(toConsole,
"%" PRId64 " tuple%s\n", rows, 
rows != 1 ? "s" : "");
+   mapi_finish(hdl);
break;
case EXPANDEDformatter:
EXPANDEDrenderer(hdl);
diff --git a/gdk/gdk_group.c b/gdk/gdk_group.c
--- a/gdk/gdk_group.c
+++ b/gdk/gdk_group.c
@@ -1080,6 +1080,16 @@ BATgroup_internal(BAT **groups, BAT **ex
} else {
nbucket = MAX(HASHmask(cnt), 1 << 16);
}
+   switch (t) {
+   case TYPE_bte:
+   nbucket = 256;
+   break;
+   case TYPE_sht:
+   nbucket = 65536;
+   break;
+   default:
+   break;
+   }
if ((hs = GDKzalloc(sizeof(Hash))) == NULL ||
(hs->heaplink.farmid = BBPselectfarm(TRANSIENT, b->ttype, 
hashheap)) < 0 ||
(hs->heapbckt.farmid = BBPselectfarm(TRANSIENT, b->ttype, 
hashheap)) < 0) {
diff --git a/sql/backends/monet5/CMakeLists.txt 
b/sql/backends/monet5/CMakeLists.txt
--- a/sql/backends/monet5/CMakeLists.txt
+++ b/sql/backends/monet5/CMakeLists.txt
@@ -30,7 +30,7 @@ set(include_sql_files
   27_rejects
   39_analytics
   40_json
-  41_md5sum
+  42_md5sum
   45_uuid
   46_profiler
   51_sys_schema_extension
@@ -46,7 +46,7 @@ set(include_sql_files
 if(HAVE_HGE)
   list(APPEND include_sql_files
 39_analytics_hge
-40_json_hge)
+41_json_hge)
 endif()
 
 create_include_object(
diff --git a/sql/backends/monet5/sql_scenario.c 
b/sql/backends/monet5/sql_scenario.c
--- a/sql/backends/monet5/sql_scenario.c
+++ b/sql/backends/monet5/sql_scenario.c
@@ -49,15 +49,24 @@
 
 #define MAX_SQL_MODULES 128
 static int sql_modules = 0;
-static const char *sql_module_name[MAX_SQL_MODULES] = {0};
-static const unsigned char *sql_module_code[MAX_SQL_MODULES] = {0};
+static struct sql_module {
+   const char *name;
+   const unsigned char *code;
+} sql_module[MAX_SQL_MODULES];
+
+static int
+sql_module_compare(const void *a, const void *b)
+{
+   const struct sql_module *l = a, *r = b;
+   return strcmp(l->name, r->name);
+}
 
 void
 sql_register(const char *name, const unsigned char *code)
 {
assert (sql_modules < MAX_SQL_MODULES);
-   sql_module_name[sql_modules] = name;
-   sql_module_code[sql_modules] = code;
+   sql_module[sql_modules].name = name;
+   sql_module[sql_modules].code = code;
sql_modules++;
 }
 
@@ -426,8 +435,9 @@ SQLinit(Client c)
SQLnewcatalog = 0;
maybeupgrade = 0;
 
+   qsort(sql_module, sql_modules, sizeof(sql_module[0]), 
sql_module_compare);
for (int i = 0; i < sql_modules && !msg; i++) {
-   const char *createdb_inline = (const 
char*)sql_module_code[i];
+   const char *createdb_inline = (const 
char*)sql_module[i].code;
 
msg = SQLstatementIntern(c, createdb_inline, 
"sql.init", TRUE, FALSE, NULL);
if (m->sa)
diff --git a/sql/scripts/40_json_hge.sql b/sql/scripts/41_json_hge.sql
rename from sql/scripts/40_json_hge.sql
rename to sql/scripts/41_json_hge.sql
diff --git a/sql/scripts/41_md5sum.sql b/sql/scripts/42_md5sum.sql
rename from sql/scripts/41_md5sum.sql
rename to sql/scripts/42_md5sum.sql
diff --git a/sql/scripts/CMakeLists.txt b/sql/scripts/CMakeLists.txt
--- a/sql/scripts/CMakeLists.txt
+++ b/sql/scripts/CMakeLists.txt
@@ -24,7 +24,7 @@ install(FILES
   27_rejects.sql
   39_analytics.sql
   40_json.sql
-  41_md5sum.sql
+  42_md5sum.sql
   45_uuid.sql
   46_profiler.sql
   51_sys_s

MonetDB: default - Merged with Oct2020

2021-01-15 Thread Pedro Ferreira
Changeset: 2b21a252268f for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=2b21a252268f
Modified Files:
gdk/gdk_bat.c
gdk/gdk_batop.c
gdk/gdk_private.h
sql/backends/monet5/sql_statement.c
sql/server/rel_exp.c
sql/test/SQLancer/Tests/sqlancer04.test
sql/test/SQLancer/Tests/sqlancer05.test
Branch: default
Log Message:

Merged with Oct2020


diffs (truncated from 572 to 300 lines):

diff --git a/gdk/gdk_align.c b/gdk/gdk_align.c
--- a/gdk/gdk_align.c
+++ b/gdk/gdk_align.c
@@ -284,8 +284,8 @@ VIEWreset(BAT *b)
 
if (tp == 0) {
/* only sharing the vheap */
-   assert(ATOMstorage(b->ttype) == TYPE_str);
-   return unshare_string_heap(b);
+   assert(ATOMvarsized(b->ttype));
+   return unshare_varsized_heap(b);
}
 
BAT *v = VIEWcreate(b->hseqbase, b);
diff --git a/gdk/gdk_bat.c b/gdk/gdk_bat.c
--- a/gdk/gdk_bat.c
+++ b/gdk/gdk_bat.c
@@ -1062,7 +1062,7 @@ BUNappend(BAT *b, const void *t, bool fo
}
}
 
-   if (unshare_string_heap(b) != GDK_SUCCEED) {
+   if (unshare_varsized_heap(b) != GDK_SUCCEED) {
return GDK_FAIL;
}
 
diff --git a/gdk/gdk_batop.c b/gdk/gdk_batop.c
--- a/gdk/gdk_batop.c
+++ b/gdk/gdk_batop.c
@@ -19,10 +19,10 @@
 #include "gdk_private.h"
 
 gdk_return
-unshare_string_heap(BAT *b)
+unshare_varsized_heap(BAT *b)
 {
assert(b->batCacheid > 0);
-   if (ATOMstorage(b->ttype) == TYPE_str &&
+   if (ATOMvarsized(b->ttype) &&
b->tvheap->parentid != b->batCacheid) {
Heap *h = GDKzalloc(sizeof(Heap));
if (h == NULL)
@@ -116,7 +116,7 @@ insert_string_bat(BAT *b, BAT *n, struct
   ci->tpe == cand_dense) {
toff = 0;
} else if (b->tvheap->parentid != bid &&
-  unshare_string_heap(b) != GDK_SUCCEED) {
+  unshare_varsized_heap(b) != GDK_SUCCEED) {
return GDK_FAIL;
}
}
@@ -191,7 +191,7 @@ insert_string_bat(BAT *b, BAT *n, struct
}
}
}
-   } else if (unshare_string_heap(b) != GDK_SUCCEED)
+   } else if (unshare_varsized_heap(b) != GDK_SUCCEED)
return GDK_FAIL;
if (toff == 0 && n->twidth == b->twidth && ci->tpe == cand_dense) {
/* we don't need to do any translation of offset
diff --git a/gdk/gdk_private.h b/gdk/gdk_private.h
--- a/gdk/gdk_private.h
+++ b/gdk/gdk_private.h
@@ -247,7 +247,7 @@ ssize_t strToStr(char **restrict dst, si
__attribute__((__visibility__("hidden")));
 gdk_return strWrite(const char *a, stream *s, size_t cnt)
__attribute__((__visibility__("hidden")));
-gdk_return unshare_string_heap(BAT *b)
+gdk_return unshare_varsized_heap(BAT *b)
__attribute__((__warn_unused_result__))
__attribute__((__visibility__("hidden")));
 void VIEWdestroy(BAT *b)
diff --git a/monetdb5/optimizer/opt_emptybind.c 
b/monetdb5/optimizer/opt_emptybind.c
--- a/monetdb5/optimizer/opt_emptybind.c
+++ b/monetdb5/optimizer/opt_emptybind.c
@@ -35,21 +35,6 @@
}  } while (0)
 
 
-static int
-withoutMitosis(MalBlkPtr mb)
-{
-   InstrPtr p;
-
-   for(int i = mb->stop-1; i>=0; i--) {
-   p = mb->stmt[i];
-   if (p->token == ENDsymbol)
-   break;
-   if (getFunctionId(p) == mitosisRef)
-   return (p->token == REMsymbol);
-}
-   return 0;
-}
-
 str
 OPTemptybindImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr 
pci)
 {
@@ -62,7 +47,6 @@ OPTemptybindImplementation(Client cntxt,
str sch,tbl;
int etop= 0, esize= 256;
str msg = MAL_SUCCEED;
-   int no_mitosis = withoutMitosis(mb);
 
(void) stk;
(void) cntxt;
@@ -211,19 +195,6 @@ OPTemptybindImplementation(Client cntxt,
continue;
}
}
-   // delta operations without updates can be replaced by an pack 
of base and inserts
-   if (getModuleId(p)== sqlRef && getFunctionId(p) == deltaRef  && 
p->argc == 5){
-   if (no_mitosis && empty[getArg(p,2)] && 
empty[getArg(p,3)]){
-   actions++;
-   clrFunction(p);
-   setModuleId(p,matRef);
-   setFunctionId(p,packRef);
-   p->argc = 3;
-   getArg(p, 2) = getArg(p, 4);
-   p->typechk= TYPE_UNKNOWN;
-   }
-   continue;
-   }
 
if (getModuleId(p)== sqlRef && getFunctionId(p) == 
proj

MonetDB: default - Merged with Oct2020

2021-01-14 Thread Pedro Ferreira
Changeset: 3756f04de0fd for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=3756f04de0fd
Modified Files:
gdk/gdk_private.h
gdk/gdk_tracer.c
gdk/gdk_utils.c
sql/backends/monet5/rel_bin.c
sql/server/rel_optimizer.c
sql/server/rel_schema.c
sql/storage/store.c
sql/test/SQLancer/Tests/sqlancer04.test
sql/test/SQLancer/Tests/sqlancer09.test
Branch: default
Log Message:

Merged with Oct2020


diffs (truncated from 527 to 300 lines):

diff --git a/gdk/gdk_private.h b/gdk/gdk_private.h
--- a/gdk/gdk_private.h
+++ b/gdk/gdk_private.h
@@ -168,7 +168,7 @@ gdk_return GDKssort_rev(void *restrict h
 gdk_return GDKssort(void *restrict h, void *restrict t, const void *restrict 
base, size_t n, int hs, int ts, int tpe)
__attribute__((__warn_unused_result__))
__attribute__((__visibility__("hidden")));
-void GDKtracer_init(void)
+void GDKtracer_init(const char *dbname, const char *dbtrace)
__attribute__((__visibility__("hidden")));
 gdk_return GDKunlink(int farmid, const char *dir, const char *nme, const char 
*extension)
__attribute__((__visibility__("hidden")));
diff --git a/gdk/gdk_tracer.c b/gdk/gdk_tracer.c
--- a/gdk/gdk_tracer.c
+++ b/gdk/gdk_tracer.c
@@ -95,24 +95,20 @@ get_timestamp(char *datetime, size_t dts
 // When BASIC adapter is active, all the log messages are getting printed to a 
file.
 // This function prepares a file in order to write the contents of the buffer 
when necessary.
 static gdk_return
-_GDKtracer_init_basic_adptr(void)
+GDKtracer_init_trace_file(const char *dbpath, const char *dbtrace)
 {
-   const char *trace_path;
-
-   trace_path = GDKgetenv("gdk_dbtrace");
-   if (trace_path == NULL) {
-   trace_path = GDKgetenv("gdk_dbpath");
-   if (trace_path == NULL) {
+   if (dbtrace == NULL) {
+   if (dbpath == NULL) {
active_tracer = stderr;
return GDK_SUCCEED;
}
if (strconcat_len(file_name, sizeof(file_name),
- trace_path, DIR_SEP_STR, FILE_NAME, NULL)
+ dbpath, DIR_SEP_STR, FILE_NAME, NULL)
>= sizeof(file_name)) {
goto too_long;
}
} else {
-   if (strcpy_len(file_name, trace_path, sizeof(file_name))
+   if (strcpy_len(file_name, dbtrace, sizeof(file_name))
>= sizeof(file_name)) {
goto too_long;
}
@@ -137,6 +133,13 @@ static gdk_return
return GDK_FAIL;
 }
 
+static gdk_return
+_GDKtracer_init_basic_adptr(void)
+{
+   return GDKtracer_init_trace_file(GDKgetenv("gdk_dbpath"),
+GDKgetenv("gdk_dbtrace"));
+}
+
 
 static void
 set_level_for_layer(int layer, int lvl)
@@ -418,13 +421,14 @@ GDKtracer_reset_adapter(void)
 static bool add_ts;/* add timestamp to error message to stderr */
 
 void
-GDKtracer_init(void)
+GDKtracer_init(const char *dbpath, const char *dbtrace)
 {
 #ifdef _MSC_VER
add_ts = GetFileType(GetStdHandle(STD_ERROR_HANDLE)) != FILE_TYPE_PIPE;
 #else
add_ts = isatty(2) || lseek(2, 0, SEEK_CUR) != (off_t) -1 || errno != 
ESPIPE;
 #endif
+   (void) GDKtracer_init_trace_file(dbpath, dbtrace);
 }
 
 void
@@ -487,7 +491,7 @@ GDKtracer_log(const char *file, const ch
if ((p = strchr(buffer, '\n')) != NULL)
*p = '\0';
 
-   if (comp == GDK && (level == M_CRITICAL || level == M_ERROR)) {
+   if (comp == GDK && level <= M_ERROR) {
/* append message to GDKerrbuf (if set) */
char *buf = GDKerrbuf;
if (buf) {
@@ -500,7 +504,7 @@ GDKtracer_log(const char *file, const ch
}
}
 
-   if (level == M_CRITICAL || level == M_ERROR || level == M_WARNING) {
+   if (level <= M_WARNING) {
fprintf(stderr, "#%s%s%s: %s: %s%s%s%s\n",
add_ts ? ts : "",
add_ts ? ": " : "",
@@ -510,12 +514,8 @@ GDKtracer_log(const char *file, const ch
if (active_tracer == NULL || active_tracer == stderr)
return;
}
-   MT_lock_set(&GDKtracer_lock);
-   if (file_name[0] == 0) {
-   MT_lock_unset(&GDKtracer_lock);
+   if (active_tracer == NULL)
return;
-   }
-   MT_lock_unset(&GDKtracer_lock);
if (syserr)
fprintf(active_tracer, "%s: %s\n", buffer, syserr);
else
@@ -527,7 +527,7 @@ GDKtracer_log(const char *file, const ch
// like mserver5 refusing to start due to allocated port
// and the error is never reported to the user because it
// is still in the buffer which it never gets flushed.
-   if (level == cur_flush_level || level == M_CRITICAL || level == M_ERROR)
+   

MonetDB: default - Merged with Oct2020

2021-01-13 Thread Pedro Ferreira
Changeset: 9972b087967b for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=9972b087967b
Modified Files:
sql/backends/monet5/rel_bin.c
sql/backends/monet5/sql_statement.c
sql/backends/monet5/sql_statement.h
sql/test/SQLancer/Tests/sqlancer09.test
Branch: default
Log Message:

Merged with Oct2020


diffs (truncated from 751 to 300 lines):

diff --git a/sql/backends/monet5/rel_bin.c b/sql/backends/monet5/rel_bin.c
--- a/sql/backends/monet5/rel_bin.c
+++ b/sql/backends/monet5/rel_bin.c
@@ -75,7 +75,7 @@ sql_unop_(backend *be, const char *fname
f->res.scale = rt->scale;
}
*/
-   return stmt_unop(be, rs, f);
+   return stmt_unop(be, rs, NULL, f);
} else if (rs) {
char *type = tail_type(rs)->type->sqlname;
 
@@ -395,9 +395,9 @@ handle_in_exps(backend *be, sql_exp *ce,
if(!i)
return NULL;
 
-   i = stmt_binop(be, c, i, cmp);
+   i = stmt_binop(be, c, i, sel, cmp);
if (s)
-   s = stmt_binop(be, s, i, a);
+   s = stmt_binop(be, s, i, sel, a);
else
s = i;
 
@@ -558,7 +558,7 @@ exp_bin_or(backend *be, sql_exp *e, stmt
if (!sin && sel1 && sel1->nrcols == 0 && s->nrcols == 0) {
sql_subfunc *f = sql_bind_func(be->mvc, "sys", 
anti?"or":"and", bt, bt, F_FUNC);
assert(f);
-   s = stmt_binop(be, sel1, s, f);
+   s = stmt_binop(be, sel1, s, sin, f);
} else if (sel1 && (sel1->nrcols == 0 || s->nrcols == 0)) {
stmt *predicate = bin_first_column(be, left);
 
@@ -585,7 +585,7 @@ exp_bin_or(backend *be, sql_exp *e, stmt
if (!sin && sel2 && sel2->nrcols == 0 && s->nrcols == 0) {
sql_subfunc *f = sql_bind_func(be->mvc, "sys", 
anti?"or":"and", bt, bt, F_FUNC);
assert(f);
-   s = stmt_binop(be, sel2, s, f);
+   s = stmt_binop(be, sel2, s, sin, f);
} else if (sel2 && (sel2->nrcols == 0 || s->nrcols == 0)) {
stmt *predicate = bin_first_column(be, left);
 
@@ -600,7 +600,7 @@ exp_bin_or(backend *be, sql_exp *e, stmt
if (sel1->nrcols == 0 && sel2->nrcols == 0) {
sql_subfunc *f = sql_bind_func(be->mvc, "sys", anti?"and":"or", 
bt, bt, F_FUNC);
assert(f);
-   return stmt_binop(be, sel1, sel2, f);
+   return stmt_binop(be, sel1, sel2, NULL, f);
}
if (sel1->nrcols == 0) {
stmt *predicate = bin_first_column(be, left);
@@ -714,7 +714,7 @@ exp2bin_case(backend *be, sql_exp *fe, s
assert(next_cond);
if (next_cond) {
if (cond) {
-   ncond = stmt_binop(be, cond, 
es, and);
+   ncond = stmt_binop(be, cond, 
es, nsel, and);
} else {
ncond = es;
}
@@ -728,12 +728,12 @@ exp2bin_case(backend *be, sql_exp *fe, s
res = NULL;
 
if (en->next) {
-   cond = stmt_unop(be, cond, not);
+   cond = stmt_unop(be, cond, nsel, not);
 
sql_subfunc *isnull = 
sql_bind_func(be->mvc, "sys", "isnull", bt, NULL, F_FUNC);
-   cond = stmt_binop(be, cond, 
stmt_unop(be, cond, isnull), or);
+   cond = stmt_binop(be, cond, 
stmt_unop(be, cond, nsel, isnull), nsel, or);
if (ocond)
-   cond = stmt_binop(be, ocond, 
cond, and);
+   cond = stmt_binop(be, ocond, 
cond, nsel, and);
ocond = cond;
if (!en->next->next)
ncond = cond;
@@ -799,7 +799,7 @@ exp2bin_coalesce(backend *be, sql_exp *f
 
if (en->next) {
sql_subfunc *a = sql_bind_func(be->mvc, 
"sys", "isnotnull", tail_type(es), NULL, F_FUNC);
-   ncond = stmt_unop(be, es, a);
+   ncond = stmt_unop(be, es, NULL, a); 
/*TODO sql/test/coalesce failing for passing 'nsel' here */
if (nco

MonetDB: default - Merged with Oct2020

2021-01-12 Thread Pedro Ferreira
Changeset: 43baac65bf3b for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=43baac65bf3b
Modified Files:
clients/Tests/MAL-signatures.stable.out
clients/Tests/MAL-signatures.stable.out.int128
sql/backends/monet5/rel_bin.c
sql/test/BugTracker-2020/Tests/values-like-join.Bug-6954.stable.out
sql/test/SQLancer/Tests/sqlancer04.test
sql/test/miscellaneous/Tests/simple_plans.stable.out
Branch: default
Log Message:

Merged with Oct2020


diffs (truncated from 444 to 300 lines):

diff --git a/clients/Tests/MAL-signatures.stable.out 
b/clients/Tests/MAL-signatures.stable.out
--- a/clients/Tests/MAL-signatures.stable.out
+++ b/clients/Tests/MAL-signatures.stable.out
@@ -621,8 +621,8 @@ stdout of test 'MAL-signatures` in direc
 [ "algebra",   "ilike","command algebra.ilike(X_1:str, X_2:str, 
X_3:str):bit ","PCREilike3;",  ""  ]
 [ "algebra",   "ilikejoin","command algebra.ilikejoin(X_1:bat[:str], 
X_2:bat[:str], X_3:bat[:oid], X_4:bat[:oid], X_5:bit, X_6:lng, 
X_7:bit):bat[:oid] ",  "ILIKEjoin1;",  ""  ]
 [ "algebra",   "ilikejoin","command algebra.ilikejoin(X_2:bat[:str], 
X_3:bat[:str], X_4:bat[:oid], X_5:bat[:oid], X_6:bit, X_7:lng, X_8:bit) 
(X_0:bat[:oid], X_1:bat[:oid]) ", "ILIKEjoin;",   ""  ]
-[ "algebra",   "ilikejoin","command algebra.ilikejoin(X_1:bat[:str], 
X_2:bat[:str], X_3:str, X_4:bat[:oid], X_5:bat[:oid], X_6:bit, X_7:lng, 
X_8:bit):bat[:oid] ", "ILIKEjoin_esc1;",  ""  ]
-[ "algebra",   "ilikejoin","command algebra.ilikejoin(X_2:bat[:str], 
X_3:bat[:str], X_4:str, X_5:bat[:oid], X_6:bat[:oid], X_7:bit, X_8:lng, 
X_9:bit) (X_0:bat[:oid], X_1:bat[:oid]) ","ILIKEjoin_esc;",   ""  ]
+[ "algebra",   "ilikejoin","command algebra.ilikejoin(X_1:bat[:str], 
X_2:bat[:str], X_3:bat[:str], X_4:bat[:oid], X_5:bat[:oid], X_6:bit, X_7:lng, 
X_8:bit):bat[:oid] ",   "ILIKEjoin_esc1;",  ""  ]
+[ "algebra",   "ilikejoin","command algebra.ilikejoin(X_2:bat[:str], 
X_3:bat[:str], X_4:bat[:str], X_5:bat[:oid], X_6:bat[:oid], X_7:bit, X_8:lng, 
X_9:bit) (X_0:bat[:oid], X_1:bat[:oid]) ",  "ILIKEjoin_esc;",   ""  
]
 [ "algebra",   "ilikeselect",  "command algebra.ilikeselect(X_1:bat[:str], 
X_2:bat[:oid], X_3:str, X_4:str, X_5:bit):bat[:oid] ",  "PCRElikeselect1;", 
""  ]
 [ "algebra",   "ilikeselect",  "command algebra.ilikeselect(X_1:bat[:str], 
X_2:bat[:oid], X_3:str, X_4:bit):bat[:oid] ",   "PCRElikeselect4;", ""  
]
 [ "algebra",   "intersect","command algebra.intersect(X_1:bat[:any_1], 
X_2:bat[:any_1], X_3:bat[:oid], X_4:bat[:oid], X_5:bit, X_6:bit, 
X_7:lng):bat[:oid] ",  "ALGintersect;",""  ]
@@ -634,8 +634,8 @@ stdout of test 'MAL-signatures` in direc
 [ "algebra",   "like", "command algebra.like(X_1:str, X_2:str, X_3:str):bit ", 
"PCRElike3;",   ""  ]
 [ "algebra",   "likejoin", "command algebra.likejoin(X_1:bat[:str], 
X_2:bat[:str], X_3:bat[:oid], X_4:bat[:oid], X_5:bit, X_6:lng, 
X_7:bit):bat[:oid] ",   "LIKEjoin1;",   ""  ]
 [ "algebra",   "likejoin", "command algebra.likejoin(X_2:bat[:str], 
X_3:bat[:str], X_4:bat[:oid], X_5:bat[:oid], X_6:bit, X_7:lng, X_8:bit) 
(X_0:bat[:oid], X_1:bat[:oid]) ",  "LIKEjoin;",""  ]
-[ "algebra",   "likejoin", "command algebra.likejoin(X_1:bat[:str], 
X_2:bat[:str], X_3:str, X_4:bat[:oid], X_5:bat[:oid], X_6:bit, X_7:lng, 
X_8:bit):bat[:oid] ",  "LIKEjoin_esc1;",   ""  ]
-[ "algebra",   "likejoin", "command algebra.likejoin(X_2:bat[:str], 
X_3:bat[:str], X_4:str, X_5:bat[:oid], X_6:bat[:oid], X_7:bit, X_8:lng, 
X_9:bit) (X_0:bat[:oid], X_1:bat[:oid]) ", "LIKEjoin_esc;",""  ]
+[ "algebra",   "likejoin", "command algebra.likejoin(X_1:bat[:str], 
X_2:bat[:str], X_3:bat[:str], X_4:bat[:oid], X_5:bat[:oid], X_6:bit, X_7:lng, 
X_8:bit):bat[:oid] ","LIKEjoin_esc1;",   ""  ]
+[ "algebra",   "likejoin", "command algebra.likejoin(X_2:bat[:str], 
X_3:bat[:str], X_4:bat[:str], X_5:bat[:oid], X_6:bat[:oid], X_7:bit, X_8:lng, 
X_9:bit) (X_0:bat[:oid], X_1:bat[:oid]) ",   "LIKEjoin_esc;","" 
 ]
 [ "algebra",   "likeselect",   "command algebra.likeselect(X_1:bat[:str], 
X_2:bat[:oid], X_3:str, X_4:str, X_5:bit, X_6:bit):bat[:oid] ",  
"PCRElikeselect2;", ""  ]
 [ "algebra",   "likeselect",   "command algebra.likeselect(X_1:bat[:str], 
X_2:bat[:oid], X_3:str, X_4:str, X_5:bit):bat[:oid] ",   
"PCRElikeselect3;", ""  ]
 [ "algebra",   "likeselect",   "command algebra.likeselect(X_1:bat[:str], 
X_2:bat[:oid], X_3:str, X_4:bit):bat[:oid] ","PCRElikeselect5;", "" 
 ]
diff --git a/clients/Tests/MAL-signatures.stable.out.int128 
b/clients/Tests/MAL-signatures.stable.out.int128
--- a/clients/Tests/MAL-signatures.stable.out.int128
+++ b/clients/Tests/MAL-signatures.stable.out.int128
@@ -734,8 +734,8 @@ stdout of test 'MAL-signatures` in direc
 [ "algebra",   "ili

MonetDB: default - Merged with Oct2020

2021-01-12 Thread Pedro Ferreira
Changeset: b2d618bb511c for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=b2d618bb511c
Branch: default
Log Message:

Merged with Oct2020


diffs (215 lines):

diff --git a/sql/test/SQLancer/Tests/sqlancer04.sql 
b/sql/test/SQLancer/Tests/sqlancer04.sql
--- a/sql/test/SQLancer/Tests/sqlancer04.sql
+++ b/sql/test/SQLancer/Tests/sqlancer04.sql
@@ -330,3 +330,25 @@ ROLLBACK;
 
 select cast(interval '29578044' second as time);
-- 08:07:24
+
+START TRANSACTION;
+create view v3(vc0) as (values (not ((r'%') is not null)), (least(cast(1 as 
boolean), not (true))), (case sql_min(r'vFP*鱍', r'&G*')
+when cast(0 as string) then (true) is null when cast(9 as string(678)) then 
((true)or(false)) end), (false)) with check option;
+create view v20(vc0) as (values (((sql_max(2, 
0.8207251106243245164506561195594258606433868408203125))&(abs(0.25579435);
+create view v37(vc0) as (values (r'1837521830'), (replace(coalesce(r'4', r'', 
r'20', r'0.5074455058602168'),
+case 1108638173 when 1 then r'PS   ' when 
0.4804786358649317801194911226048134267330169677734375 then r'' else
+r'XCWVB' end, cast(false as string with check option;
+create view v40(vc0) as (values ((true) not in (false, false)), 
("isauuid"(case 8 when 4 then r'F&' when 0 then r'&' end)));
+
+select cast(sum(count) as bigint) from (select cast(greatest(false, true) as 
int) as count from v37 full outer join
+(select all 1074663557)%(0.8367095941704169)))%(scale_up(v20.vc0, 
0.25281408194923194))), 0.573499282341099
+from v20 where true)or(true)))or(true)) group by 2) as sub0 on
+((case 0.28276833606549456323620006514829583466053009033203125 when 1 then 
v37.vc0 when 1436332976 then r'FALSE'
+when 0.4573545 then v37.vc0 else r'G1hw7' end)not ilike(sql_min(r'46', 
v37.vc0))) inner join (select (case v3.vc0
+when v40.vc0 then -2078582481 when v40.vc0 then 
0.26386297637506184177169643589877523481845855712890625 when v3.vc0
+then 6 when v40.vc0 then 
0.37311851701627662958316022923099808394908905029296875 when v40.vc0
+then 0.78255921469665923329017687137820757925510406494140625 end) is null, + 
(case r'14' when r'p.e4xf'
+then 0.8350239383024128 when r'6r' then 932574625 when r'[]' then 9 when r'' 
then 5 when r'LnP/Amb9' then 2 end)
+from v40, v3 where (0.490620891559853081140194903127849102020263671875) 
not in (1654919043, 6)) as sub1
+on ((trim(v37.vc0))>=(substr(v37.vc0, 9, 8 as res;
+ROLLBACK;
diff --git a/sql/test/SQLancer/Tests/sqlancer04.stable.out 
b/sql/test/SQLancer/Tests/sqlancer04.stable.out
--- a/sql/test/SQLancer/Tests/sqlancer04.stable.out
+++ b/sql/test/SQLancer/Tests/sqlancer04.stable.out
@@ -52,23 +52,23 @@ stdout of test 'sqlancer04` in directory
 #SELECT 1 FROM t1 LEFT OUTER JOIN t0 ON TRUE 
 #LEFT OUTER JOIN (SELECT 1 FROM t0) AS sub0 ON TRUE 
 #WHERE (TIME '00:25:07') IN (TIME '07:29:34', CASE 2 WHEN 2 THEN TIME 
'17:23:46' ELSE TIME '05:14:30' END);
-% .%21 # table_name
-% %21 # name
+% .%6 # table_name
+% %6 # name
 % tinyint # type
 % 1 # length
 #SELECT 1 FROM t1 LEFT OUTER JOIN t0 ON TRUE 
 #LEFT OUTER JOIN (SELECT 1 FROM t0) AS sub0 ON TRUE 
 #WHERE t0.c0 <= t0.c0 AND (TIME '00:25:07') IN (TIME '07:29:34', CASE 2 WHEN 2 
THEN TIME '17:23:46' ELSE TIME '05:14:30' END);
-% .%21 # table_name
-% %21 # name
+% .%6 # table_name
+% %6 # name
 % tinyint # type
 % 1 # length
 #SELECT ALL COUNT(TIME '06:32:50') FROM t1 LEFT OUTER JOIN t0 ON TRUE 
 #LEFT OUTER JOIN (SELECT t1.c1, t0.c1, 0.43 FROM t0, t1) AS sub0 ON TRUE 
 #WHERE ((NOT ((TIME '00:25:07') IN (TIME '07:29:34', TIME '05:21:58', CASE 
0.54 WHEN 0.65 THEN TIME '17:23:46' ELSE TIME '05:14:30' END 
 #GROUP BY TIMESTAMP '1969-12-08 01:47:58';
-% .%13 # table_name
-% %13 # name
+% .%7 # table_name
+% %7 # name
 % bigint # type
 % 1 # length
 [ 3]
@@ -121,15 +121,15 @@ stdout of test 'sqlancer04` in directory
 [ 11   ]
 #SELECT CAST(SUM(ALL 0.14) AS DECIMAL(10,2)) FROM sys.t0 JOIN sys.t1 ON 
CAST(CASE t0.c1 WHEN t1.c1 THEN NOT (FALSE) WHEN t1.c1 THEN (t0.c0) NOT  
BETWEEN ASYMMETRIC (t1.c0) AND (t0.c0) WHEN t0.c1 
 #THEN (0.2) IN (0.3) END AS BOOLEAN) GROUP BY NOT (FALSE), 
COALESCE(((COALESCE(2, 4, 1))<<(COALESCE(5, -6))), ((COALESCE('-8', -4, 
6))|(COALESCE(-2, 3, 4, 5, -6;
-% .%10 # table_name
-% %10 # name
+% .%6 # table_name
+% %6 # name
 % decimal # type
 % 12 # length
 [ 0.42 ]
 #SELECT PROD(ALL 0.14) FROM t0 JOIN t1 ON CAST(CASE t0.c1 WHEN t1.c1 THEN NOT 
(FALSE) WHEN t1.c1 THEN (t0.c0) NOT  BETWEEN ASYMMETRIC (t1.c0) AND (t0.c0) 
WHEN t0.c1 
 #THEN (0.2) IN (0.3) END AS BOOLEAN) GROUP BY NOT (FALSE), 
COALESCE(((COALESCE(2, 4, 1))<<(COALESCE(5, -6))), ((COALESCE(r'-8', -4, 
6))|(COALESCE(-2, 3, 4, 5, -6;
-% .%7 # table_name
-% %7 # name
+% .%5 # table_name
+% %5 # name
 % double # type
 % 24 # length
 [ 0.002744 ]
@@ -191,8 +191,8 @@ stdout of test 'sqlancer04` in directory
 #SELECT ALL MAX(ALL CASE WHEN (DATE '1970-01-04') IS NULL THEN CAST(CASE t1.c0 
WHEN t1.c0 THEN TIME '11:33:56' END AS VARCHAR

MonetDB: default - Merged with Oct2020

2021-01-12 Thread Pedro Ferreira
Changeset: 048a5e75c5cd for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=048a5e75c5cd
Modified Files:
sql/backends/monet5/sql_fround_impl.h
sql/server/rel_select.c
sql/test/SQLancer/Tests/sqlancer02.sql
sql/test/SQLancer/Tests/sqlancer02.stable.out
Branch: default
Log Message:

Merged with Oct2020


diffs (247 lines):

diff --git a/sql/backends/monet5/sql_fround_impl.h 
b/sql/backends/monet5/sql_fround_impl.h
--- a/sql/backends/monet5/sql_fround_impl.h
+++ b/sql/backends/monet5/sql_fround_impl.h
@@ -38,6 +38,8 @@ dec_round_wrap(TYPE *res, const TYPE *v,
if (rr <= 0)
throw(MAL, "round", SQLSTATE(42000) "Argument 2 to round 
function must be positive");
*res = ISNIL(TYPE)(*v) ? NIL(TYPE) : dec_round_body(*v, rr);
+   if (isinf(*res))
+   throw(MAL, "round", SQLSTATE(22003) "Overflow in round");
return MAL_SUCCEED;
 }
 
@@ -95,6 +97,10 @@ bat_dec_round_wrap(Client cntxt, MalBlkP
nils = true;
} else {
dst[i] = dec_round_body(x, r);
+   if (isinf(dst[i])) {
+   msg = createException(MAL, "round", 
SQLSTATE(22003) "Overflow in round");
+   goto bailout;
+   }
}
}
} else {
@@ -107,6 +113,10 @@ bat_dec_round_wrap(Client cntxt, MalBlkP
nils = true;
} else {
dst[i] = dec_round_body(x, r);
+   if (isinf(dst[i])) {
+   msg = createException(MAL, "round", 
SQLSTATE(22003) "Overflow in round");
+   goto bailout;
+   }
}
}
}
@@ -168,6 +178,10 @@ bat_dec_round_wrap_cst(Client cntxt, Mal
nils = true;
} else {
dst[i] = dec_round_body(x, r);
+   if (isinf(dst[i])) {
+   msg = createException(MAL, "round", 
SQLSTATE(22003) "Overflow in round");
+   goto bailout;
+   }
}
}
} else {
@@ -186,6 +200,10 @@ bat_dec_round_wrap_cst(Client cntxt, Mal
nils = true;
} else {
dst[i] = dec_round_body(x, r);
+   if (isinf(dst[i])) {
+   msg = createException(MAL, "round", 
SQLSTATE(22003) "Overflow in round");
+   goto bailout;
+   }
}
}
}
@@ -257,6 +275,10 @@ bat_dec_round_wrap_nocst(Client cntxt, M
nils = true;
} else {
dst[i] = dec_round_body(x, rr);
+   if (isinf(dst[i])) {
+   msg = createException(MAL, "round", 
SQLSTATE(22003) "Overflow in round");
+   goto bailout;
+   }
}
}
} else {
@@ -276,6 +298,10 @@ bat_dec_round_wrap_nocst(Client cntxt, M
nils = true;
} else {
dst[i] = dec_round_body(x, rr);
+   if (isinf(dst[i])) {
+   msg = createException(MAL, "round", 
SQLSTATE(22003) "Overflow in round");
+   goto bailout;
+   }
}
}
}
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
@@ -5293,21 +5293,18 @@ static sql_rel*
 rel_having_limits_nodes(sql_query *query, sql_rel *rel, SelectNode *sn, 
exp_kind ek, int group_totals)
 {
mvc *sql = query->sql;
+   sql_rel *inner = NULL;
+   int single_value = 1;
+
+   if (is_project(rel->op) && rel->l) {
+   inner = rel->l;
+   single_value = 0;
+   }
 
if (sn->having) {
-   sql_rel *inner = NULL;
-   int single_value = 1;
-
-   if (is_project(rel->op) && rel->l) {
-   inner = rel->l;
-   single_value = 0;
-   }
-
if (inner && is_groupby(inner->op))
set_processed(inner);
-   inner = rel_logical_exp(query, inner, sn->having, sql_having | 
group_totals);
-
-   if

MonetDB: default - Merged with Oct2020

2021-01-12 Thread Pedro Ferreira
Changeset: c44814e45a41 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=c44814e45a41
Modified Files:
sql/server/rel_optimizer.c
Branch: default
Log Message:

Merged with Oct2020


diffs (212 lines):

diff --git a/monetdb5/optimizer/opt_pushselect.c 
b/monetdb5/optimizer/opt_pushselect.c
--- a/monetdb5/optimizer/opt_pushselect.c
+++ b/monetdb5/optimizer/opt_pushselect.c
@@ -323,25 +323,45 @@ OPTpushselectImplementation(Client cntxt
!isaBatType(getArgType(mb, q, 
2)) && /* pattern is a value */
(q->argc != 4 || 
!isaBatType(getArgType(mb, q, 3))) /* escape is a value */
) {
-   InstrPtr r = newInstruction(mb, 
algebraRef, likeselectRef);
-   int has_cand = (getArgType(mb, p, 2) == 
newBatType(TYPE_oid));
+   bool has_null_semantics = false;
+   int has_cand = (getArgType(mb, p, 2) == 
newBatType(TYPE_oid)), offset = 0;
int a, anti = (getFunctionId(q)[0] == 
'n'), ignore_case = (getFunctionId(q)[anti?4:0] == 'i');
 
-   getArg(r,0) = getArg(p,0);
-   r = addArgument(mb, r, getArg(q, 1));
-   if (has_cand)
-   r = addArgument(mb, r, 
getArg(p, 2));
-   for(a = 2; aargc; a++)
-   r = addArgument(mb, r, 
getArg(q, a));
-   if (r->argc < (4+has_cand))
-   r = pushStr(mb, r, ""); /* 
default esc */
-   if (r->argc < (5+has_cand))
-   r = pushBit(mb, r, ignore_case);
-   if (r->argc < (6+has_cand))
-   r = pushBit(mb, r, anti);
-   freeInstruction(p);
-   p = r;
-   actions++;
+   /* TODO at the moment we cannot convert 
if the select statement has NULL semantics
+   we can convert it into VAL is 
NULL or PATERN is NULL or ESCAPE is NULL
+   */
+   if (getFunctionId(p) == selectRef && 
isVarConstant(mb,getArg(p, 2 + has_cand)) && isVarConstant(mb,getArg(p, 3 + 
has_cand))
+   && isVarConstant(mb,getArg(p, 4 
+ has_cand)) && isVarConstant(mb,getArg(p, 5 + has_cand))) {
+   ValRecord low = 
getVarConstant(mb, getArg(p, 2 + has_cand)), high = getVarConstant(mb, 
getArg(p, 3 + has_cand));
+   bit li = *(bit*)getVarValue(mb, 
getArg(p, 4 + has_cand)), hi = *(bit*)getVarValue(mb, getArg(p, 5 + has_cand));
+
+   if (li && hi && VALisnil(&low) 
&& VALisnil(&high))
+   has_null_semantics = 
true;
+   }
+
+   if (!has_null_semantics) {
+   InstrPtr r = newInstruction(mb, 
algebraRef, likeselectRef);
+   getArg(r,0) = getArg(p,0);
+   r = addArgument(mb, r, 
getArg(q, 1));
+   if (has_cand) {
+   r = addArgument(mb, r, 
getArg(p, 2));
+   offset = 1;
+   } else if 
(isaBatType(getArgType(mb, q, 1))) { /* likeselect calls have a candidate 
parameter */
+   r = pushNil(mb, r, 
TYPE_bat);
+   offset = 1;
+   }
+   for(a = 2; aargc; a++)
+   r = addArgument(mb, r, 
getArg(q, a));
+   if (r->argc < (4+offset))
+   r = pushStr(mb, r, ""); 
/* default esc */
+   if (r->argc < (5+offset))
+   r = pushBit(mb, r, 
ignore_case);
+   if (r->argc < (6+offset))
+ 

MonetDB: default - Merged with Oct2020

2021-01-08 Thread Pedro Ferreira
Changeset: da6be94e2d68 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=da6be94e2d68
Modified Files:
sql/backends/monet5/sql_fround_impl.h
sql/test/SQLancer/Tests/sqlancer09.test
Branch: default
Log Message:

Merged with Oct2020


diffs (truncated from 388 to 300 lines):

diff --git a/gdk/gdk_calc.c b/gdk/gdk_calc.c
--- a/gdk/gdk_calc.c
+++ b/gdk/gdk_calc.c
@@ -7956,7 +7956,7 @@ div_##TYPE1##_##TYPE2##_##TYPE3(const TY
nils++; \
} else if (rgt[j] == 0 ||   \
   (ABSOLUTE(rgt[j]) < 1 && \
-   GDK_##TYPE3##_max * ABSOLUTE(rgt[j]) < 
lft[i])) { \
+   GDK_##TYPE3##_max * ABSOLUTE(rgt[j]) < 
ABSOLUTE(lft[i]))) { \
/* only check for overflow, not for underflow 
*/ \
if (abort_on_error) {   \
if (rgt[j] == 0)\
@@ -7986,7 +7986,7 @@ div_##TYPE1##_##TYPE2##_##TYPE3(const TY
nils++; \
} else if (rgt[j] == 0 ||   \
   (ABSOLUTE(rgt[j]) < 1 && \
-   GDK_##TYPE3##_max * ABSOLUTE(rgt[j]) < 
lft[i])) { \
+   GDK_##TYPE3##_max * ABSOLUTE(rgt[j]) < 
ABSOLUTE(lft[i]))) { \
/* only check for overflow, not for underflow 
*/ \
if (abort_on_error) {   \
if (rgt[j] == 0)\
diff --git a/gdk/gdk_system.c b/gdk/gdk_system.c
--- a/gdk/gdk_system.c
+++ b/gdk/gdk_system.c
@@ -247,6 +247,8 @@ find_winthread(DWORD tid)
 const char *
 MT_thread_getname(void)
 {
+   if (threadslot == TLS_OUT_OF_INDEXES)
+   return mainthread.threadname;
struct winthread *w = TlsGetValue(threadslot);
return w ? w->threadname : UNKNOWN_THREAD;
 }
@@ -254,6 +256,8 @@ MT_thread_getname(void)
 void
 MT_thread_setdata(void *data)
 {
+   if (threadslot == TLS_OUT_OF_INDEXES)
+   return;
struct winthread *w = TlsGetValue(threadslot);
 
if (w)
@@ -263,6 +267,8 @@ MT_thread_setdata(void *data)
 void
 MT_thread_setlockwait(MT_Lock *lock)
 {
+   if (threadslot == TLS_OUT_OF_INDEXES)
+   return;
struct winthread *w = TlsGetValue(threadslot);
 
if (w)
@@ -272,6 +278,8 @@ MT_thread_setlockwait(MT_Lock *lock)
 void
 MT_thread_setsemawait(MT_Sema *sema)
 {
+   if (threadslot == TLS_OUT_OF_INDEXES)
+   return;
struct winthread *w = TlsGetValue(threadslot);
 
if (w)
@@ -281,6 +289,8 @@ MT_thread_setsemawait(MT_Sema *sema)
 void
 MT_thread_setworking(const char *work)
 {
+   if (threadslot == TLS_OUT_OF_INDEXES)
+   return;
struct winthread *w = TlsGetValue(threadslot);
 
if (w)
@@ -290,6 +300,8 @@ MT_thread_setworking(const char *work)
 void
 MT_thread_setalgorithm(const char *algo)
 {
+   if (threadslot == TLS_OUT_OF_INDEXES)
+   return;
struct winthread *w = TlsGetValue(threadslot);
 
if (w) {
@@ -309,6 +321,8 @@ MT_thread_setalgorithm(const char *algo)
 const char *
 MT_thread_getalgorithm(void)
 {
+   if (threadslot == TLS_OUT_OF_INDEXES)
+   return NULL;
struct winthread *w = TlsGetValue(threadslot);
 
return w && w->algorithm[0] ? w->algorithm : NULL;
@@ -317,6 +331,8 @@ MT_thread_getalgorithm(void)
 bool
 MT_thread_override_limits(void)
 {
+   if (threadslot == TLS_OUT_OF_INDEXES)
+   return false;
struct winthread *w = TlsGetValue(threadslot);
 
return w && w->working && strcmp(w->working, "store locked") == 0;
@@ -325,6 +341,8 @@ MT_thread_override_limits(void)
 void *
 MT_thread_getdata(void)
 {
+   if (threadslot == TLS_OUT_OF_INDEXES)
+   return;
struct winthread *w = TlsGetValue(threadslot);
 
return w ? w->data : NULL;
@@ -471,6 +489,9 @@ MT_getpid(void)
 void
 MT_exiting_thread(void)
 {
+   if (threadslot == TLS_OUT_OF_INDEXES)
+   return;
+
struct winthread *w = TlsGetValue(threadslot);
 
if (w) {
@@ -555,6 +576,7 @@ static pthread_mutex_t posthread_lock = 
 static MT_Id MT_thread_id = 1;
 
 static pthread_key_t threadkey;
+static bool thread_initialized = false;
 
 void
 dump_threads(void)
@@ -584,6 +606,7 @@ MT_thread_init(void)
GDKsyserr(ret, "Creating specific key for thread failed");
return false;
}
+   thread_initialized = true;
mainthread.tid = pthread_self();
if ((ret = pthread_setspecific(threadkey, &mainthread)) != 0) {
GDKsyserr(re

MonetDB: default - Merged with Oct2020

2021-01-08 Thread Pedro Ferreira
Changeset: 68e5327f51d1 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=68e5327f51d1
Modified Files:
gdk/gdk_join.c
sql/backends/monet5/sql_fround_impl.h
sql/backends/monet5/sql_round_impl.h
Branch: default
Log Message:

Merged with Oct2020


diffs (truncated from 705 to 300 lines):

diff --git a/gdk/gdk_calc.c b/gdk/gdk_calc.c
--- a/gdk/gdk_calc.c
+++ b/gdk/gdk_calc.c
@@ -66,6 +66,23 @@ checkbats(BAT *b1, BAT *b2, const char *
return GDK_SUCCEED;
 }
 
+#define ON_OVERFLOW1(TYPE, OP) \
+   do {\
+   GDKerror("22003!overflow in calculation "   \
+OP "(" FMT##TYPE ").\n",   \
+CST##TYPE src[x]); \
+   BBPreclaim(bn); \
+   return NULL;\
+   } while (0)
+
+#define ON_OVERFLOW(TYPE1, TYPE2, OP)  \
+   do {\
+   GDKerror("22003!overflow in calculation "   \
+FMT##TYPE1 OP FMT##TYPE2 ".\n",\
+CST##TYPE1 ((TYPE1 *)lft)[i], CST##TYPE2 ((TYPE2 
*)rgt)[j]); \
+   return BUN_NONE;\
+   } while (0)
+
 #define UNARY_2TYPE_FUNC(TYPE1, TYPE2, FUNC)   \
do {\
const TYPE1 *restrict src = (const TYPE1 *) Tloc(b, 0); \
@@ -81,6 +98,24 @@ checkbats(BAT *b1, BAT *b2, const char *
}   \
} while (0)
 
+#define UNARY_2TYPE_FUNC_nilcheck(TYPE1, TYPE2, FUNC, on_overflow) \
+   do {\
+   const TYPE1 *restrict src = (const TYPE1 *) Tloc(b, 0); \
+   TYPE2 *restrict dst = (TYPE2 *) Tloc(bn, 0);\
+   for (i = 0; i < ci.ncand; i++) {\
+   x = canditer_next(&ci) - b->hseqbase;   \
+   if (is_##TYPE1##_nil(src[x])) { \
+   nils++; \
+   dst[i] = TYPE2##_nil;   \
+   } else {\
+   dst[i] = FUNC(src[x]);  \
+   if (is_##TYPE2##_nil(dst[i])) { \
+   on_overflow;\
+   }   \
+   }   \
+   }   \
+   } while (0)
+
 #define BINARY_3TYPE_FUNC(TYPE1, TYPE2, TYPE3, FUNC)   \
do {\
i = j = 0;  \
@@ -117,6 +152,46 @@ checkbats(BAT *b1, BAT *b2, const char *
}   \
} while (0)
 
+#define BINARY_3TYPE_FUNC_nilcheck(TYPE1, TYPE2, TYPE3, FUNC, on_overflow) \
+   do {\
+   i = j = 0;  \
+   if (ci1->tpe == cand_dense && ci2->tpe == cand_dense) { \
+   for (k = 0; k < ci1->ncand; k++) {  \
+   if (incr1)  \
+   i = canditer_next_dense(ci1) - 
candoff1; \
+   if (incr2)  \
+   j = canditer_next_dense(ci2) - 
candoff2; \
+   TYPE1 v1 = ((const TYPE1 *) lft)[i];\
+   TYPE2 v2 = ((const TYPE2 *) rgt)[j];\
+   if (is_##TYPE1##_nil(v1) || 
is_##TYPE2##_nil(v2)) { \
+   nils++; \
+   ((TYPE3 *) dst)[k] = TYPE3##_nil; \
+   } else {\
+   ((TYPE3 *) dst)[k] = FUNC(v1, v2); \
+   if (is_##TYPE3##_nil(((TYPE3 *) 
dst)[k])) \
+   on_overflow;\
+   }   \
+   }   \
+   } else { 

MonetDB: default - Merged with Oct2020

2021-01-07 Thread Pedro Ferreira
Changeset: afff2f2c983a for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=afff2f2c983a
Modified Files:
MonetDB.spec
sql/backends/monet5/rel_bin.c
sql/common/sql_types.c
sql/common/sql_types.h
sql/server/rel_optimizer.c
sql/server/rel_unnest.c
sql/server/sql_atom.c
sql/server/sql_mvc.c
sql/server/sql_mvc.h
sql/server/sql_parser.y
sql/server/sql_semantic.c
sql/storage/sql_storage.h
sql/storage/store.c
sql/test/SQLancer/Tests/sqlancer09.test
sql/test/sysmon/Tests/All
Branch: default
Log Message:

Merged with Oct2020


diffs (truncated from 4951 to 300 lines):

diff --git a/MonetDB.spec b/MonetDB.spec
--- a/MonetDB.spec
+++ b/MonetDB.spec
@@ -41,25 +41,15 @@
 %global fedpkgs 1
 %endif
 
-%if %{?rhel:1}%{!?rhel:0} && 0%{?rhel} < 7
-# RedHat Enterprise Linux < 7
-# There is no macro _rundir, and no directory /run, instead use /var/run.
-%global _rundir %{_localstatedir}/run
-%endif
-
 # On Fedora, the geos library is available, and so we can require it
 # and build the geom modules.  On RedHat Enterprise Linux and
 # derivatives (CentOS, Scientific Linux), the geos library is not
 # available.  However, the geos library is available in the Extra
-# Packages for Enterprise Linux (EPEL).  However, On RHEL 6, the geos
-# library is too old for us, so we need an extra check for an
-# up-to-date version of RHEL.
+# Packages for Enterprise Linux (EPEL).
 %if %{fedpkgs}
-%if %{?rhel:0}%{!?rhel:1} || 0%{?rhel} >= 7
 # By default create the MonetDB-geom-MonetDB5 package on Fedora and RHEL 7
 %bcond_without geos
 %endif
-%endif
 
 # By default use PCRE for the implementation of the SQL LIKE and ILIKE
 # operators.  Otherwise the POSIX regex functions are used.
@@ -73,11 +63,8 @@
 %bcond_without rintegration
 %endif
 
-%if 0%{?rhel} >= 7 || 0%{?fedora} > 0
-# On RHEL 6, Python 3 is too old.  On RHEL 7, Python 3 was too old
-# when RHEL 7 was released, but now it is ok.
+# By default, include Python 3 integration.
 %bcond_without py3integration
-%endif
 
 %if %{fedpkgs}
 # By default, create the MonetDB-cfitsio package.
@@ -104,13 +91,10 @@ Source: https://www.monetdb.org/download
 # that doesn't exist and we need systemd, so instead we just require
 # the macro file that contains the definitions.
 # We need checkpolicy and selinux-policy-devel for the SELinux policy.
-%if %{?rhel:0}%{!?rhel:1} || 0%{?rhel} >= 7
-# RHEL >= 7, and all current Fedora
 BuildRequires: /usr/lib/rpm/macros.d/macros.systemd
 BuildRequires: checkpolicy
 BuildRequires: selinux-policy-devel
 BuildRequires: hardlink
-%endif
 BuildRequires: cmake3 >= 3.12
 BuildRequires: gcc
 BuildRequires: bison
@@ -497,9 +481,7 @@ Suggests: %{name}-client%{?_isa} = %{ver
 %endif
 # versions up to 1.0.5 don't accept the queryid field in the result set
 Conflicts: python-pymonetdb < 1.0.6
-%if %{?rhel:0}%{!?rhel:1} || 0%{?rhel} >= 7
 Requires(pre): systemd
-%endif
 
 %description -n MonetDB5-server
 MonetDB is a database management system that is developed from a
@@ -535,9 +517,7 @@ exit 0
 
 %files -n MonetDB5-server
 %defattr(-,root,root)
-%if %{?rhel:0}%{!?rhel:1} || 0%{?rhel} >= 7
 %{_sysusersdir}/monetdb.conf
-%endif
 %attr(2750,monetdb,monetdb) %dir %{_localstatedir}/lib/monetdb
 %attr(2770,monetdb,monetdb) %dir %{_localstatedir}/monetdb5
 %attr(2770,monetdb,monetdb) %dir %{_localstatedir}/monetdb5/dbfarm
@@ -589,9 +569,7 @@ Provides: %{name}-SQL-server5-hugeint%{?
 %if (0%{?fedora} >= 22)
 Suggests: %{name}-client%{?_isa} = %{version}-%{release}
 %endif
-%if %{?rhel:0}%{!?rhel:1} || 0%{?rhel} >= 7
 %{?systemd_requires}
-%endif
 
 %description SQL-server5
 MonetDB is a database management system that is developed from a
@@ -602,7 +580,6 @@ accelerators.  It also has an SQL front 
 This package contains the monetdb and monetdbd programs and the systemd
 configuration.
 
-%if %{?rhel:0}%{!?rhel:1} || 0%{?rhel} >= 7
 %post SQL-server5
 %systemd_post monetdbd.service
 
@@ -611,7 +588,6 @@ configuration.
 
 %postun SQL-server5
 %systemd_postun_with_restart monetdbd.service
-%endif
 
 %files SQL-server5
 %defattr(-,root,root)
@@ -619,16 +595,9 @@ configuration.
 %{_bindir}/monetdbd
 %dir %attr(775,monetdb,monetdb) %{_localstatedir}/log/monetdb
 %dir %attr(775,monetdb,monetdb) %{_rundir}/monetdb
-%if %{?rhel:0}%{!?rhel:1} || 0%{?rhel} >= 7
 # RHEL >= 7, and all current Fedora
 %{_tmpfilesdir}/monetdbd.conf
 %{_unitdir}/monetdbd.service
-%else
-# RedHat Enterprise Linux < 7
-%exclude %{_sysconfdir}/tmpfiles.d/monetdbd.conf
-# no _unitdir macro
-%exclude %{_prefix}/lib/systemd/system/monetdbd.service
-%endif
 %config(noreplace) %attr(664,monetdb,monetdb) 
%{_localstatedir}/monetdb5/dbfarm/.merovingian_properties
 %verify(not mtime) %attr(664,monetdb,monetdb) 
%{_localstatedir}/monetdb5/dbfarm/.merovingian_lock
 %config(noreplace) %attr(644,root,root) %{_sysconfdir}/logrotate.d/monetdbd
@@ -716,7 +685,6 @@ developer, but if you do wan

MonetDB: default - Merged with Oct2020

2021-01-06 Thread Pedro Ferreira
Changeset: 10efb81646f5 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=10efb81646f5
Modified Files:
monetdb5/modules/atoms/uuid.c
sql/backends/monet5/rel_bin.c
sql/backends/monet5/sql_statement.c
sql/server/rel_rel.c
sql/server/sql_scan.c
Branch: default
Log Message:

Merged with Oct2020


diffs (truncated from 519 to 300 lines):

diff --git a/debian/libmonetdb-client12.install 
b/debian/libmonetdb-client12.install
--- a/debian/libmonetdb-client12.install
+++ b/debian/libmonetdb-client12.install
@@ -1,2 +1,1 @@
-debian/tmp/usr/lib/x86_64-linux-gnu/libmapi.so.12 /usr/lib/x86_64-linux-gnu
-debian/tmp/usr/lib/x86_64-linux-gnu/libmapi.so.12.* /usr/lib/x86_64-linux-gnu
+debian/tmp/usr/lib/x86_64-linux-gnu/libmapi.so.* /usr/lib/x86_64-linux-gnu
diff --git a/debian/libmonetdb-stream14.install 
b/debian/libmonetdb-stream14.install
--- a/debian/libmonetdb-stream14.install
+++ b/debian/libmonetdb-stream14.install
@@ -1,2 +1,1 @@
-debian/tmp/usr/lib/x86_64-linux-gnu/libstream.so.14 usr/lib/x86_64-linux-gnu
-debian/tmp/usr/lib/x86_64-linux-gnu/libstream.so.14.* usr/lib/x86_64-linux-gnu
+debian/tmp/usr/lib/x86_64-linux-gnu/libstream.so.* usr/lib/x86_64-linux-gnu
diff --git a/debian/libmonetdb21.install b/debian/libmonetdb21.install
--- a/debian/libmonetdb21.install
+++ b/debian/libmonetdb21.install
@@ -1,2 +1,1 @@
-debian/tmp/usr/lib/x86_64-linux-gnu/libbat.so.21 usr/lib/x86_64-linux-gnu
-debian/tmp/usr/lib/x86_64-linux-gnu/libbat.so.21.* usr/lib/x86_64-linux-gnu
+debian/tmp/usr/lib/x86_64-linux-gnu/libbat.so.* usr/lib/x86_64-linux-gnu
diff --git a/debian/libmonetdbe1.install b/debian/libmonetdbe1.install
--- a/debian/libmonetdbe1.install
+++ b/debian/libmonetdbe1.install
@@ -1,2 +1,1 @@
-debian/tmp/usr/lib/x86_64-linux-gnu/libmonetdbe.so.1 usr/lib/x86_64-linux-gnu
-debian/tmp/usr/lib/x86_64-linux-gnu/libmonetdbe.so.1.* usr/lib/x86_64-linux-gnu
+debian/tmp/usr/lib/x86_64-linux-gnu/libmonetdbe.so.* usr/lib/x86_64-linux-gnu
diff --git a/monetdb5/modules/atoms/uuid.c b/monetdb5/modules/atoms/uuid.c
--- a/monetdb5/modules/atoms/uuid.c
+++ b/monetdb5/modules/atoms/uuid.c
@@ -407,7 +407,7 @@ UUIDhash(const void *v)
(ulng) u->u[10] << 40 | (ulng) u->u[11] << 32 |
(ulng) u->u[12] << 24 | (ulng) u->u[13] << 16 |
(ulng) u->u[14] << 8 | (ulng) u->u[15];
-   /* we're not using mix_hge since this we way get the same result
+   /* we're not using mix_hge since this way we get the same result
 * on systems with and without 128 bit integer support */
return (BUN) (mix_lng(u1) ^ mix_lng(u2));
 }
diff --git a/sql/backends/monet5/rel_bin.c b/sql/backends/monet5/rel_bin.c
--- a/sql/backends/monet5/rel_bin.c
+++ b/sql/backends/monet5/rel_bin.c
@@ -31,6 +31,13 @@ static stmt * subrel_bin(backend *be, sq
 
 static stmt *check_types(backend *be, sql_subtype *ct, stmt *s, check_type 
tpe);
 
+static void
+clean_mal_statements(backend *be, int oldstop, int oldvtop)
+{
+   MSresetInstructions(be->mb, oldstop);
+   freeVariables(be->client, be->mb, NULL, oldvtop);
+}
+
 static stmt *
 stmt_selectnil( backend *be, stmt *col)
 {
@@ -429,6 +436,8 @@ handle_in_exps(backend *be, sql_exp *ce,
 
/* The actual in-value-list should not contain duplicates to 
ensure that final join results are unique. */
s = distinct_value_list(be, nl, &last_null_value);
+   if (!s)
+   return NULL;
 
if (last_null_value) {
/* The actual in-value-list should not contain null 
values. */
@@ -1164,7 +1173,7 @@ exp_bin(backend *be, sql_exp *e, stmt *l
}   break;
case e_cmp: {
stmt *l = NULL, *r = NULL, *r2 = NULL;
-   int swapped = 0, is_select = 0;
+   int swapped = 0, is_select = 0, oldvtop, oldstop;
sql_exp *re = e->r, *re2 = e->f;
 
/* general predicate, select and join */
@@ -1177,10 +1186,13 @@ exp_bin(backend *be, sql_exp *e, stmt *l
ops = sa_list(sql->sa);
args = e->l;
for( n = args->h; n; n = n->next ) {
+   oldvtop = be->mb->vtop;
+   oldstop = be->mb->stop;
s = NULL;
if (!swapped)
s = exp_bin(be, n->data, left, NULL, 
grp, ext, cnt, NULL, depth+1, 0, push);
if (!s && (first || swapped)) {
+   clean_mal_statements(be, oldstop, 
oldvtop);
s = exp_bin(be, n->data, right, NULL, 
grp, ext, cnt, NULL, depth+1, 0, push);
swapped = 1;
}
@@ -1202,7 +1214,7 @@ exp_bin(backend *be, sql_exp *e, stmt *l
}
   

MonetDB: default - Merged with Oct2020

2020-12-31 Thread Pedro Ferreira
Changeset: 16eb162a6f37 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=16eb162a6f37
Modified Files:
clients/mapiclient/mhelp.c
sql/backends/monet5/rel_bin.c
sql/server/rel_select.c
sql/test/SQLancer/Tests/sqlancer08.sql
sql/test/miscellaneous/Tests/simple_selects.sql
sql/test/miscellaneous/Tests/simple_selects.stable.out
Branch: default
Log Message:

Merged with Oct2020


diffs (251 lines):

diff --git a/clients/mapiclient/mhelp.c b/clients/mapiclient/mhelp.c
--- a/clients/mapiclient/mhelp.c
+++ b/clients/mapiclient/mhelp.c
@@ -54,7 +54,7 @@ SQLhelp sqlhelp1[] = {
 "",
 "ALTER SCHEMA [ IF EXISTS ] ident RENAME TO ident",
 "ident",
-"See also 
https://www.monetdb.org/Documentation/SQLreference/TableDefinitions/AlterStatement"},
+"See also 
https://www.monetdb.org/Documentation/SQLReference/DataDefinition/SchemaDefinitions"},
{"ALTER SEQUENCE",
 "",
 "ALTER SEQUENCE qname [ AS seq_int_datatype] [ RESTART [WITH intval]] 
[INCREMENT BY intval]\n"
@@ -191,7 +191,7 @@ SQLhelp sqlhelp1[] = {
 "",
 "CREATE REPLICA TABLE [ IF NOT EXISTS ] qname table_source",
 NULL,
-"See also 
https://www.monetdb.org/Documentation/Cookbooks/SQLrecipes/TransactionReplication"},
+"See also 
https://www.monetdb.org/Documentation/SQLReference/TableDefinitions"},
{"CREATE ROLE",
 "Create a new role. You can grant privileges to a role and next\n"
 "grant a role (or multiple roles) to specific users",
@@ -246,7 +246,7 @@ SQLhelp sqlhelp1[] = {
 "RETURNS function_return_data_type\n"
 "EXTERNAL NAME ident ',' ident",
 "qname,param,function_return_data_type,ident",
-"See also 
https://www.monetdb.org/Documentation/SQLreference/ProgrammingSQL/Functions"},
+"See also 
https://www.monetdb.org/Documentation/SQLReference/DataManipulation/WindowFunctions"},
{"CURRENT_DATE",
 "Pseudo column or function to get the current date",
 "CURRENT_DATE [ '(' ')' ]",
@@ -291,7 +291,7 @@ SQLhelp sqlhelp1[] = {
 "Debug a SQL statement using MAL debugger",
 "DEBUG statement",
 NULL,
-
"https://www.monetdb.org/Documentation/SQLreference/RuntimeFeatures/Debug"},
+"See also 
https://www.monetdb.org/Documentation/SQLreference/RuntimeFeatures/Debug"},
{"DECLARE",
 "Define a local variable",
 "DECLARE ident_list data_type",
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
@@ -449,8 +449,7 @@ static list *
 check_arguments_and_find_largest_any_type(mvc *sql, sql_rel *rel, list *exps, 
sql_subfunc *sf, int maybe_zero_or_one)
 {
list *nexps = new_exp_list(sql->sa);
-   sql_subtype *atp = NULL;
-   sql_arg *aa = NULL;
+   sql_subtype *atp = NULL, super;
 
/* find largest any type argument */
for (node *n = exps->h, *m = sf->func->ops->h; n && m; n = n->next, m = 
m->next) {
@@ -458,15 +457,17 @@ check_arguments_and_find_largest_any_typ
sql_exp *e = n->data;
sql_subtype *t = exp_subtype(e);
 
-   if (!aa && a->type.type->eclass == EC_ANY) {
-   atp = t;
-   aa = a;
-   }
-   if (aa && a->type.type->eclass == EC_ANY && t && atp && 
(t->type->localtype > atp->type->localtype || (t->type->localtype == 
atp->type->localtype && t->digits > atp->digits && t->scale == atp->scale))) {
-   atp = t;
-   aa = a;
-   }
-   }
+   if (a->type.type->eclass == EC_ANY) {
+   if (t && atp) {
+   result_datatype(&super, t, atp);
+   atp = &super;
+   } else if (t) {
+   atp = t;
+   }
+   }
+   }
+   if (atp && atp->type->localtype == TYPE_void) /* NULL */
+   atp = sql_bind_localtype("str");
for (node *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;
@@ -483,7 +484,7 @@ check_arguments_and_find_largest_any_typ
append(nexps, e);
}
/* dirty hack */
-   if (sf->func->type != F_PROC && sf->func->type != F_UNION && 
sf->func->type != F_LOADER && sf->res && aa && atp)
+   if (sf->func->type != F_PROC && sf->func->type != F_UNION && 
sf->func->type != F_LOADER && sf->res && atp)
sf->res->h->data = sql_create_subtype(sql->sa, atp->type, 
atp->digits, atp->scale);
return nexps;
 }
diff --git a/sql/test/SQLancer/Tests/sqlancer08.sql 
b/sql/test/SQLancer/Tests/sqlancer08.sql
--- a/sql/test/SQLancer/Tests/sqlancer08.sql
+++ b/sql/test/SQLancer/Tests/

MonetDB: default - Merged with Oct2020

2020-12-29 Thread Pedro Ferreira
Changeset: 7bdf7c8ebc65 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=7bdf7c8ebc65
Modified Files:
sql/server/rel_updates.c
sql/test/BugTracker-2020/Tests/All
sql/test/SQLancer/Tests/sqlancer09.test
testing/Mtest.py.in
Branch: default
Log Message:

Merged with Oct2020


diffs (truncated from 335 to 300 lines):

diff --git a/sql/server/rel_updates.c b/sql/server/rel_updates.c
--- a/sql/server/rel_updates.c
+++ b/sql/server/rel_updates.c
@@ -1244,7 +1244,7 @@ merge_into_table(sql_query *query, dlist
mvc *sql = query->sql;
char *sname = qname_schema(qname), *tname = qname_schema_object(qname);
sql_table *t = NULL;
-   sql_rel *bt, *joined, *join_rel = NULL, *extra_project, *insert = NULL, 
*upd_del = NULL, *res = NULL;
+   sql_rel *bt, *joined, *join_rel = NULL, *extra_project, *insert = NULL, 
*upd_del = NULL, *res = NULL, *no_tid = NULL;
int processed = 0;
const char *bt_name;
 
@@ -1347,7 +1347,9 @@ merge_into_table(sql_query *query, dlist
 
//project joined values which didn't match on the join 
and insert them
extra_project = rel_project(sql->sa, join_rel, 
rel_projections(sql, joined, NULL, 1, 0));
-   extra_project = rel_setop(sql->sa, rel_dup(joined), 
extra_project, op_except);
+   no_tid = rel_project(sql->sa, rel_dup(joined), 
rel_projections(sql, joined, NULL, 1, 0));
+   extra_project = rel_setop(sql->sa, no_tid, 
extra_project, op_except);
+   rel_setop_set_exps(sql, extra_project, 
rel_projections(sql, extra_project, NULL, 1, 0));
 
if (!(insert = merge_generate_inserts(query, t, 
extra_project, sts->h->data.lval, sts->h->next->data.sym)))
return NULL;
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
@@ -42,4 +42,5 @@ view_with_aggr_column.Bug-7023
 delete-transaction-loose-inserts.Bug-7024
 revokeRoleUserLoggedIN.Bug-7026
 drop-table-with-auto_increment.Bug-7030
+HAVE_PYMONETDB?dbfarm-foreign-chars.Bug-7031
 user-update-privs.Bug-7035
diff --git a/sql/test/BugTracker-2020/Tests/dbfarm-foreign-chars.Bug-7031.py 
b/sql/test/BugTracker-2020/Tests/dbfarm-foreign-chars.Bug-7031.py
new file mode 100644
--- /dev/null
+++ b/sql/test/BugTracker-2020/Tests/dbfarm-foreign-chars.Bug-7031.py
@@ -0,0 +1,32 @@
+import sys, os, socket, tempfile, pymonetdb
+
+try:
+from MonetDBtesting import process
+except ImportError:
+import process
+
+def freeport():
+sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+sock.bind(('', 0))
+port = sock.getsockname()[1]
+sock.close()
+return port
+
+with tempfile.TemporaryDirectory() as farm_dir:
+mypath = os.path.join(farm_dir, '进起都家', 'myserver','mynode')
+os.makedirs(mypath)
+
+prt = freeport()
+with process.server(mapiport=prt, dbname='mynode', dbfarm=mypath,
+stdin=process.PIPE, stdout=process.PIPE,
+stderr=process.PIPE) as prc:
+conn = pymonetdb.connect(database='mynode', port=prt, autocommit=True)
+cur = conn.cursor()
+
+cur.execute('SELECT \'进起都家\';')
+if cur.fetchall() != [('进起都家',)]:
+sys.stderr.write("'进起都家' expected")
+
+cur.close()
+conn.close()
+prc.communicate()
diff --git 
a/sql/test/BugTracker-2020/Tests/dbfarm-foreign-chars.Bug-7031.stable.err 
b/sql/test/BugTracker-2020/Tests/dbfarm-foreign-chars.Bug-7031.stable.err
new file mode 100644
--- /dev/null
+++ b/sql/test/BugTracker-2020/Tests/dbfarm-foreign-chars.Bug-7031.stable.err
@@ -0,0 +1,12 @@
+stderr of test 'dbfarm-foreign-chars.Bug-7031` in directory 
'sql/test/BugTracker-2020` itself:
+
+
+# 10:13:05 >  
+# 10:13:05 >  "/usr/bin/python3.9" "dbfarm-foreign-chars.Bug-7031.py" 
"dbfarm-foreign-chars.Bug-7031"
+# 10:13:05 >  
+
+
+# 10:13:07 >  
+# 10:13:07 >  "Done."
+# 10:13:07 >  
+
diff --git 
a/sql/test/BugTracker-2020/Tests/dbfarm-foreign-chars.Bug-7031.stable.out 
b/sql/test/BugTracker-2020/Tests/dbfarm-foreign-chars.Bug-7031.stable.out
new file mode 100644
--- /dev/null
+++ b/sql/test/BugTracker-2020/Tests/dbfarm-foreign-chars.Bug-7031.stable.out
@@ -0,0 +1,12 @@
+stdout of test 'dbfarm-foreign-chars.Bug-7031` in directory 
'sql/test/BugTracker-2020` itself:
+
+
+# 10:13:05 >  
+# 10:13:05 >  "/usr/bin/python3.9" "dbfarm-foreign-chars.Bug-7031.py" 
"dbfarm-foreign-chars.Bug-7031"
+# 10:13:05 >  
+
+
+# 10:13:07 >  
+# 10:13:07 >  "Done."
+# 10:13:07 >  
+
diff --git a/sql/test/SQLancer/Tests/sqlancer09.sql 
b/sql/test/SQLancer/Tests/sqlancer09.sql
--- a/sql/test/SQLancer/Tests/sqlancer09.sql
+++ b/sql/test/SQLancer/Tests/sqlancer09.sql
@@ -19,3 +19,56 @@ CREATE TABLE "t0" ("tc0" TINYINT NOT NUL
 update t0 set tc2 = 119, tc0 = cast(t0.tc

MonetDB: default - Merged with Oct2020

2020-12-28 Thread Pedro Ferreira
Changeset: 098b79a0c2bb for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=098b79a0c2bb
Modified Files:
sql/server/sql_privileges.c
sql/test/Users/Tests/renameUser.SQL.py
Branch: default
Log Message:

Merged with Oct2020


diffs (47 lines):

diff --git a/sql/server/sql_privileges.c b/sql/server/sql_privileges.c
--- a/sql/server/sql_privileges.c
+++ b/sql/server/sql_privileges.c
@@ -858,11 +858,12 @@ sql_alter_user(mvc *sql, char *user, cha
if (strNil(user))
user = NULL;
/* USER == NULL -> current_user */
-   if (user != NULL && backend_find_user(sql, user) < 0)
-   throw(SQL,"sql.alter_user", SQLSTATE(42M32) "ALTER USER: no 
such user '%s'", user);
 
if (!admin_privs(sql->user_id) && !admin_privs(sql->role_id) && user != 
NULL && strcmp(user, get_string_global_var(sql, "current_user")) != 0)
throw(SQL,"sql.alter_user", SQLSTATE(M1M05) "Insufficient 
privileges to change user '%s'", user);
+
+   if (user != NULL && backend_find_user(sql, user) < 0)
+   throw(SQL,"sql.alter_user", SQLSTATE(42M32) "ALTER USER: no 
such user '%s'", user);
if (schema && (schema_id = sql_find_schema(sql, schema)) < 0)
throw(SQL,"sql.alter_user", SQLSTATE(3F000) "ALTER USER: no 
such schema '%s'", schema);
if (backend_alter_user(sql, user, passwd, enc, schema_id, schema_path, 
oldpasswd) == FALSE)
@@ -873,13 +874,13 @@ sql_alter_user(mvc *sql, char *user, cha
 char *
 sql_rename_user(mvc *sql, char *olduser, char *newuser)
 {
+   if (!admin_privs(sql->user_id) && !admin_privs(sql->role_id))
+   throw(SQL,"sql.rename_user", SQLSTATE(M1M05) "ALTER USER: 
insufficient privileges to rename user '%s'", olduser);
+
if (backend_find_user(sql, olduser) < 0)
throw(SQL,"sql.rename_user", SQLSTATE(42M32) "ALTER USER: no 
such user '%s'", olduser);
if (backend_find_user(sql, newuser) >= 0)
throw(SQL,"sql.rename_user", SQLSTATE(42M31) "ALTER USER: user 
'%s' already exists", newuser);
-   if (!admin_privs(sql->user_id) && !admin_privs(sql->role_id))
-   throw(SQL,"sql.rename_user", SQLSTATE(M1M05) "ALTER USER: 
insufficient privileges to rename user '%s'", olduser);
-
if (backend_rename_user(sql, olduser, newuser) == FALSE)
throw(SQL,"sql.rename_user", SQLSTATE(M1M05) "%s", sql->errstr);
return NULL;
diff --git a/sql/test/Users/Tests/renameUser.SQL.py 
b/sql/test/Users/Tests/renameUser.SQL.py
--- a/sql/test/Users/Tests/renameUser.SQL.py
+++ b/sql/test/Users/Tests/renameUser.SQL.py
@@ -52,7 +52,7 @@ with SQLTestCase() as mdb:
 # Check that a user with no special permissions cannot rename users.
 # FIXME: might need to change the err_message (see issue #7037)
 tc2.execute("ALTER USER april2 RENAME TO april3;")\
-.assertFailed(err_code="42M32", err_message="ALTER USER: no such 
user 'april2'")
+.assertFailed(err_code="M1M05", err_message="ALTER USER: 
insufficient privileges to rename user 'april2'")
 
 mdb.connect(username='monetdb', password='monetdb')
 # Check that the admin cannot:
___
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list


MonetDB: default - Merged with Oct2020

2020-12-17 Thread Pedro Ferreira
Changeset: bf888184fc89 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=bf888184fc89
Modified Files:
sql/server/rel_dump.c
sql/test/BugTracker-2009/Tests/copy_multiple_files.SF-2902320.stable.out

sql/test/BugTracker-2009/Tests/copy_multiple_files.SF-2902320.stable.out.Windows
sql/test/BugTracker-2011/Tests/crash_on_alias.Bug-2798.stable.out

sql/test/BugTracker-2018/Tests/count_from_commented_function_signatures.Bug-6542.stable.out

sql/test/BugTracker-2018/Tests/local_replica_table_not_detected.Bug-6620.stable.out
sql/test/BugTracker-2020/Tests/table-udf-on-remote.Bug-6971.py
sql/test/BugTracker-2020/Tests/table-udf-on-remote.Bug-6971.stable.out
sql/test/BugTracker-2020/Tests/values-like-join.Bug-6954.sql
sql/test/BugTracker-2020/Tests/values-like-join.Bug-6954.stable.out
sql/test/BugTracker/Tests/jdbc_no_debug.SF-1739356.stable.out
sql/test/miscellaneous/Tests/groupby_error.stable.out
sql/test/miscellaneous/Tests/groupby_prepare.stable.out
sql/test/miscellaneous/Tests/simple_plans.stable.out
sql/test/out2in/Tests/out2in.stable.out
Branch: default
Log Message:

Merged with Oct2020


diffs (truncated from 3606 to 300 lines):

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
@@ -75,6 +75,25 @@ cmp_print(mvc *sql, stream *fout, int cm
mnstr_printf(fout, " %s ", r);
 }
 
+static const char *
+dump_escape_ident(sql_allocator *sa, const char *s)
+{
+   char *res = NULL;
+   if (s) {
+   size_t l = strlen(s);
+   char *r = SA_NEW_ARRAY(sa, char, (l * 2) + 1);
+
+   res = r;
+   while (*s) {
+   if (*s == '"')
+   *r++ = '\\';
+   *r++ = *s++;
+   }
+   *r = '\0';
+   }
+   return res;
+}
+
 static void exps_print(mvc *sql, stream *fout, list *exps, int depth, list 
*refs, int alias, int brackets);
 
 static void
@@ -90,8 +109,8 @@ exp_print(mvc *sql, stream *fout, sql_ex
const char *rname = exp_relname(e);
int level = GET_PSM_LEVEL(e->flag);
if (rname)
-   mnstr_printf(fout, "\"%s\".", rname);
-   mnstr_printf(fout, "\"%s\" = ", exp_name(e));
+   mnstr_printf(fout, "\"%s\".", 
dump_escape_ident(sql->ta, rname));
+   mnstr_printf(fout, "\"%s\" = ",  
dump_escape_ident(sql->ta, exp_name(e)));
exp_print(sql, fout, e->l, depth, refs, 0, 0);
mnstr_printf(fout, " FRAME %d ", level);
alias = 0;
@@ -102,8 +121,8 @@ exp_print(mvc *sql, stream *fout, sql_ex
int level = GET_PSM_LEVEL(e->flag);
mnstr_printf(fout, "declare ");
if (rname)
-   mnstr_printf(fout, "\"%s\".", rname);
-   mnstr_printf(fout, "\"%s\" %s FRAME %d ", exp_name(e), 
type_str ? type_str : "", level);
+   mnstr_printf(fout, "\"%s\".", 
dump_escape_ident(sql->ta, rname));
+   mnstr_printf(fout, "\"%s\" %s FRAME %d ", 
dump_escape_ident(sql->ta, exp_name(e)), type_str ? type_str : "", level);
alias = 0;
} else if (e->flag & PSM_RETURN) {
int level = GET_PSM_LEVEL(e->flag);
@@ -142,10 +161,10 @@ exp_print(mvc *sql, stream *fout, sql_ex
atom *a = e->l;
if (atom_type(a)->type->localtype == TYPE_ptr) {
sql_table *t = a->data.val.pval;
-   mnstr_printf(fout, "%s(%s)",
+   mnstr_printf(fout, "%s(\"%s\")",
isMergeTable(t)?"merge table":
isReplicaTable(t)?"replica 
table":"table",
-   t->base.name);
+   dump_escape_ident(sql->ta, 
t->base.name));
} else {
char *t = sql_subtype_string(sql->ta, 
atom_type(a));
if (a->isnull)
@@ -163,8 +182,8 @@ exp_print(mvc *sql, stream *fout, sql_ex
if (e->r) { /* named parameters and declared variables 
*/
sql_var_name *vname = (sql_var_name*) e->r;
if (vname->sname)
-   mnstr_printf(fout, "\"%s\".", 
vname->sname);
-   mnstr_printf(fout, "\"%s\"", vname->name);
+   mnstr_printf(fout, "\"%s\".", 
dump_escape_ident(sql->ta, vname->sname));
+

MonetDB: default - Merged with Oct2020

2020-12-13 Thread Pedro Ferreira
Changeset: 63dcb5a3792b for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=63dcb5a3792b
Modified Files:
sql/server/rel_select.c
Branch: default
Log Message:

Merged with Oct2020


diffs (225 lines):

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
@@ -497,8 +497,15 @@ find_table_function(mvc *sql, sql_schema
if (!f && list_length(tl)) {
int len, match = 0;
list *funcs = sql_find_funcs(sql->sa, s, fname, 
list_length(tl), type);
-   if (!funcs)
-   return sql_error(sql, 02, SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
+
+   for (node *n = funcs->h; n ; ) { /* Reduce on privileges */
+   sql_subfunc *sf = n->data;
+   node *nn = n->next;
+
+   if (!execute_priv(sql, sf->func))
+   list_remove_node(funcs, n);
+   n = nn;
+   }
len = list_length(funcs);
if (len > 1) {
int i, score = 0;
@@ -647,8 +654,7 @@ rel_op_(mvc *sql, sql_schema *s, char *f
sql_ftype type = (ek.card == card_loader)?F_LOADER:((ek.card == 
card_none)?F_PROC:
   ((ek.card == card_relation)?F_UNION:F_FUNC));
 
-   f = sql_bind_func(sql->sa, s, fname, NULL, NULL, type);
-   if (f && check_card(ek.card, f)) {
+   if ((f = bind_func_(sql, s, fname, NULL, type)) && check_card(ek.card, 
f)) {
return exp_op(sql->sa, NULL, f);
} else {
return sql_error(sql, 02, SQLSTATE(42000) "SELECT: no such 
operator '%s'", fname);
@@ -1454,9 +1460,7 @@ rel_filter(mvc *sql, sql_rel *rel, list 
if (sname && !(s = mvc_bind_schema(sql, sname)))
return sql_error(sql, 02, SQLSTATE(3F000) "SELECT: no such 
schema '%s'", sname);
/* find filter function */
-   f = sql_bind_func_(sql->sa, s, filter_op, tl, F_FILT);
-
-   if (!f)
+   if (!(f = bind_func_(sql, s, filter_op, tl, F_FILT)))
f = find_func(sql, s, filter_op, list_length(tl), F_FILT, NULL);
if (f) {
node *n,*m = f->func->ops->h;
@@ -1724,8 +1728,15 @@ static sql_exp*
if (!f && list_length(tl)) {
int len, match = 0;
list *funcs = sql_find_funcs(sql->sa, s, fname, 
list_length(tl), type);
-   if (!funcs)
-   return sql_error(sql, 02, SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
+
+   for (node *n = funcs->h; n ; ) { /* Reduce on privileges */
+   sql_subfunc *sf = n->data;
+   node *nn = n->next;
+
+   if (!execute_priv(sql, sf->func))
+   list_remove_node(funcs, n);
+   n = nn;
+   }
len = list_length(funcs);
if (len > 1) {
int i, score = 0;
@@ -2809,6 +2820,8 @@ rel_binop_(mvc *sql, sql_rel *rel, sql_e
/* handle param's early */
if (!t1 || !t2) {
f = sql_resolve_function_with_undefined_parameters(sql->sa, s, 
fname, list_append(list_append(sa_list(sql->sa), t1), t2), type);
+   if (f && !execute_priv(sql, f->func))
+   f = NULL;
if (f) { /* add types using f */
if (!t1) {
sql_subtype *t = 
arg_type(f->func->ops->h->data);
@@ -3630,6 +3643,8 @@ static sql_exp *
a = (sql_subfunc *) m->data;
op = a->func->ops->h;
 
+   if (!execute_priv(sql, a->func))
+   a = NULL;
for (n = exps->h ; a && op && n; op = op->next, 
n = n->next ) {
sql_arg *arg = op->data;
sql_exp *e = n->data;
diff --git a/sql/test/Users/Tests/All b/sql/test/Users/Tests/All
--- a/sql/test/Users/Tests/All
+++ b/sql/test/Users/Tests/All
@@ -29,3 +29,4 @@ schemaRights
 metadataConsistency
 sessioncontrol
 createUserRollback
+HAVE_PYMONETDB?userCallFunction
diff --git a/sql/test/Users/Tests/grantRole.Bug-3772.SQL.py 
b/sql/test/Users/Tests/grantRole.Bug-3772.SQL.py
--- a/sql/test/Users/Tests/grantRole.Bug-3772.SQL.py
+++ b/sql/test/Users/Tests/grantRole.Bug-3772.SQL.py
@@ -2,7 +2,7 @@
 # Let any user grant any role (not possible).
 ###
 
-import os, sys
+import os
 try:
 from MonetDBtesting import process
 except ImportError:
@@ -22,9 +22,14 @@ CREATE ROLE role1;
 GRANT ALL ON s1.test to role1;
 """)
 
-
 sql_test_client('bruce', 'bruce', input="""\
 GRANT role1 to bruce;
 SET role role1;
 select * from test;
 """)
+
+sql_test_client('monetdb', 'monetdb', input="""\
+DROP USER bruce;
+DROP ROLE role1;
+DROP SCHEMA s1 CASCADE;
+""")
di

MonetDB: default - merged with oct2020

2020-12-12 Thread Niels Nes
Changeset: 03027f1e1378 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=03027f1e1378
Modified Files:
sql/storage/store.c
Branch: default
Log Message:

merged with oct2020


diffs (31 lines):

diff --git a/sql/storage/store.c b/sql/storage/store.c
--- a/sql/storage/store.c
+++ b/sql/storage/store.c
@@ -2363,6 +2363,11 @@ cleanup_table(sql_table *t)
for (int i = 0; ischemas.set->h; m; m = 
m->next) {
sql_schema * schema = m->data;
+
+   if (schema->tables.dset) {
+   list_destroy(schema->tables.dset);
+   schema->tables.dset = NULL;
+   }
node *o = find_sql_table_node(schema, 
t->base.id);
if (o) {
list_remove_node(schema->tables.set, o);
@@ -4125,6 +4130,7 @@ rollforward_changeset_updates(sql_trans 
list_destroy(fs->dset);
fs->dset = NULL;
}
+   /*
if (!apply && ts->dset) {
for (n = ts->dset->h; ok == LOG_OK && n; n = n->next) {
sql_base *tb = n->data;
@@ -4133,6 +4139,7 @@ rollforward_changeset_updates(sql_trans 
ok = rollforward_deletes(tr, tb, mode);
}
}
+   */
if (apply && ts->dset && !cf) {
list_destroy(ts->dset);
ts->dset = NULL;
___
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list


MonetDB: default - Merged with Oct2020

2020-12-11 Thread Pedro Ferreira
Changeset: a94148c55215 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=a94148c55215
Modified Files:
sql/server/rel_updates.c
sql/server/sql_privileges.c
sql/test/BugTracker-2020/Tests/All
Branch: default
Log Message:

Merged with Oct2020


diffs (219 lines):

diff --git a/sql/server/rel_updates.c b/sql/server/rel_updates.c
--- a/sql/server/rel_updates.c
+++ b/sql/server/rel_updates.c
@@ -894,7 +894,7 @@ rel_update(mvc *sql, sql_rel *t, sql_rel
 sql_exp *
 update_check_column(mvc *sql, sql_table *t, sql_column *c, sql_exp *v, sql_rel 
*r, char *cname, const char *action)
 {
-   if (!table_privs(sql, t, PRIV_UPDATE) && !sql_privilege(sql, 
sql->user_id, c->base.id, PRIV_UPDATE))
+   if (!table_privs(sql, t, PRIV_UPDATE) && sql_privilege(sql, 
sql->user_id, c->base.id, PRIV_UPDATE) < 0)
return sql_error(sql, 02, SQLSTATE(42000) "%s: insufficient 
privileges for user '%s' to update table '%s' on column '%s'", action, 
get_string_global_var(sql, "current_user"), t->base.name, cname);
if (!v || (v = exp_check_type(sql, &c->type, r, v, type_equal)) == NULL)
return NULL;
diff --git a/sql/server/sql_privileges.c b/sql/server/sql_privileges.c
--- a/sql/server/sql_privileges.c
+++ b/sql/server/sql_privileges.c
@@ -119,7 +119,7 @@ sql_grant_global_privs( mvc *sql, char *
if (grantee_id <= 0)
throw(SQL,"sql.grant_global",SQLSTATE(01007) "GRANT: User/role 
'%s' unknown", grantee);
/* first check if privilege isn't already given */
-   if ((sql_privilege(sql, grantee_id, GLOBAL_OBJID, privs)))
+   if ((sql_privilege(sql, grantee_id, GLOBAL_OBJID, privs) >= 0))
throw(SQL,"sql.grant_global",SQLSTATE(01007) "GRANT: User/role 
'%s' already has this privilege", grantee);
sql_insert_priv(sql, grantee_id, GLOBAL_OBJID, privs, grantor, grant);
tr->schema_updates++;
@@ -168,13 +168,13 @@ sql_grant_table_privs( mvc *sql, char *g
throw(SQL,"sql.grant_table", SQLSTATE(01007) "GRANT: User/role 
'%s' unknown", grantee);
/* first check if privilege isn't already given */
if ((privs == all &&
-   (sql_privilege(sql, grantee_id, t->base.id, PRIV_SELECT) ||
-sql_privilege(sql, grantee_id, t->base.id, PRIV_UPDATE) ||
-sql_privilege(sql, grantee_id, t->base.id, PRIV_INSERT) ||
-sql_privilege(sql, grantee_id, t->base.id, PRIV_DELETE) ||
-sql_privilege(sql, grantee_id, t->base.id, PRIV_TRUNCATE))) ||
-   (privs != all && !c && sql_privilege(sql, grantee_id, t->base.id, 
privs)) ||
-   (privs != all && c && sql_privilege(sql, grantee_id, c->base.id, 
privs))) {
+   (sql_privilege(sql, grantee_id, t->base.id, PRIV_SELECT) >= 0 ||
+sql_privilege(sql, grantee_id, t->base.id, PRIV_UPDATE) >= 0 ||
+sql_privilege(sql, grantee_id, t->base.id, PRIV_INSERT) >= 0 ||
+sql_privilege(sql, grantee_id, t->base.id, PRIV_DELETE) >= 0 ||
+sql_privilege(sql, grantee_id, t->base.id, PRIV_TRUNCATE) >= 0)) ||
+   (privs != all && !c && sql_privilege(sql, grantee_id, t->base.id, 
privs) >= 0) ||
+   (privs != all && c && sql_privilege(sql, grantee_id, c->base.id, 
privs) >= 0)) {
throw(SQL, "sql.grant", SQLSTATE(01007) "GRANT: User/role '%s' 
already has this privilege", grantee);
}
if (privs == all) {
@@ -215,7 +215,7 @@ sql_grant_func_privs( mvc *sql, char *gr
if (grantee_id <= 0)
throw(SQL, "sql.grant_func", SQLSTATE(01007) "GRANT: User/role 
'%s' unknown", grantee);
/* first check if privilege isn't already given */
-   if (sql_privilege(sql, grantee_id, f->base.id, privs))
+   if (sql_privilege(sql, grantee_id, f->base.id, privs) >= 0)
throw(SQL,"sql.grant", SQLSTATE(01007) "GRANT: User/role '%s' 
already has this privilege", grantee);
sql_insert_priv(sql, grantee_id, f->base.id, privs, grantor, grant);
tr->schema_updates++;
@@ -428,7 +428,7 @@ int
 sql_privilege(mvc *m, sqlid auth_id, sqlid obj_id, int priv)
 {
oid rid = sql_privilege_rid(m, auth_id, obj_id, priv);
-   int res = 0;
+   int res = -1;
 
if (!is_oid_nil(rid)) {
/* found priv */
@@ -513,7 +513,7 @@ role_granting_privs(mvc *m, oid role_rid
owner_id = table_funcs.column_find_sqlid(m->session->tr, auths_grantor, 
role_rid);
if (owner_id == grantor_id)
return true;
-   if (sql_privilege(m, grantor_id, role_id, PRIV_ROLE_ADMIN))
+   if (sql_privilege(m, grantor_id, role_id, PRIV_ROLE_ADMIN) == 
PRIV_ROLE_ADMIN)
return true;
/* check for grant rights in the privs table */
return false;
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
@@ 

MonetDB: default - Merged with Oct2020

2020-12-10 Thread Pedro Ferreira
Changeset: 3c9a5240825e for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=3c9a5240825e
Modified Files:
clients/mapiclient/mhelp.c
gdk/gdk.h
gdk/gdk_bat.c
gdk/gdk_batop.c
gdk/gdk_join.c
sql/backends/monet5/rel_bin.c
sql/server/rel_psm.c
sql/server/sql_atom.c
sql/storage/bat/bat_storage.c
sql/test/BugTracker-2020/Tests/All
sql/test/miscellaneous/Tests/simple_selects.sql
sql/test/miscellaneous/Tests/simple_selects.stable.out
Branch: default
Log Message:

Merged with Oct2020


diffs (truncated from 1153 to 300 lines):

diff --git a/clients/mapiclient/mhelp.c b/clients/mapiclient/mhelp.c
--- a/clients/mapiclient/mhelp.c
+++ b/clients/mapiclient/mhelp.c
@@ -217,7 +217,7 @@ SQLhelp sqlhelp1[] = {
 "See also 
https://www.monetdb.org/Documentation/Manuals/SQLreference/Tables"},
{"CREATE TRIGGER",
 "Define a triggered action for a table data update event",
-"CREATE [ OR REPLACE ] TRIGGER qname { BEFORE | AFTER }\n"
+"CREATE [ OR REPLACE ] TRIGGER ident { BEFORE | AFTER }\n"
 " { INSERT | DELETE | TRUNCATE | UPDATE [ OF ident_list ] }\n"
 " ON qname [ REFERENCING trigger_reference [...] ] triggered_action",
 "qname,ident_list,trigger_reference,triggered_action",
diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -2028,6 +2028,7 @@ enum prop_t {
GDK_MAX_POS,/* BUN position of largest value  */
GDK_HASH_BUCKETS,   /* last used hash bucket size */
GDK_NUNIQUE,/* number of unique values */
+   GDK_UNIQUE_ESTIMATE,/* estimate of number of distinct values */
 };
 
 /*
diff --git a/gdk/gdk_bat.c b/gdk/gdk_bat.c
--- a/gdk/gdk_bat.c
+++ b/gdk/gdk_bat.c
@@ -1080,6 +1080,7 @@ BUNappend(BAT *b, const void *t, bool fo
IMPSdestroy(b); /* no support for inserts in imprints yet */
OIDXdestroy(b);
BATrmprop(b, GDK_NUNIQUE);
+   BATrmprop(b, GDK_UNIQUE_ESTIMATE);
 #if 0  /* enable if we have more properties than just min/max */
PROPrec *prop;
do {
@@ -1170,6 +1171,7 @@ BUNdelete(BAT *b, oid o)
OIDXdestroy(b);
HASHdestroy(b);
BATrmprop(b, GDK_NUNIQUE);
+   BATrmprop(b, GDK_UNIQUE_ESTIMATE);
 #if 0  /* enable if we have more properties than just min/max */
do {
for (prop = b->tprops; prop; prop = prop->next)
@@ -1263,6 +1265,7 @@ BUNinplace(BAT *b, BUN p, const void *t,
}
}
BATrmprop(b, GDK_NUNIQUE);
+   BATrmprop(b, GDK_UNIQUE_ESTIMATE);
 #if 0  /* enable if we have more properties than just min/max */
do {
for (prop = b->tprops; prop; prop = prop->next)
diff --git a/gdk/gdk_batop.c b/gdk/gdk_batop.c
--- a/gdk/gdk_batop.c
+++ b/gdk/gdk_batop.c
@@ -587,6 +587,7 @@ BATappend2(BAT *b, BAT *n, BAT *s, bool 
}
}
BATrmprop(b, GDK_NUNIQUE);
+   BATrmprop(b, GDK_UNIQUE_ESTIMATE);
 #if 0  /* enable if we have more properties than just min/max */
do {
for (prop = b->tprops; prop; prop = prop->next)
@@ -904,6 +905,7 @@ BATreplace(BAT *b, BAT *p, BAT *n, bool 
OIDXdestroy(b);
IMPSdestroy(b);
BATrmprop(b, GDK_NUNIQUE);
+   BATrmprop(b, GDK_UNIQUE_ESTIMATE);
 
b->tsorted = b->trevsorted = false;
b->tnosorted = b->tnorevsorted = 0;
diff --git a/gdk/gdk_join.c b/gdk/gdk_join.c
--- a/gdk/gdk_join.c
+++ b/gdk/gdk_join.c
@@ -3041,12 +3041,19 @@ guess_uniques(BAT *b, struct canditer *c
if (b->tkey)
return (double) ci->ncand;
 
-   if (ci->s) {
+   if (ci->s == NULL ||
+   (ci->tpe == cand_dense && ci->ncand == BATcount(b))) {
+   PROPrec *p = BATgetprop(b, GDK_UNIQUE_ESTIMATE);
+   if (p) {
+   TRC_DEBUG(ALGO, "b=" ALGOBATFMT " use cached value\n",
+ ALGOBATPAR(b));
+   return p->v.val.dval;
+   }
+   s1 = BATsample(b, 1000);
+   } else {
BAT *s2 = BATsample(ci->s, 1000);
s1 = BATproject(s2, ci->s);
BBPreclaim(s2);
-   } else {
-   s1 = BATsample(b, 1000);
}
BUN n2 = BATcount(s1);
BUN n1 = n2 / 2;
@@ -3056,7 +3063,12 @@ guess_uniques(BAT *b, struct canditer *c
double A = (double) (cnt2 - cnt1) / (n2 - n1);
double B = cnt1 - n1 * A;
 
-   return A * ci->ncand + B;
+   B += A * ci->ncand;
+   if (ci->s == NULL ||
+   (ci->tpe == cand_dense && ci->ncand == BATcount(b))) {
+   BATsetprop(b, GDK_UNIQUE_ESTIMATE, TYPE_dbl, &B);
+   }
+   return B;
 }
 
 #define MASK_EQ1
diff --git a/gdk/gdk_project.c b/gdk/gdk_project.c
--- a/gdk/gdk_project.c
+++ b/gdk/g

MonetDB: default - merged with Oct2020

2020-12-09 Thread Niels Nes
Changeset: 5769ac120b14 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=5769ac120b14
Modified Files:
sql/backends/monet5/sql_execute.c
sql/test/BugTracker-2020/Tests/All
Branch: default
Log Message:

merged with Oct2020


diffs (truncated from 398 to 300 lines):

diff --git a/monetdb5/mal/mal_interpreter.c b/monetdb5/mal/mal_interpreter.c
--- a/monetdb5/mal/mal_interpreter.c
+++ b/monetdb5/mal/mal_interpreter.c
@@ -764,9 +764,16 @@ str runMALsequence(Client cntxt, MalBlkP
}
if (ret == MAL_SUCCEED && ii == pci->argc) {
ret = runMALsequence(cntxt, pci->blk, 
1, pci->blk->stop, nstk, stk, pci);
+   //garbageCollector(cntxt, pci->blk, 
nstk, 0);
for (ii = 0; ii < nstk->stktop; ii++)
if 
(ATOMextern(nstk->stk[ii].vtype))

GDKfree(nstk->stk[ii].val.pval);
+   arg = q->retc;
+   for (ii = pci->retc; ii < pci->argc; 
ii++,arg++) {
+   lhs = &nstk->stk[q->argv[arg]];
+   if (lhs->vtype == TYPE_bat)
+   
BBPrelease(lhs->val.bval);
+   }
GDKfree(nstk);
}
}
diff --git a/sql/backends/monet5/sql_execute.c 
b/sql/backends/monet5/sql_execute.c
--- a/sql/backends/monet5/sql_execute.c
+++ b/sql/backends/monet5/sql_execute.c
@@ -206,6 +206,7 @@ SQLrun(Client c, mvc *m)
*m->errstr=0;
return msg;
}
+   TRC_INFO(SQL_EXECUTION, "Executing: %s", c->query);
MT_thread_setworking(c->query);
// locate and inline the query template instruction
mb = copyMalBlk(c->curprg->def);
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
@@ -35,3 +35,6 @@ deallocate-id.Bug-7010
 values-groupby.Bug-7013
 txtsim-parallel.Bug-7016
 release_old_savepoint.Bug-7020
+savepoints_crash_mserver5_1.Bug-7021
+savepoints_crash_mserver5_2.Bug-7021
+transaction_with_unreleased_savepoint.Bug-7022
diff --git 
a/sql/test/BugTracker-2020/Tests/savepoints_crash_mserver5_1.Bug-7021.sql 
b/sql/test/BugTracker-2020/Tests/savepoints_crash_mserver5_1.Bug-7021.sql
new file mode 100644
--- /dev/null
+++ b/sql/test/BugTracker-2020/Tests/savepoints_crash_mserver5_1.Bug-7021.sql
@@ -0,0 +1,15 @@
+-- triggers a SIGSEGV in sql/storage/store.c:185: if (--(i->base.refcnt) > 0)
+start transaction;
+create table savepointtest (id int, primary key(id));
+savepoint name1;
+insert into savepointtest values(1), (2), (3);
+savepoint name2;
+insert into savepointtest values(4), (5), (6);
+insert into savepointtest values(7), (8), (9);
+--savepoint name3;
+select * from savepointtest;
+commit;
+
+select 42;
+select * from savepointtest;
+
diff --git 
a/sql/test/BugTracker-2020/Tests/savepoints_crash_mserver5_1.Bug-7021.stable.err
 
b/sql/test/BugTracker-2020/Tests/savepoints_crash_mserver5_1.Bug-7021.stable.err
new file mode 100644
--- /dev/null
+++ 
b/sql/test/BugTracker-2020/Tests/savepoints_crash_mserver5_1.Bug-7021.stable.err
@@ -0,0 +1,12 @@
+stderr of test 'savepoints_crash_mserver5_1.Bug-7021` in directory 
'sql/test/BugTracker-2020` itself:
+
+
+# 11:57:43 >  
+# 11:57:43 >  "mclient" "-lsql" "-ftest" "-tnone" "-Eutf-8" "-i" "-e" 
"--host=/var/tmp/mtest-153790" "--port=36420"
+# 11:57:43 >  
+
+
+# 11:57:44 >  
+# 11:57:44 >  "Done."
+# 11:57:44 >  
+
diff --git 
a/sql/test/BugTracker-2020/Tests/savepoints_crash_mserver5_1.Bug-7021.stable.out
 
b/sql/test/BugTracker-2020/Tests/savepoints_crash_mserver5_1.Bug-7021.stable.out
new file mode 100644
--- /dev/null
+++ 
b/sql/test/BugTracker-2020/Tests/savepoints_crash_mserver5_1.Bug-7021.stable.out
@@ -0,0 +1,57 @@
+stdout of test 'savepoints_crash_mserver5_1.Bug-7021` in directory 
'sql/test/BugTracker-2020` itself:
+
+
+# 11:57:43 >  
+# 11:57:43 >  "mclient" "-lsql" "-ftest" "-tnone" "-Eutf-8" "-i" "-e" 
"--host=/var/tmp/mtest-153790" "--port=36420"
+# 11:57:43 >  
+
+#start transaction;
+#create table savepointtest (id int, primary key(id));
+#savepoint name1;
+#insert into savepointtest values(1), (2), (3);
+[ 3]
+#savepoint name2;
+#insert into savepointtest values(4), (5), (6);
+[ 3]
+#insert into savepointtest values(7), (8), (9);
+[ 3]
+#select * from savepointtest;
+% sys.savepointtest # table_name
+% id # name
+% int # type
+% 1 # length
+[ 1]
+[ 2]
+[ 3]
+[ 4]
+[ 5]
+[ 6]
+[ 7]
+[ 8]
+[ 9]
+#commit;
+#select 42;
+% .%2 # table_name
+% %2 # na

MonetDB: default - merged with Oct2020

2020-12-09 Thread Niels Nes
Changeset: 04a7c778a7e3 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=04a7c778a7e3
Modified Files:
gdk/gdk_logger.c
sql/backends/monet5/sql.c
sql/server/rel_exp.c
sql/test/BugTracker-2020/Tests/All
Branch: default
Log Message:

merged with Oct2020


diffs (295 lines):

diff --git a/gdk/gdk_logger.c b/gdk/gdk_logger.c
--- a/gdk/gdk_logger.c
+++ b/gdk/gdk_logger.c
@@ -3182,6 +3182,7 @@ bm_commit(logger *lg, lng save_id)
return GDK_FAIL;
}
BBPrelease(bid);
+   assert(BBP_lrefs(bid)<=0 && BBP_refs(bid)==0);
}
if (leftover) {
nfreed = logbat_new(TYPE_int, leftover, TRANSIENT);
diff --git a/sql/backends/monet5/sql.c b/sql/backends/monet5/sql.c
--- a/sql/backends/monet5/sql.c
+++ b/sql/backends/monet5/sql.c
@@ -563,7 +563,6 @@ mvc_bind(mvc *m, const char *sname, cons
return NULL;
 
b = store_funcs.bind_col(tr, c, access);
-   assert(b);
return b;
 }
 
diff --git a/sql/backends/monet5/sql_subquery.c 
b/sql/backends/monet5/sql_subquery.c
--- a/sql/backends/monet5/sql_subquery.c
+++ b/sql/backends/monet5/sql_subquery.c
@@ -16,7 +16,7 @@ zero_or_one_error(ptr ret, const bat *bi
BAT *b;
BUN c;
size_t _s;
-   const void *p;
+   const void *p = NULL;
 
if ((b = BATdescriptor(*bid)) == NULL) {
throw(SQL, "sql.zero_or_one", SQLSTATE(HY005) "Cannot access 
column descriptor");
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
@@ -1695,46 +1695,20 @@ rel_find_exp_and_corresponding_rel(sql_r
case op_right:
case op_full:
case op_join:
+   case op_semi:
+   case op_anti:
ne = rel_find_exp_and_corresponding_rel(rel->l, e, res, 
under_join);
-   if (!ne)
+   if (!ne && is_join(rel->op))
ne = rel_find_exp_and_corresponding_rel(rel->r, 
e, res, under_join);
if (ne && under_join)
*under_join = true;
break;
case op_table:
-   if (rel->exps && e->type == e_column && e->l && 
exps_bind_column2(rel->exps, e->l, e->r, NULL))
-   ne = e;
-   if (ne && res)
-   *res = rel;
-   break;
-   case op_union:
-   case op_except:
-   case op_inter:
-   {
-   if (rel->l)
-   ne = rel_find_exp_and_corresponding_rel(rel->l, 
e, res, under_join);
-   else if (rel->exps && e->l) {
-   ne = exps_bind_column2(rel->exps, e->l, e->r, 
NULL);
-   if (ne && res)
-   *res = rel;
-   } else if (rel->exps) {
-   ne = exps_bind_column(rel->exps, e->r, NULL, 
NULL, 1);
-   if (ne && res)
-   *res = rel;
-   }
-   }
-   break;
case op_basetable:
-   if (rel->exps && e->type == e_column && e->l)
-   ne = exps_bind_column2(rel->exps, e->l, e->r, 
NULL);
-   if (ne && res)
-   *res = rel;
break;
default:
if (!is_project(rel->op) && rel->l)
ne = rel_find_exp_and_corresponding_rel(rel->l, 
e, res, under_join);
-   if (ne && (rel->op == op_semi || rel->op == op_anti) && 
under_join)
-   *under_join = true;
}
}
return ne;
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
@@ -34,3 +34,4 @@ drop-stream-table.Bug-7005
 deallocate-id.Bug-7010
 values-groupby.Bug-7013
 txtsim-parallel.Bug-7016
+release_old_savepoint.Bug-7020
diff --git a/sql/test/BugTracker-2020/Tests/release_old_savepoint.Bug-7020.sql 
b/sql/test/BugTracker-2020/Tests/release_old_savepoint.Bug-7020.sql
new file mode 100644
--- /dev/null
+++ b/sql/test/BugTracker-2020/Tests/release_old_savepoint.Bug-7020.sql
@@ -0,0 +1,18 @@
+start transaction;
+
+create table savepointtest (id int, primary key(id));
+savepoint name1;
+
+insert into savepointtest values(1), (2), (3);
+select * from savepointtest;
+savepoint name2;
+
+insert into savepointtest values(4), (5), (6);
+insert into savepointtest values(7), (8), (9);
+select * from savepointtest;
+savepoint name3;
+
+release savepoin

MonetDB: default - Merged with Oct2020

2020-12-07 Thread Pedro Ferreira
Changeset: cabc2db814c9 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=cabc2db814c9
Modified Files:
sql/storage/store.c
Branch: default
Log Message:

Merged with Oct2020


diffs (68 lines):

diff --git a/monetdb5/modules/mal/txtsim.c b/monetdb5/modules/mal/txtsim.c
--- a/monetdb5/modules/mal/txtsim.c
+++ b/monetdb5/modules/mal/txtsim.c
@@ -346,8 +346,6 @@ CMDqgramnormalize(str *res, str *Input)
  * =
  */
 
-#define PARAMS(proto) proto
-
 /*
  * Data on one input string being compared.
  */
@@ -417,9 +415,7 @@ struct partition {
cause suboptimal diff output.  It cannot cause incorrect diff
output.  */
 
-static int diag PARAMS((int, int, int, int, int, struct partition *, int, 
struct string_data *, int *, int *));
-
-static int
+static inline int
 diag(int xoff, int xlim, int yoff, int ylim, int minimal, struct partition 
*part, int too_expensive, struct string_data *string, int *fdiag, int *bdiag)
 {
int *const fd = fdiag;  /* Give the compiler a chance. */
@@ -602,9 +598,7 @@ diag(int xoff, int xlim, int yoff, int y
If MINIMAL is nonzero, find a minimal difference no matter how
expensive it is.  */
 
-static void compareseq PARAMS((int, int, int, int, int, int, int, struct 
string_data *, int*, int*));
-
-static void
+static inline void
 compareseq(int xoff, int xlim, int yoff, int ylim, int minimal, int max_edits, 
int too_expensive, struct string_data *string, int *fdiag, int *bdiag) /* 
compareseq stops when edits > max_edits */
 {
const char *const xv = string[0].data;  /* Help the compiler.  */
diff --git a/sql/server/sql_partition.c b/sql/server/sql_partition.c
--- a/sql/server/sql_partition.c
+++ b/sql/server/sql_partition.c
@@ -352,8 +352,12 @@ initialize_sql_parts(mvc *sql, sql_table
memcpy(nv->value, 
VALget(&vvalue), vvalue.len);
nv->length = vvalue.len;
}
-   list_append(p->part.values, nv);
VALclear(&vvalue);
+   if (list_append_sorted(p->part.values, 
nv, &found, sql_values_list_element_validate_and_insert)) {
+   res = createException(SQL, 
"sql.partition",
+   
SQLSTATE(42000) "Internal error while bootstrapping partitioned 
tables");
+   goto finish;
+   }
if (!ok) {
res = createException(SQL, 
"sql.partition",

  SQLSTATE(42000) "Internal error while bootstrapping partitioned 
tables");
diff --git a/sql/storage/store.c b/sql/storage/store.c
--- a/sql/storage/store.c
+++ b/sql/storage/store.c
@@ -833,12 +833,7 @@ load_value_partition(sql_trans *tr, sql_
nextv->value = sa_alloc(tr->sa, vvalue.len);
memcpy(nextv->value, VALget(&vvalue), 
vvalue.len);
nextv->length = vvalue.len;
-   if (list_append_sorted(vals, nextv, empty, 
sql_values_list_element_validate_and_insert) != NULL) {
-   VALclear(&vvalue);
-   table_funcs.rids_destroy(rs);
-   list_destroy(vals);
-   return -i - 1;
-   }
+   list_append(vals, nextv);
}
}
VALclear(&vvalue);
___
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list


MonetDB: default - Merged with Oct2020

2020-12-07 Thread Pedro Ferreira
Changeset: 56acedc51735 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=56acedc51735
Modified Files:
clients/Tests/MAL-signatures.stable.out
clients/Tests/MAL-signatures.stable.out.int128
sql/storage/store.c
sql/test/BugTracker-2020/Tests/All
Branch: default
Log Message:

Merged with Oct2020


diffs (truncated from 516 to 300 lines):

diff --git a/clients/Tests/MAL-signatures.stable.out 
b/clients/Tests/MAL-signatures.stable.out
--- a/clients/Tests/MAL-signatures.stable.out
+++ b/clients/Tests/MAL-signatures.stable.out
@@ -6638,6 +6638,7 @@ stdout of test 'MAL-signatures` in direc
 [ "batstr","unicodeAt","pattern batstr.unicodeAt(X_1:str, 
X_2:bat[:int], X_3:bat[:oid]):bat[:int] ",   "STRbatWChrAt_strcst;", ""  ]
 [ "batstr","unicodeAt","pattern batstr.unicodeAt(X_1:bat[:str], 
X_2:int):bat[:int] ",  "STRbatWChrAtcst;", ""  ]
 [ "batstr","unicodeAt","pattern batstr.unicodeAt(X_1:bat[:str], 
X_2:int, X_3:bat[:oid]):bat[:int] ",   "STRbatWChrAtcst;", ""  ]
+[ "battxtsim", "similarity",   "command battxtsim.similarity(X_1:bat[:str], 
X_2:bat[:str]):bat[:dbl] ","fstrcmp0_impl_bulk;",  ""  ]
 [ "batudf","fuse", "command batudf.fuse(X_1:bat[:bte], 
X_2:bat[:bte]):bat[:sht] ", "UDFBATfuse;",  ""  ]
 [ "batudf","fuse", "command batudf.fuse(X_1:bat[:int], 
X_2:bat[:int]):bat[:lng] ", "UDFBATfuse;",  ""  ]
 [ "batudf","fuse", "command batudf.fuse(X_1:bat[:sht], 
X_2:bat[:sht]):bat[:int] ", "UDFBATfuse;",  ""  ]
diff --git a/clients/Tests/MAL-signatures.stable.out.int128 
b/clients/Tests/MAL-signatures.stable.out.int128
--- a/clients/Tests/MAL-signatures.stable.out.int128
+++ b/clients/Tests/MAL-signatures.stable.out.int128
@@ -9197,6 +9197,7 @@ stdout of test 'MAL-signatures` in direc
 [ "batstr","unicodeAt","pattern batstr.unicodeAt(X_1:str, 
X_2:bat[:int], X_3:bat[:oid]):bat[:int] ",   "STRbatWChrAt_strcst;", ""  ]
 [ "batstr","unicodeAt","pattern batstr.unicodeAt(X_1:bat[:str], 
X_2:int):bat[:int] ",  "STRbatWChrAtcst;", ""  ]
 [ "batstr","unicodeAt","pattern batstr.unicodeAt(X_1:bat[:str], 
X_2:int, X_3:bat[:oid]):bat[:int] ",   "STRbatWChrAtcst;", ""  ]
+[ "battxtsim", "similarity",   "command battxtsim.similarity(X_1:bat[:str], 
X_2:bat[:str]):bat[:dbl] ","fstrcmp0_impl_bulk;",  ""  ]
 [ "batudf","fuse", "command batudf.fuse(X_1:bat[:bte], 
X_2:bat[:bte]):bat[:sht] ", "UDFBATfuse;",  ""  ]
 [ "batudf","fuse", "command batudf.fuse(X_1:bat[:int], 
X_2:bat[:int]):bat[:lng] ", "UDFBATfuse;",  ""  ]
 [ "batudf","fuse", "command batudf.fuse(X_1:bat[:lng], 
X_2:bat[:lng]):bat[:hge] ", "UDFBATfuse;",  ""  ]
diff --git a/monetdb5/modules/mal/txtsim.c b/monetdb5/modules/mal/txtsim.c
--- a/monetdb5/modules/mal/txtsim.c
+++ b/monetdb5/modules/mal/txtsim.c
@@ -263,7 +263,6 @@ soundex_code(char *Name, char *Key)
}
 }
 
-
 static str
 soundex_impl(str *res, str *Name)
 {
@@ -362,38 +361,6 @@ struct string_data {
int edit_count;
 };
 
-static struct string_data string[2];
-
-static int max_edits;  /* compareseq stops when edits > max_edits */
-
-#ifdef MINUS_H_FLAG
-
-/* This corresponds to the diff -H flag.  With this heuristic, for
-   strings with a constant small density of changes, the algorithm is
-   linear in the strings size.  This is unlikely in typical uses of
-   fstrcmp, and so is usually compiled out.  Besides, there is no
-   interface to set it true.  */
-static int heuristic;
-
-#endif
-
-
-/* Vector, indexed by diagonal, containing 1 + the X coordinate of the
-   point furthest along the given diagonal in the forward search of the
-   edit matrix.  */
-static int *fdiag;
-
-/* Vector, indexed by diagonal, containing the X coordinate of the point
-   furthest along the given diagonal in the backward search of the edit
-   matrix.  */
-static int *bdiag;
-
-/* Edit scripts longer than this are too expensive to compute.  */
-static int too_expensive;
-
-/* Snakes bigger than this are considered `big'.  */
-#define SNAKE_LIMIT20
-
 struct partition {
/* Midpoints of this partition.  */
int xmid, ymid;
@@ -405,7 +372,6 @@ struct partition {
int hi_minimal;
 };
 
-
 /* NAME
diag - find diagonal path
 
@@ -450,10 +416,10 @@ struct partition {
cause suboptimal diff output.  It cannot cause incorrect diff
output.  */
 
-static int diag PARAMS((int, int, int, int, int, struct partition *));
+static int diag PARAMS((int, int, int, int, int, struct partition *, int, 
struct string_data *, int *, int *));
 
 static int
-diag(int xoff, int xlim, int yoff, int ylim, int minimal, struct partition 
*part)
+diag(int xoff, int xlim, int yoff, int ylim, int minimal, struct partition 
*part, int too_expensive, struct string_data *string, int *fdiag, int *bdiag)
 {
int *const fd = fdiag;  /* Give the compiler a chance. */
int *c

MonetDB: default - Merged with Oct2020

2020-12-05 Thread Pedro Ferreira
Changeset: f27f119a1453 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=f27f119a1453
Branch: default
Log Message:

Merged with Oct2020


diffs (70 lines):

diff --git a/sql/test/merge-partitions/Tests/mergepart30.sql 
b/sql/test/merge-partitions/Tests/mergepart30.sql
--- a/sql/test/merge-partitions/Tests/mergepart30.sql
+++ b/sql/test/merge-partitions/Tests/mergepart30.sql
@@ -106,10 +106,16 @@ ALTER TABLE table1 ADD TABLE another3 AS
 ALTER TABLE table1 ADD TABLE another4 AS PARTITION FOR NULL VALUES;
 
 ALTER TABLE table1 ADD TABLE another5 AS PARTITION FROM -100 TO -1; --error, 
conflicts with another1
+ALTER TABLE table1 ADD TABLE another5 AS PARTITION FROM RANGE MINVALUE TO -1; 
--error, conflicts with another1
+ALTER TABLE table1 ADD TABLE another5 AS PARTITION FROM RANGE MINVALUE TO 0; 
--error, conflicts with another1
+ALTER TABLE table1 ADD TABLE another5 AS PARTITION FROM RANGE MINVALUE TO 
RANGE MAXVALUE; --error, conflicts with another1
 ALTER TABLE table1 ADD TABLE another5 AS PARTITION FROM 0 TO 0; --error, 
conflicts with another1
 ALTER TABLE table1 ADD TABLE another5 AS PARTITION FROM 10 TO 10; --error, 
conflicts with another2
 ALTER TABLE table1 ADD TABLE another5 AS PARTITION FROM 10 TO 11; --error, 
conflicts with another2
+ALTER TABLE table1 ADD TABLE another5 AS PARTITION FROM 10 TO RANGE MAXVALUE; 
--error, conflicts with another2
+ALTER TABLE table1 ADD TABLE another5 AS PARTITION FROM 20 TO RANGE MAXVALUE; 
--error, conflicts with another2
 ALTER TABLE table1 ADD TABLE another5 AS PARTITION FROM 9 TO 10; --error, 
conflicts with another3
+ALTER TABLE table1 ADD TABLE another5 AS PARTITION FROM 9 TO 10 WITH NULL 
VALUES; --error, conflicts with another3
 ALTER TABLE table1 ADD TABLE another5 AS PARTITION FOR NULL VALUES; --error, 
conflicts with another4
 
 ALTER TABLE table1 DROP TABLE another1;
diff --git a/sql/test/merge-partitions/Tests/mergepart30.stable.err 
b/sql/test/merge-partitions/Tests/mergepart30.stable.err
--- a/sql/test/merge-partitions/Tests/mergepart30.stable.err
+++ b/sql/test/merge-partitions/Tests/mergepart30.stable.err
@@ -109,7 +109,19 @@ MAPI  = (monetdb) /var/tmp/mtest-99796/.
 QUERY = ALTER TABLE table1 ADD TABLE another5 AS PARTITION FROM -100 TO -1; 
--error, conflicts with another1
 ERROR = !ALTER TABLE: conflicting partitions: -100 to -1 and absolute min 
value to 0 from table sys.another1
 CODE  = 42000
-MAPI  = (monetdb) /var/tmp/mtest-131881/.s.monetdb.39742
+MAPI  = (monetdb) /var/tmp/mtest-158968/.s.monetdb.39045
+QUERY = ALTER TABLE table1 ADD TABLE another5 AS PARTITION FROM RANGE MINVALUE 
TO -1; --error, conflicts with another1
+ERROR = !ALTER TABLE: conflicting partitions: absolute min value to -1 and 
absolute min value to 0 from table sys.another1
+CODE  = 42000
+MAPI  = (monetdb) /var/tmp/mtest-158968/.s.monetdb.39045
+QUERY = ALTER TABLE table1 ADD TABLE another5 AS PARTITION FROM RANGE MINVALUE 
TO 0; --error, conflicts with another1
+ERROR = !ALTER TABLE: conflicting partitions: absolute min value to 0 and 
absolute min value to 0 from table sys.another1
+CODE  = 42000
+MAPI  = (monetdb) /var/tmp/mtest-158968/.s.monetdb.39045
+QUERY = ALTER TABLE table1 ADD TABLE another5 AS PARTITION FROM RANGE MINVALUE 
TO RANGE MAXVALUE; --error, conflicts with another1
+ERROR = !ALTER TABLE: conflicting partitions: absolute min value to absolute 
max value and absolute min value to 0 from table sys.another1
+CODE  = 42000
+MAPI  = (monetdb) /var/tmp/mtest-158968/.s.monetdb.39045
 QUERY = ALTER TABLE table1 ADD TABLE another5 AS PARTITION FROM 0 TO 0; 
--error, conflicts with another1
 ERROR = !ALTER TABLE: conflicting partitions: 0 to 0 and absolute min value to 
0 from table sys.another1
 CODE  = 42000
@@ -121,11 +133,23 @@ MAPI  = (monetdb) /var/tmp/mtest-127940/
 QUERY = ALTER TABLE table1 ADD TABLE another5 AS PARTITION FROM 10 TO 11; 
--error, conflicts with another2
 ERROR = !ALTER TABLE: conflicting partitions: 10 to 11 and 10 to absolute max 
value from table sys.another2
 CODE  = 42000
-MAPI  = (monetdb) /var/tmp/mtest-27/.s.monetdb.37141
+MAPI  = (monetdb) /var/tmp/mtest-158968/.s.monetdb.39045
+QUERY = ALTER TABLE table1 ADD TABLE another5 AS PARTITION FROM 10 TO RANGE 
MAXVALUE; --error, conflicts with another2
+ERROR = !ALTER TABLE: conflicting partitions: 10 to absolute max value and 10 
to absolute max value from table sys.another2
+CODE  = 42000
+MAPI  = (monetdb) /var/tmp/mtest-158968/.s.monetdb.39045
+QUERY = ALTER TABLE table1 ADD TABLE another5 AS PARTITION FROM 20 TO RANGE 
MAXVALUE; --error, conflicts with another2
+ERROR = !ALTER TABLE: conflicting partitions: 20 to absolute max value and 10 
to absolute max value from table sys.another2
+CODE  = 42000
+MAPI  = (monetdb) /var/tmp/mtest-158968/.s.monetdb.39045
 QUERY = ALTER TABLE table1 ADD TABLE another5 AS PARTITION FROM 9 TO 10; 
--error, conflicts with another3
 ERROR = !ALTER TABLE: conflicting partitions: 9 to 10 and 0 to 10 from table 
sys.anot

MonetDB: default - Merged with Oct2020

2020-12-04 Thread Pedro Ferreira
Changeset: 49e9171c9d5d for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=49e9171c9d5d
Modified Files:
sql/server/rel_optimizer.c
Branch: default
Log Message:

Merged with Oct2020


diffs (truncated from 703 to 300 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
@@ -9062,19 +9062,26 @@ rel_merge_table_rewrite(visitor *v, sql_

skip |= nskip;

}

} else { /* limit1 to limit2 (general case), 
limit2 is exclusive */
+   
bool max_differ_min = 
ATOMcmp(col->type.type->localtype, &rmin->data.val, &rmax->data.val) != 0;
+

if (lval) {

if (next->flag == cmp_equal) {
-   
skip |= next->anti ? 
exp_range_overlap(rmin, rmax, lval, hval, false, true) != 0 :
-   

 exp_range_overlap(rmin, rmax, lval, hval, false, true) == 0;
+   
skip |= next->anti ? 
exp_range_overlap(rmin, rmax, lval, hval, false, max_differ_min) != 0 :
+   

 exp_range_overlap(rmin, rmax, lval, hval, false, 
max_differ_min) == 0;

} else if (hval != lval) { /* 
For the between case */

comp_type higher = 
range2rcompare(next->flag);
-   
skip |= next->anti ? 
exp_range_overlap(rmin, rmax, lval, hval, higher == cmp_lt, true) != 0 :
-   

 exp_range_overlap(rmin, rmax, lval, hval, higher == cmp_lt, 
true) == 0;
+   
skip |= next->anti ? 
exp_range_overlap(rmin, rmax, lval, hval, higher == cmp_lt, max_differ_min) != 
0 :
+   

 exp_range_overlap(rmin, rmax, lval, hval, higher == cmp_lt, 
max_differ_min) == 0;

} else {

switch (next->flag) {

case cmp_gt:
+   
skip |= 
next->anti ? VALcmp(&(lval->data), &(rmax->data)) < 0 : VALcmp(&(lval->data), 
&(rmax->data)) >= 0;
+   
break;

case cmp_gte:
-   
skip |= 
next->anti ? VALcmp(&(lval->data), &(rmax->data)) < 0 : VALcmp(&(lval->data), 
&(rma

MonetDB: default - Merged with Oct2020

2020-12-04 Thread Pedro Ferreira
Changeset: 03ef2f1eac20 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=03ef2f1eac20
Modified Files:
clients/mapilib/mapi.c
sql/backends/monet5/sql.c
sql/backends/monet5/sql_result.c
sql/storage/bat/bat_storage.c
sql/storage/store.c
Branch: default
Log Message:

Merged with Oct2020


diffs (truncated from 1057 to 300 lines):

diff --git a/clients/mapilib/.editorconfig b/clients/mapilib/.editorconfig
new file mode 100644
--- /dev/null
+++ b/clients/mapilib/.editorconfig
@@ -0,0 +1,3 @@
+[*.{c,h}]
+tab_width = 8
+max_line_length = 72
diff --git a/clients/mapilib/mapi.c b/clients/mapilib/mapi.c
--- a/clients/mapilib/mapi.c
+++ b/clients/mapilib/mapi.c
@@ -1524,8 +1524,7 @@ close_result(MapiHdl hdl)
   (hdl->npending_close > 0 && hdl->pending_close != NULL));
if (mid->active &&
(mid->active->active != result ||
-result->cache.tuplecount < result->row_count))
-   {
+result->cache.tuplecount < result->row_count)) {
/* results for which we got all tuples at the initial
 * response, need not to be closed as the server already
 * did that immediately */
@@ -1689,9 +1688,9 @@ mapi_next_result(MapiHdl hdl)
return MERROR;
if (hdl->result &&
(hdl->result->querytype == -1 ||
-/* basically exclude Q_PARSE and Q_BLOCK */
-(hdl->result->querytype >= Q_TABLE &&
- hdl->result->querytype <= Q_PREPARE) ||
+/* basically exclude Q_PARSE and Q_BLOCK */
+(hdl->result->querytype >= Q_TABLE &&
+ hdl->result->querytype <= Q_PREPARE) ||
 hdl->result->errorstr != NULL))
return 1;
}
@@ -1727,9 +1726,9 @@ mapi_more_results(MapiHdl hdl)
while (result->next) {
result = result->next;
if (result->querytype == -1 ||
-   /* basically exclude Q_PARSE and Q_BLOCK */
-   (hdl->result->querytype >= Q_TABLE &&
-hdl->result->querytype <= Q_PREPARE) ||
+   /* basically exclude Q_PARSE and Q_BLOCK */
+   (hdl->result->querytype >= Q_TABLE &&
+hdl->result->querytype <= Q_PREPARE) ||
result->errorstr != NULL)
return true;
}
@@ -2286,7 +2285,7 @@ mapi_reconnect(Mapi mid)
/* see comment above for why
 * we don't stat */
snprintf(buf, sizeof(buf),
-"%s/.s.monetdb.%d", 
host, MAPI_PORT);
+"%s/.s.monetdb.%d", host, 
MAPI_PORT);
host = buf;
}
 #endif
@@ -2479,12 +2478,12 @@ mapi_reconnect(Mapi mid)
closesocket(s);
}
snprintf(errbuf, sizeof(errbuf),
-"could not connect to %s:%s: %s",
-mid->hostname, port,
+"could not connect to %s:%s: %s",
+mid->hostname, port,
 #ifdef _MSC_VER
-wsaerror(WSAGetLastError())
+wsaerror(WSAGetLastError())
 #else
-strerror(errno)
+strerror(errno)
 #endif
);
}
@@ -2510,15 +2509,15 @@ mapi_reconnect(Mapi mid)
praddrlen = (socklen_t) sizeof(praddr.ss);
if (getsockname(s, (struct sockaddr *) &myaddr.ss, &myaddrlen) 
== 0 &&
getpeername(s, (struct sockaddr *) &praddr.ss, &praddrlen) 
== 0 &&
-   myaddr.ss.ss_family == praddr.ss.ss_family &&
-   (myaddr.ss.ss_family == AF_INET
-? myaddr.i4.sin_port == praddr.i4.sin_port
-: myaddr.i6.sin6_port == praddr.i6.sin6_port) &&
-   (myaddr.ss.ss_family == AF_INET
-? myaddr.i4.sin_addr.s_addr == 
praddr.i4.sin_addr.s_addr
-: memcmp(myaddr.i6.sin6_addr.s6_addr,
- praddr.i6.sin6_addr.s6_addr,
- sizeof(praddr.i6.sin6_addr.s6_addr)) 
== 0)) {
+   myaddr.ss.ss_family == praddr.ss.ss_family &&
+   (myaddr.ss.ss_family == AF_INET
+? myaddr.i4.sin_port == praddr.i4.sin_port
+ 

MonetDB: default - Merged with Oct2020

2020-12-03 Thread Pedro Ferreira
Changeset: 0faee038cabb for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=0faee038cabb
Modified Files:
sql/server/rel_exp.c
sql/server/rel_optimizer.c
sql/test/SQLancer/Tests/sqlancer01.stable.out
sql/test/miscellaneous/Tests/simple_plans.stable.out
sql/test/miscellaneous/Tests/simple_selects.stable.out
Branch: default
Log Message:

Merged with Oct2020


diffs (truncated from 424 to 300 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
@@ -410,6 +410,8 @@ exp_atom(sql_allocator *sa, atom *a)
e->card = CARD_ATOM;
e->tpe = a->tpe;
e->l = a;
+   if (!a->isnull)
+   set_has_no_nil(e);
return e;
 }
 
@@ -1875,6 +1877,9 @@ exp_is_zero(sql_exp *e)
 int
 exp_is_not_null(sql_exp *e)
 {
+   if (!has_nil(e))
+   return true;
+
switch (e->type) {
case e_atom:
if (e->f) /* values list */
@@ -1907,6 +1912,9 @@ exp_is_not_null(sql_exp *e)
 int
 exp_is_null(sql_exp *e )
 {
+   if (!has_nil(e))
+   return false;
+
switch (e->type) {
case e_atom:
if (e->f) /* values list */
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
@@ -8890,8 +8890,8 @@ rel_merge_table_rewrite(visitor *v, sql_
int skip = 0;
list *exps = NULL;
 
-   /* do not include empty 
partitions. Don't skip when storage_based_opt is not applicable */
-   if (v->storage_based_opt && pt 
&& isTable(pt) && pt->access == TABLE_READONLY && 
!store_funcs.count_col(v->sql->session->tr, pt->columns.set->h->data, 1))
+   /* Do not include empty 
partitions */
+   if (pt && isTable(pt) && 
pt->access == TABLE_READONLY && !store_funcs.count_col(v->sql->session->tr, 
pt->columns.set->h->data, 1))
continue;
 
prel = rel_rename_part(v->sql, 
prel, tname, t);
diff --git a/sql/test/BugTracker-2015/Tests/crash.Bug-3736.stable.out 
b/sql/test/BugTracker-2015/Tests/crash.Bug-3736.stable.out
--- a/sql/test/BugTracker-2015/Tests/crash.Bug-3736.stable.out
+++ b/sql/test/BugTracker-2015/Tests/crash.Bug-3736.stable.out
@@ -114,7 +114,7 @@ project (
 | | | | ) [ "b2"."id" NOT NULL HASHCOL  = "%3"."%3" ]
 | | | ) [ "b2"."increase" NOT NULL, "o"."open_auction_id" NOT NULL as 
"%6"."%6" ]
 | | ) [ "o"."open_auction_id" NOT NULL * = "%6"."%6" NOT NULL ]
-| ) [ sys.sql_mul("%2"."%2" NOT NULL, double "2") <= "b2"."increase" NOT NULL ]
+| ) [ sys.sql_mul("%2"."%2" NOT NULL, double "2") NOT NULL <= "b2"."increase" 
NOT NULL ]
 ) [ "b"."id" NOT NULL HASHCOL , "b"."open_auction_id" NOT NULL, "b"."date" NOT 
NULL, "b"."time" NOT NULL, "b"."personref" NOT NULL, "b"."increase" NOT NULL ]
 #Select b.* FROM open_auctions o, bidder b WHERE (select b3.INCREASE from 
bidder b3 where b3.id = (select min(b3a.id) from bidder b3a where 
b3a.open_auction_id = o.open_auction_id)) * 2 <= (Select b2.INCREASE from 
bidder b2 where b2.id = (SELECT MAX(b2a.id) from bidder b2a where 
b2a.open_auction_id = o.open_auction_id)) AND o.open_auction_id = 
b.open_auction_id order by date, time;
 % sys.b,   sys.b,  sys.b,  sys.b,  sys.b,  sys.b # table_name
diff --git 
a/sql/test/BugTracker-2015/Tests/crash_in_reduce_groupby.Bug-3818.stable.out 
b/sql/test/BugTracker-2015/Tests/crash_in_reduce_groupby.Bug-3818.stable.out
--- a/sql/test/BugTracker-2015/Tests/crash_in_reduce_groupby.Bug-3818.stable.out
+++ b/sql/test/BugTracker-2015/Tests/crash_in_reduce_groupby.Bug-3818.stable.out
@@ -54,12 +54,12 @@ stdout of test 'crash_in_reduce_groupby.
 % .plan # table_name
 % rel # name
 % clob # type
-% 180 # length
+% 189 # length
 project (
 | group by (
 | | table(sys.t2a) [ "t2a"."tib0" ] COUNT 
-| ) [ tinyint "0" as "sora" ] [ tinyint "0" as "cods", tinyint "0" as "elrik", 
tinyint "0" as "ether", tinyint "0" as "jaelen", "sora", sys.min no nil 
("t2a"."tib0") as "%1"."%1" ]
-) [ "cods", "elrik", "ether", "jaelen", "sora", "%1"."%1" ]
+| ) [ tinyint "0" as "sora" ] [ tinyint "0" as "cods", tinyint "0" as "elrik", 
tinyint "0" as "ether", tinyint "0" as "jaelen", "sora" NOT NULL, sys.min no 
nil ("t2a"."tib0") as "%1"."%1" ]
+) [ "cods" NOT NULL, "elrik" NOT NULL, "ether" NOT NULL, "jaelen" NOT NULL, 
"sora" NOT NULL, "%1"."%1" ]
 #drop table t2a;
 #drop table t1a;
 
diff --git 
a/sql/test/BugTracker-2015/Tests/quantile_function_resolution.Bug-3773.stable.out
 
b/sql/test/BugTracker-2015/Tests/quantile_function_resolution.Bug-3773.stable.out
--- 
a/sql/test/BugTracker-2015/Tests/quantile_function_resolut

MonetDB: default - Merged with Oct2020

2020-12-02 Thread Pedro Ferreira
Changeset: 8ecd046e7584 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=8ecd046e7584
Modified Files:
clients/Tests/exports.stable.out
gdk/gdk_batop.c
gdk/gdk_logger.c
sql/backends/monet5/rel_bin.c
sql/backends/monet5/sql.c
sql/backends/monet5/sql_cat.c
sql/backends/monet5/sql_execute.c
sql/backends/monet5/sql_gencode.c
sql/backends/monet5/sql_statement.c
sql/backends/monet5/sql_upgrades.c
sql/server/rel_exp.c
sql/server/rel_optimizer.c
sql/server/rel_rel.h
sql/server/rel_unnest.c
sql/server/sql_mvc.h
sql/storage/bat/bat_logger.c
sql/storage/bat/bat_storage.c
sql/storage/sql_storage.h
sql/storage/store.c
Branch: default
Log Message:

Merged with Oct2020


diffs (truncated from 1648 to 300 lines):

diff --git a/clients/Tests/exports.stable.out b/clients/Tests/exports.stable.out
--- a/clients/Tests/exports.stable.out
+++ b/clients/Tests/exports.stable.out
@@ -516,6 +516,7 @@ gdk_return log_bat_clear(logger *lg, con
 gdk_return log_bat_persists(logger *lg, BAT *b, const char *n, char tpe, oid 
id);
 gdk_return log_bat_transient(logger *lg, const char *n, char tpe, oid id);
 gdk_return log_delta(logger *lg, BAT *uid, BAT *uval, const char *n, char tpe, 
oid id);
+lng log_save_id(logger *lg);
 gdk_return log_sequence(logger *lg, int seq, lng id);
 gdk_return log_tend(logger *lg);
 gdk_return log_tstart(logger *lg);
@@ -525,9 +526,8 @@ gdk_return logger_cleanup(logger *lg);
 logger *logger_create(int debug, const char *fn, const char *logdir, int 
version, preversionfix_fptr prefuncp, postversionfix_fptr postfuncp);
 gdk_return logger_del_bat(logger *lg, log_bid bid) 
__attribute__((__warn_unused_result__));
 void logger_destroy(logger *lg);
-gdk_return logger_exit(logger *lg);
 log_bid logger_find_bat(logger *lg, const char *name, char tpe, oid id);
-gdk_return logger_restart(logger *lg);
+gdk_return logger_flush(logger *lg, lng save_id);
 int logger_sequence(logger *lg, int seq, lng *id);
 gdk_return logger_upgrade_bat(logger *lg, const char *name, char tpe, oid id) 
__attribute__((__warn_unused_result__));
 void logger_with_ids(logger *lg);
diff --git a/gdk/gdk_logger.c b/gdk/gdk_logger.c
--- a/gdk/gdk_logger.c
+++ b/gdk/gdk_logger.c
@@ -160,7 +160,7 @@ typedef enum {LOG_OK, LOG_EOF, LOG_ERR} 
  * indicate that to the function wkbREAD during reading of the log. */
 static bool geomisoldversion;
 
-static gdk_return bm_commit(logger *lg);
+static gdk_return bm_commit(logger *lg, lng save_id);
 static gdk_return tr_grow(trans *tr);
 
 static BUN
@@ -1401,7 +1401,7 @@ logger_readlogs(logger *lg, FILE *fp, ch
 }
 
 static gdk_return
-logger_commit(logger *lg)
+logger_commit(logger *lg, lng save_id)
 {
if (lg->debug & 1)
fprintf(stderr, "#logger_commit\n");
@@ -1416,7 +1416,7 @@ logger_commit(logger *lg)
BATcommit(lg->snapshots_tid);
BATcommit(lg->dsnapshots);
}
-   return bm_commit(lg);
+   return bm_commit(lg, save_id);
 }
 
 static gdk_return
@@ -1721,6 +1721,7 @@ logger_load(int debug, const char *fn, c
lg->snapshots_tid = NULL;
lg->dsnapshots = NULL;
lg->freed = NULL;
+   lg->freed_lid = NULL;
lg->seqs_id = NULL;
lg->seqs_val = NULL;
lg->dseqs = NULL;
@@ -2006,6 +2007,15 @@ logger_load(int debug, const char *fn, c
if (BBPrename(lg->freed->batCacheid, bak) < 0) {
goto error;
}
+   lg->freed_lid = logbat_new(TYPE_lng, 1, TRANSIENT);
+   if (lg->freed_lid == NULL) {
+   GDKerror("Logger_new: failed to create freed_lid bat");
+   goto error;
+   }
+   strconcat_len(bak, sizeof(bak), fn, "_freed_lid", NULL);
+   if (BBPrename(lg->freed_lid->batCacheid, bak) < 0) {
+   goto error;
+   }
snapshots_bid = logger_find_bat(lg, "snapshots_bid", 0, 0);
if (snapshots_bid == 0) {
lg->snapshots_bid = logbat_new(TYPE_int, 1, PERSISTENT);
@@ -2129,7 +2139,7 @@ logger_load(int debug, const char *fn, c
needcommit = true;
}
GDKdebug &= ~CHECKMASK;
-   if (needcommit && bm_commit(lg) != GDK_SUCCEED) {
+   if (needcommit && bm_commit(lg, lg->tid+1) != GDK_SUCCEED) {
GDKerror("Logger_new: commit failed");
goto error;
}
@@ -2303,6 +2313,7 @@ logger_load(int debug, const char *fn, c
logbat_destroy(lg->snapshots_tid);
logbat_destroy(lg->dsnapshots);
logbat_destroy(lg->freed);
+   logbat_destroy(lg->freed_lid);
logbat_destroy(lg->seqs_id);
logbat_destroy(lg->seqs_val);
logbat_destroy(lg->dseqs);
@@ -2392,6 +2403,12 @@ logger_new(int debug, const char *fn, co
return NULL;
 }
 
+static gdk_return
+logger_restart(logger *lg)
+{
+   return logger_flush(lg, lg->tid);
+}
+
 /* Create a n

MonetDB: default - Merged with Oct2020

2020-12-01 Thread Pedro Ferreira
Changeset: eb37641ca4fe for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=eb37641ca4fe
Modified Files:
sql/server/rel_exp.c
sql/server/rel_optimizer.c
sql/server/rel_select.c
sql/server/rel_unnest.c
Branch: default
Log Message:

Merged with Oct2020


diffs (153 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
@@ -396,7 +396,7 @@ exp_aggr( sql_allocator *sa, list *l, sq
set_distinct(e);
if (no_nils)
set_no_nil(e);
-   if (!has_nils)
+   if ((!a->func->semantics && !has_nils) || (!a->func->s && 
strcmp(a->func->base.name, "count") == 0))
set_has_no_nil(e);
return e;
 }
@@ -416,7 +416,6 @@ exp_atom(sql_allocator *sa, atom *a)
 sql_exp *
 exp_atom_max(sql_allocator *sa, sql_subtype *tpe)
 {
-
if (tpe->type->localtype == TYPE_bte) {
return exp_atom_bte(sa, GDK_bte_max);
} else if (tpe->type->localtype == TYPE_sht) {
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
@@ -5613,7 +5613,7 @@ sql_class_base_score(mvc *sql, sql_colum
case TYPE_dbl:
return 75 - 53;
default: {
-   if (equality_based && c && (de = 
sql_trans_is_duplicate_eliminated(sql->session->tr, c)))
+   if (equality_based && c && (de = 
mvc_is_duplicate_eliminated(sql, c)))
return 150 - de * 8;
/* strings and blobs not duplicate eliminated don't get 
any points here */
return 0;
@@ -8697,7 +8697,7 @@ rel_add_dicts(visitor *v, sql_rel *rel)
if (!is_func(e->type) && oname[0] != '%') {
sql_column *c = find_sql_column(t, oname);
 
-   if ((de = 
sql_trans_is_duplicate_eliminated(v->sql->session->tr, c)) != 0) {
+   if ((de = mvc_is_duplicate_eliminated(v->sql, 
c)) != 0) {
int nr = ++v->sql->label;
char name[16], *nme;
sql_rel *vt = rel_dicttable(v->sql, c, 
rname, de);
diff --git a/sql/server/rel_rel.c b/sql/server/rel_rel.c
--- a/sql/server/rel_rel.c
+++ b/sql/server/rel_rel.c
@@ -533,7 +533,14 @@ rel_setop_set_exps(mvc *sql, sql_rel *re
for (node *n = exps->h, *m = lexps->h, *o = rexps->h ; m && m && o ; n 
= n->next, m = m->next,o = o->next) {
sql_exp *e = n->data, *f = m->data, *g = o->data;
 
-   e->card = is_union(rel->op) ? MAX(f->card, g->card) : f->card;
+   if (is_union(rel->op)) { /* propagate set_has_no_nil only if 
it's applicable to both sides of the union*/
+   if (has_nil(f) || has_nil(g))
+   set_has_nil(e);
+   else
+   set_has_no_nil(e);
+   e->card = MAX(f->card, g->card);
+   } else
+   e->card = f->card;
}
rel->nrcols = l->nrcols;
rel->exps = exps;
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
@@ -3651,7 +3651,8 @@ static sql_exp *
}
}
if (a && execute_priv(sql,a->func)) {
-   sql_exp *e = exp_aggr(sql->sa, exps, a, distinct, no_nil, 
groupby?groupby->card:CARD_ATOM, have_nil(exps));
+   bool hasnil = have_nil(exps) || (strcmp(aname, "count") != 0 && 
(!groupby || list_empty(groupby->r))); /* for global case, the aggregate may 
return NULL */
+   sql_exp *e = exp_aggr(sql->sa, exps, a, distinct, no_nil, 
groupby?groupby->card:CARD_ATOM, hasnil);
 
if (!groupby)
return e;
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
@@ -1611,6 +1611,8 @@ rewrite_exp_rel(visitor *v, sql_rel *rel
if (!exp_name(ne))
ne = exp_label(v->sql->sa, ne, ++v->sql->label);
e = ne;
+   if (depth) /* a projection from an outer join may have 
nulls */
+   set_has_nil(e);
} else {
e = exp_rel_update_exp(v->sql, e);
}
diff --git a/sql/test/BugTracker-2015/Tests/crash.Bug-3736.stable.out 
b/sql/test/BugTracker-2015/Tests/crash.Bug-3736.stable.out
--- a/sql/test/BugTracker-2015/Tests/crash.Bug-3736.stable.out
+++ b/sql/test/BugTracker-2015/Tests/crash.Bug-3736.stable.out
@@ -89,9 +89,9 @@ single project (
 | | | | | | ) [ "o"."open_auction_id" NOT NULL ] [ "o"."open_auction_id" NOT 
NULL ],
 | | | | | | ta

MonetDB: default - Merged with Oct2020

2020-11-27 Thread Pedro Ferreira
Changeset: cec6ceb82f7a for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=cec6ceb82f7a
Modified Files:
monetdb5/mal/mal_authorize.c
monetdb5/mal/mal_prelude.c
monetdb5/mal/mal_profiler.c
monetdb5/modules/kernel/batmmath.c
monetdb5/modules/kernel/batstr.c
monetdb5/modules/mal/remote.c
sql/backends/monet5/rel_bin.c
sql/backends/monet5/sql.c
sql/backends/monet5/sql_cat.c
sql/include/sql_catalog.h
sql/server/rel_optimizer.c
sql/server/rel_schema.c
sql/server/rel_select.c
sql/server/rel_updates.c
sql/storage/store.c
tools/monetdbe/monetdbe.c
Branch: default
Log Message:

Merged with Oct2020


diffs (truncated from 2896 to 300 lines):

diff --git a/buildtools/coverity_model.c b/buildtools/coverity_model.c
new file mode 100644
--- /dev/null
+++ b/buildtools/coverity_model.c
@@ -0,0 +1,166 @@
+/*
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0.  If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * Copyright 1997 - July 2008 CWI, August 2008 - 2020 MonetDB B.V.
+ */
+
+/*
+ * This file contains a model for Coverity Scan.
+ * This file is not a normal source file.  It is not compiled by any
+ * compiler, but instead it is uploaded to the Coverity site and used
+ * during any analysis they do on our code.
+ *
+ * We model our use of the various allocation functions.
+ * Things we want to do is model that GDKmalloc and friends are paired
+ * with GDKfree, and that exceptions created by createException and
+ * createMalException should be freed with freeException.
+ *
+ * author: Sjoerd Mullender
+ */
+
+typedef enum { GDK_FAIL, GDK_SUCCEED } gdk_return;
+typedef struct {} *MalBlkPtr;
+
+void
+GDKfree(void *blk)
+{
+   if (blk) {
+   __coverity_free__(blk);
+   __coverity_mark_as_afm_freed__(blk, "GDKfree");
+   }
+}
+
+void *
+GDKmalloc(size_t size)
+{
+   int has_memory;
+   __coverity_negative_sink__(size);
+   if(has_memory) {
+   void *p = __coverity_alloc__(size);
+   __coverity_mark_as_afm_allocated__(p, "GDKfree");
+   __coverity_mark_as_uninitialized_buffer__(p);
+   return p;
+   }
+   return 0;
+}
+
+void *
+GDKzalloc(size_t size)
+{
+   void *p = GDKmalloc(size);
+   if (p) {
+   for (size_t i = 0; i < size; i++)
+   ((char *) p)[i] = 0;
+   }
+   return p;
+}
+
+char *
+GDKstrdup(const char *s)
+{
+   char *p;
+   size_t i;
+   int has_memory;
+   if (s == 0)
+   return 0;
+   __coverity_string_null_sink__(s);
+   __coverity_string_size_sink__(s);
+   if (has_memory) {
+   p = __coverity_alloc_nosize__();
+   __coverity_mark_as_afm_allocated__(p, "GDKfree");
+   for (i = 0; (p[i] = s[i]); i++)
+   ;
+   return p;
+   }
+   return 0;
+}
+
+char *
+GDKstrndup(const char *s, size_t size)
+{
+   char *p;
+   size_t i;
+   __coverity_negative_sink__(size);
+   if (s == 0)
+   return 0;
+   p = GDKmalloc(size + 1);
+   if (p) {
+   for (i = 0; i < size && (p[i] = s[i]); i++)
+   ;
+   p[i] = 0;
+   }
+   return p;
+}
+
+void *
+GDKrealloc(void *blk, size_t size)
+{
+   void *p = GDKmalloc(size);
+   if (p != 0)
+   GDKfree(blk);
+   return p;
+}
+
+void *
+GDKmmap(const char *path, int mode, size_t size)
+{
+   int has_memory;
+   __coverity_negative_sink__(size);
+   if (has_memory) {
+   void *p = __coverity_alloc__(size);
+   __coverity_mark_as_afm_allocated__(p, "GDKmunmap");
+   __coverity_writeall__(p);
+   return p;
+   }
+   return 0;
+}
+
+gdk_return
+GDKmunmap(void *p, size_t size)
+{
+   int failed;
+   __coverity_free__(p);
+   __coverity_mark_as_afm_freed__(p, "GDKmunmap");
+   return failed ? GDK_FAIL : GDK_SUCCEED;
+}
+
+void *
+GDKmremap(const char *path, int mode, void *old_address, size_t old_size, 
size_t *new_size)
+{
+   void *p = GDKmmap(path, mode, new_size);
+   if (p) {
+   (void) GDKmunmap(old_address, old_size);
+   }
+   return p;
+}
+
+char *
+createException(enum malexception type, const char *fcn, const char *format, 
...)
+{
+   char *p;
+   __coverity_format_string_sink__(format);
+   p = __coverity_alloc_nosize__();
+   __coverity_mark_as_afm_allocated__(p, "freeException");
+   return p;
+}
+
+char *
+createMalException(MalBlkPtr mb, int pc, enum malexception type, const char 
*format, ...)
+{
+   char *p;
+   __coverity_format_string_sink__(format);
+   p = __coverity_alloc_nosize__();
+   __coverity_mark_as

MonetDB: default - Merged with Oct2020

2020-11-26 Thread Pedro Ferreira
Changeset: 7b1fb26f8dcf for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=7b1fb26f8dcf
Modified Files:
MonetDB.spec
clients/mapilib/mapi.c
gdk/gdk_join.c
gdk/gdk_logger.c
monetdb5/mal/mal_profiler.c
monetdb5/modules/mal/mal_mapi.c
monetdb5/modules/mal/remote.c
monetdb5/modules/mal/tablet.c
sql/server/rel_psm.c
sql/storage/store.c
sql/test/miscellaneous/Tests/simple_selects.sql
tools/monetdbe/monetdbe.c
tools/mserver/shutdowntest.c
Branch: default
Log Message:

Merged with Oct2020


diffs (truncated from 2127 to 300 lines):

diff --git a/MonetDB.spec b/MonetDB.spec
--- a/MonetDB.spec
+++ b/MonetDB.spec
@@ -161,16 +161,13 @@ BuildRequires: pkgconfig(libR)
 BuildRequires: texlive-obsolete
 %endif
 %endif
-# if we were to compile with cmocka support (-DWITH_CMOCKA=ON):
-# BuildRequires: pkgconfig(cmocka)
-# if we were to compile with NetCDF support (-DNETCDF=ON):
-# BuildRequires: pkgconfig(netcdf)
-# if we were to compile with proj support (-DWITH_PROJ=ON):
-# BuildRequires: pkgconfig(proj)
-# if we were to compile with snappy support (-DWITH_SNAPPY=ON):
-# BuildRequires: pkgconfig(snappy)
-# if we were to compile with valgrind support (-DWITH_VALGRIND=ON):
-# BuildRequires: pkgconfig(valgrind)
+# optional packages:
+# BuildRequires: pkgconfig(cmocka) # -DWITH_CMOCKA=ON
+# BuildRequires: pkgconfig(gdal)   # -DSHP=ON
+# BuildRequires: pkgconfig(netcdf) # -DNETCDF=ON
+# BuildRequires: pkgconfig(proj)   # -DWITH_PROJ=ON
+# BuildRequires: pkgconfig(snappy) # -DWITH_SNAPPY=ON
+# BuildRequires: pkgconfig(valgrind)   # -DWITH_VALGRIND=ON
 
 %if (0%{?fedora} >= 22)
 Recommends: %{name}-SQL-server5%{?_isa} = %{version}-%{release}
diff --git a/clients/mapiclient/ReadlineTools.c 
b/clients/mapiclient/ReadlineTools.c
--- a/clients/mapiclient/ReadlineTools.c
+++ b/clients/mapiclient/ReadlineTools.c
@@ -23,6 +23,12 @@
 #include/* for strncasecmp */
 #endif
 
+#ifndef WIN32
+/* for umask */
+#include 
+#include 
+#endif
+
 static const char *sql_commands[] = {
"SELECT",
"INSERT",
@@ -313,37 +319,40 @@ invoke_editor(int cnt, int key) {
char *read_buff = NULL;
char *editor = NULL;
FILE *fp = NULL;
-   size_t content_len;
+   long content_len;
size_t read_bytes, idx;
-#ifdef WIN32
-   char *mytemp;
-   char template[] = "mclient_temp_XX";
-#else
-   int mytemp;
-   char template[] = "/tmp/mclient_temp_XX";
-#endif
 
(void) cnt;
(void) key;
 
 #ifdef WIN32
+   char *mytemp;
+   char template[] = "mclient_temp_XX";
if ((mytemp = _mktemp(template)) == NULL) {
-#else
-   if ((mytemp = mkstemp(template)) == 0) {
-#endif
readline_show_error("invoke_editor: Cannot create temp file\n");
goto bailout;
}
-
-#ifdef WIN32
if ((fp = fopen(mytemp, "r+")) == NULL) {
-#else
-   if ((fp = fdopen(mytemp, "r+")) == NULL) {
-#endif
// Notify the user that we cannot create temp file
readline_show_error("invoke_editor: Cannot create temp file\n");
goto bailout;
}
+#else
+   int mytemp;
+   char template[] = "/tmp/mclient_temp_XX";
+   mode_t msk = umask(077);
+   mytemp = mkstemp(template);
+   (void) umask(msk);
+   if (mytemp == -1) {
+   readline_show_error("invoke_editor: Cannot create temp file\n");
+   goto bailout;
+   }
+   if ((fp = fdopen(mytemp, "r+")) == NULL) {
+   // Notify the user that we cannot create temp file
+   readline_show_error("invoke_editor: Cannot create temp file\n");
+   goto bailout;
+   }
+#endif
 
fwrite(rl_line_buffer, sizeof(char), rl_end, fp);
fflush(fp);
@@ -368,24 +377,24 @@ invoke_editor(int cnt, int key) {
rewind(fp);
 
if (content_len > 0) {
-   read_buff = (char *)malloc(content_len*sizeof(char));
+   read_buff = (char *)malloc(content_len + 1);
if (read_buff == NULL) {
readline_show_error("invoke_editor: Cannot allocate 
memory\n");
goto bailout;
}
 
-   read_bytes = fread(read_buff, sizeof(char), content_len, fp);
-   if (read_bytes != content_len) {
+   read_bytes = fread(read_buff, sizeof(char), (size_t) 
content_len, fp);
+   if (read_bytes != (size_t) content_len) {
readline_show_error("invoke_editor: Did not read from 
file correctly\n");
goto bailout;
}
 
-   *(read_buff + read_bytes) = 0;
+   read_buff[read_bytes] = 0;
 
/* Remove trailing whitespace */
idx = read_bytes - 1;
while(isspace(*(read_buff + idx))) 

MonetDB: default - Merged with Oct2020

2020-11-25 Thread Pedro Ferreira
Changeset: 803d2aa8de78 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=803d2aa8de78
Modified Files:
gdk/gdk_utils.c
tools/merovingian/daemon/controlrunner.c
Branch: default
Log Message:

Merged with Oct2020


diffs (211 lines):

diff --git a/cmake/monetdb-defines.cmake b/cmake/monetdb-defines.cmake
--- a/cmake/monetdb-defines.cmake
+++ b/cmake/monetdb-defines.cmake
@@ -70,7 +70,6 @@ function(monetdb_configure_defines)
   # Linux specific, in the future, it might be ported to other platforms
   check_symbol_exists("fallocate" "fcntl.h" HAVE_FALLOCATE)
   check_function_exists("fcntl" HAVE_FCNTL)
-  check_symbol_exists("F_GETLK" "fcntl.h" HAVE_F_GETLK)
   check_symbol_exists("fork" "unistd.h" HAVE_FORK)
   check_symbol_exists("fsync" "unistd.h" HAVE_FSYNC)
   check_symbol_exists("ftime" "sys/timeb.h" HAVE_FTIME)
@@ -181,13 +180,7 @@ macro(monetdb_macro_variables)
   if(HAVE_GETOPT_H)
 set(HAVE_GETOPT 1)
   endif()
-  # Check with STATIC_CODE_ANALYSIS
   # compiler options, profiling (google perf tools), valgrind
-  set(ENABLE_STATIC_ANALYSIS
-"NO"
-CACHE
-STRING
-"Configure for static code analysis (use only if you know what you are 
doing)")
   # Check that posix regex is available when pcre is not found
   # "monetdb5/module/mal/pcre.c" assumes the regex library is available
   # as an alternative without checking this in the C code.
diff --git a/cmake/monetdb-options.cmake b/cmake/monetdb-options.cmake
--- a/cmake/monetdb-options.cmake
+++ b/cmake/monetdb-options.cmake
@@ -17,41 +17,41 @@ else()
   set(DEVELOPMENT FALSE)
 endif()
 
-option(TESTING 
+option(TESTING
   "Enable support for testing"
   ON)
 
-cmake_dependent_option(CINTEGRATION 
+cmake_dependent_option(CINTEGRATION
   "Enable support for C UDFs (default=ON)"
   ON
   "NOT WIN32"
   OFF)
 
-option(PY3INTEGRATION 
+option(PY3INTEGRATION
   "Enable support for Python 3 integration into MonetDB (default=ON)"
   ON)
 
-option(RINTEGRATION 
+option(RINTEGRATION
   "Enable support for R integration into MonetDB (default=ON)"
   ON)
 
-option(FITS 
+option(FITS
   "Enable support for FITS (default=ON)"
   ON)
 
 option(GEOM
   "Enable support for geom module (default=ON)"
-  ON) 
+  ON)
 
-option(INT128 
+option(INT128
   "Enable support for 128-bit integers (default=ON)"
-  ON) 
-
-option(NETCDF 
-  "Enable support for netcdf (default=ON)" 
   ON)
 
-option(ODBC 
+option(NETCDF
+  "Enable support for netcdf (default=ON)"
+  ON)
+
+option(ODBC
   "Compile the MonetDB ODBC driver (default=ON)"
   ON)
 
@@ -61,15 +61,19 @@ cmake_dependent_option(SHP
   "GEOM"
   OFF)
 
-option(SANITIZER 
+option(SANITIZER
   "Enable support for the GCC address sanitizer (default=OFF)"
   OFF)
 
-option(STRICT 
+option(STATIC_CODE_ANALYSIS
+  "configure for static code analysis (use only if you know what you are 
doing) (default=OFF)"
+  OFF)
+
+option(STRICT
   "Enable strict compiler flags (default=ON for development sources, OFF for 
tarball installation)"
   "${DEVELOPMENT}")
 
-option(ASSERT 
+option(ASSERT
   "Enable asserts (default=ON for development sources, OFF for tarball 
installation)"
   "${DEVELOPMENT}")
 
diff --git a/common/utils/msabaoth.c b/common/utils/msabaoth.c
--- a/common/utils/msabaoth.c
+++ b/common/utils/msabaoth.c
@@ -681,39 +681,6 @@ msab_getMyStatus(sabdb** ret)
 
 #define MAINTENANCEFILE ".maintenance"
 
-#ifndef WIN32
-/* returns pid of the process holding the gdk lock, or 0 if that is not 
possible.
- * 'not possible' could be for a variety of reasons.
- */
-static pid_t
-MT_get_locking_pid(const char *filename)
-{
-#if !defined(HAVE_FCNTL) || !defined(HAVE_F_GETLK)
-   (void)filename;
-   return 0;
-#else
-   int fd;
-   struct flock fl = {
-   .l_type = F_WRLCK,
-   .l_whence = SEEK_SET,
-   .l_start = 4,
-   .l_len = 1,
-   };
-   pid_t pid = 0;
-
-   fd = open(filename, O_RDONLY | O_CLOEXEC, 0);
-   if (fd < 0)
-   return 0;
-
-   if (fcntl(fd, F_GETLK, &fl) == 0)
-   pid = fl.l_pid;
-
-   close(fd);
-   return pid;
-#endif
-}
-#endif
-
 static sabdb *
 msab_getSingleStatus(const char *pathbuf, const char *dbname, sabdb *next)
 {
@@ -732,11 +699,9 @@ msab_getSingleStatus(const char *pathbuf
return next;
 
sdb = malloc(sizeof(sabdb));
-   *sdb = (sabdb) { 0 };
-   sdb->uplog = NULL;
-   sdb->uri = NULL;
-   sdb->secret = NULL;
-   sdb->next = next;
+   *sdb = (sabdb) {
+   .next = next,
+   };
 
/* store the database name */
snprintf(buf, sizeof(buf), "%s/%s", pathbuf, dbname);
@@ -788,8 +753,13 @@ msab_getSingleStatus(const char *pathbuf
sdb->state = SABdbInactive;
} else if (fd == -1) {
 #ifndef WIN32
-   /* file is locked, so mserver is running. can we find it? */
-   sdb->pid = MT_get_locking_pid(buf);
+   /* extract pro

MonetDB: default - Merged with Oct2020

2020-11-23 Thread Pedro Ferreira
Changeset: a13e520c099b for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=a13e520c099b
Modified Files:
sql/server/rel_select.c
sql/test/BugTracker-2020/Tests/All
Branch: default
Log Message:

Merged with Oct2020


diffs (258 lines):

diff --git a/monetdb5/optimizer/opt_pushselect.c 
b/monetdb5/optimizer/opt_pushselect.c
--- a/monetdb5/optimizer/opt_pushselect.c
+++ b/monetdb5/optimizer/opt_pushselect.c
@@ -22,6 +22,7 @@ PushArgument(MalBlkPtr mb, InstrPtr p, i
return p;
 }
 
+#if 0
 static InstrPtr
 PushNil(MalBlkPtr mb, InstrPtr p, int pos, int tpe)
 {
@@ -34,6 +35,7 @@ PushNil(MalBlkPtr mb, InstrPtr p, int po
getArg(p, pos) = arg;
return p;
 }
+#endif
 
 static InstrPtr
 ReplaceWithNil(MalBlkPtr mb, InstrPtr p, int pos, int tpe)
@@ -74,6 +76,7 @@ subselect_add( subselect_t *subselects, 
return i;
 }
 
+#if 0
 static int
 subselect_find_tids( subselect_t *subselects, int subselect)
 {
@@ -99,6 +102,7 @@ subselect_find_subselect( subselect_t *s
}
return -1;
 }
+#endif
 
 static int
 lastbat_arg(MalBlkPtr mb, InstrPtr p)
@@ -298,7 +302,7 @@ OPTpushselectImplementation(Client cntxt
}
}
 
-   if (/* DISABLES CODE */ (0) && subselects.nr) {
+   if (nr_likes || subselects.nr) {
if (newMalBlkStmt(mb, mb->ssize) <0 ) {
GDKfree(vars);
goto wrapup;
@@ -309,12 +313,16 @@ OPTpushselectImplementation(Client cntxt
for (i = 1; i < limit; i++) {
p = old[i];
 
-   /* rewrite batalgebra.like + select -> likeselect */
-   if (getModuleId(p) == algebraRef && p->retc == 1 && 
getFunctionId(p) == selectRef) {
+   /* rewrite batalgebra.like + [theta]select -> 
likeselect */
+   if (getModuleId(p) == algebraRef && p->retc == 1 &&
+   (getFunctionId(p) == selectRef || 
getFunctionId(p) == thetaselectRef)) {
int var = getArg(p, 1);
InstrPtr q = mb->stmt[vars[var]]; /* BEWARE: 
the optimizer may not add or remove statements ! */
 
-   if (isLikeOp(q)) { /* TODO check if getArg(p, 
3) value == TRUE */
+   if (isLikeOp(q) &&
+   !isaBatType(getArgType(mb, q, 
2)) && /* pattern is a value */
+   (q->argc != 4 || 
!isaBatType(getArgType(mb, q, 3))) /* escape is a value */
+   ) {
InstrPtr r = newInstruction(mb, 
algebraRef, likeselectRef);
int has_cand = (getArgType(mb, p, 2) == 
newBatType(TYPE_oid));
int a, anti = (getFunctionId(q)[0] == 
'n'), ignore_case = (getFunctionId(q)[anti?4:0] == 'i');
@@ -340,6 +348,7 @@ OPTpushselectImplementation(Client cntxt
/* inject table ids into subselect
 * s = subselect(c, C1..) => subselect(c, t, C1..)
 */
+#if 0
if (isSelect(p) && p->retc == 1) {
int tid = 0;
 
@@ -445,6 +454,7 @@ OPTpushselectImplementation(Client cntxt
}
}
}
+#endif
pushInstruction(mb,p);
}
for (; isa);
exp_kind ek = {type_value, card_value, TRUE};
-   unsigned int card = dlist_length(rowlist) == 1 ? CARD_ATOM : CARD_MULTI;
 
for (dnode *o = rowlist->h; o; o = o->next) {
dlist *values = o->data.lval;
@@ -803,7 +802,9 @@ rel_values(sql_query *query, symbol *tab
}
}
}
+
/* loop to check types and cardinality */
+   unsigned int card = exps->h && 
list_length(((sql_exp*)exps->h->data)->f) > 1 ? CARD_MULTI : CARD_ATOM;
for (m = exps->h; m; m = m->next) {
sql_exp *e = m->data;
 
diff --git 
a/sql/test/BugTracker-2012/Tests/rewrite_like_into_likesubselect.Bug-3179.stable.out
 
b/sql/test/BugTracker-2012/Tests/rewrite_like_into_likesubselect.Bug-3179.stable.out
--- 
a/sql/test/BugTracker-2012/Tests/rewrite_like_into_likesubselect.Bug-3179.stable.out
+++ 
b/sql/test/BugTracker-2012/Tests/rewrite_like_into_likesubselect.Bug-3179.stable.out
@@ -263,12 +263,13 @@ function user.main():void;
 X_44:bat[:int] := bat.pack(0:int, 0:int);
 X_4:int := sql.mvc();
 X_17:bat[:str] := sql.bind(X_4:int, "sys":str, "functions":str, 
"name":str, 0:int);
+C_5:bat[:oid] := sql.tid(X_4:int, "sys":str, "functions":str);
+C_131:bat[:oid] := algebra.likeselect(X_17:bat[:str], C_5:bat[:oid], 
"%optimizers%":str, "":str, false:bit, false:bit);
 (X_19

MonetDB: default - Merged with Oct2020. Don't forget to escape S...

2020-11-20 Thread Pedro Ferreira
Changeset: 666b3fcab133 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=666b3fcab133
Modified Files:
tools/monetdbe/monetdbe.c
Branch: default
Log Message:

Merged with Oct2020. Don't forget to escape SQL identifiers when building SQL 
queries!


diffs (155 lines):

diff --git a/common/utils/msabaoth.c b/common/utils/msabaoth.c
--- a/common/utils/msabaoth.c
+++ b/common/utils/msabaoth.c
@@ -611,6 +611,7 @@ msab_pickSecret(char **generated_secret)
if (generated_secret)
// do not return an error, just continue without a secret
*generated_secret = NULL;
+   free(secret);
return NULL;
 #endif
 #endif
@@ -629,6 +630,7 @@ msab_pickSecret(char **generated_secret)
char err[512];
snprintf(err, sizeof(err), "unable to open '%s': %s",
pathbuf, strerror(errno));
+   free(secret);
return strdup(err);
}
if ((f = fdopen(fd, "w")) == NULL) {
@@ -637,6 +639,7 @@ msab_pickSecret(char **generated_secret)
pathbuf, strerror(errno));
close(fd);
(void)remove(pathbuf);
+   free(secret);
return strdup(err);
}
if (fwrite(secret, 1, SECRET_LENGTH, f) < SECRET_LENGTH || fclose(f) < 
0) {
@@ -645,11 +648,14 @@ msab_pickSecret(char **generated_secret)
strerror(errno));
fclose(f);
(void)remove(pathbuf);
+   free(secret);
return strdup(err);
}
 
if (generated_secret)
*generated_secret = (char*)secret;
+   else
+   free(secret);
return NULL;
 #endif
 }
diff --git a/tools/monetdbe/monetdbe.c b/tools/monetdbe/monetdbe.c
--- a/tools/monetdbe/monetdbe.c
+++ b/tools/monetdbe/monetdbe.c
@@ -1443,12 +1443,53 @@ cleanup_get_columns_result(size_t column
column_types = NULL;
 }
 
+static char *
+escape_identifier(const char *s) /* Escapes a SQL identifier string, ie the " 
and \ characters */
+{
+   char *ret = NULL, *q;
+   const char *p = s;
+
+   /* At most we will need 2*strlen(s) + 1 characters */
+   if (!(ret = (char *)GDKmalloc(2*strlen(s) + 1)))
+   return NULL;
+
+   for (q = ret; *p; p++, q++) {
+   *q = *p;
+   if (*p == '"')
+   *(++q) = '"';
+   else if (*p == '\\')
+   *(++q) = '\\';
+   }
+
+   *q = '\0';
+   return ret;
+}
+
 static char*
 monetdbe_get_columns_remote(monetdbe_database_internal *mdbe, const char* 
schema_name, const char *table_name, size_t *column_count,
char ***column_names, int 
**column_types)
 {
-   char buf[140];
-   snprintf(buf, 140, "SELECT * FROM %s.%s WHERE FALSE;", schema_name, 
table_name);
+   char buf[1024], *escaped_schema_name = NULL, *escaped_table_name = NULL;
+
+   if (schema_name && !(escaped_schema_name = 
escape_identifier(schema_name))) {
+   mdbe->msg = createException(MAL, 
"monetdbe.monetdbe_get_columns", MAL_MALLOC_FAIL);
+   return mdbe->msg;
+   }
+   if (!(escaped_table_name = escape_identifier(table_name))) {
+   GDKfree(escaped_schema_name);
+   mdbe->msg = createException(MAL, 
"monetdbe.monetdbe_get_columns", MAL_MALLOC_FAIL);
+   return mdbe->msg;
+   }
+
+   int len = snprintf(buf, 1024, "SELECT * FROM %s%s%s\"%s\" WHERE FALSE;",
+  escaped_schema_name ? "\"" : "",  
escaped_schema_name ? escaped_schema_name : "", 
+  escaped_schema_name ? 
escaped_schema_name : "\".", escaped_table_name);
+   GDKfree(escaped_schema_name);
+   GDKfree(escaped_table_name);
+   if (len == -1 || len >= 1024) {
+   mdbe->msg = createException(MAL, 
"monetdbe.monetdbe_get_columns", "Schema and table path is too large");
+   return mdbe->msg;
+   }
 
monetdbe_result* result = NULL;
 
@@ -1538,14 +1579,14 @@ monetdbe_get_columns(monetdbe_database d
return mdbe->msg;
if (schema_name) {
if (!(s = mvc_bind_schema(m, schema_name))) {
-   mdbe->msg = createException(MAL, 
"monetdbe.monetdbe_get_columns", "Could not find schema %s", schema_name);
+   mdbe->msg = createException(SQL, 
"monetdbe.monetdbe_get_columns", "Could not find schema '%s'", schema_name);
goto cleanup;
}
} else {
s = cur_schema(m);
}
if (!(t = mvc_bind_table(m, s, table_name))) {
-   mdbe->msg = createException(MAL, 
"monetdbe.monetdbe_get_columns", "Could not find table %s", table_name);
+   mdbe->msg = createException(SQL, 
"monetdbe.mon

MonetDB: default - Merged with Oct2020

2020-11-20 Thread Pedro Ferreira
Changeset: 493db7435a9a for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=493db7435a9a
Modified Files:
MonetDB.spec
sql/backends/monet5/sql_cat.c
sql/backends/monet5/sql_scenario.c
sql/include/sql_catalog.h
sql/server/rel_optimizer.c
sql/server/rel_schema.c
sql/storage/store.c
sql/test/BugTracker-2020/Tests/All
sql/test/miscellaneous/Tests/simple_selects.sql
sql/test/miscellaneous/Tests/simple_selects.stable.out
Branch: default
Log Message:

Merged with Oct2020


diffs (truncated from 860 to 300 lines):

diff --git a/MonetDB.spec b/MonetDB.spec
--- a/MonetDB.spec
+++ b/MonetDB.spec
@@ -868,6 +868,15 @@ else
 fi
 %endif
 
+%if %{?rhel:0}%{!?rhel:1} || 0%{?rhel} >= 7
+# fix up some paths (/var/run -> /run)
+# needed because CMAKE_INSTALL_RUNSTATEDIR refers to /var/run
+sed -i 's|/var/run|/run|' \
+%{buildroot}%{_tmpfilesdir}/monetdbd.conf \
+%{buildroot}%{_localstatedir}/monetdb5/dbfarm/.merovingian_properties \
+%{buildroot}%{_unitdir}/monetdbd.service
+%endif
+
 %post -p /sbin/ldconfig
 
 %postun -p /sbin/ldconfig
diff --git a/clients/mapiclient/mclient.c b/clients/mapiclient/mclient.c
--- a/clients/mapiclient/mclient.c
+++ b/clients/mapiclient/mclient.c
@@ -3678,8 +3678,9 @@ main(int argc, char **argv)
s = open_rastream(arg);
}
if (s == NULL) {
-   fprintf(stderr, "%s: cannot open: %s", arg, 
mnstr_peek_error(NULL));
+   fprintf(stderr, "%s: cannot open: %s\n", arg, 
mnstr_peek_error(NULL));
c |= 1;
+   optind++;
continue;
}
// doFile closes 's'.
diff --git a/monetdb5/mal/mal_builder.c b/monetdb5/mal/mal_builder.c
--- a/monetdb5/mal/mal_builder.c
+++ b/monetdb5/mal/mal_builder.c
@@ -26,7 +26,8 @@ newAssignment(MalBlkPtr mb)
InstrPtr q = newInstruction(mb,NULL,NULL);
int k;
 
-   assert(q);
+   if (q == NULL)
+   return NULL;
k = newTmpVariable(mb,TYPE_any);
if (k < 0) {
// construct an exception message to be passed to upper layers 
using ->errors
@@ -46,7 +47,8 @@ newStmt(MalBlkPtr mb, const char *module
str mName = putName(module), nName = putName(name);
 
q = newInstruction(mb, mName, nName);
-   assert(q);
+   if (q == NULL)
+   return NULL;
setDestVar(q, newTmpVariable(mb, TYPE_any));
if (getDestVar(q) < 0 ){
str msg = createException(MAL, "newStmt", "Can not allocate 
variable");
@@ -64,7 +66,8 @@ newStmtArgs(MalBlkPtr mb, const char *mo
str mName = putName(module), nName = putName(name);
 
q = newInstructionArgs(mb, mName, nName, args);
-   assert(q);
+   if (q == NULL)
+   return NULL;
 
setDestVar(q, newTmpVariable(mb, TYPE_any));
if (getDestVar(q) < 0 || mb->errors != MAL_SUCCEED) {
@@ -82,7 +85,8 @@ newReturnStmt(MalBlkPtr mb)
InstrPtr q = newInstruction(mb, NULL, NULL);
int k;
 
-   assert(q);
+   if (q == NULL)
+   return NULL;
k = newTmpVariable(mb,TYPE_any);
if (k < 0 ){
str msg = createException(MAL, "newReturnStmt", "Can not 
allocate return variable");
@@ -115,7 +119,8 @@ newComment(MalBlkPtr mb, const char *val
ValRecord cst;
int k;
 
-   assert(q);
+   if (q == NULL)
+   return NULL;
q->token = REMsymbol;
q->barrier = 0;
cst.vtype= TYPE_str;
@@ -143,7 +148,8 @@ newCatchStmt(MalBlkPtr mb, str nme)
int i= findVariable(mb,nme);
int k;
 
-   assert(q);
+   if (q == NULL)
+   return NULL;
q->barrier = CATCHsymbol;
if ( i< 0) {
k = newVariable(mb, nme, strlen(nme),TYPE_str);
@@ -166,7 +172,8 @@ newRaiseStmt(MalBlkPtr mb, str nme)
int i= findVariable(mb,nme);
int k;
 
-   assert(q);
+   if (q == NULL)
+   return NULL;
q->barrier = RAISEsymbol;
if ( i< 0) {
k = newVariable(mb, nme, strlen(nme),TYPE_str);
@@ -188,7 +195,8 @@ newExitStmt(MalBlkPtr mb, str nme)
int i= findVariable(mb,nme);
int k;
 
-   assert(q);
+   if (q == NULL)
+   return NULL;
q->barrier = EXITsymbol;
if ( i< 0) {
k= newVariable(mb, nme,strlen(nme),TYPE_str);
@@ -208,7 +216,8 @@ pushEndInstruction(MalBlkPtr mb)
 {
 InstrPtr q = newInstruction(mb,NULL, NULL);
 
-   assert(q);
+   if (q == NULL)
+   return NULL;
 q->token = ENDsymbol;
 q->barrier = 0;
 q->argc = 0;
@@ -273,7 +282,8 @@ pushBte(MalBlkPtr mb, InstrPtr q, bte va
int _t;
ValRecord cst;
 
-   assert(q);
+   

MonetDB: default - Merged with Oct2020

2020-11-18 Thread Pedro Ferreira
Changeset: 0430cf8508fa for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=0430cf8508fa
Modified Files:
clients/Tests/MAL-signatures.stable.out
clients/Tests/MAL-signatures.stable.out.int128
monetdb5/modules/kernel/mmath.c
sql/backends/monet5/rel_bin.c
Branch: default
Log Message:

Merged with Oct2020


diffs (217 lines):

diff --git a/clients/Tests/MAL-signatures.stable.out 
b/clients/Tests/MAL-signatures.stable.out
--- a/clients/Tests/MAL-signatures.stable.out
+++ b/clients/Tests/MAL-signatures.stable.out
@@ -6064,6 +6064,8 @@ stdout of test 'MAL-signatures` in direc
 [ "batmmath",  "radians",  "pattern batmmath.radians(X_1:bat[:dbl], 
X_2:bat[:oid]):bat[:dbl] ","CMDscience_bat_radians;",  ""  ]
 [ "batmmath",  "radians",  "pattern 
batmmath.radians(X_1:bat[:flt]):bat[:flt] ",   "CMDscience_bat_radians;",  
""  ]
 [ "batmmath",  "radians",  "pattern batmmath.radians(X_1:bat[:flt], 
X_2:bat[:oid]):bat[:flt] ","CMDscience_bat_radians;",  ""  ]
+[ "batmmath",  "rand", "unsafe pattern batmmath.rand(X_1:bat[:int]):bat[:int] 
",   "CMDscience_bat_randintarg;",   ""  ]
+[ "batmmath",  "rand", "unsafe pattern batmmath.rand(X_1:bat[:int], 
X_2:bat[:oid]):bat[:int] ","CMDscience_bat_randintarg;",   ""  ]
 [ "batmmath",  "sin",  "pattern batmmath.sin(X_1:bat[:dbl]):bat[:dbl] ",   
"CMDscience_bat_sin;",  ""  ]
 [ "batmmath",  "sin",  "pattern batmmath.sin(X_1:bat[:dbl], 
X_2:bat[:oid]):bat[:dbl] ","CMDscience_bat_sin;",  ""  ]
 [ "batmmath",  "sin",  "pattern batmmath.sin(X_1:bat[:flt]):bat[:flt] ",   
"CMDscience_bat_sin;",  ""  ]
diff --git a/clients/Tests/MAL-signatures.stable.out.int128 
b/clients/Tests/MAL-signatures.stable.out.int128
--- a/clients/Tests/MAL-signatures.stable.out.int128
+++ b/clients/Tests/MAL-signatures.stable.out.int128
@@ -8594,6 +8594,8 @@ stdout of test 'MAL-signatures` in direc
 [ "batmmath",  "radians",  "pattern batmmath.radians(X_1:bat[:dbl], 
X_2:bat[:oid]):bat[:dbl] ","CMDscience_bat_radians;",  ""  ]
 [ "batmmath",  "radians",  "pattern 
batmmath.radians(X_1:bat[:flt]):bat[:flt] ",   "CMDscience_bat_radians;",  
""  ]
 [ "batmmath",  "radians",  "pattern batmmath.radians(X_1:bat[:flt], 
X_2:bat[:oid]):bat[:flt] ","CMDscience_bat_radians;",  ""  ]
+[ "batmmath",  "rand", "unsafe pattern batmmath.rand(X_1:bat[:int]):bat[:int] 
",   "CMDscience_bat_randintarg;",   ""  ]
+[ "batmmath",  "rand", "unsafe pattern batmmath.rand(X_1:bat[:int], 
X_2:bat[:oid]):bat[:int] ","CMDscience_bat_randintarg;",   ""  ]
 [ "batmmath",  "sin",  "pattern batmmath.sin(X_1:bat[:dbl]):bat[:dbl] ",   
"CMDscience_bat_sin;",  ""  ]
 [ "batmmath",  "sin",  "pattern batmmath.sin(X_1:bat[:dbl], 
X_2:bat[:oid]):bat[:dbl] ","CMDscience_bat_sin;",  ""  ]
 [ "batmmath",  "sin",  "pattern batmmath.sin(X_1:bat[:flt]):bat[:flt] ",   
"CMDscience_bat_sin;",  ""  ]
diff --git a/monetdb5/modules/kernel/batmmath.c 
b/monetdb5/modules/kernel/batmmath.c
--- a/monetdb5/modules/kernel/batmmath.c
+++ b/monetdb5/modules/kernel/batmmath.c
@@ -7,11 +7,10 @@
  */
 
 #include "monetdb_config.h"
-#include "gdk.h"
 #include 
+#include "mmath_private.h"
 #include "mal_exception.h"
 #include "mal_interpreter.h"
-#include "mmath_private.h"
 
 static str
 CMDscienceUNARY(MalStkPtr stk, InstrPtr pci,
@@ -414,6 +413,62 @@ degreesf(float x)
return (float) (x * (180.0 / M_PI));
 }
 
+static str
+CMDscience_bat_randintarg(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr 
pci)
+{
+   BAT *bn = NULL, *b = NULL, *bs = NULL;
+   BUN q = 0;
+   int *restrict vals;
+   str msg = MAL_SUCCEED;
+   struct canditer ci = {0};
+   bat *res = getArgReference_bat(stk, pci, 0), *bid = 
getArgReference_bat(stk, pci, 1),
+   *sid = pci->argc == 3 ? getArgReference_bat(stk, pci, 2) : NULL;
+
+   (void) cntxt;
+   (void) mb;
+   if (!(b = BATdescriptor(*bid))) {
+   msg = createException(MAL, "batmmath.rand", SQLSTATE(HY005) 
RUNTIME_OBJECT_MISSING);
+   goto bailout;
+   }
+   if (sid && !is_bat_nil(*sid) && !(bs = BATdescriptor(*sid))) {
+   msg = createException(MAL, "batmmath.rand", SQLSTATE(HY005) 
RUNTIME_OBJECT_MISSING);
+   goto bailout;
+   }
+   q = canditer_init(&ci, b, bs);
+   if (!(bn = COLnew(ci.hseq, TYPE_int, q, TRANSIENT))) {
+   msg = createException(MAL, "batmmath.rand", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
+   goto bailout;
+   }
+
+   vals = Tloc(bn, 0);
+#ifdef STATIC_CODE_ANALYSIS
+   for (BUN i = 0; i < q; i++)
+   vals[i] = 0;
+#else
+   MT_lock_set(&mmath_rse_lock);
+   for (BUN i = 0; i < q; i++)
+   vals[i] = (int) (next(mmath_rse) >> 33);
+   MT_lock_unset(&mmath_rse_lock);
+#endif
+
+bailout:
+   if (b)

MonetDB: default - Merged with Oct2020

2020-11-17 Thread Pedro Ferreira
Changeset: f50201252dba for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=f50201252dba
Modified Files:
clients/Tests/MAL-signatures.stable.out
clients/Tests/MAL-signatures.stable.out.int128
monetdb5/modules/atoms/uuid.c
sql/backends/monet5/sql_upgrades.c
sql/test/sys-schema/Tests/systemfunctions.stable.out
sql/test/sys-schema/Tests/systemfunctions.stable.out.int128
Branch: default
Log Message:

Merged with Oct2020


diffs (232 lines):

diff --git a/clients/Tests/MAL-signatures.stable.out 
b/clients/Tests/MAL-signatures.stable.out
--- a/clients/Tests/MAL-signatures.stable.out
+++ b/clients/Tests/MAL-signatures.stable.out
@@ -6639,6 +6639,7 @@ stdout of test 'MAL-signatures` in direc
 [ "batudf","fuse", "command batudf.fuse(X_1:bat[:sht], 
X_2:bat[:sht]):bat[:int] ", "UDFBATfuse;",  ""  ]
 [ "batudf","reverse",  "command 
batudf.reverse(X_1:bat[:str]):bat[:str] ", "UDFBATreverse;",   ""  ]
 [ "batuuid",   "isaUUID",  "command 
batuuid.isaUUID(X_1:bat[:str]):bat[:bit] ","UUIDisaUUID_bulk;",""  ]
+[ "batuuid",   "new",  "unsafe command batuuid.new(X_1:bat[:int]):bat[:uuid] 
","UUIDgenerateUuidInt_bulk;",""  ]
 [ "batxml","attribute","command batxml.attribute(X_1:str, 
X_2:bat[:str]):bat[:xml] ",  "BATXMLattribute;", ""  ]
 [ "batxml","comment",  "command 
batxml.comment(X_1:bat[:str]):bat[:xml] ", "BATXMLcomment;",   ""  ]
 [ "batxml","concat",   "command batxml.concat(X_1:bat[:xml], 
X_2:bat[:xml]):bat[:xml] ",   "BATXMLconcat;",""  ]
diff --git a/clients/Tests/MAL-signatures.stable.out.int128 
b/clients/Tests/MAL-signatures.stable.out.int128
--- a/clients/Tests/MAL-signatures.stable.out.int128
+++ b/clients/Tests/MAL-signatures.stable.out.int128
@@ -9199,6 +9199,7 @@ stdout of test 'MAL-signatures` in direc
 [ "batudf","fuse", "command batudf.fuse(X_1:bat[:sht], 
X_2:bat[:sht]):bat[:int] ", "UDFBATfuse;",  ""  ]
 [ "batudf","reverse",  "command 
batudf.reverse(X_1:bat[:str]):bat[:str] ", "UDFBATreverse;",   ""  ]
 [ "batuuid",   "isaUUID",  "command 
batuuid.isaUUID(X_1:bat[:str]):bat[:bit] ","UUIDisaUUID_bulk;",""  ]
+[ "batuuid",   "new",  "unsafe command batuuid.new(X_1:bat[:int]):bat[:uuid] 
","UUIDgenerateUuidInt_bulk;",""  ]
 [ "batxml","attribute","command batxml.attribute(X_1:str, 
X_2:bat[:str]):bat[:xml] ",  "BATXMLattribute;", ""  ]
 [ "batxml","comment",  "command 
batxml.comment(X_1:bat[:str]):bat[:xml] ", "BATXMLcomment;",   ""  ]
 [ "batxml","concat",   "command batxml.concat(X_1:bat[:xml], 
X_2:bat[:xml]):bat[:xml] ",   "BATXMLconcat;",""  ]
diff --git a/clients/mapiclient/ReadlineTools.c 
b/clients/mapiclient/ReadlineTools.c
--- a/clients/mapiclient/ReadlineTools.c
+++ b/clients/mapiclient/ReadlineTools.c
@@ -312,7 +312,7 @@ invoke_editor(int cnt, int key) {
char editor_command[BUFFER_SIZE];
char *read_buff = NULL;
char *editor = NULL;
-   FILE *fp;
+   FILE *fp = NULL;
size_t content_len;
size_t read_bytes, idx;
 #ifdef WIN32
diff --git a/monetdb5/modules/atoms/uuid.c b/monetdb5/modules/atoms/uuid.c
--- a/monetdb5/modules/atoms/uuid.c
+++ b/monetdb5/modules/atoms/uuid.c
@@ -189,22 +189,9 @@ UUIDcompare(const void *L, const void *R
 #endif
 }
 
-static str
-#ifdef HAVE_HGE
-UUIDgenerateUuid(uuid *retval)
-#else
-UUIDgenerateUuid(uuid **retval)
-#endif
+static inline void
+UUIDgenerateUuid_internal(uuid *u)
 {
-   uuid *u;
-
-#ifdef HAVE_HGE
-   u = retval;
-#else
-   if (*retval == NULL && (*retval = GDKmalloc(UUID_SIZE)) == NULL)
-   throw(MAL, "uuid.new", SQLSTATE(HY013) MAL_MALLOC_FAIL);
-   u = *retval;
-#endif
 #ifdef HAVE_UUID
uuid_generate(u->u);
 #else
@@ -226,6 +213,25 @@ UUIDgenerateUuid(uuid **retval)
/* make sure this is version 4 (random UUID) */
u->u[6] = (u->u[6] & 0x0F) | 0x40;
 #endif
+}
+
+static str
+#ifdef HAVE_HGE
+UUIDgenerateUuid(uuid *retval)
+#else
+UUIDgenerateUuid(uuid **retval)
+#endif
+{
+   uuid *u;
+
+#ifdef HAVE_HGE
+   u = retval;
+#else
+   if (*retval == NULL && (*retval = GDKmalloc(UUID_SIZE)) == NULL)
+   throw(MAL, "uuid.new", SQLSTATE(HY013) MAL_MALLOC_FAIL);
+   u = *retval;
+#endif
+   UUIDgenerateUuid_internal(u);
return MAL_SUCCEED;
 }
 
@@ -256,6 +262,42 @@ isaUUID(str s)
 }
 
 static str
+UUIDgenerateUuidInt_bulk(bat *ret, const bat *bid)
+{
+   BAT *b = NULL, *bn = NULL;
+   BUN n = 0;
+   str msg = MAL_SUCCEED;
+   uuid *restrict bnt = NULL;
+
+   if ((b = BATdescriptor(*bid)) == NULL)  {
+   msg = createException(MAL, "uuid.generateuuidint_bulk", 
SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);
+   goto bailout;
+   }
+   n = BATcount(b);
+   if ((bn = COL

MonetDB: default - Merged with Oct2020

2020-11-16 Thread Pedro Ferreira
Changeset: 8e77a42eae7d for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=8e77a42eae7d
Modified Files:
sql/server/rel_optimizer.c
sql/server/rel_rel.h
sql/server/rel_select.c
sql/server/rel_unnest.c
Branch: default
Log Message:

Merged with Oct2020


diffs (truncated from 1260 to 300 lines):

diff --git a/clients/mapiclient/ReadlineTools.c 
b/clients/mapiclient/ReadlineTools.c
--- a/clients/mapiclient/ReadlineTools.c
+++ b/clients/mapiclient/ReadlineTools.c
@@ -88,7 +88,7 @@ sql_tablename_generator(const char *text
 static char *
 sql_command_generator(const char *text, int state)
 {
-   static int idx, len;
+   static size_t idx, len;
const char *name;
 
if (!state) {
@@ -303,20 +303,43 @@ readline_show_error(const char *msg) {
 #define BUFFER_SIZE 1024
 #endif
 
+#ifdef WIN32
+#define unlink _unlink
+#endif
+
 static int
 invoke_editor(int cnt, int key) {
-   char template[] = "/tmp/mclient_temp_XX";
char editor_command[BUFFER_SIZE];
char *read_buff = NULL;
char *editor = NULL;
FILE *fp;
size_t content_len;
size_t read_bytes, idx;
+#ifdef WIN32
+   char *mytemp;
+   char template[] = "mclient_temp_XX";
+#else
+   int mytemp;
+   char template[] = "/tmp/mclient_temp_XX";
+#endif
 
(void) cnt;
(void) key;
 
-   if ((fp = fdopen(mkstemp(template), "r+")) == NULL) {
+#ifdef WIN32
+   if ((mytemp = _mktemp(template)) == NULL) {
+#else
+   if ((mytemp = mkstemp(template)) == 0) {
+#endif
+   readline_show_error("invoke_editor: Cannot create temp file\n");
+   goto bailout;
+   }
+
+#ifdef WIN32
+   if ((fp = fopen(mytemp, "r+")) == NULL) {
+#else
+   if ((fp = fdopen(mytemp, "r+")) == NULL) {
+#endif
// Notify the user that we cannot create temp file
readline_show_error("invoke_editor: Cannot create temp file\n");
goto bailout;
@@ -367,7 +390,7 @@ invoke_editor(int cnt, int key) {
}
 
rl_replace_line(read_buff, 0);
-   rl_point = idx + 1;  // place the point one character after the 
end of the string
+   rl_point = (int)(idx + 1);  // place the point one character 
after the end of the string
 
free(read_buff);
} else {
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
@@ -8931,8 +8931,13 @@ rel_merge_table_rewrite(visitor *v, sql_

if (!next->semantics && ((lval && lval->isnull) 
|| (hval && hval->isnull))) {

skip = 1; /* NULL values don't match, 
skip them */

} else if (!next->semantics) {
-   
if (next->flag == cmp_equal || hval != 
lval) {
-   
skip |= next->anti ? 
exp_range_overlap(cmin, cmax, lval, hval, false, false) != 0 : 
exp_range_overlap(cmin, cmax, lval, hval, false, false) == 0;
+   
if (next->flag == cmp_equal) {
+   
skip |= next->anti ? 
exp_range_overlap(cmin, cmax, lval, hval, false, false) != 0 :
+   

 exp_range_overlap(cmin, cmax, lval, hval, false, false) == 0;
+   
} else if (hval != lval) { /* range 
case */
+   
comp_type lower = 
range2lcompare(next->flag), higher = range2rcompare(next->flag);
+   
skip |= next->anti ? 
exp_range_overlap(cmin, cmax, lval, hval, higher == cmp_lt, lower == cmp_gt) != 
0 :
+   

 exp_range_overlap(cmin, cmax, lval, hval, higher == cmp_lt,

MonetDB: default - Merged with Oct2020

2020-11-06 Thread Pedro Ferreira
Changeset: 06be397123ee for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=06be397123ee
Modified Files:
sql/server/rel_schema.c
sql/server/rel_updates.c
Branch: default
Log Message:

Merged with Oct2020


diffs (truncated from 658 to 300 lines):

diff --git a/sql/server/rel_schema.c b/sql/server/rel_schema.c
--- a/sql/server/rel_schema.c
+++ b/sql/server/rel_schema.c
@@ -2489,26 +2489,26 @@ rel_rename_schema(mvc *sql, char *old_na
 }
 
 static sql_rel *
-rel_rename_table(mvc *sql, char* schema_name, char *old_name, char *new_name, 
int if_exists)
+rel_rename_table(mvc *sql, char *schema_name, char *old_name, char *new_name, 
int if_exists)
 {
-   sql_schema *s;
+   sql_schema *s = cur_schema(sql);
sql_table *t;
sql_rel *rel;
list *exps;
 
-   assert(schema_name && old_name && new_name);
+   assert(old_name && new_name);
 
-   if (!(s = mvc_bind_schema(sql, schema_name))) {
+   if (schema_name && !(s = mvc_bind_schema(sql, schema_name))) {
if (if_exists)
return rel_psm_block(sql->sa, new_exp_list(sql->sa));
return sql_error(sql, 02, SQLSTATE(42S02) "ALTER TABLE: no such 
schema '%s'", schema_name);
}
if (!mvc_schema_privs(sql, s))
-   return sql_error(sql, 02, SQLSTATE(42000) "ALTER TABLE: access 
denied for %s to schema '%s'", get_string_global_var(sql, "current_user"), 
schema_name);
+   return sql_error(sql, 02, SQLSTATE(42000) "ALTER TABLE: access 
denied for %s to schema '%s'", get_string_global_var(sql, "current_user"), 
s->base.name);
if (!(t = find_table_on_scope(sql, &s, schema_name, old_name))) {
if (if_exists)
return rel_psm_block(sql->sa, new_exp_list(sql->sa));
-   return sql_error(sql, 02, SQLSTATE(42S02) "ALTER TABLE: no such 
table '%s' in schema '%s'", old_name, schema_name);
+   return sql_error(sql, 02, SQLSTATE(42S02) "ALTER TABLE: no such 
table '%s' in schema '%s'", old_name, s->base.name);
}
if (t->system)
return sql_error(sql, 02, SQLSTATE(42000) "ALTER TABLE: cannot 
rename a system table");
@@ -2520,13 +2520,13 @@ rel_rename_table(mvc *sql, char* schema_
return sql_error(sql, 02, SQLSTATE(2BM37) "ALTER TABLE: unable 
to rename table '%s' (there are database objects which depend on it)", 
old_name);
if (strNil(new_name) || *new_name == '\0')
return sql_error(sql, 02, SQLSTATE(3F000) "ALTER TABLE: invalid 
new table name");
-   if (find_table_on_scope(sql, &s, schema_name, new_name))
-   return sql_error(sql, 02, SQLSTATE(3F000) "ALTER TABLE: there 
is a table named '%s' in schema '%s'", new_name, schema_name);
+   if (find_table_on_scope(sql, &s, s->base.name, new_name))
+   return sql_error(sql, 02, SQLSTATE(3F000) "ALTER TABLE: there 
is a table named '%s' in schema '%s'", new_name, s->base.name);
 
rel = rel_create(sql->sa);
exps = new_exp_list(sql->sa);
-   append(exps, exp_atom_clob(sql->sa, schema_name));
-   append(exps, exp_atom_clob(sql->sa, schema_name));
+   append(exps, exp_atom_clob(sql->sa, s->base.name));
+   append(exps, exp_atom_clob(sql->sa, s->base.name));
append(exps, exp_atom_clob(sql->sa, old_name));
append(exps, exp_atom_clob(sql->sa, new_name));
rel->op = op_ddl;
@@ -2536,27 +2536,27 @@ rel_rename_table(mvc *sql, char* schema_
 }
 
 static sql_rel *
-rel_rename_column(mvc *sql, char* schema_name, char *table_name, char 
*old_name, char *new_name, int if_exists)
+rel_rename_column(mvc *sql, char *schema_name, char *table_name, char 
*old_name, char *new_name, int if_exists)
 {
-   sql_schema *s;
+   sql_schema *s = cur_schema(sql);
sql_table *t;
sql_column *col;
sql_rel *rel;
list *exps;
 
-   assert(schema_name && table_name && old_name && new_name);
+   assert(table_name && old_name && new_name);
 
-   if (!(s = mvc_bind_schema(sql, schema_name))) {
+   if (schema_name && !(s = mvc_bind_schema(sql, schema_name))) {
if (if_exists)
return rel_psm_block(sql->sa, new_exp_list(sql->sa));
return sql_error(sql, 02, SQLSTATE(42S02) "ALTER TABLE: no such 
schema '%s'", schema_name);
}
if (!mvc_schema_privs(sql, s))
-   return sql_error(sql, 02, SQLSTATE(42000) "ALTER TABLE: access 
denied for %s to schema '%s'", get_string_global_var(sql, "current_user"), 
schema_name);
+   return sql_error(sql, 02, SQLSTATE(42000) "ALTER TABLE: access 
denied for %s to schema '%s'", get_string_global_var(sql, "current_user"), 
s->base.name);
if (!(t = find_table_on_scope(sql, &s, schema_name, table_name))) {
if (if_exists)
return rel_psm_block(sql->sa, new_exp_list(sql->sa));
- 

MonetDB: default - Merged with Oct2020

2020-11-04 Thread Pedro Ferreira
Changeset: 44ba56fc4197 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=44ba56fc4197
Branch: default
Log Message:

Merged with Oct2020


diffs (125 lines):

diff --git a/monetdb5/mal/mal_runtime.c b/monetdb5/mal/mal_runtime.c
--- a/monetdb5/mal/mal_runtime.c
+++ b/monetdb5/mal/mal_runtime.c
@@ -262,7 +262,7 @@ runtimeProfileInit(Client cntxt, MalBlkP
QRYqueue[qhead].mb = mb;
QRYqueue[qhead].tag = qtag++;
QRYqueue[qhead].stk = stk;  // for status 
pause 'p'/running '0'/ quiting 'q'
-   QRYqueue[qhead].finished =
+   QRYqueue[qhead].finished = 0;
QRYqueue[qhead].start = time(0);
q = isaSQLquery(mb);
QRYqueue[qhead].query = q? GDKstrdup(q):0;
diff --git a/monetdb5/modules/mal/sysmon.c b/monetdb5/modules/mal/sysmon.c
--- a/monetdb5/modules/mal/sysmon.c
+++ b/monetdb5/modules/mal/sysmon.c
@@ -82,10 +82,14 @@ SYSMONstatistics(Client cntxt, MalBlkPtr
goto bailout;
}
 
-   tsn = timestamp_fromtime(USRstats[i].finished);
-   if (is_timestamp_nil(tsn)) {
-   msg = createException(MAL, "SYSMONstatistics", 
SQLSTATE(22003) "failed to convert finish time");
-   goto bailout;
+   if (USRstats[i].finished == 0) {
+   tsn = timestamp_nil;
+   } else {
+   tsn = timestamp_fromtime(USRstats[i].finished);
+   if (is_timestamp_nil(tsn)) {
+   msg = createException(MAL, 
"SYSMONstatistics", SQLSTATE(22003) "failed to convert finish time");
+   goto bailout;
+   }
}
if (BUNappend(finished, &tsn, false) != GDK_SUCCEED){
msg = createException(MAL, "SYSMONstatistics", 
"Failed to append 'finished'");
@@ -218,10 +222,14 @@ SYSMONqueue(Client cntxt, MalBlkPtr mb, 
if (BUNappend(started, &tsn, false) != GDK_SUCCEED)
goto bailout;
 
-   tsn = timestamp_fromtime(QRYqueue[i].finished);
-   if (is_timestamp_nil(tsn)) {
-   msg = createException(MAL, "SYSMONqueue", 
SQLSTATE(22003) "cannot convert time");
-   goto bailout;
+   if (QRYqueue[i].finished == 0) {
+   tsn = timestamp_nil;
+   } else {
+   tsn = timestamp_fromtime(QRYqueue[i].finished);
+   if (is_timestamp_nil(tsn)) {
+   msg = createException(MAL, 
"SYSMONqueue", SQLSTATE(22003) "cannot convert time");
+   goto bailout;
+   }
}
if (BUNappend(finished, &tsn, false) != GDK_SUCCEED)
goto bailout;
diff --git a/sql/jdbc/tests/Tests/ValidateSystemCatalogTables.stable.out 
b/sql/jdbc/tests/Tests/ValidateSystemCatalogTables.stable.out
--- a/sql/jdbc/tests/Tests/ValidateSystemCatalogTables.stable.out
+++ b/sql/jdbc/tests/Tests/ValidateSystemCatalogTables.stable.out
@@ -14,7 +14,7 @@ stdout of test 'ValidateSystemCatalogTab
 Checking 45 tables/keys  in schema sys for Primary Key uniqueness 
violations.
 Checking 45 columns  in schema sys for Primary Key Not Null violations.
 Checking 30 tables/keys  in schema sys for Unique Constraint violations.
-Checking 96 foreign keys in schema sys for Foreign Key referential 
integrity violations.
+Checking 95 foreign keys in schema sys for Foreign Key referential 
integrity violations.
 Checking169 columns  in schema sys for Not Null violations.
 Checking153 columns  in schema sys for Max Character Length violations.
 Checking  6 tables/keys  in schema tmp for Primary Key uniqueness 
violations.
diff --git 
a/sql/jdbc/tests/Tests/ValidateSystemCatalogTables.stable.out.Windows 
b/sql/jdbc/tests/Tests/ValidateSystemCatalogTables.stable.out.Windows
--- a/sql/jdbc/tests/Tests/ValidateSystemCatalogTables.stable.out.Windows
+++ b/sql/jdbc/tests/Tests/ValidateSystemCatalogTables.stable.out.Windows
@@ -14,7 +14,7 @@ stdout of test 'ValidateSystemCatalogTab
 Checking 45 tables/keys  in schema sys for Primary Key uniqueness 
violations.
 Checking 45 columns  in schema sys for Primary Key Not Null violations.
 Checking 30 tables/keys  in schema sys for Unique Constraint violations.
-Checking 96 foreign keys in schema sys for Foreign Key referential 
integrity violations.
+Checking 95 foreign keys in schema sys for Foreign Key referential 
integrity violations.
 Checking169 columns  i

MonetDB: default - Merged with Oct2020

2020-10-30 Thread Pedro Ferreira
Changeset: a534d20b6c00 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=a534d20b6c00
Modified Files:
sql/backends/monet5/rel_bin.c
sql/backends/monet5/sql_scenario.c
sql/server/rel_dump.c
Branch: default
Log Message:

Merged with Oct2020


diffs (truncated from 763 to 300 lines):

diff --git a/sql/backends/monet5/rel_bin.c b/sql/backends/monet5/rel_bin.c
--- a/sql/backends/monet5/rel_bin.c
+++ b/sql/backends/monet5/rel_bin.c
@@ -2178,11 +2178,11 @@ split_join_exps(sql_rel *rel, list *join
left_reference = 
right_reference = 1;
}
} else {
-   if (l->card != CARD_ATOM) {
+   if (l->card != CARD_ATOM || 
!exp_is_atom(l)) {
left_reference += 
rel_find_exp(rel->l, l) != NULL;
right_reference += 
rel_find_exp(rel->r, l) != NULL;
}
-   if (r->card != CARD_ATOM) {
+   if (r->card != CARD_ATOM || 
!exp_is_atom(r)) {
left_reference += 
rel_find_exp(rel->l, r) != NULL;
right_reference += 
rel_find_exp(rel->r, r) != NULL;
}
@@ -2193,7 +2193,7 @@ split_join_exps(sql_rel *rel, list *join
for (node *n = l->h ; n ; n = n->next) {
sql_exp *ee = n->data;
 
-   if (ee->card != CARD_ATOM) {
+   if (ee->card != CARD_ATOM || 
!exp_is_atom(ee)) {
left_reference += 
rel_find_exp(rel->l, ee) != NULL;
right_reference += 
rel_find_exp(rel->r, ee) != NULL;
}
@@ -2201,7 +2201,7 @@ split_join_exps(sql_rel *rel, list *join
for (node *n = r->h ; n ; n = n->next) {
sql_exp *ee = n->data;
 
-   if (ee->card != CARD_ATOM) {
+   if (ee->card != CARD_ATOM || 
!exp_is_atom(ee)) {
left_reference += 
rel_find_exp(rel->l, ee) != NULL;
right_reference += 
rel_find_exp(rel->r, ee) != NULL;
}
diff --git a/sql/backends/monet5/sql_scenario.c 
b/sql/backends/monet5/sql_scenario.c
--- a/sql/backends/monet5/sql_scenario.c
+++ b/sql/backends/monet5/sql_scenario.c
@@ -337,6 +337,10 @@ SQLinit(Client c)
backend *be = NULL;
mvc *m = NULL;
sql_allocator *sa = NULL;
+   const char *opt_pipe;
+
+   if ((opt_pipe = GDKgetenv("sql_optimizer")) && 
!isOptimizerPipe(opt_pipe))
+   throw(SQL, "sql.init", SQLSTATE(42000) "invalid sql optimizer 
pipeline %s", opt_pipe);
 
MT_lock_set(&sql_contextLock);
 
diff --git a/sql/jdbc/tests/Tests/All b/sql/jdbc/tests/Tests/All
--- a/sql/jdbc/tests/Tests/All
+++ b/sql/jdbc/tests/Tests/All
@@ -46,3 +46,4 @@ HAVE_JDBCTESTS?Bug_PrepStmtSetString_638
 HAVE_JDBCTESTS?Bug_LargeQueries_6571_6693
 HAVE_JDBCTESTS?Bug_IsValid_Timeout_Bug_6782
 HAVE_JDBCTESTS?Bug_PrepStmt_With_Errors_Jira292
+HAVE_JDBCCLIENT_JAR?ValidateSystemCatalogTables
diff --git a/sql/jdbc/tests/Tests/ValidateSystemCatalogTables.SQL.bat 
b/sql/jdbc/tests/Tests/ValidateSystemCatalogTables.SQL.bat
new file mode 100755
--- /dev/null
+++ b/sql/jdbc/tests/Tests/ValidateSystemCatalogTables.SQL.bat
@@ -0,0 +1,11 @@
+@echo off
+
+echo user=monetdb> .monetdb
+echo password=monetdb>>.monetdb
+
+prompt # $t $g  
+echo on
+
+call java nl.cwi.monetdb.client.JdbcClient -h %HOST% -p %MAPIPORT% -d %TSTDB% 
-e -f "%TSTSRCBASE%\%TSTDIR%\Tests\ValidateSystemCatalogTables.sql"
+
+@del .monetdb
diff --git a/sql/jdbc/tests/Tests/ValidateSystemCatalogTables.SQL.sh 
b/sql/jdbc/tests/Tests/ValidateSystemCatalogTables.SQL.sh
new file mode 100755
--- /dev/null
+++ b/sql/jdbc/tests/Tests/ValidateSystemCatalogTables.SQL.sh
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+cat << EOF > .monetdb
+user=monetdb
+password=monetdb
+EOF
+
+Mlog -x "java nl.cwi.monetdb.client.JdbcClient -h $HOST -p $MAPIPORT -d 
${TSTDB} -e -f $TSTSRCBASE/$TSTDIR/Tests/ValidateSystemCatalogTables.sql"
+
+rm -f .monetdb
diff --git a/sql/jdbc/tests/Tests/ValidateSystemCatalogTables.sql 
b/sql/jdbc/tests/Tests/ValidateSystemCatalogTables.sql
new 

MonetDB: default - Merged with Oct2020

2020-10-28 Thread Pedro Ferreira
Changeset: 4718459e3fec for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=4718459e3fec
Modified Files:
sql/server/rel_select.c
Branch: default
Log Message:

Merged with Oct2020


diffs (truncated from 880 to 300 lines):

diff --git a/ctest/cmake/detect-bz2.cmake b/ctest/cmake/detect-bz2.cmake
--- a/ctest/cmake/detect-bz2.cmake
+++ b/ctest/cmake/detect-bz2.cmake
@@ -27,19 +27,7 @@ elseif (${LINUX_DISTRO} STREQUAL "ubuntu
   variablename BZIP2_FOUND)
   endif()
 elseif(${LINUX_DISTRO} STREQUAL "fedora")
-  if(${LINUX_DISTRO_VERSION} STREQUAL "30")
-assert_package_detected(
-  detect TRUE
-  legacyvariable HAVE_LIBBZ2
-  variablename BZIP2_FOUND)
-  endif()
-  if(${LINUX_DISTRO_VERSION} STREQUAL "31")
-assert_package_detected(
-  detect TRUE
-  legacyvariable HAVE_LIBBZ2
-  variablename BZIP2_FOUND)
-  endif()
-  if(${LINUX_DISTRO_VERSION} STREQUAL "32")
+  if(${LINUX_DISTRO_VERSION} VERSION_GREATER_EQUAL "30")
 assert_package_detected(
   detect TRUE
   legacyvariable HAVE_LIBBZ2
diff --git a/ctest/cmake/detect-commoncrypto.cmake 
b/ctest/cmake/detect-commoncrypto.cmake
--- a/ctest/cmake/detect-commoncrypto.cmake
+++ b/ctest/cmake/detect-commoncrypto.cmake
@@ -27,19 +27,7 @@ elseif (${LINUX_DISTRO} STREQUAL "ubuntu
   variablename COMMONCRYPTO_FOUND)
   endif()
 elseif(${LINUX_DISTRO} STREQUAL "fedora")
-  if(${LINUX_DISTRO_VERSION} STREQUAL "30")
-assert_package_detected(
-  detect FALSE
-  legacyvariable HAVE_COMMONCRYPTO
-  variablename COMMONCRYPTO_FOUND)
-  endif()
-  if(${LINUX_DISTRO_VERSION} STREQUAL "31")
-assert_package_detected(
-  detect FALSE
-  legacyvariable HAVE_COMMONCRYPTO
-  variablename COMMONCRYPTO_FOUND)
-  endif()
-  if(${LINUX_DISTRO_VERSION} STREQUAL "32")
+  if(${LINUX_DISTRO_VERSION} VERSION_GREATER_EQUAL "30")
 assert_package_detected(
   detect FALSE
   legacyvariable HAVE_COMMONCRYPTO
diff --git a/ctest/cmake/detect-curl.cmake b/ctest/cmake/detect-curl.cmake
--- a/ctest/cmake/detect-curl.cmake
+++ b/ctest/cmake/detect-curl.cmake
@@ -27,19 +27,7 @@ elseif (${LINUX_DISTRO} STREQUAL "ubuntu
   variablename CURL_FOUND)
   endif()
 elseif(${LINUX_DISTRO} STREQUAL "fedora")
-  if(${LINUX_DISTRO_VERSION} STREQUAL "30")
-assert_package_detected(
-  detect TRUE
-  legacyvariable HAVE_CURL
-  variablename CURL_FOUND)
-  endif()
-  if(${LINUX_DISTRO_VERSION} STREQUAL "31")
-assert_package_detected(
-  detect TRUE
-  legacyvariable HAVE_CURL
-  variablename CURL_FOUND)
-  endif()
-  if(${LINUX_DISTRO_VERSION} STREQUAL "32")
+  if(${LINUX_DISTRO_VERSION} VERSION_GREATER_EQUAL "30")
 assert_package_detected(
   detect TRUE
   legacyvariable HAVE_CURL
diff --git a/ctest/cmake/detect-fits.cmake b/ctest/cmake/detect-fits.cmake
--- a/ctest/cmake/detect-fits.cmake
+++ b/ctest/cmake/detect-fits.cmake
@@ -31,19 +31,7 @@ elseif (${LINUX_DISTRO} STREQUAL "ubuntu
   variablename CFITSIO_FOUND)
   endif()
 elseif(${LINUX_DISTRO} STREQUAL "fedora")
-  if(${LINUX_DISTRO_VERSION} STREQUAL "30")
-assert_package_detected(
-  detect TRUE
-  legacyvariable HAVE_FITS
-  variablename CFITSIO_FOUND)
-  endif()
-  if(${LINUX_DISTRO_VERSION} STREQUAL "31")
-assert_package_detected(
-  detect TRUE
-  legacyvariable HAVE_FITS
-  variablename CFITSIO_FOUND)
-  endif()
-  if(${LINUX_DISTRO_VERSION} STREQUAL "32")
+  if(${LINUX_DISTRO_VERSION} VERSION_GREATER_EQUAL "30")
 assert_package_detected(
   detect TRUE
   legacyvariable HAVE_FITS
diff --git a/ctest/cmake/detect-gdal.cmake b/ctest/cmake/detect-gdal.cmake
--- a/ctest/cmake/detect-gdal.cmake
+++ b/ctest/cmake/detect-gdal.cmake
@@ -27,24 +27,17 @@ elseif (${LINUX_DISTRO} STREQUAL "ubuntu
   variablename GDAL_FOUND)
   endif()
 elseif(${LINUX_DISTRO} STREQUAL "fedora")
-  if(${LINUX_DISTRO_VERSION} STREQUAL "30")
+  if(${LINUX_DISTRO_VERSION} VERSION_GREATER_EQUAL "32")
 assert_package_detected(
-  detect FALSE
+  detect TRUE
   legacyvariable HAVE_SHP
   variablename GDAL_FOUND)
-  endif()
-  if(${LINUX_DISTRO_VERSION} STREQUAL "31")
+  elseif(${LINUX_DISTRO_VERSION} VERSION_GREATER_EQUAL "30")
 assert_package_detected(
   detect FALSE
   legacyvariable HAVE_SHP
   variablename GDAL_FOUND)
   endif()
-  if(${LINUX_DISTRO_VERSION} STREQUAL "32")
-assert_package_detected(
-  detect TRUE
-  legacyvariable HAVE_SHP
-  variablename GDAL_FOUND)
-  endif()
 else()
   message(ERROR "Linux distro: ${LINUX_DISTRO} not known")
   message(ERROR "Linux distro version: ${LINUX_DISTRO_VERSION} not known")
diff --git a/ctest/cmake/detect-geos.cmake b/ctest/cmake/detect-geos.cmake
--- a/ctest/cmake/detect-geos.cmake
+++ b/ctest/cmake/detect-geos.cmake
@@ -27,19 +27,7 @@ elseif (${LINUX_DISTRO} STREQUAL "ubuntu
   variablename GEOS_FOUND)
   endif()
 elseif(${LINUX_DISTRO} STREQUAL "fedora")
-  if(${LINUX_D

MonetDB: default - Merged with Oct2020

2020-10-20 Thread Pedro Ferreira
Changeset: a557e84dab3c for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=a557e84dab3c
Modified Files:
MonetDB.spec
tools/monetdbe/CMakeLists.txt
Branch: default
Log Message:

Merged with Oct2020


diffs (truncated from 445 to 300 lines):

diff --git a/MonetDB.spec b/MonetDB.spec
--- a/MonetDB.spec
+++ b/MonetDB.spec
@@ -784,8 +784,6 @@ export CFLAGS
 %endif
 %cmake3 \
-DRELEASE_VERSION=ON \
-   -DRUNDIR=%{_rundir}/monetdb \
-   -DLOGDIR=%{_localstatedir}/log/monetdb \
-DASSERT=OFF \
-DCINTEGRATION=%{?with_cintegration:ON}%{!?with_cintegration:OFF} \
-DFITS=%{?with_fits:ON}%{!?with_fits:OFF} \
@@ -817,7 +815,10 @@ export CFLAGS
 %cmake3_build
 
 %install
+mkdir -p "%{buildroot}/usr"
+for d in etc var; do mkdir "%{buildroot}/$d"; ln -s ../$d 
"%{buildroot}/usr/$d"; done
 %cmake3_install
+rm "%{buildroot}/usr/var" "%{buildroot}/usr/etc"
 
 # move file to correct location
 %if %{?rhel:0}%{!?rhel:1} || 0%{?rhel} >= 7
diff --git a/buildtools/conf/monetdbd.conf.in b/buildtools/conf/monetdbd.conf.in
--- a/buildtools/conf/monetdbd.conf.in
+++ b/buildtools/conf/monetdbd.conf.in
@@ -1,3 +1,3 @@
 # this file is for systemd
 # monetdbd needs a directory in /run that is owned by monetdb:monetdb
-d @RUNDIR@ 0775 monetdb monetdb -
+d @CMAKE_INSTALL_FULL_RUNSTATEDIR@/monetdb 0775 monetdb monetdb -
diff --git a/cmake/monetdb-deb-packages.cmake b/cmake/monetdb-deb-packages.cmake
--- a/cmake/monetdb-deb-packages.cmake
+++ b/cmake/monetdb-deb-packages.cmake
@@ -8,7 +8,7 @@
 
 set(CPACK_DEBIAN_PACKAGE_MAINTAINER "MonetDB BV ")
 set(CPACK_DEB_COMPONENT_INSTALL ON)
-set(CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS ON)
+set(CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS OFF)
 set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)
 set(CPACK_DEBIAN_PACKAGE_SECTION "misc")
 set(CPACK_DEBIAN_PACKAGE_SOURCE "monetdb")
@@ -171,18 +171,6 @@ set(CPACK_DEBIAN_SERVER_PACKAGE_CONTROL_
   ${CMAKE_CURRENT_SOURCE_DIR}/debian/monetdb5-server.postinst
 )
 
-set(CPACK_DEBIAN_HUGEINT_PACKAGE_NAME "monetdb5-server-hugeint")
-set(CPACK_DEBIAN_HUGEINT_PACKAGE_DEPENDS "monetdb5-server (= 
\\\${source:Version})")
-set(CPACK_DEBIAN_HUGEINT_PACKAGE_ARCHITECTURE "amd64")
-set(CPACK_COMPONENT_HUGEINT_DESCRIPTION "MonetDB - 128-bit integer support for 
MonetDB5-server
- MonetDB is a database management system that is developed from a
- main-memory perspective with use of a fully decomposed storage model,
- automatic index management, extensibility of data types and search
- accelerators.  It also has an SQL front end.
- .
- This package provides HUGEINT (128-bit integer) support for the
- MonetDB5-server component.")
-
 set(CPACK_DEBIAN_SERVERDEV_PACKAGE_NAME "monetdb5-server-dev")
 set(CPACK_DEBIAN_SERVERDEV_PACKAGE_DEPENDS "\\\${shlibs:Depends}, 
\\\${misc:Depends},
  monetdb5-server (= \\\${source:Version}), libmonetdb-dev (= 
\\\${source:Version})")
@@ -200,8 +188,6 @@ set(CPACK_DEBIAN_SQL_PACKAGE_DEPENDS
   "\\\${shlibs:Depends}"
   "\\\${misc:Depends}"
   "monetdb5-server (= \\\${source:Version})")
-set(CPACK_DEBIAN_SQL_PACKAGE_RECOMMENDS
-  "monetdb5-sql-hugeint (= \\\${source:Version}) [amd64]")
 set(CPACK_DEBIAN_SQL_PACKAGE_SUGGEST "monetdb-client (= \\\${source:Version})")
 set(CPACK_COMPONENT_SQL_DESCRIPTION "MonetDB SQL support for monetdb5
  MonetDB is a database management system that is developed from a
@@ -218,20 +204,6 @@ set(CPACK_DEBIAN_SQL_PACKAGE_CONTROL_FIL
   ${CMAKE_CURRENT_SOURCE_DIR}/debian/monetdb5-sql.postinst
   )
 
-set(CPACK_DEBIAN_SQLINT128_PACKAGE_NAME "monetdb5-sql-hugeint")
-set(CPACK_DEBIAN_SQLINT128_PACKAGE_DEPENDS
-  "monetdb5-sql (= \\\${source:Version})"
-  "monetdb5-server-hugeint (= \\\${source:Version})")
-set(CPACK_DEBIAN_SQLINT128_PACKAGE_ARCHITECTURE "amd64")
-set(CPACK_COMPONENT_SQLINT128_DESCRIPTION "MonetDB5 128 bit integer (hugeint) 
support for SQL
- MonetDB is a database management system that is developed from a
- main-memory perspective with use of a fully decomposed storage model,
- automatic index management, extensibility of data types and search
- accelerators.  It also has an SQL front end.
- .
- This package provides HUGEINT (128-bit integer) support for the SQL
- front end of MonetDB.")
-
 set(CPACK_DEBIAN_PYAPI3_PACKAGE_NAME "monetdb-python3")
 set(CPACK_DEBIAN_PYAPI3_PACKAGE_DEPENDS
   "\\\${shlibs:Depends}"
diff --git a/cmake/monetdb-defines.cmake b/cmake/monetdb-defines.cmake
--- a/cmake/monetdb-defines.cmake
+++ b/cmake/monetdb-defines.cmake
@@ -206,7 +206,6 @@ macro(monetdb_macro_variables)
   set(BINDIR "${CMAKE_INSTALL_FULL_BINDIR}")
   set(LIBDIR "${CMAKE_INSTALL_FULL_LIBDIR}")
   set(DATADIR "${CMAKE_INSTALL_FULL_DATADIR}")
-  set(DATA_DIR "${CMAKE_INSTALL_FULL_DATADIR}")
   set(LOCALSTATEDIR "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}")
   if(WIN32)
 # Fix cmake conversions
@@ -219,22 +218,12 @@ macro(monetdb_macro_variables)
   endif()
 
   set(DATAROOTDIR "${CMAKE_INSTALL_FULL_DATAROOTDIR}")
-  set(BIN_DIR "${CMAKE_INSTALL_FULL_BINDIR}")
   se

MonetDB: default - Merged with Oct2020

2020-10-05 Thread Pedro Ferreira
Changeset: 151ce470cc85 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=151ce470cc85
Modified Files:
clients/Tests/MAL-signatures.stable.out
clients/Tests/MAL-signatures.stable.out.int128
monetdb5/modules/atoms/mtime.c
Branch: default
Log Message:

Merged with Oct2020


diffs (truncated from 29018 to 300 lines):

diff --git a/clients/Tests/MAL-signatures.stable.out 
b/clients/Tests/MAL-signatures.stable.out
--- a/clients/Tests/MAL-signatures.stable.out
+++ b/clients/Tests/MAL-signatures.stable.out
@@ -6175,6 +6175,10 @@ stdout of test 'MAL-signatures` in direc
 [ "batmtime",  "epoch","command 
batmtime.epoch(X_1:bat[:timestamp]):bat[:int] ",   
"MTIMEseconds_since_epoch_bulk;",   ""  ]
 [ "batmtime",  "epoch","command 
batmtime.epoch(X_1:bat[:lng]):bat[:timestamp] ",   
"MTIMEtimestamp_frommsec_bulk;",""  ]
 [ "batmtime",  "epoch","command 
batmtime.epoch(X_1:bat[:int]):bat[:timestamp] ",   
"MTIMEtimestamp_fromsecond_bulk;",  ""  ]
+[ "batmtime",  "epoch_ms", "command 
batmtime.epoch_ms(X_1:bat[:date]):bat[:lng] ", 
"MTIMEdate_extract_epoch_ms_bulk;", ""  ]
+[ "batmtime",  "epoch_ms", "command 
batmtime.epoch_ms(X_1:bat[:daytime]):bat[:lng] ",  
"MTIMEdaytime_extract_epoch_ms_bulk;",  ""  ]
+[ "batmtime",  "epoch_ms", "command 
batmtime.epoch_ms(X_1:bat[:lng]):bat[:lng] ",  
"MTIMEmsec_extract_epoch_ms_bulk;", ""  ]
+[ "batmtime",  "epoch_ms", "command 
batmtime.epoch_ms(X_1:bat[:timestamp]):bat[:lng] ",
"MTIMEtimestamp_extract_epoch_ms_bulk;",""  ]
 [ "batmtime",  "hours","command 
batmtime.hours(X_1:bat[:daytime]):bat[:int] ", 
"MTIMEdaytime_extract_hours_bulk;", ""  ]
 [ "batmtime",  "hours","command 
batmtime.hours(X_1:bat[:lng]):bat[:int] ", "MTIMEsql_hours_bulk;", ""  ]
 [ "batmtime",  "hours","command 
batmtime.hours(X_1:bat[:timestamp]):bat[:int] ",   
"MTIMEtimestamp_hours_bulk;",   ""  ]
@@ -8939,6 +8943,10 @@ stdout of test 'MAL-signatures` in direc
 [ "mtime", "epoch","command mtime.epoch(X_1:timestamp):int ",  
"MTIMEseconds_since_epoch;",""  ]
 [ "mtime", "epoch","command mtime.epoch(X_1:lng):timestamp ",  
"MTIMEtimestamp_frommsec;", ""  ]
 [ "mtime", "epoch","command mtime.epoch(X_1:int):timestamp ",  
"MTIMEtimestamp_fromsecond;",   ""  ]
+[ "mtime", "epoch_ms", "command mtime.epoch_ms(X_1:date):lng ",
"MTIMEdate_extract_epoch_ms;",  ""  ]
+[ "mtime", "epoch_ms", "command mtime.epoch_ms(X_1:daytime):lng ", 
"MTIMEdaytime_extract_epoch_ms;",   ""  ]
+[ "mtime", "epoch_ms", "command mtime.epoch_ms(X_1:lng):lng ", 
"MTIMEmsec_extract_epoch_ms;",  ""  ]
+[ "mtime", "epoch_ms", "command mtime.epoch_ms(X_1:timestamp):lng ",   
"MTIMEtimestamp_extract_epoch_ms;", ""  ]
 [ "mtime", "hours","command mtime.hours(X_1:daytime):int ",
"MTIMEdaytime_extract_hours;",  ""  ]
 [ "mtime", "hours","command mtime.hours(X_1:lng):int ",
"MTIMEsql_hours;",  ""  ]
 [ "mtime", "hours","command mtime.hours(X_1:timestamp):int ",  
"MTIMEtimestamp_hours;",""  ]
diff --git a/clients/Tests/MAL-signatures.stable.out.int128 
b/clients/Tests/MAL-signatures.stable.out.int128
--- a/clients/Tests/MAL-signatures.stable.out.int128
+++ b/clients/Tests/MAL-signatures.stable.out.int128
@@ -8744,6 +8744,10 @@ stdout of test 'MAL-signatures` in direc
 [ "batmtime",  "epoch","command 
batmtime.epoch(X_1:bat[:timestamp]):bat[:int] ",   
"MTIMEseconds_since_epoch_bulk;",   ""  ]
 [ "batmtime",  "epoch","command 
batmtime.epoch(X_1:bat[:lng]):bat[:timestamp] ",   
"MTIMEtimestamp_frommsec_bulk;",""  ]
 [ "batmtime",  "epoch","command 
batmtime.epoch(X_1:bat[:int]):bat[:timestamp] ",   
"MTIMEtimestamp_fromsecond_bulk;",  ""  ]
+[ "batmtime",  "epoch_ms", "command 
batmtime.epoch_ms(X_1:bat[:date]):bat[:lng] ", 
"MTIMEdate_extract_epoch_ms_bulk;", ""  ]
+[ "batmtime",  "epoch_ms", "command 
batmtime.epoch_ms(X_1:bat[:daytime]):bat[:lng] ",  
"MTIMEdaytime_extract_epoch_ms_bulk;",  ""  ]
+[ "batmtime",  "epoch_ms", "command 
batmtime.epoch_ms(X_1:bat[:lng]):bat[:lng] ",  
"MTIMEmsec_extract_epoch_ms_bulk;", ""  ]
+[ "batmtime",  "epoch_ms", "command 
batmtime.epoch_ms(X_1:bat[:timestamp]):bat[:lng] ",
"MTIMEtimestamp_extract_epoch_ms_bulk;",""  ]
 [ "batmtime",  "hours","command 
batmtime.hours(X_1:bat[:daytime]):bat[:int] ", 
"MTIMEdaytime_extract_hours_bulk;", ""  ]
 [ "batmtime",  "hours","command 
batmtime.hours(X_1:bat[:lng]):bat[:int] ", "MTIMEsql_hours_bulk;", ""  ]
 [ "batmtime",  "hours","command 
batmtime.hours(X_1:bat[:timestamp]):bat[:int] ",   

MonetDB: default - merged with Oct2020

2020-10-03 Thread Niels Nes
Changeset: 11fd8da893db for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=11fd8da893db
Modified Files:
gdk/gdk_heap.c
tools/monetdbe/monetdbe.c
Branch: default
Log Message:

merged with Oct2020


diffs (truncated from 308 to 300 lines):

diff --git a/cmake/Modules/FindUUID.cmake b/cmake/Modules/FindUUID.cmake
--- a/cmake/Modules/FindUUID.cmake
+++ b/cmake/Modules/FindUUID.cmake
@@ -19,6 +19,8 @@ if(NOT UUID_LIBRARIES)
   set(UUID_LIBRARIES "" CACHE INTERNAL "uuid libraries path")
 endif()
 # Find uuid_generate symbol, which we require and some platforms don't have it
+set(CMAKE_REQUIRED_LIBRARIES ${UUID_LIBRARIES})
+set(CMAKE_REQUIRED_INCLUDES ${UUID_INCLUDE_DIR})
 check_symbol_exists("uuid_generate" "uuid/uuid.h" HAVE_UUID_GENERATE)
 cmake_pop_check_state()
 
diff --git a/cmake/monetdb-defines.cmake b/cmake/monetdb-defines.cmake
--- a/cmake/monetdb-defines.cmake
+++ b/cmake/monetdb-defines.cmake
@@ -43,7 +43,6 @@ function(monetdb_configure_defines)
   check_include_file("sys/types.h" HAVE_SYS_TYPES_H)
   check_include_file("sys/uio.h" HAVE_SYS_UIO_H)
   check_include_file("sys/un.h" HAVE_SYS_UN_H)
-  check_include_file("sys/utime.h" HAVE_SYS_UTIME_H)
   check_include_file("sys/wait.h" HAVE_SYS_WAIT_H)
   check_include_file("unistd.h" HAVE_UNISTD_H)
   check_include_file("uuid/uuid.h" HAVE_UUID_UUID_H)
@@ -116,8 +115,11 @@ function(monetdb_configure_defines)
   check_function_exists("uname" HAVE_UNAME)
   # Some libc versions on Linux distributions don't have it
   check_symbol_exists("semtimedop" "sys/types.h;sys/ipc.h;sys/sem.h" 
HAVE_SEMTIMEDOP)
-  check_function_exists("pthread_kill" HAVE_PTHREAD_KILL)
-  check_function_exists("pthread_sigmask" HAVE_PTHREAD_SIGMASK)
+  cmake_push_check_state()
+ set(CMAKE_REQUIRED_LINK_OPTIONS "-lpthread")
+check_function_exists("pthread_kill" HAVE_PTHREAD_KILL)
+check_function_exists("pthread_sigmask" HAVE_PTHREAD_SIGMASK)
+  cmake_pop_check_state()
   check_symbol_exists("regcomp" "regex.h" HAVE_POSIX_REGEX)
 endfunction()
 
diff --git a/ctest/cmake/detect-gdal.cmake b/ctest/cmake/detect-gdal.cmake
--- a/ctest/cmake/detect-gdal.cmake
+++ b/ctest/cmake/detect-gdal.cmake
@@ -41,7 +41,7 @@ elseif(${LINUX_DISTRO} STREQUAL "fedora"
   endif()
   if(${LINUX_DISTRO_VERSION} STREQUAL "32")
 assert_package_detected(
-  detect FALSE
+  detect TRUE
   legacyvariable HAVE_SHP
   variablename GDAL_FOUND)
   endif()
diff --git a/ctest/cmake/detect-iconv.cmake b/ctest/cmake/detect-iconv.cmake
--- a/ctest/cmake/detect-iconv.cmake
+++ b/ctest/cmake/detect-iconv.cmake
@@ -20,18 +20,12 @@ if (${LINUX_DISTRO} STREQUAL "debian")
   variablename Iconv_FOUND)
   endif()
 elseif (${LINUX_DISTRO} STREQUAL "ubuntu")
-  if(${LINUX_DISTRO_VERSION} VERSION_GREATER_EQUAL "20")
+  if(${LINUX_DISTRO_VERSION} VERSION_GREATER_EQUAL "18")
 assert_package_detected(
   detect TRUE
   legacyvariable HAVE_ICONV
   variablename Iconv_FOUND)
   endif()
-  if(${LINUX_DISTRO_VERSION} VERSION_GREATER_EQUAL "18")
-assert_package_detected(
-  detect FALSE
-  legacyvariable HAVE_ICONV
-  variablename Iconv_FOUND)
-  endif()
 elseif(${LINUX_DISTRO} STREQUAL "fedora")
   if(${LINUX_DISTRO_VERSION} STREQUAL "30")
 assert_package_detected(
diff --git a/ctest/cmake/detect-libz.cmake b/ctest/cmake/detect-libz.cmake
--- a/ctest/cmake/detect-libz.cmake
+++ b/ctest/cmake/detect-libz.cmake
@@ -22,7 +22,7 @@ if (${LINUX_DISTRO} STREQUAL "debian")
 elseif (${LINUX_DISTRO} STREQUAL "ubuntu")
   if(${LINUX_DISTRO_VERSION} VERSION_GREATER_EQUAL "18")
 assert_package_detected(
-  detect FALSE
+  detect TRUE
   legacyvariable HAVE_LIBZ
   variablename ZLIB_FOUND)
   endif()
diff --git a/ctest/cmake/detect-openssl.cmake b/ctest/cmake/detect-openssl.cmake
--- a/ctest/cmake/detect-openssl.cmake
+++ b/ctest/cmake/detect-openssl.cmake
@@ -22,7 +22,7 @@ if (${LINUX_DISTRO} STREQUAL "debian")
 elseif (${LINUX_DISTRO} STREQUAL "ubuntu")
   if(${LINUX_DISTRO_VERSION} VERSION_GREATER_EQUAL "18")
 assert_package_detected(
-  detect FALSE
+  detect TRUE
   legacyvariable HAVE_OPENSSL
   variablename OPENSSL_FOUND)
   endif()
diff --git a/ctest/cmake/detect-pcre.cmake b/ctest/cmake/detect-pcre.cmake
--- a/ctest/cmake/detect-pcre.cmake
+++ b/ctest/cmake/detect-pcre.cmake
@@ -22,7 +22,7 @@ if (${LINUX_DISTRO} STREQUAL "debian")
 elseif (${LINUX_DISTRO} STREQUAL "ubuntu")
   if(${LINUX_DISTRO_VERSION} VERSION_GREATER_EQUAL "18")
 assert_package_detected(
-  detect FALSE
+  detect TRUE
   legacyvariable HAVE_LIBPCRE
   variablename PCRE_FOUND)
   endif()
diff --git a/ctest/cmake/detect-pthreadkill.cmake 
b/ctest/cmake/detect-pthreadkill.cmake
--- a/ctest/cmake/detect-pthreadkill.cmake
+++ b/ctest/cmake/detect-pthreadkill.cmake
@@ -25,17 +25,9 @@ elseif (${LINUX_DISTRO} STREQUAL "ubuntu
 set(UNDETECT "1")
   endif()
 elseif(${LINUX_DISTRO} STREQUAL "fedora")
-  if(${LINUX_D

MonetDB: default - Merged with Oct2020

2020-10-02 Thread Pedro Ferreira
Changeset: c34045dafe06 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=c34045dafe06
Modified Files:
tools/merovingian/daemon/controlrunner.c
tools/monetdbe/monetdbe.c
Branch: default
Log Message:

Merged with Oct2020


diffs (truncated from 25002 to 300 lines):

diff --git a/Config.cmake.in b/Config.cmake.in
--- a/Config.cmake.in
+++ b/Config.cmake.in
@@ -12,6 +12,7 @@ include("${CMAKE_CURRENT_LIST_DIR}/monet
 include("${CMAKE_CURRENT_LIST_DIR}/streamTargets.cmake")
 include("${CMAKE_CURRENT_LIST_DIR}/mapiTargets.cmake")
 include("${CMAKE_CURRENT_LIST_DIR}/matomicTargets.cmake")
+include("${CMAKE_CURRENT_LIST_DIR}/mstringTargets.cmake")
 include("${CMAKE_CURRENT_LIST_DIR}/gdkTargets.cmake")
 include("${CMAKE_CURRENT_LIST_DIR}/monetdb5Targets.cmake")
 include("${CMAKE_CURRENT_LIST_DIR}/sqlTargets.cmake")
diff --git a/ctest/tools/monetdbe/example1.c b/ctest/tools/monetdbe/example1.c
--- a/ctest/tools/monetdbe/example1.c
+++ b/ctest/tools/monetdbe/example1.c
@@ -48,7 +48,7 @@ main(void)
}
case monetdbe_str: {
monetdbe_column_str * col = 
(monetdbe_column_str *) rcol;
-   if (col->is_null(col->data[r])) {
+   if (col->is_null(col->data+r)) {
printf("NULL");
} else {
printf("%s", (char*) 
col->data[r]);
diff --git a/ctest/tools/monetdbe/example2.c b/ctest/tools/monetdbe/example2.c
--- a/ctest/tools/monetdbe/example2.c
+++ b/ctest/tools/monetdbe/example2.c
@@ -120,7 +120,7 @@ main(void)
}
case monetdbe_str: {
monetdbe_column_str * col = 
(monetdbe_column_str *) rcol;
-   if (col->is_null(col->data[r])) {
+   if (col->is_null(col->data+r)) {
printf("NULL");
} else {
printf("%s", (char*) 
col->data[r]);
diff --git a/ctest/tools/monetdbe/example_append.c 
b/ctest/tools/monetdbe/example_append.c
--- a/ctest/tools/monetdbe/example_append.c
+++ b/ctest/tools/monetdbe/example_append.c
@@ -56,7 +56,7 @@ main(void)
}
case monetdbe_str: {
monetdbe_column_str * col = 
(monetdbe_column_str *) rcol[c];
-   if (col->is_null(col->data[r])) {
+   if (col->is_null(col->data+r)) {
printf("NULL");
} else {
printf("%s", (char*) 
col->data[r]);
@@ -141,7 +141,7 @@ main(void)
}
case monetdbe_str: {
monetdbe_column_str * col = 
(monetdbe_column_str *) rcol[c];
-   if (col->is_null(col->data[r])) {
+   if (col->is_null(col->data+r)) {
printf("NULL");
} else {
printf("%s", (char*) 
col->data[r]);
diff --git a/ctest/tools/monetdbe/example_append_raw.c 
b/ctest/tools/monetdbe/example_append_raw.c
--- a/ctest/tools/monetdbe/example_append_raw.c
+++ b/ctest/tools/monetdbe/example_append_raw.c
@@ -39,7 +39,7 @@ main(void)
int32_t i2 = *(int32_t*)monetdbe_null(mdbe, monetdbe_int32_t);
int32_t ints[2] = { i1, i2 };
monetdbe_column col0 = { .type = monetdbe_int32_t, .data = &ints, 
.count = 2 };
-   
+
// str
char* dstr[2] = { "Hello", "World" };
monetdbe_column col1 = { .type = monetdbe_str, .data = &dstr, .count = 
2 };
@@ -52,7 +52,7 @@ main(void)
monetdbe_data_timestamp tss[2] = { t1, t2 };
monetdbe_column col2 = { .type = monetdbe_timestamp, .data = &tss, 
.count = 2 };
 
-   // date 
+   // date
monetdbe_data_date d1 = dt;
monetdbe_data_date d2 = *(monetdbe_data_date*)monetdbe_null(mdbe, 
monetdbe_date);
monetdbe_data_date dts[2] = { d1, d2 };
@@ -94,7 +94,7 @@ main(void)
}
case monetdbe_str: {
monetdbe_column_str * col = 
(monetdbe_column_str *) rcol[c];
-   if (col->is_null(col->data[r])) {
+   if (col->is_null(col->data+r)) {
printf("NULL");
 

  1   2   >