MonetDB: default - Only define _XOPEN_SOURCE on Cygwin.

2021-02-02 Thread Sjoerd Mullender
Changeset: 433d4fbac5b2 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=433d4fbac5b2
Modified Files:
monetdb_config.h.in
Branch: default
Log Message:

Only define _XOPEN_SOURCE on Cygwin.


diffs (12 lines):

diff --git a/monetdb_config.h.in b/monetdb_config.h.in
--- a/monetdb_config.h.in
+++ b/monetdb_config.h.in
@@ -28,7 +28,7 @@
 
 #endif
 
-#ifndef _XOPEN_SOURCE
+#if !defined(_XOPEN_SOURCE) && defined(__CYGWIN__)
 #define _XOPEN_SOURCE 700
 #endif
 
___
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list


MonetDB: nospare - fixing leaks..

2021-02-02 Thread Niels Nes
Changeset: c3ef74a5252a for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=c3ef74a5252a
Modified Files:
sql/backends/monet5/rel_bin.c
sql/backends/monet5/sql_gencode.c
sql/backends/monet5/sql_scenario.c
sql/common/sql_changeset.c
sql/server/rel_optimizer.c
sql/server/sql_mvc.c
sql/storage/bat/bat_storage.c
sql/storage/sql_storage.h
sql/storage/store.c
testing/suppres.txt
Branch: nospare
Log Message:

fixing leaks..


diffs (truncated from 1344 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
@@ -5301,6 +5301,7 @@ check_for_foreign_key_references(mvc *sq
size_t n_deletes = 
store->storage_api.count_del(sql->session->tr, c->t);
assert (n_rows >= 
n_deletes);
if (n_rows - n_deletes 
> 0) {
+   
list_destroy(keys);
sql_error(sql, 
02, SQLSTATE(23000) "TRUNCATE: FOREIGN KEY %s.%s depends on %s", 
k->t->base.name, k->base.name, t->base.name);
*error = 1;
return;
@@ -5313,6 +5314,7 @@ check_for_foreign_key_references(mvc *sq
}
if (!found) {
if ((new_node = 
SA_NEW(sql->ta, struct tablelist)) == NULL) {
+   
list_destroy(keys);

sql_error(sql, 02, SQLSTATE(HY013) MAL_MALLOC_FAIL);
*error 
= 1;
return;
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
@@ -934,12 +934,16 @@ backend_create_r_func(backend *be, sql_f
(void)be;
switch(f->type) {
case  F_AGGR:
+   _DELETE(f->mod);
+   _DELETE(f->imp);
f->mod = GDKstrdup("rapi");
f->imp = GDKstrdup("eval_aggr");
break;
case  F_PROC: /* no output */
case  F_FUNC:
default: /* ie also F_FILT and F_UNION for now */
+   _DELETE(f->mod);
+   _DELETE(f->imp);
f->mod = GDKstrdup("rapi");
f->imp = GDKstrdup("eval");
break;
@@ -954,16 +958,22 @@ backend_create_py_func(backend *be, sql_
(void)be;
switch(f->type) {
case  F_AGGR:
+   _DELETE(f->mod);
+   _DELETE(f->imp);
f->mod = GDKstrdup("pyapi3");
f->imp = GDKstrdup("eval_aggr");
break;
case F_LOADER:
+   _DELETE(f->mod);
+   _DELETE(f->imp);
f->mod = GDKstrdup("pyapi3");
f->imp = GDKstrdup("eval_loader");
break;
case  F_PROC: /* no output */
case  F_FUNC:
default: /* ie also F_FILT and F_UNION for now */
+   _DELETE(f->mod);
+   _DELETE(f->imp);
f->mod = GDKstrdup("pyapi3");
f->imp = GDKstrdup("eval");
break;
@@ -977,12 +987,16 @@ backend_create_map_py_func(backend *be, 
(void)be;
switch(f->type) {
case  F_AGGR:
+   _DELETE(f->mod);
+   _DELETE(f->imp);
f->mod = GDKstrdup("pyapi3map");
f->imp = GDKstrdup("eval_aggr");
break;
case  F_PROC: /* no output */
case  F_FUNC:
default: /* ie also F_FILT and F_UNION for now */
+   _DELETE(f->mod);
+   _DELETE(f->imp);
f->mod = GDKstrdup("pyapi3map");
f->imp = GDKstrdup("eval");
break;
@@ -1013,6 +1027,8 @@ backend_create_c_func(backend *be, sql_f
(void)be;
switch(f->type) {
case  F_AGGR:
+   _DELETE(f->mod);
+   _DELETE(f->imp);
f->mod = GDKstrdup("capi");
f->imp = GDKstrdup("eval_aggr");
break;
@@ -1020,6 +1036,8 @@ backend_create_c_func(backend *be, sql_f
case F_PROC: /* no output */
case F_FUNC:
default: /* ie also F_FILT and F_UNION for now */
+   _DELETE(f->mod);
+   _DELETE(f->imp);
f->mod = 

MonetDB: nospare - suppres some sanitizer leaks outside of our s...

2021-02-02 Thread Niels Nes
Changeset: eac2ed14ce2b for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=eac2ed14ce2b
Added Files:
testing/suppres.txt
Branch: nospare
Log Message:

suppres some sanitizer leaks outside of our scope


diffs (16 lines):

diff --git a/testing/suppres.txt b/testing/suppres.txt
new file mode 100644
--- /dev/null
+++ b/testing/suppres.txt
@@ -0,0 +1,11 @@
+# when running testing with sanatizer use
+# export ASAN_OPTIONS=print_suppressions=0
+# export LSAN_OPTIONS=suppressions=$src/testing/suppres.txt 
+# This is a known leak.
+leak:PyObject_Malloc
+leak:PyMem_Malloc
+leak:_PyObject_GC_Resize
+leak:PyThread_allocate_lock
+leak:*libpython*.so*
+leak:*cpython*.so*
+leak:*libgomp.so*
___
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list


MonetDB: default - Only include if available.

2021-02-02 Thread Sjoerd Mullender
Changeset: a5ef85577363 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=a5ef85577363
Modified Files:
common/stream/socket_stream.c
Branch: default
Log Message:

Only include if available.


diffs (13 lines):

diff --git a/common/stream/socket_stream.c b/common/stream/socket_stream.c
--- a/common/stream/socket_stream.c
+++ b/common/stream/socket_stream.c
@@ -11,7 +11,9 @@
 #include "monetdb_config.h"
 #include "stream.h"
 #include "stream_internal.h"
+#ifdef HAVE_SYS_TIME_H
 #include 
+#endif
 
 
 /* -- */
___
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list


MonetDB: default - Don't attempt to redefine.

2021-02-02 Thread Sjoerd Mullender
Changeset: 73c0339800d3 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=73c0339800d3
Modified Files:
monetdb_config.h.in
Branch: default
Log Message:

Don't attempt to redefine.


diffs (13 lines):

diff --git a/monetdb_config.h.in b/monetdb_config.h.in
--- a/monetdb_config.h.in
+++ b/monetdb_config.h.in
@@ -28,7 +28,9 @@
 
 #endif
 
+#ifndef _XOPEN_SOURCE
 #define _XOPEN_SOURCE 700
+#endif
 
 #include 
 #if defined(_MSC_VER) && defined(_DEBUG) && defined(_CRTDBG_MAP_ALLOC)
___
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list


MonetDB: default - Ported to Cygwin.

2021-02-02 Thread Sjoerd Mullender
Changeset: ec8e384abd46 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=ec8e384abd46
Removed Files:
sql/backends/monet5/UDF/capi/capi.h
Modified Files:
CMakeLists.txt
clients/mapilib/CMakeLists.txt
common/stream/CMakeLists.txt
common/stream/socket_stream.c
common/stream/stream_internal.h
common/stream/stream_socket.h
common/utils/CMakeLists.txt
gdk/gdk_posix.h
monetdb5/modules/atoms/strptime.c
monetdb5/modules/kernel/CMakeLists.txt
monetdb5/modules/kernel/microbenchmark.c
monetdb5/modules/mal/mal_mapi.c
monetdb5/scheduler/run_adder.c
monetdb5/scheduler/run_isolate.c
monetdb5/scheduler/run_memo.c
monetdb_config.h.in
sql/backends/monet5/CMakeLists.txt
sql/backends/monet5/UDF/capi/CMakeLists.txt
sql/backends/monet5/UDF/capi/capi.c
sql/backends/monet5/sql.c
tools/CMakeLists.txt
Branch: default
Log Message:

Ported to Cygwin.
It compiled once.  Otherwise untested.


diffs (truncated from 492 to 300 lines):

diff --git a/CMakeLists.txt b/CMakeLists.txt
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -69,8 +69,10 @@ monetdb_configure_defines()
 if(HAVE_NETDB_H)
   set(CMAKE_EXTRA_INCLUDE_FILES "netdb.h" "unistd.h")
 endif()
-if(HAVE_WINSOCK_H)
-  set(CMAKE_EXTRA_INCLUDE_FILES "winsock.h")
+if(NOT HAVE_SYS_SOCKET_H)
+  if(HAVE_WINSOCK_H)
+set(CMAKE_EXTRA_INCLUDE_FILES "winsock.h")
+  endif()
 endif()
 set(CMAKE_REQUIRED_INCLUDES "/usr/include")
 
diff --git a/clients/mapilib/CMakeLists.txt b/clients/mapilib/CMakeLists.txt
--- a/clients/mapilib/CMakeLists.txt
+++ b/clients/mapilib/CMakeLists.txt
@@ -37,11 +37,9 @@ target_link_libraries(mapi
   stream
   $<$:ws2_32>)
 
-if(WIN32)
-  target_compile_definitions(mapi
-PRIVATE
-LIBMAPI)
-endif()
+target_compile_definitions(mapi
+  PRIVATE
+  LIBMAPI)
 
 set_target_properties(mapi
   PROPERTIES
diff --git a/common/stream/CMakeLists.txt b/common/stream/CMakeLists.txt
--- a/common/stream/CMakeLists.txt
+++ b/common/stream/CMakeLists.txt
@@ -52,11 +52,9 @@ target_include_directories(stream
   $
   $)
 
-if(WIN32)
-  target_compile_definitions(stream
-PRIVATE
-LIBSTREAM)
-endif()
+target_compile_definitions(stream
+  PRIVATE
+  LIBSTREAM)
 
 target_link_libraries(stream
   PRIVATE
diff --git a/common/stream/socket_stream.c b/common/stream/socket_stream.c
--- a/common/stream/socket_stream.c
+++ b/common/stream/socket_stream.c
@@ -11,6 +11,7 @@
 #include "monetdb_config.h"
 #include "stream.h"
 #include "stream_internal.h"
+#include 
 
 
 /* -- */
diff --git a/common/stream/stream_internal.h b/common/stream/stream_internal.h
--- a/common/stream/stream_internal.h
+++ b/common/stream/stream_internal.h
@@ -174,6 +174,10 @@ struct stream {
char errmsg[1024]; // avoid allocation on error. We don't have THAT 
many streams..
 };
 
+#ifdef __CYGWIN__
+#define __visibility__(a)
+#endif
+
 void mnstr_va_set_error(stream *s, mnstr_error_kind kind, const char *fmt, 
va_list ap)
__attribute__((__visibility__("hidden")));
 
diff --git a/common/stream/stream_socket.h b/common/stream/stream_socket.h
--- a/common/stream/stream_socket.h
+++ b/common/stream/stream_socket.h
@@ -14,10 +14,11 @@
 
 #ifdef HAVE_SYS_SOCKET_H
 #include 
-#endif
+#else
 #ifdef HAVE_WINSOCK_H
 # include 
 #endif
+#endif
 
 #ifndef INVALID_SOCKET
 #define INVALID_SOCKET (-1)
diff --git a/common/utils/CMakeLists.txt b/common/utils/CMakeLists.txt
--- a/common/utils/CMakeLists.txt
+++ b/common/utils/CMakeLists.txt
@@ -29,12 +29,10 @@ target_link_libraries(mutils
   PRIVATE
   monetdb_config_header)
 
-if(WIN32)
-  target_compile_definitions(mutils PRIVATE
-LIBMUTILS
-LIBGDK
-LIBMEROUTIL)
-endif()
+target_compile_definitions(mutils PRIVATE
+  LIBMUTILS
+  LIBGDK
+  LIBMEROUTIL)
 
 set_target_properties(mutils
   PROPERTIES
@@ -59,13 +57,11 @@ target_link_libraries(mcrypt
   $<$:OpenSSL::Crypto>
   monetdb_config_header)
 
-if(WIN32)
-  target_compile_definitions(mcrypt
-PRIVATE
-LIBMONETDB5
-LIBMAPI
-LIBMCRYPT)
-endif()
+target_compile_definitions(mcrypt
+  PRIVATE
+  LIBMONETDB5
+  LIBMAPI
+  LIBMCRYPT)
 
 set_target_properties(mcrypt
   PROPERTIES
@@ -97,12 +93,10 @@ target_link_libraries(msabaoth
   mutils
   monetdb_config_header)
 
-if(WIN32)
-  target_compile_definitions(msabaoth
-PRIVATE
-LIBMSABAOTH
-LIBMONETDB5)
-endif()
+target_compile_definitions(msabaoth
+  PRIVATE
+  LIBMSABAOTH
+  LIBMONETDB5)
 
 set_target_properties(msabaoth
   PROPERTIES
diff --git a/gdk/gdk_posix.h b/gdk/gdk_posix.h
--- a/gdk/gdk_posix.h
+++ b/gdk/gdk_posix.h
@@ -20,9 +20,11 @@
 #include   /* gettimeofday */
 #endif
 
+#ifndef HAVE_SYS_SOCKET_H
 #ifdef HAVE_WINSOCK_H
 #include/* for timeval */
 #endif
+#endif
 
 #include "gdk_system.h" /* gdk_export */
 
diff --git 

monetdb-java: default - Allow to set fetchsize from the connecti...

2021-02-02 Thread Joeri van Ruth
Changeset: de2ef68b672f for monetdb-java
URL: https://dev.monetdb.org/hg/monetdb-java?cmd=changeset;node=de2ef68b672f
Modified Files:
release.txt
src/main/java/org/monetdb/jdbc/MonetConnection.java
Branch: default
Log Message:

Allow to set fetchsize from the connection url


diffs (60 lines):

diff --git a/release.txt b/release.txt
--- a/release.txt
+++ b/release.txt
@@ -25,6 +25,7 @@ Supported connection properties are:
treat_clob_as_varchar=falsedefault is: true
treat_blob_as_binary=false default is: true
language=  default is: sql
+  fetchsize= default is: 250
debug=true default is: false
logfile=
hash=
diff --git a/src/main/java/org/monetdb/jdbc/MonetConnection.java 
b/src/main/java/org/monetdb/jdbc/MonetConnection.java
--- a/src/main/java/org/monetdb/jdbc/MonetConnection.java
+++ b/src/main/java/org/monetdb/jdbc/MonetConnection.java
@@ -204,6 +204,17 @@ public class MonetConnection
if (hash != null)
conn_props.setProperty("hash", hash);
 
+   final String fetchsize_prop = props.getProperty("fetchsize");
+   if (fetchsize_prop != null) {
+   int fetchsize = Integer.parseInt(fetchsize_prop);
+   if (fetchsize > 0) {
+   this.defaultFetchSize = fetchsize;
+   conn_props.setProperty("fetchsize", 
fetchsize_prop);
+   } else {
+   addWarning("Fetch size must be positive. Value 
ignored", "M1M05");
+   }
+   }
+
final String treatBlobAsVarBinary_prop = 
props.getProperty("treat_blob_as_binary");
if (treatBlobAsVarBinary_prop != null) {
treatBlobAsVarBinary = 
Boolean.parseBoolean(treatBlobAsVarBinary_prop);
@@ -263,7 +274,7 @@ public class MonetConnection
int offsetMillis = cal.get(Calendar.ZONE_OFFSET) + 
cal.get(Calendar.DST_OFFSET);
int offsetSeconds = offsetMillis / 1000;
handshakeOptions.setTimeZone(offsetSeconds);
-   handshakeOptions.setReplySize(DEF_FETCHSIZE);
+   handshakeOptions.setReplySize(defaultFetchSize);
server.setHandshakeOptions(handshakeOptions);
 
// we're debugging here... uhm, should be off in real life
@@ -2040,6 +2051,9 @@ public class MonetConnection
 
/** the default number of rows that are (attempted to) read at once */
private static final int DEF_FETCHSIZE = 250;
+
+   /** the default number of rows to read at once from this connection */
+   private int defaultFetchSize = DEF_FETCHSIZE;
/** The sequence counter */
private static int seqCounter = 0;
 
@@ -2927,7 +2941,7 @@ public class MonetConnection
 * then ignore this call.  If it is set 
to 0 we get a
 * prompt after the server sent it's 
header.
 */
-   int size = (cachesize == 0 ? 
DEF_FETCHSIZE : cachesize);
+   int size = (cachesize == 0 ? 
defaultFetchSize : cachesize);
if (maxrows > 0 && maxrows < size)
size = (int)maxrows;
// don't do work if it's not needed
___
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list


monetdb-java: default - Send reply size and time zone during ini...

2021-02-02 Thread Joeri van Ruth
Changeset: 8368cbc670bf for monetdb-java
URL: https://dev.monetdb.org/hg/monetdb-java?cmd=changeset;node=8368cbc670bf
Added Files:
src/main/java/org/monetdb/mcl/net/HandshakeOptions.java
Modified Files:
src/main/java/org/monetdb/jdbc/MonetConnection.java
src/main/java/org/monetdb/mcl/net/MapiSocket.java
Branch: default
Log Message:

Send reply size and time zone during initial handshake


diffs (233 lines):

diff --git a/src/main/java/org/monetdb/jdbc/MonetConnection.java 
b/src/main/java/org/monetdb/jdbc/MonetConnection.java
--- a/src/main/java/org/monetdb/jdbc/MonetConnection.java
+++ b/src/main/java/org/monetdb/jdbc/MonetConnection.java
@@ -35,6 +35,7 @@ import java.util.concurrent.Executor;
 
 import org.monetdb.mcl.io.BufferedMCLReader;
 import org.monetdb.mcl.io.BufferedMCLWriter;
+import org.monetdb.mcl.net.HandshakeOptions;
 import org.monetdb.mcl.net.MapiSocket;
 import org.monetdb.mcl.parser.HeaderLineParser;
 import org.monetdb.mcl.parser.MCLParseException;
@@ -257,6 +258,14 @@ public class MonetConnection
server.setDatabase(database);
server.setLanguage(language);
 
+   HandshakeOptions handshakeOptions = new HandshakeOptions();
+   final Calendar cal = Calendar.getInstance();
+   int offsetMillis = cal.get(Calendar.ZONE_OFFSET) + 
cal.get(Calendar.DST_OFFSET);
+   int offsetSeconds = offsetMillis / 1000;
+   handshakeOptions.setTimeZone(offsetSeconds);
+   handshakeOptions.setReplySize(DEF_FETCHSIZE);
+   server.setHandshakeOptions(handshakeOptions);
+
// we're debugging here... uhm, should be off in real life
if (debug) {
try {
@@ -336,20 +345,27 @@ public class MonetConnection
lang = LANG_UNKNOWN;
}
 
+   if (!handshakeOptions.mustSendReplySize()) {
+   // Initially, it had to be sent. If it no more needs to 
be sent now,
+   // it must have been sent during the auth 
challenge/response.
+   // Record the value it was set to.
+   this.curReplySize = handshakeOptions.getReplySize();
+   }
+
// the following initialisers are only valid when the language 
is SQL...
if (lang == LANG_SQL) {
// enable auto commit
setAutoCommit(true);
 
-   // set our time zone on the server
-   final Calendar cal = Calendar.getInstance();
-   int offset = cal.get(Calendar.ZONE_OFFSET) + 
cal.get(Calendar.DST_OFFSET);
-   offset /= (60 * 1000); // milliseconds to minutes
-   String tz = offset < 0 ? "-" : "+";
-   tz += (Math.abs(offset) / 60 < 10 ? "0" : "") + 
(Math.abs(offset) / 60) + ":";
-   offset -= (offset / 60) * 60;
-   tz += (offset < 10 ? "0" : "") + offset;
-   sendIndependentCommand("SET TIME ZONE INTERVAL '" + tz 
+ "' HOUR TO MINUTE");
+   // set our time zone on the server, if we haven't 
already
+   if (handshakeOptions.mustSendTimeZone()) {
+   int offsetMinutes = 
handshakeOptions.getTimeZone() / 60;
+   String tz = offsetMinutes < 0 ? "-" : "+";
+   tz += (Math.abs(offsetMinutes) / 60 < 10 ? "0" 
: "") + (Math.abs(offsetMinutes) / 60) + ":";
+   offsetMinutes -= (offsetMinutes / 60) * 60;
+   tz += (offsetMinutes < 10 ? "0" : "") + 
offsetMinutes;
+   sendIndependentCommand("SET TIME ZONE INTERVAL 
'" + tz + "' HOUR TO MINUTE");
+   }
}
 
// we're absolutely not closed, since we're brand new
diff --git a/src/main/java/org/monetdb/mcl/net/HandshakeOptions.java 
b/src/main/java/org/monetdb/mcl/net/HandshakeOptions.java
new file mode 100644
--- /dev/null
+++ b/src/main/java/org/monetdb/mcl/net/HandshakeOptions.java
@@ -0,0 +1,98 @@
+package org.monetdb.mcl.net;
+
+/** Keep track of MAPI handshake options.
+ *
+ * Recent server versions allow you to send configuration information during
+ * the authentication handshake so no additional round trips are necessary
+ * when that has completed.
+ *
+ * This class keeps track of the options to send, and whether they have already
+ * been sent.
+ */
+public class HandshakeOptions {
+
+   // public Boolean autoCommit;
+   int replySize;
+   // public Integer replySize;
+   // public Integer ColumnarProtocol;
+   int timeZone;
+
+   boolean mustSendReplySize;
+   boolean mustSendTimeZone;
+
+   public int getReplySize() {
+   return replySize;
+   }
+
+  

MonetDB: mapihandshake - Keep msqldump in the UTC timezone

2021-02-02 Thread Joeri van Ruth
Changeset: 532746974b5d for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=532746974b5d
Modified Files:
clients/mapiclient/msqldump.c
Branch: mapihandshake
Log Message:

Keep msqldump in the UTC timezone


diffs (21 lines):

diff --git a/clients/mapiclient/msqldump.c b/clients/mapiclient/msqldump.c
--- a/clients/mapiclient/msqldump.c
+++ b/clients/mapiclient/msqldump.c
@@ -198,7 +198,7 @@ main(int argc, char **argv)
if (passwd == NULL)
passwd = simple_prompt("password", BUFSIZ, 0, NULL);
 
-   mid = mapi_connect(host, port, user, passwd, "sql", dbname);
+   mid = mapi_mapi(host, port, user, passwd, "sql", dbname);
if (user)
free(user);
if (passwd)
@@ -209,6 +209,8 @@ main(int argc, char **argv)
fprintf(stderr, "failed to allocate Mapi structure\n");
exit(2);
}
+   mapi_set_time_zone(mid, 0);
+   mapi_reconnect(mid);
if (mapi_error(mid)) {
mapi_explain(mid, stderr);
exit(2);
___
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list


MonetDB: mapihandshake - Approve clients/exports

2021-02-02 Thread Joeri van Ruth
Changeset: e280fd3a18f9 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=e280fd3a18f9
Modified Files:
clients/Tests/exports.stable.out
Branch: mapihandshake
Log Message:

Approve clients/exports


diffs (19 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
@@ -625,6 +625,7 @@ int mapi_get_scale(MapiHdl hdl, int fnr)
 int64_t mapi_get_sqloptimizertime(MapiHdl hdl) __attribute__((__nonnull__(1)));
 char *mapi_get_table(MapiHdl hdl, int fnr) __attribute__((__nonnull__(1)));
 int mapi_get_tableid(MapiHdl hdl) __attribute__((__nonnull__(1)));
+int mapi_get_time_zone(Mapi mid) __attribute__((__nonnull__(1)));
 stream *mapi_get_to(Mapi mid) __attribute__((__nonnull__(1)));
 bool mapi_get_trace(Mapi mid) __attribute__((__nonnull__(1)));
 char *mapi_get_type(MapiHdl hdl, int fnr) __attribute__((__nonnull__(1)));
@@ -664,6 +665,7 @@ MapiHdl mapi_send(Mapi mid, const char *
 MapiMsg mapi_setAutocommit(Mapi mid, bool autocommit) 
__attribute__((__nonnull__(1)));
 MapiMsg mapi_set_columnar_protocol(Mapi mid, bool columnar_protocol) 
__attribute__((__nonnull__(1)));
 MapiMsg mapi_set_size_header(Mapi mid, bool value) 
__attribute__((__nonnull__(1)));
+MapiMsg mapi_set_time_zone(Mapi mid, int seconds_east_of_utc) 
__attribute__((__nonnull__(1)));
 MapiMsg mapi_set_timeout(Mapi mid, unsigned int timeout, bool (*callback)(void 
*), void *callback_data) __attribute__((__nonnull__(1)));
 void mapi_setfilecallback(Mapi mid, char *(*getfunc)(void *priv, const char 
*filename, bool binary, uint64_t offset, size_t *size), char *(*putfunc)(void 
*priv, const char *filename, const void *data, size_t size), void *priv) 
__attribute__((__nonnull__(1)));
 int mapi_split_line(MapiHdl hdl) __attribute__((__nonnull__(1)));
___
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list


MonetDB: mapihandshake - Also deal with clients which don't supp...

2021-02-02 Thread Joeri van Ruth
Changeset: 654500e66cae for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=654500e66cae
Modified Files:
monetdb5/mal/mal_session.c
Branch: mapihandshake
Log Message:

Also deal with clients which don't support FILETRANS


diffs (13 lines):

diff --git a/monetdb5/mal/mal_session.c b/monetdb5/mal/mal_session.c
--- a/monetdb5/mal/mal_session.c
+++ b/monetdb5/mal/mal_session.c
@@ -249,6 +249,9 @@ MSscheduleClient(str command, str challe
if (s && strncmp(s, "FILETRANS:", 10) == 0) {
s += 10;
filetrans = true;
+   } else if (s && s[0] == ':') {
+   s += 1;
+   filetrans = false;
}
 
if (s && strchr(s, ':') != NULL) {
___
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list


MonetDB: mapihandshake - Also pass the columnar_protocol boolean

2021-02-02 Thread Joeri van Ruth
Changeset: 0c1cff6d415e for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=0c1cff6d415e
Modified Files:
clients/mapilib/mapi.c
clients/mapilib/mapi.h
sql/backends/monet5/sql_scenario.c
Branch: mapihandshake
Log Message:

Also pass the columnar_protocol boolean


diffs (64 lines):

diff --git a/clients/mapilib/mapi.c b/clients/mapilib/mapi.c
--- a/clients/mapilib/mapi.c
+++ b/clients/mapilib/mapi.c
@@ -2835,6 +2835,9 @@ mapi_reconnect(Mapi mid)
if (mid->handshake_options > MAPI_HANDSHAKE_SIZE_HEADER) {
CHECK_SNPRINTF(",size_header=%d", mid->sizeheader); // with 
underscore, despite X command without
}
+   if (mid->handshake_options > MAPI_HANDSHAKE_COLUMNAR_PROTOCOL) {
+   CHECK_SNPRINTF(",columnar_protocol=%d", mid->columnar_protocol);
+   }
if (mid->handshake_options > MAPI_HANDSHAKE_TIME_ZONE) {
CHECK_SNPRINTF(",time_zone=%d", mid->time_zone);
}
@@ -3060,6 +3063,9 @@ mapi_reconnect(Mapi mid)
if (result != MOK)
return mid->error;
}
+   // There is no if  (mid->handshake_options <= 
MAPI_HANDSHAKE_COLUMNAR_PROTOCOL && mid->columnar_protocol != 
MapiStructDefaults.columnar_protocol)
+   // The reason is that columnar_protocol is very new. If it isn't 
supported in the handshake it isn't supported at
+   // all so sending the Xcommand would just give an error.
if (mid->handshake_options <= MAPI_HANDSHAKE_TIME_ZONE) {
mapi_set_time_zone(mid, mid->time_zone);
}
@@ -3789,6 +3795,8 @@ mapi_set_columnar_protocol(Mapi mid, boo
if (mid->columnar_protocol == columnar_protocol)
return MOK;
mid->columnar_protocol = columnar_protocol;
+   if (!mid->connected)
+   return MOK;
if (columnar_protocol)
return mapi_Xcommand(mid, "columnar_protocol", "1");
else
diff --git a/clients/mapilib/mapi.h b/clients/mapilib/mapi.h
--- a/clients/mapilib/mapi.h
+++ b/clients/mapilib/mapi.h
@@ -29,10 +29,12 @@ typedef int MapiMsg;
 
 enum mapi_handshake_options_levels {
MAPI_HANDSHAKE_AUTOCOMMIT = 1,
-   MAPI_HANDSHAKE_REPLY_SIZE,
-   MAPI_HANDSHAKE_SIZE_HEADER,
-   MAPI_HANDSHAKE_TIME_ZONE,
-   // this must always be the last one:
+   MAPI_HANDSHAKE_REPLY_SIZE = 2,
+   MAPI_HANDSHAKE_SIZE_HEADER = 3,
+   MAPI_HANDSHAKE_COLUMNAR_PROTOCOL = 4,
+   MAPI_HANDSHAKE_TIME_ZONE = 5,
+   // make sure to insert new option levels before this one.
+   // it is the value sent by the server during the initial handshake.
MAPI_HANDSHAKE_OPTIONS_LEVEL,
 };
 
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
@@ -296,6 +296,8 @@ SQLprepareClient(Client c, int login)
m->reply_size = value;
} else if (sscanf(tok, "size_header=%d", ) == 1) {
be->sizeheader = value != 0;
+   } else if (sscanf(tok, "columnar_protocol=%d", ) 
== 1) {
+   c->protocol = (value != 0) ? PROTOCOL_COLUMNAR 
: PROTOCOL_9;
} else if (sscanf(tok, "time_zone=%d", ) == 1) {
m->timezone = 1000 * value;
} else {
___
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list


MonetDB: mapihandshake - Add fallback code for gmtime_r and loca...

2021-02-02 Thread Joeri van Ruth
Changeset: 9b4b9a2b8e02 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=9b4b9a2b8e02
Modified Files:
clients/mapilib/mapi.c
Branch: mapihandshake
Log Message:

Add fallback code for gmtime_r and localtime_r

Because mapi.c doesn't have access to the implementations in gdk_posix.c
we can't use those.


diffs (41 lines):

diff --git a/clients/mapilib/mapi.c b/clients/mapilib/mapi.c
--- a/clients/mapilib/mapi.c
+++ b/clients/mapilib/mapi.c
@@ -726,6 +726,37 @@
 # include  /* gettimeofday */
 #endif
 
+/* Copied from gdk_posix, but without taking a lock because we don't have 
access to
+ * MT_lock_set/unset here. We just have to hope for the best
+ */
+#ifndef HAVE_LOCALTIME_R
+struct tm *
+localtime_r(const time_t *restrict timep, struct tm *restrict result)
+{
+   struct tm *tmp;
+   tmp = localtime(timep);
+   if (tmp)
+   *result = *tmp;
+   return tmp ? result : NULL;
+}
+#endif
+
+/* Copied from gdk_posix, but without taking a lock because we don't have 
access to
+ * MT_lock_set/unset here. We just have to hope for the best
+ */
+#ifndef HAVE_GMTIME_R
+struct tm *
+gmtime_r(const time_t *restrict timep, struct tm *restrict result)
+{
+   struct tm *tmp;
+   tmp = gmtime(timep);
+   if (tmp)
+   *result = *tmp;
+   return tmp ? result : NULL;
+}
+#endif
+
+
 #ifdef HAVE_FCNTL_H
 #include 
 #endif
___
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list


MonetDB: mapihandshake - Also pass the time zone

2021-02-02 Thread Joeri van Ruth
Changeset: 0a5e42d415dd for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=0a5e42d415dd
Modified Files:
clients/mapiclient/mclient.c
clients/mapilib/mapi.c
clients/mapilib/mapi.h
sql/backends/monet5/sql_scenario.c
Branch: mapihandshake
Log Message:

Also pass the time zone


diffs (231 lines):

diff --git a/clients/mapiclient/mclient.c b/clients/mapiclient/mclient.c
--- a/clients/mapiclient/mclient.c
+++ b/clients/mapiclient/mclient.c
@@ -2893,75 +2893,6 @@ doFile(Mapi mid, stream *fp, bool useins
return errseen;
 }
 
-static void
-set_timezone(Mapi mid)
-{
-   char buf[128];
-   int tzone;
-   MapiHdl hdl;
-
-   /* figure out our current timezone */
-#if defined HAVE_GETDYNAMICTIMEZONEINFORMATION
-   DYNAMIC_TIME_ZONE_INFORMATION tzinf;
-
-   /* documentation says: UTC = localtime + Bias (in minutes),
-* but experimentation during DST period says, UTC = localtime
-* + Bias + DaylightBias, and presumably during non DST
-* period, UTC = localtime + Bias */
-   switch (GetDynamicTimeZoneInformation()) {
-   case TIME_ZONE_ID_STANDARD:
-   case TIME_ZONE_ID_UNKNOWN:
-   tzone = (int) tzinf.Bias * 60;
-   break;
-   case TIME_ZONE_ID_DAYLIGHT:
-   tzone = (int) (tzinf.Bias + tzinf.DaylightBias) * 60;
-   break;
-   default:
-   /* call failed, we don't know the time zone */
-   tzone = 0;
-   break;
-   }
-#elif defined HAVE_STRUCT_TM_TM_ZONE
-   time_t t;
-   struct tm *tmp;
-
-   t = time(NULL);
-   tmp = localtime();
-   tzone = (int) -tmp->tm_gmtoff;
-#else
-   time_t t, lt, gt;
-   struct tm *tmp;
-
-   t = time(NULL);
-   tmp = gmtime();
-   gt = mktime(tmp);
-   tmp = localtime();
-   tmp->tm_isdst=0; /* We need the difference without dst */
-   lt = mktime(tmp);
-   assert((int64_t) gt - (int64_t) lt >= (int64_t) INT_MIN && (int64_t) gt 
- (int64_t) lt <= (int64_t) INT_MAX);
-   tzone = (int) (gt - lt);
-#endif
-   if (tzone < 0)
-   snprintf(buf, sizeof(buf),
-"SET TIME ZONE INTERVAL '+%02d:%02d' HOUR TO MINUTE",
--tzone / 3600, (-tzone % 3600) / 60);
-   else
-   snprintf(buf, sizeof(buf),
-"SET TIME ZONE INTERVAL '-%02d:%02d' HOUR TO MINUTE",
-tzone / 3600, (tzone % 3600) / 60);
-   if ((hdl = mapi_query(mid, buf)) == NULL) {
-   if (formatter == TABLEformatter) {
-   mapi_noexplain(mid, "");
-   } else {
-   mapi_noexplain(mid, NULL);
-   }
-   mapi_explain(mid, stderr);
-   errseen = true;
-   return;
-   }
-   mapi_close_handle(hdl);
-}
-
 struct privdata {
stream *f;
char *buf;
@@ -3541,6 +3472,8 @@ main(int argc, char **argv)
 
mapi_cache_limit(mid, -1);
mapi_setAutocommit(mid, autocommit);
+   if (mode == SQL && !settz)
+   mapi_set_time_zone(mid, 0);
 
if (mid && mapi_error(mid) == MOK)
mapi_reconnect(mid);/* actually, initial connect */
@@ -3616,9 +3549,6 @@ main(int argc, char **argv)
 mapi_get_autocommit(mid) ? "on" : "off");
}
 
-   if (mode == SQL && settz)
-   set_timezone(mid);
-
if (command != NULL) {
 #if !defined(_MSC_VER) && defined(HAVE_ICONV)
/* no need on Windows: using wmain interface */
diff --git a/clients/mapilib/mapi.c b/clients/mapilib/mapi.c
--- a/clients/mapilib/mapi.c
+++ b/clients/mapilib/mapi.c
@@ -883,6 +883,7 @@ struct MapiStruct {
bool auto_commit;
bool columnar_protocol;
bool sizeheader;
+   int time_zone;  /* seconds EAST of UTC */
MapiHdl first;  /* start of doubly-linked list */
MapiHdl active; /* set when not all rows have been received */
 
@@ -1382,6 +1383,13 @@ mapi_get_columnar_protocol(Mapi mid)
return mid->columnar_protocol;
 }
 
+int
+mapi_get_time_zone(Mapi mid)
+{
+   mapi_check0(mid);
+   return mid->time_zone;
+}
+
 static int64_t
 usec(void)
 {
@@ -1898,6 +1906,16 @@ mapi_new(void)
mid->blk.buf[0] = 0;
mid->blk.buf[mid->blk.lim] = 0;
 
+   /* also the current timezone, seconds EAST of UTC */
+   time_t t = time(NULL);
+   struct tm *gm_tm = gmtime_r(, &(struct tm){0});
+   time_t gt = mktime(gm_tm);
+   struct tm *local_tm = localtime_r(, &(struct tm){0});
+   local_tm->tm_isdst=0; /* We need the difference without dst */
+   time_t lt = mktime(local_tm);
+   assert((int64_t) gt - (int64_t) lt >= (int64_t) INT_MIN && (int64_t) gt 
- (int64_t) lt <= (int64_t) INT_MAX);
+   mid->time_zone = (int) (lt - gt);
+
return mid;
 }
 
@@ 

MonetDB: mapihandshake - Also handshake sizeheader command

2021-02-02 Thread Joeri van Ruth
Changeset: a2dc9ad52144 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=a2dc9ad52144
Modified Files:
clients/mapilib/mapi.c
clients/mapilib/mapi.h
sql/backends/monet5/sql_scenario.c
Branch: mapihandshake
Log Message:

Also handshake sizeheader command


diffs (81 lines):

diff --git a/clients/mapilib/mapi.c b/clients/mapilib/mapi.c
--- a/clients/mapilib/mapi.c
+++ b/clients/mapilib/mapi.c
@@ -882,6 +882,7 @@ struct MapiStruct {
int handshake_options;  /* which settings can be sent during 
challenge/response? */
bool auto_commit;
bool columnar_protocol;
+   bool sizeheader;
MapiHdl first;  /* start of doubly-linked list */
MapiHdl active; /* set when not all rows have been received */
 
@@ -2782,6 +2783,10 @@ mapi_reconnect(Mapi mid)
if (mid->handshake_options > MAPI_HANDSHAKE_REPLY_SIZE) {
CHECK_SNPRINTF(",reply_size=%d", mid->cachelimit);
}
+   if (mid->handshake_options > MAPI_HANDSHAKE_SIZE_HEADER) {
+   CHECK_SNPRINTF(",size_header=%d", mid->sizeheader); // with 
underscore, despite X command without
+   }
+   }
if (mid->handshake_options > 0) {
CHECK_SNPRINTF(":");
}
@@ -2997,6 +3002,13 @@ mapi_reconnect(Mapi mid)
if (result != MOK)
return mid->error;
}
+   if (mid->handshake_options <= MAPI_HANDSHAKE_SIZE_HEADER && 
mid->sizeheader != MapiStructDefaults.sizeheader) {
+   char buf[50];
+   sprintf(buf, "%d", !!mid->sizeheader);
+   MapiMsg result = mapi_Xcommand(mid, "sizeheader", buf); // no 
underscore!
+   if (result != MOK)
+   return mid->error;
+   }
 
return mid->error;
 }
@@ -3711,6 +3723,9 @@ mapi_set_size_header(Mapi mid, bool valu
mapi_setError(mid, "size header only supported in SQL", 
__func__, MERROR);
return MERROR;
}
+   mid->sizeheader = value;
+   if (!mid->connected)
+   return MOK;
if (value)
return mapi_Xcommand(mid, "sizeheader", "1");
else
diff --git a/clients/mapilib/mapi.h b/clients/mapilib/mapi.h
--- a/clients/mapilib/mapi.h
+++ b/clients/mapilib/mapi.h
@@ -30,6 +30,7 @@ typedef int MapiMsg;
 enum mapi_handshake_options_levels {
MAPI_HANDSHAKE_AUTOCOMMIT = 1,
MAPI_HANDSHAKE_REPLY_SIZE,
+   MAPI_HANDSHAKE_SIZE_HEADER,
// this must always be the last one:
MAPI_HANDSHAKE_OPTIONS_LEVEL,
 };
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
@@ -294,8 +294,10 @@ SQLprepareClient(Client c, int login)
goto bailout;
}
m->reply_size = value;
+   } else if (sscanf(tok, "size_header=%d", ) == 1) {
+   be->sizeheader = value != 0;
} else {
-   msg = createException(SQL, "SQLprepareClent", 
SQLSTATE(42000) "unexpected handshake option: %s", tok);
+   msg = createException(SQL, "SQLprepareClient", 
SQLSTATE(42000) "unexpected handshake option: %s", tok);
goto bailout;
}
 
@@ -1048,7 +1050,7 @@ SQLparser(Client c)
in->pos = in->len;  /* HACK: should use parsed 
length */
return MAL_SUCCEED;
}
-   if (strncmp(in->buf + in->pos, "sizeheader", 10) == 0) {
+   if (strncmp(in->buf + in->pos, "sizeheader", 10) == 0) { // no 
underscore
v = (int) strtol(in->buf + in->pos + 10, NULL, 10);
be->sizeheader = v != 0;
in->pos = in->len;  /* HACK: should use parsed 
length */
___
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list


MonetDB: mapihandshake - Send auto_commit and reply_size during ...

2021-02-02 Thread Joeri van Ruth
Changeset: 7a8306f47513 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=7a8306f47513
Modified Files:
clients/mapiclient/mclient.c
clients/mapilib/mapi.c
monetdb5/mal/mal_client.c
monetdb5/mal/mal_client.h
monetdb5/mal/mal_session.c
sql/backends/monet5/sql_scenario.c
Branch: mapihandshake
Log Message:

Send auto_commit and reply_size during the handshake

not as a separate Xcommand round trip


diffs (229 lines):

diff --git a/clients/mapiclient/mclient.c b/clients/mapiclient/mclient.c
--- a/clients/mapiclient/mclient.c
+++ b/clients/mapiclient/mclient.c
@@ -3538,6 +3538,10 @@ main(int argc, char **argv)
if (dbname)
free(dbname);
dbname = NULL;
+
+   mapi_cache_limit(mid, -1);
+   mapi_setAutocommit(mid, autocommit);
+
if (mid && mapi_error(mid) == MOK)
mapi_reconnect(mid);/* actually, initial connect */
 
@@ -3553,7 +3557,6 @@ main(int argc, char **argv)
mnstr_printf(stderr_stream, "%s\n", 
mapi_error_str(mid));
exit(2);
}
-   mapi_cache_limit(mid, -1);
if (dump) {
if (mode == SQL) {
exit(dump_database(mid, toConsole, 0, useinserts, 
false));
@@ -3567,9 +3570,6 @@ main(int argc, char **argv)
priv = (struct privdata) {0};
mapi_setfilecallback(mid, getfile, putfile, );
 
-   if (!autocommit)
-   mapi_setAutocommit(mid, autocommit);
-
if (logfile)
mapi_log(mid, logfile);
 
diff --git a/clients/mapilib/mapi.c b/clients/mapilib/mapi.c
--- a/clients/mapilib/mapi.c
+++ b/clients/mapilib/mapi.c
@@ -996,6 +996,7 @@ static int mapi_extend_bindings(MapiHdl 
 static int mapi_extend_params(MapiHdl hdl, int minparams);
 static void close_connection(Mapi mid);
 static MapiMsg read_into_cache(MapiHdl hdl, int lookahead);
+static MapiMsg mapi_Xcommand(Mapi mid, const char *cmdname, const char 
*cmdvalue);
 static int unquote(const char *msg, char **start, const char **next, int 
endchar, size_t *lenp);
 static int mapi_slice_row(struct MapiResultSet *result, int cr);
 static void mapi_store_bind(struct MapiResultSet *result, int cr);
@@ -1864,6 +1865,17 @@ mapi_close_handle(MapiHdl hdl)
return MOK;
 }
 
+static const struct MapiStruct MapiStructDefaults = {
+   .auto_commit = true,
+   .error = MOK,
+   .languageId = LANG_SQL,
+   .mapiversion = "mapi 1.0",
+   .cachelimit = 100,
+   .redirmax = 10,
+   .blk.eos = false,
+   .blk.lim = BLOCK,
+};
+
 /* Allocate a new connection handle. */
 static Mapi
 mapi_new(void)
@@ -1876,17 +1888,8 @@ mapi_new(void)
return NULL;
 
/* then fill in some details */
-   *mid = (struct MapiStruct) {
-   .index = (uint32_t) ATOMIC_ADD(, 1),  /* for 
distinctions in log records */
-   .auto_commit = true,
-   .error = MOK,
-   .languageId = LANG_SQL,
-   .mapiversion = "mapi 1.0",
-   .cachelimit = 100,
-   .redirmax = 10,
-   .blk.eos = false,
-   .blk.lim = BLOCK,
-   };
+   *mid = MapiStructDefaults;
+   mid->index =  (uint32_t) ATOMIC_ADD(, 1); /* for distinctions in 
log records */
if ((mid->blk.buf = malloc(mid->blk.lim + 1)) == NULL) {
mapi_destroy(mid);
return NULL;
@@ -2975,8 +2978,26 @@ mapi_reconnect(Mapi mid)
if (mid->languageId != LANG_SQL)
return mid->error;
 
-   /* tell server about cachelimit */
-   mapi_cache_limit(mid, mid->cachelimit);
+   if (mid->error != MOK)
+   return mid->error;
+
+   /* use X commands to send options that couldn't be sent in the 
handshake */
+   /* tell server about auto_complete and cache limit if handshake options 
weren't used */
+   if (mid->handshake_options <= MAPI_HANDSHAKE_AUTOCOMMIT && 
mid->auto_commit != MapiStructDefaults.auto_commit) {
+   char buf[2];
+   sprintf(buf, "%d", !!mid->auto_commit);
+   MapiMsg result = mapi_Xcommand(mid, "auto_commit", buf);
+   if (result != MOK)
+   return mid->error;
+   }
+   if (mid->handshake_options <= MAPI_HANDSHAKE_REPLY_SIZE && 
mid->cachelimit != MapiStructDefaults.cachelimit) {
+   char buf[50];
+   sprintf(buf, "%d", mid->cachelimit);
+   MapiMsg result = mapi_Xcommand(mid, "reply_size", buf);
+   if (result != MOK)
+   return mid->error;
+   }
+
return mid->error;
 }
 
@@ -3663,6 +3684,8 @@ mapi_setAutocommit(Mapi mid, bool autoco
return MERROR;
}
mid->auto_commit = autocommit;
+   if (!mid->connected)
+   return MOK;
if (autocommit)
return mapi_Xcommand(mid, "auto_commit", "1");

MonetDB: mapihandshake - Send settings in handshake response

2021-02-02 Thread Joeri van Ruth
Changeset: 878b5dbc5c37 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=878b5dbc5c37
Modified Files:
clients/mapilib/mapi.c
clients/mapilib/mapi.h
Branch: mapihandshake
Log Message:

Send settings in handshake response


diffs (123 lines):

diff --git a/clients/mapilib/mapi.c b/clients/mapilib/mapi.c
--- a/clients/mapilib/mapi.c
+++ b/clients/mapilib/mapi.c
@@ -879,6 +879,7 @@ struct MapiStruct {
struct BlockCache blk;
bool connected;
bool trace; /* Trace Mapi interaction */
+   int handshake_options;  /* which settings can be sent during 
challenge/response? */
bool auto_commit;
bool columnar_protocol;
MapiHdl first;  /* start of doubly-linked list */
@@ -2614,7 +2615,6 @@ mapi_reconnect(Mapi mid)
NULL
};
char **algs = algsv;
-   char *p;
 
/* rBuCQ9WTn3:mserver:9:RIPEMD160,SHA256,SHA1,MD5:LIT:SHA1: */
 
@@ -2639,6 +2639,16 @@ mapi_reconnect(Mapi mid)
* can't login. */
char *serverhash = strtok_r(NULL, ":", _state);
 
+   char *handshake_options = strtok_r(NULL, ":", _state);
+   if (handshake_options) {
+   if (sscanf(handshake_options, "sql=%d", 
>handshake_options) != 1) {
+   mapi_setError(mid, "invalid handshake options",
+   __func__, MERROR);
+   close_connection(mid);
+   return mid->error;
+   }
+   }
+
/* hash password, if not already */
if (mid->password[0] != '\1') {
char *pwdhash = NULL;
@@ -2701,14 +2711,15 @@ mapi_reconnect(Mapi mid)
 #endif
}
 
-   p = mid->password + 1;
+
+   char *pw = mid->password + 1;
 
char *hash = NULL;
for (; *algs != NULL; algs++) {
/* TODO: make this actually obey the separation by
* commas, and only allow full matches */
if (strstr(hashes, *algs) != NULL) {
-   char *pwh = mcrypt_hashPassword(*algs, p, chal);
+   char *pwh = mcrypt_hashPassword(*algs, pw, chal);
size_t len;
if (pwh == NULL)
continue;
@@ -2733,21 +2744,45 @@ mapi_reconnect(Mapi mid)
 
mnstr_set_bigendian(mid->from, strcmp(byteo, "BIG") == 0);
 
+   char *p = buf;
+   int remaining = sizeof(buf);
+   int n;
+#define CHECK_SNPRINTF(...) \
+   do { \
+   n = snprintf(p, remaining, __VA_ARGS__); \
+   if (n < remaining) { \
+   remaining -= n; \
+   p += n; \
+   } else { \
+   mapi_setError(mid, "combination of database name and 
user name too long", __func__, MERROR); \
+   free(hash); \
+   close_connection(mid); \
+   return mid->error; \
+   } \
+   } while (0)
+
+#ifdef WORDS_BIGENDIAN
+   char *our_endian = "BIG";
+#else
+   char *our_endian = "LIT";
+#endif
/* note: if we make the database field an empty string, it
* means we want the default.  However, it *should* be there. */
-   if (snprintf(buf, sizeof(buf), "%s:%s:%s:%s:%s:FILETRANS:\n",
-#ifdef WORDS_BIGENDIAN
-   "BIG",
-#else
-   "LIT",
-#endif
+   CHECK_SNPRINTF("%s:%s:%s:%s:%s:FILETRANS:",
+   our_endian,
mid->username, hash, mid->language,
-   mid->database == NULL ? "" : mid->database) >= (int) 
sizeof(buf)) {;
-   mapi_setError(mid, "combination of database name and user name 
too long", __func__, MERROR);
-   free(hash);
-   close_connection(mid);
-   return mid->error;
+   mid->database == NULL ? "" : mid->database);
+
+   if (mid->handshake_options > MAPI_HANDSHAKE_AUTOCOMMIT) {
+   CHECK_SNPRINTF("auto_commit=%d", mid->auto_commit);
}
+   if (mid->handshake_options > MAPI_HANDSHAKE_REPLY_SIZE) {
+   CHECK_SNPRINTF(",reply_size=%d", mid->cachelimit);
+   }
+   if (mid->handshake_options > 0) {
+   CHECK_SNPRINTF(":");
+   }
+   CHECK_SNPRINTF("\n");
 
free(hash);
 
diff --git a/clients/mapilib/mapi.h b/clients/mapilib/mapi.h
--- a/clients/mapilib/mapi.h
+++ b/clients/mapilib/mapi.h
@@ -28,7 +28,7 @@ typedef int MapiMsg;
 #define MSERVER(-4)
 
 enum mapi_handshake_options_levels {
-   MAPI_HANDSHAKE_AUTOCOMMIT,
+   MAPI_HANDSHAKE_AUTOCOMMIT = 1,
MAPI_HANDSHAKE_REPLY_SIZE,
// this must always be the last one:
MAPI_HANDSHAKE_OPTIONS_LEVEL,
___
checkin-list mailing list
checkin-list@monetdb.org

MonetDB: mapihandshake - Use strtok_r to parse the challenge line

2021-02-02 Thread Joeri van Ruth
Changeset: 2298085eeefc for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=2298085eeefc
Modified Files:
clients/mapilib/mapi.c
Branch: mapihandshake
Log Message:

Use strtok_r to parse the challenge line


diffs (127 lines):

diff --git a/clients/mapilib/mapi.c b/clients/mapilib/mapi.c
--- a/clients/mapilib/mapi.c
+++ b/clients/mapilib/mapi.c
@@ -2205,11 +2205,6 @@ mapi_reconnect(Mapi mid)
char buf[BLOCK];
size_t len;
MapiHdl hdl;
-   int pversion = 0;
-   char *chal;
-   char *server;
-   char *protover;
-   char *rest;
 
if (mid->connected)
close_connection(mid);
@@ -2556,27 +2551,29 @@ mapi_reconnect(Mapi mid)
return mid->error;
}
/* buf at this point looks like "challenge:servertype:protover[:.*]" */
-   chal = buf;
-   server = strchr(chal, ':');
+
+   char *strtok_state = NULL;
+   char *chal = strtok_r(buf, ":", _state);
+   if (chal == NULL) {
+   mapi_setError(mid, "Challenge string is not valid, challenge 
not found", __func__, MERROR);
+   close_connection(mid);
+   return mid->error;
+   }
+
+   char *server = strtok_r(NULL, ":", _state);
if (server == NULL) {
mapi_setError(mid, "Challenge string is not valid, server not 
found", __func__, MERROR);
close_connection(mid);
return mid->error;
}
-   *server++ = '\0';
-   protover = strchr(server, ':');
+
+   char *protover = strtok_r(NULL, ":", _state);
if (protover == NULL) {
mapi_setError(mid, "Challenge string is not valid, protocol not 
found", __func__, MERROR);
close_connection(mid);
return mid->error;
}
-   *protover++ = '\0';
-   rest = strchr(protover, ':');
-   if (rest != NULL) {
-   *rest++ = '\0';
-   }
-   pversion = atoi(protover);
-
+   int pversion = atoi(protover);
if (pversion != 9) {
/* because the headers changed, and because it makes no sense to
 * try and be backwards (or forwards) compatible, we bail out
@@ -2588,10 +2585,13 @@ mapi_reconnect(Mapi mid)
return mid->error;
}
 
-   char *hash = NULL;
-   char *hashes = NULL;
-   char *byteo = NULL;
-   char *serverhash = NULL;
+   char *hashes = strtok_r(NULL, ":", _state);
+   if (hashes == NULL) {
+   /* protocol violation, not enough fields */
+   mapi_setError(mid, "Not enough fields in challenge string", 
__func__, MERROR);
+   close_connection(mid);
+   return mid->error;
+   }
char *algsv[] = {
 #ifdef HAVE_RIPEMD160_UPDATE
"RIPEMD160",
@@ -2628,39 +2628,17 @@ mapi_reconnect(Mapi mid)
/* the database has sent a list of supported hashes to us, it's
* in the form of a comma separated list and in the variable
* rest.  We try to use the strongest algorithm. */
-   if (rest == NULL) {
-   /* protocol violation, not enough fields */
-   mapi_setError(mid, "Not enough fields in challenge string",
-   __func__, MERROR);
-   close_connection(mid);
-   return mid->error;
-   }
-   hashes = rest;
-   hash = strchr(hashes, ':'); /* temp misuse hash */
-   if (hash) {
-   *hash = '\0';
-   rest = hash + 1;
-   }
+
+
/* in rest now should be the byte order of the server */
-   byteo = rest;
-   hash = strchr(byteo, ':');
-   if (hash) {
-   *hash = '\0';
-   rest = hash + 1;
-   }
-   hash = NULL;
+   char *byteo = strtok_r(NULL, ":", _state);
 
/* Proto v9 is like v8, but mandates that the password is a
* hash, that is salted like in v8.  The hash algorithm is
* specified in the 6th field.  If we don't support it, we
* can't login. */
-   serverhash = rest;
-   hash = strchr(serverhash, ':');
-   if (hash) {
-   *hash = '\0';
-   /* rest = hash + 1; -- rest of string ignored */
-   }
-   hash = NULL;
+   char *serverhash = strtok_r(NULL, ":", _state);
+
/* hash password, if not already */
if (mid->password[0] != '\1') {
char *pwdhash = NULL;
@@ -2725,6 +2703,7 @@ mapi_reconnect(Mapi mid)
 
p = mid->password + 1;
 
+   char *hash = NULL;
for (; *algs != NULL; algs++) {
/* TODO: make this actually obey the separation by
* commas, and only allow full matches */
___
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list


MonetDB: mapihandshake - Reindent after flipping the version check

2021-02-02 Thread Joeri van Ruth
Changeset: 979f67cf4872 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=979f67cf4872
Modified Files:
clients/mapilib/mapi.c
Branch: mapihandshake
Log Message:

Reindent after flipping the version check


diffs (truncated from 349 to 300 lines):

diff --git a/clients/mapilib/mapi.c b/clients/mapilib/mapi.c
--- a/clients/mapilib/mapi.c
+++ b/clients/mapilib/mapi.c
@@ -2586,191 +2586,192 @@ mapi_reconnect(Mapi mid)
mapi_setError(mid, buf, __func__, MERROR);
close_connection(mid);
return mid->error;
-   } else {
-   char *hash = NULL;
-   char *hashes = NULL;
-   char *byteo = NULL;
-   char *serverhash = NULL;
-   char *algsv[] = {
+   }
+
+   char *hash = NULL;
+   char *hashes = NULL;
+   char *byteo = NULL;
+   char *serverhash = NULL;
+   char *algsv[] = {
 #ifdef HAVE_RIPEMD160_UPDATE
-   "RIPEMD160",
+   "RIPEMD160",
 #endif
 #ifdef HAVE_SHA512_UPDATE
-   "SHA512",
+   "SHA512",
 #endif
 #ifdef HAVE_SHA384_UPDATE
-   "SHA384",
+   "SHA384",
 #endif
 #ifdef HAVE_SHA256_UPDATE
-   "SHA256",
+   "SHA256",
 #endif
 #ifdef HAVE_SHA224_UPDATE
-   "SHA224",
+   "SHA224",
 #endif
 #ifdef HAVE_SHA1_UPDATE
-   "SHA1",
+   "SHA1",
 #endif
-   NULL
-   };
-   char **algs = algsv;
-   char *p;
-
-   /* rBuCQ9WTn3:mserver:9:RIPEMD160,SHA256,SHA1,MD5:LIT:SHA1: */
-
-   if (mid->username == NULL || mid->password == NULL) {
-   mapi_setError(mid, "username and password must be set",
- __func__, MERROR);
-   close_connection(mid);
-   return mid->error;
-   }
-
-   /* the database has sent a list of supported hashes to us, it's
-* in the form of a comma separated list and in the variable
-* rest.  We try to use the strongest algorithm. */
-   if (rest == NULL) {
-   /* protocol violation, not enough fields */
-   mapi_setError(mid, "Not enough fields in challenge 
string",
- __func__, MERROR);
-   close_connection(mid);
-   return mid->error;
-   }
-   hashes = rest;
-   hash = strchr(hashes, ':'); /* temp misuse hash */
-   if (hash) {
-   *hash = '\0';
-   rest = hash + 1;
-   }
-   /* in rest now should be the byte order of the server */
-   byteo = rest;
-   hash = strchr(byteo, ':');
-   if (hash) {
-   *hash = '\0';
-   rest = hash + 1;
-   }
-   hash = NULL;
-
-   /* Proto v9 is like v8, but mandates that the password is a
-* hash, that is salted like in v8.  The hash algorithm is
-* specified in the 6th field.  If we don't support it, we
-* can't login. */
-   serverhash = rest;
-   hash = strchr(serverhash, ':');
-   if (hash) {
-   *hash = '\0';
-   /* rest = hash + 1; -- rest of string ignored */
-   }
-   hash = NULL;
-   /* hash password, if not already */
-   if (mid->password[0] != '\1') {
-   char *pwdhash = NULL;
+   NULL
+   };
+   char **algs = algsv;
+   char *p;
+
+   /* rBuCQ9WTn3:mserver:9:RIPEMD160,SHA256,SHA1,MD5:LIT:SHA1: */
+
+   if (mid->username == NULL || mid->password == NULL) {
+   mapi_setError(mid, "username and password must be set",
+   __func__, MERROR);
+   close_connection(mid);
+   return mid->error;
+   }
+
+   /* the database has sent a list of supported hashes to us, it's
+   * in the form of a comma separated list and in the variable
+   * rest.  We try to use the strongest algorithm. */
+   if (rest == NULL) {
+   /* protocol violation, not enough fields */
+   mapi_setError(mid, "Not enough fields in challenge string",
+   __func__, MERROR);
+   close_connection(mid);
+   return mid->error;
+   }
+   hashes = rest;
+   hash = strchr(hashes, ':'); /* temp misuse hash */
+   if (hash) {
+   *hash = '\0';
+   rest = hash + 1;
+   }
+   /* in rest now should be the byte order of the server */
+   byteo 

MonetDB: mapihandshake - Invert mapi version check

2021-02-02 Thread Joeri van Ruth
Changeset: e76b19affeda for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=e76b19affeda
Modified Files:
clients/mapilib/mapi.c
Branch: mapihandshake
Log Message:

Invert mapi version check


diffs (37 lines):

diff --git a/clients/mapilib/mapi.c b/clients/mapilib/mapi.c
--- a/clients/mapilib/mapi.c
+++ b/clients/mapilib/mapi.c
@@ -2577,7 +2577,16 @@ mapi_reconnect(Mapi mid)
}
pversion = atoi(protover);
 
-   if (pversion == 9) {
+   if (pversion != 9) {
+   /* because the headers changed, and because it makes no sense to
+* try and be backwards (or forwards) compatible, we bail out
+* with a friendly message saying so */
+   snprintf(buf, sizeof(buf), "unsupported protocol version: %d, "
+"this client only supports version 9", pversion);
+   mapi_setError(mid, buf, __func__, MERROR);
+   close_connection(mid);
+   return mid->error;
+   } else {
char *hash = NULL;
char *hashes = NULL;
char *byteo = NULL;
@@ -2761,15 +2770,6 @@ mapi_reconnect(Mapi mid)
}
 
free(hash);
-   } else {
-   /* because the headers changed, and because it makes no sense to
-* try and be backwards (or forwards) compatible, we bail out
-* with a friendly message saying so */
-   snprintf(buf, sizeof(buf), "unsupported protocol version: %d, "
-"this client only supports version 9", pversion);
-   mapi_setError(mid, buf, __func__, MERROR);
-   close_connection(mid);
-   return mid->error;
}
if (mid->trace) {
printf("sending first request [%zu]:%s", sizeof(buf), buf);
___
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list


MonetDB: mapihandshake - Have mserver send :XOPTIONS:

2021-02-02 Thread Joeri van Ruth
Changeset: a686165c7116 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=a686165c7116
Modified Files:
clients/mapilib/mapi.h
monetdb5/modules/mal/mal_mapi.c
Branch: mapihandshake
Log Message:

Have mserver send :XOPTIONS:


diffs (41 lines):

diff --git a/clients/mapilib/mapi.h b/clients/mapilib/mapi.h
--- a/clients/mapilib/mapi.h
+++ b/clients/mapilib/mapi.h
@@ -27,6 +27,13 @@ typedef int MapiMsg;
 #define MMORE  (-3)
 #define MSERVER(-4)
 
+enum mapi_handshake_options_levels {
+   MAPI_HANDSHAKE_AUTOCOMMIT,
+   MAPI_HANDSHAKE_REPLY_SIZE,
+   // this must always be the last one:
+   MAPI_HANDSHAKE_OPTIONS_LEVEL,
+};
+
 /*
  * The table field information is extracted from the table headers
  * obtained from the server. This list may be extended in the future.
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
@@ -161,8 +161,8 @@ doChallenge(void *data)
return;
}
 
-   // send the challenge over the block stream
-   mnstr_printf(fdout, "%s:mserver:9:%s:%s:%s:",
+   // Send the challenge over the block stream
+   mnstr_printf(fdout, "%s:mserver:9:%s:%s:%s:sql=%d:",
challenge,
mcrypt_getHashAlgorithms(),
 #ifdef WORDS_BIGENDIAN
@@ -170,7 +170,8 @@ doChallenge(void *data)
 #else
"LIT",
 #endif
-   MONETDB5_PASSWDHASH
+   MONETDB5_PASSWDHASH,
+   MAPI_HANDSHAKE_OPTIONS_LEVEL
);
mnstr_flush(fdout, MNSTR_FLUSH_DATA);
/* get response */
___
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list


MonetDB: properties - Merged with default

2021-02-02 Thread Pedro Ferreira
Changeset: 6428e8b351b0 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=6428e8b351b0
Modified Files:
gdk/gdk_bbp.c
sql/backends/monet5/rel_bin.c
sql/server/rel_exp.c
sql/server/rel_optimizer.c
sql/server/rel_rewriter.c
sql/server/rel_rewriter.h
sql/server/sql_atom.c
sql/storage/store.c
Branch: properties
Log Message:

Merged with default


diffs (truncated from 3574 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
@@ -336,16 +336,25 @@ size_t HEAPmemsize(Heap *h);
 size_t HEAPvmsize(Heap *h);
 void IMPSdestroy(BAT *b);
 lng IMPSimprintsize(BAT *b);
+int MT_access(const char *pathname, int mode);
 int MT_check_nr_cores(void);
 int MT_create_thread(MT_Id *t, void (*function)(void *), void *arg, enum 
MT_thr_detach d, const char *threadname);
 void MT_exiting_thread(void);
+FILE *MT_fopen(const char *filename, const char *mode);
+char *MT_getcwd(char *buffer, size_t size);
 MT_Id MT_getpid(void);
 size_t MT_getrss(void);
 void MT_init(void);
 int MT_join_thread(MT_Id t);
-int MT_lockf(char *filename, int mode);
+int MT_lockf(const char *filename, int mode);
+int MT_mkdir(const char *dirname);
+int MT_open(const char *filename, int flags);
 bool MT_path_absolute(const char *path);
+int MT_remove(const char *filename);
+int MT_rename(const char *old, const char *new);
+int MT_rmdir(const char *dirname);
 void MT_sleep_ms(unsigned int ms);
+int MT_stat(const char *filename, struct stat *stb);
 const char *MT_thread_getalgorithm(void);
 void *MT_thread_getdata(void);
 const char *MT_thread_getname(void);
@@ -562,12 +571,9 @@ ssize_t timestamp_precision_tostr(str *b
 ssize_t timestamp_tostr(str *buf, size_t *len, const timestamp *val, bool 
external);
 ssize_t timestamp_tz_fromstr(const char *buf, size_t *len, timestamp **ret, 
bool external);
 const timestamp unixepoch;
+wchar_t *utf8towchar(const char *src);
 gdk_return void_inplace(BAT *b, oid id, const void *val, bool force) 
__attribute__((__warn_unused_result__));
-int win_mkdir(const char *, const int mode);
-int win_rename(const char *, const char *);
-int win_rmdir(const char *);
-int win_stat(const char *, struct stat *);
-int win_unlink(const char *);
+char *wchartoutf8(const wchar_t *src);
 int winerror(int);
 
 # mapi
diff --git a/clients/mapiclient/mclient.c b/clients/mapiclient/mclient.c
--- a/clients/mapiclient/mclient.c
+++ b/clients/mapiclient/mclient.c
@@ -1939,7 +1939,7 @@ format_result(Mapi mid, MapiHdl hdl, boo
if (timerHumanCalled)
timerHuman(sqloptimizer, maloptimizer, querytime, singleinstr, 
true);
if (mnstr_errnr(toConsole)) {
-   fprintf(stderr, "write error: %s\n", 
mnstr_peek_error(toConsole));
+   mnstr_printf(stderr_stream, "write error: %s\n", 
mnstr_peek_error(toConsole));
mnstr_clearerr(toConsole);
errseen = true;
}
@@ -2020,7 +2020,7 @@ doFileBulk(Mapi mid, stream *fp)
bufsize = 10240;
buf = malloc(bufsize + 1);
if (!buf) {
-   fprintf(stderr, "cannot allocate memory for send buffer\n");
+   mnstr_printf(stderr_stream, "cannot allocate memory for send 
buffer\n");
if (fp)
close_stream(fp);
return true;
@@ -2043,7 +2043,7 @@ doFileBulk(Mapi mid, stream *fp)
} else {
buf[length] = 0;
if (strlen(buf) < (size_t) length) {
-   fprintf(stderr, "NULL byte in input\n");
+   mnstr_printf(stderr_stream, "NULL byte in 
input\n");
errseen = true;
break;
}
@@ -2235,7 +2235,7 @@ doFile(Mapi mid, stream *fp, bool useins
rl.s = fp;
rl.buf = NULL;
if ((fp = callback_stream(, myread, NULL, NULL, mydestroy, 
mnstr_name(fp))) == NULL) {
-   fprintf(stderr,"Malloc for doFile failed");
+   mnstr_printf(stderr_stream,"Malloc for doFile failed");
exit(2);
}
 #endif
@@ -2243,7 +2243,7 @@ doFile(Mapi mid, stream *fp, bool useins
 #ifdef HAVE_ICONV
if (encoding) {
if ((fp = iconv_rstream(fp, encoding, mnstr_name(fp))) == NULL) 
{
-   fprintf(stderr,"Malloc failure");
+   mnstr_printf(stderr_stream,"Malloc failure");
exit(2);
}
}
@@ -2257,7 +2257,7 @@ doFile(Mapi mid, stream *fp, bool useins
bufsiz = READBLOCK;
buf = malloc(bufsiz);
if (buf == NULL) {
-   fprintf(stderr,"Malloc for doFile failed");
+   mnstr_printf(stderr_stream,"Malloc for doFile failed");
   

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: Oct2020 - Merged with Jun2020

2021-02-02 Thread Pedro Ferreira
Changeset: 0a258a97c2c0 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=0a258a97c2c0
Modified Files:
sql/backends/monet5/rel_bin.c
Branch: Oct2020
Log Message:

Merged with Jun2020


diffs (40 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
@@ -2524,13 +2524,16 @@ rel2bin_semijoin(backend *be, sql_rel *r
list *l, *sexps = NULL;
node *en = NULL, *n;
stmt *left = NULL, *right = NULL, *join = NULL, *jl, *jr, *c, *lcand = 
NULL;
-   int semijoin_only = 0;
+   int semijoin_only = 0, l_is_base = 0;
 
if (rel->op == op_anti && !list_empty(rel->exps) && 
list_length(rel->exps) == 1 && ((sql_exp*)rel->exps->h->data)->flag == 
mark_notin)
return rel2bin_antijoin(be, rel, refs);
 
-   if (rel->l) /* first construct the left sub relation */
-   left = subrel_bin(be, rel->l, refs);
+   if (rel->l) { /* first construct the left sub relation */
+   sql_rel *l = rel->l;
+   l_is_base = is_basetable(l->op);
+   left = subrel_bin(be, l, refs);
+   }
if (rel->r) /* first construct the right sub relation */
right = subrel_bin(be, rel->r, refs);
if (!left || !right)
@@ -2730,10 +2733,14 @@ rel2bin_semijoin(backend *be, sql_rel *r
 
/* project all the left columns */
for( n = left->op4.lval->h; n; n = n->next ) {
-   stmt *c = n->data;
+   stmt *c = n->data, *s;
const char *rnme = table_name(sql->sa, c);
const char *nme = column_name(sql->sa, c);
-   stmt *s = stmt_project(be, join, column(be, c));
+
+   if (l_is_base && nme[0] == '%' && strcmp(nme, TID) == 0)
+   s = join;
+   else
+   s = stmt_project(be, join, column(be, c));
 
s = stmt_alias(be, s, rnme, nme);
list_append(l, s);
___
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list


MonetDB: properties - Another swap

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

Another swap


diffs (14 lines):

diff --git a/sql/server/rel_statistics_functions.c 
b/sql/server/rel_statistics_functions.c
--- a/sql/server/rel_statistics_functions.c
+++ b/sql/server/rel_statistics_functions.c
@@ -498,8 +498,8 @@ sql_day_propagate_statistics(mvc *sql, s
}
}
 
-   set_property(sql, e, PROP_MAX, atom_int(sql->sa, 
sql_bind_localtype(localtype), nmin));
-   set_property(sql, e, PROP_MIN, atom_int(sql->sa, 
sql_bind_localtype(localtype), nmax));
+   set_property(sql, e, PROP_MAX, atom_int(sql->sa, 
sql_bind_localtype(localtype), nmax));
+   set_property(sql, e, PROP_MIN, atom_int(sql->sa, 
sql_bind_localtype(localtype), nmin));
 }
 
 static void
___
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list


MonetDB: properties - I messed some some functions min/max values

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

I messed some some functions min/max values


diffs (145 lines):

diff --git a/sql/server/rel_statistics_functions.c 
b/sql/server/rel_statistics_functions.c
--- a/sql/server/rel_statistics_functions.c
+++ b/sql/server/rel_statistics_functions.c
@@ -106,8 +106,8 @@ sql_sub_propagate_statistics(mvc *sql, s
str msg1 = NULL, msg2 = NULL;
 
if (strcmp(f->func->mod, "calc") == 0) {
-   res1 = atom_sub(atom_dup(sql->sa, lmax), 
atom_dup(sql->sa, rmax));
-   res2 = atom_sub(atom_dup(sql->sa, lmin), 
atom_dup(sql->sa, rmin));
+   res1 = atom_sub(atom_dup(sql->sa, lmax), 
atom_dup(sql->sa, rmin));
+   res2 = atom_sub(atom_dup(sql->sa, lmin), 
atom_dup(sql->sa, rmax));
} else {
sql_subtype tp;
 
@@ -117,16 +117,16 @@ sql_sub_propagate_statistics(mvc *sql, s
 
switch (t1->type->eclass) {
case EC_DATE: {
-   res1 = atom_int(sql->sa, 
sql_bind_localtype("int"), date_diff_imp((date)lmax->data.val.ival, 
(date)rmax->data.val.ival));
-   res2 = atom_int(sql->sa, 
sql_bind_localtype("int"), date_diff_imp((date)lmin->data.val.ival, 
(date)rmin->data.val.ival));
+   res1 = atom_int(sql->sa, 
sql_bind_localtype("int"), date_diff_imp((date)lmax->data.val.ival, 
(date)rmin->data.val.ival));
+   res2 = atom_int(sql->sa, 
sql_bind_localtype("int"), date_diff_imp((date)lmin->data.val.ival, 
(date)rmax->data.val.ival));
} break;
case EC_TIME: {
-   res1 = atom_int(sql->sa, 
sql_bind_localtype("lng"), daytime_diff((daytime)lmax->data.val.lval, 
(daytime)rmax->data.val.lval));
-   res2 = atom_int(sql->sa, 
sql_bind_localtype("lng"), daytime_diff((daytime)lmin->data.val.lval, 
(daytime)rmin->data.val.lval));
+   res1 = atom_int(sql->sa, 
sql_bind_localtype("lng"), daytime_diff((daytime)lmax->data.val.lval, 
(daytime)rmin->data.val.lval));
+   res2 = atom_int(sql->sa, 
sql_bind_localtype("lng"), daytime_diff((daytime)lmin->data.val.lval, 
(daytime)rmax->data.val.lval));
} break;
case EC_TIMESTAMP: {
-   res1 = atom_int(sql->sa, 
sql_bind_localtype("lng"), tsdiff((timestamp)lmax->data.val.lval, 
(timestamp)rmax->data.val.lval));
-   res2 = atom_int(sql->sa, 
sql_bind_localtype("lng"), tsdiff((timestamp)lmin->data.val.lval, 
(timestamp)rmin->data.val.lval));
+   res1 = atom_int(sql->sa, 
sql_bind_localtype("lng"), tsdiff((timestamp)lmax->data.val.lval, 
(timestamp)rmin->data.val.lval));
+   res2 = atom_int(sql->sa, 
sql_bind_localtype("lng"), tsdiff((timestamp)lmin->data.val.lval, 
(timestamp)rmax->data.val.lval));
} break;
default:
break;
@@ -134,8 +134,8 @@ sql_sub_propagate_statistics(mvc *sql, s
} else if (strcmp(f->func->imp, 
"date_sub_msec_interval") == 0) {
date sub1, sub2;
 
-   if (!(msg1 = date_sub_msec_interval(, 
(date)lmax->data.val.ival, rmax->data.val.lval)) &&
-   !(msg2 = date_sub_msec_interval(, 
(date)lmin->data.val.ival, rmin->data.val.lval))) {
+   if (!(msg1 = date_sub_msec_interval(, 
(date)lmax->data.val.ival, rmin->data.val.lval)) &&
+   !(msg2 = date_sub_msec_interval(, 
(date)lmin->data.val.ival, rmax->data.val.lval))) {
sql_find_subtype(, "date", 0, 0);
res1 = atom_general_ptr(sql->sa, , 
);
res2 = atom_general_ptr(sql->sa, , 
);
@@ -143,15 +143,15 @@ sql_sub_propagate_statistics(mvc *sql, s
} else if (strcmp(f->func->imp, 
"date_sub_month_interval") == 0) {
date sub1, sub2;
 
-   if (!(msg1 = date_submonths(, 
(date)lmax->data.val.ival, rmax->data.val.ival)) &&
-   !(msg2 = date_submonths(, 
(date)lmin->data.val.ival, rmin->data.val.ival))) {
+   if (!(msg1 = date_submonths(, 

MonetDB: nospare - properly initialize schema

2021-02-02 Thread Niels Nes
Changeset: 9f60966ec4ee for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=9f60966ec4ee
Modified Files:
sql/storage/store.c
Branch: nospare
Log Message:

properly initialize schema


diffs (25 lines):

diff --git a/sql/storage/store.c b/sql/storage/store.c
--- a/sql/storage/store.c
+++ b/sql/storage/store.c
@@ -3499,7 +3499,11 @@ schema_dup(sql_trans *tr, sql_schema *s)
 {
sql_schema *ns = SA_ZNEW(tr->sa, sql_schema);
 
-   *ns = *s;
+   base_init(tr->sa, >base, s->base.id, 0, s->base.name);
+   ns->auth_id = s->auth_id;
+   ns->owner = s->owner;
+   ns->system = s->system;
+
ns->tables = os_new(tr->sa, (destroy_fptr) _destroy, 
isTempSchema(s), true);
ns->seqs = os_new(tr->sa, (destroy_fptr) _destroy, isTempSchema(s), 
true);
ns->keys = os_new(tr->sa, (destroy_fptr) _destroy, isTempSchema(s), 
true);
@@ -3522,6 +3526,8 @@ schema_dup(sql_trans *tr, sql_schema *s)
/* we can share the funcs and types */
ns->funcs = os_dup(s->funcs);
ns->types = os_dup(s->types);
+   ns->store = s->store;
+   ns->internal = NULL;
return ns;
 }
 
___
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list


MonetDB: properties - Global aggregates may return NULL

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

Global aggregates may return NULL


diffs (13 lines):

diff --git a/sql/server/rel_statistics.c b/sql/server/rel_statistics.c
--- a/sql/server/rel_statistics.c
+++ b/sql/server/rel_statistics.c
@@ -350,7 +350,8 @@ rel_propagate_statistics(visitor *v, sql
if (look)
look(sql, e);
}
-   if (!e->semantics && e->l && !have_nil(e->l))
+   assert(e->type == e_func || is_groupby(rel->op));
+   if (!e->semantics && e->l && !have_nil(e->l) && (e->type != 
e_aggr || list_length(rel->r)))
set_has_no_nil(e);
} break;
case e_atom: {
___
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list


MonetDB: nospare - merged

2021-02-02 Thread Niels Nes
Changeset: 94bd88d5484e for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=94bd88d5484e
Branch: nospare
Log Message:

merged


diffs (51 lines):

diff --git a/sql/storage/objectset.c b/sql/storage/objectset.c
--- a/sql/storage/objectset.c
+++ b/sql/storage/objectset.c
@@ -12,13 +12,7 @@
 
 #include "gdk_atoms.h"
 
-
-/* TODO
- * implement new double linked list
- * keep hash/map of names -> objectversion
- */
-
-struct versionhead ;// TODO: rename to object_version_chain
+struct versionhead ;
 
 #define active (0)
 #define id_based_rollbacked(1)
@@ -109,7 +103,6 @@ find_id(objectset *os, sqlid id)
return NULL;
}
MT_lock_unset(>ht_lock);
-   // TODO: can we actually reach this point?
for (versionhead  *n = os->id_based_h; n; n = n->next) {
objectversion *ov = n->ov;
 
@@ -145,7 +138,7 @@ node_destroy(objectset *os, sqlstore *st
 {
if (!os->sa)
_DELETE(n);
-   (void)store; /* todo destroy b */
+   (void)store;
 }
 
 static versionhead  *
@@ -663,7 +656,6 @@ find_name(objectset *os, const char *nam
return NULL;
}
MT_lock_unset(>ht_lock);
-   // TODO: can we actually reach this point?
for (versionhead  *n = os->name_based_h; n; n = n->next) {
objectversion *ov = n->ov;
 
@@ -676,7 +668,6 @@ find_name(objectset *os, const char *nam
return NULL;
 }
 
-
 static objectversion*
 get_valid_object_name(sql_trans *tr, objectversion *ov)
 {
___
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list


MonetDB: nospare - fixed some leaks

2021-02-02 Thread Niels Nes
Changeset: 1c99592f6b9f for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=1c99592f6b9f
Modified Files:
sql/backends/monet5/rel_bin.c
sql/server/rel_psm.c
sql/storage/store.c
Branch: nospare
Log Message:

fixed some leaks


diffs (97 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
@@ -4523,12 +4523,16 @@ cascade_ukey(backend *be, stmt **updates
case ACT_SET_NULL:
case ACT_SET_DEFAULT:
case ACT_CASCADE:
-   if (!sql_update_cascade_Fkeys(be, fk, tids, 
updates, ((sql_fkey*)fk)->on_update))
+   if (!sql_update_cascade_Fkeys(be, fk, tids, 
updates, ((sql_fkey*)fk)->on_update)) {
+   list_destroy(keys);
return -1;
+   }
break;
default:/*RESTRICT*/
-   if (!join_updated_pkey(be, fk, tids, updates))
+   if (!join_updated_pkey(be, fk, tids, updates)) {
+   list_destroy(keys);
return -1;
+   }
}
}
list_destroy(keys);
diff --git a/sql/server/rel_psm.c b/sql/server/rel_psm.c
--- a/sql/server/rel_psm.c
+++ b/sql/server/rel_psm.c
@@ -1018,10 +1018,14 @@ rel_create_func(sql_query *query, dlist 
return sql_error(sql, 01, SQLSTATE(42000) 
"CREATE %s: external name %s.%s not bound (%s.%s)", F, fmod, fnme, 
s->base.name, fname );
} else {
sql_func *f = sf->func;
-   if (!f->mod || strcmp(f->mod, fmod))
+   if (!f->mod || strcmp(f->mod, fmod)) {
+   _DELETE(f->mod);
f->mod = SA_STRDUP(NULL, fmod) 
;//(f->sa)?sa_strdup(f->sa, fmod):sa_strdup(sql->pa, fmod);
-   if (!f->imp || strcmp(f->imp, fnme))
+   }
+   if (!f->imp || strcmp(f->imp, fnme)) {
+   _DELETE(f->imp);
f->imp = SA_STRDUP(NULL, 
fnme);//(f->sa)?sa_strdup(f->sa, fnme):sa_strdup(sql->pa, fnme);
+   }
if (!f->mod || !f->imp)
return sql_error(sql, 02, 
SQLSTATE(HY013) "CREATE %s: could not allocate space", F);
f->sql = 0; /* native */
diff --git a/sql/storage/store.c b/sql/storage/store.c
--- a/sql/storage/store.c
+++ b/sql/storage/store.c
@@ -3375,7 +3375,7 @@ sql_trans_rollback(sql_trans *tr)
list_prepend(tr->localtmps.set, 
dup_table(tt));
n = next;
}
-   list_destroy(tr->localtmps.dset);
+   list_destroy2(tr->localtmps.dset, tr->store);
}
/* cleanup new */
if (tr->localtmps.nelm) {
@@ -3459,6 +3459,7 @@ sql_trans_destroy(sql_trans *tr)
}
if (tr->changes)
sql_trans_rollback(tr);
+   cs_destroy(>localtmps, tr->store);
_DELETE(tr);
return res;
 }
@@ -3531,7 +3532,7 @@ sql_trans_create(sqlstore *store, sql_tr
if (tr) {
tr->ts = store_timestamp(store);
tr->active = 1;
-   cs_new(>localtmps, tr->sa, (fdestroy) NULL);
+   cs_new(>localtmps, tr->sa, (fdestroy) _destroy);
}
return tr;
 }
@@ -3854,10 +3855,15 @@ sys_drop_default_object(sql_trans *tr, s
char *schema = NULL, *seq_name = NULL;
 
extract_schema_and_sequence_name(tr->sa, col->def + 
strlen(next_value_for), , _name);
-   if (!schema || !seq_name || !(s = find_sql_schema(tr, schema)))
+   if (!schema || !seq_name || !(s = find_sql_schema(tr, schema))) 
{
+   _DELETE(schema);
+   _DELETE(seq_name);
return -1;
+   }
 
seq = find_sql_sequence(tr, s, seq_name);
+   _DELETE(schema);
+   _DELETE(seq_name);
if (seq && sql_trans_get_dependency_type(tr, seq->base.id, 
BEDROPPED_DEPENDENCY) > 0) {
sys_drop_sequence(tr, seq, drop_action);
if (os_del(s->seqs, tr, seq->base.name, 
dup_base(>base)))
@@ -5897,7 +5903,7 @@ sql_trans_create_sequence(sql_trans *tr,
sql_table *sysseqs = find_sql_table(tr, syss, "sequences");

MonetDB: nospare - Update some comments.

2021-02-02 Thread Aris Koning
Changeset: 22260eda62b3 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=22260eda62b3
Modified Files:
sql/storage/objectset.c
Branch: nospare
Log Message:

Update some comments.


diffs (51 lines):

diff --git a/sql/storage/objectset.c b/sql/storage/objectset.c
--- a/sql/storage/objectset.c
+++ b/sql/storage/objectset.c
@@ -12,13 +12,7 @@
 
 #include "gdk_atoms.h"
 
-
-/* TODO
- * implement new double linked list
- * keep hash/map of names -> objectversion
- */
-
-struct versionhead ;// TODO: rename to object_version_chain
+struct versionhead ;
 
 #define active (0)
 #define id_based_rollbacked(1)
@@ -109,7 +103,6 @@ find_id(objectset *os, sqlid id)
return NULL;
}
MT_lock_unset(>ht_lock);
-   // TODO: can we actually reach this point?
for (versionhead  *n = os->id_based_h; n; n = n->next) {
objectversion *ov = n->ov;
 
@@ -145,7 +138,7 @@ node_destroy(objectset *os, sqlstore *st
 {
if (!os->sa)
_DELETE(n);
-   (void)store; /* todo destroy b */
+   (void)store;
 }
 
 static versionhead  *
@@ -663,7 +656,6 @@ find_name(objectset *os, const char *nam
return NULL;
}
MT_lock_unset(>ht_lock);
-   // TODO: can we actually reach this point?
for (versionhead  *n = os->name_based_h; n; n = n->next) {
objectversion *ov = n->ov;
 
@@ -676,7 +668,6 @@ find_name(objectset *os, const char *nam
return NULL;
 }
 
-
 static objectversion*
 get_valid_object_name(sql_trans *tr, objectversion *ov)
 {
___
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list


MonetDB: default - Use wide character interface on Windows.

2021-02-02 Thread Sjoerd Mullender
Changeset: 3db95780d2ea for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=3db95780d2ea
Modified Files:
clients/mapiclient/mclient.c
clients/mapiclient/msqldump.c
Branch: default
Log Message:

Use wide character interface on Windows.


diffs (truncated from 414 to 300 lines):

diff --git a/clients/mapiclient/mclient.c b/clients/mapiclient/mclient.c
--- a/clients/mapiclient/mclient.c
+++ b/clients/mapiclient/mclient.c
@@ -1939,7 +1939,7 @@ format_result(Mapi mid, MapiHdl hdl, boo
if (timerHumanCalled)
timerHuman(sqloptimizer, maloptimizer, querytime, singleinstr, 
true);
if (mnstr_errnr(toConsole)) {
-   fprintf(stderr, "write error: %s\n", 
mnstr_peek_error(toConsole));
+   mnstr_printf(stderr_stream, "write error: %s\n", 
mnstr_peek_error(toConsole));
mnstr_clearerr(toConsole);
errseen = true;
}
@@ -2020,7 +2020,7 @@ doFileBulk(Mapi mid, stream *fp)
bufsize = 10240;
buf = malloc(bufsize + 1);
if (!buf) {
-   fprintf(stderr, "cannot allocate memory for send buffer\n");
+   mnstr_printf(stderr_stream, "cannot allocate memory for send 
buffer\n");
if (fp)
close_stream(fp);
return true;
@@ -2043,7 +2043,7 @@ doFileBulk(Mapi mid, stream *fp)
} else {
buf[length] = 0;
if (strlen(buf) < (size_t) length) {
-   fprintf(stderr, "NULL byte in input\n");
+   mnstr_printf(stderr_stream, "NULL byte in 
input\n");
errseen = true;
break;
}
@@ -2235,7 +2235,7 @@ doFile(Mapi mid, stream *fp, bool useins
rl.s = fp;
rl.buf = NULL;
if ((fp = callback_stream(, myread, NULL, NULL, mydestroy, 
mnstr_name(fp))) == NULL) {
-   fprintf(stderr,"Malloc for doFile failed");
+   mnstr_printf(stderr_stream,"Malloc for doFile failed");
exit(2);
}
 #endif
@@ -2243,7 +2243,7 @@ doFile(Mapi mid, stream *fp, bool useins
 #ifdef HAVE_ICONV
if (encoding) {
if ((fp = iconv_rstream(fp, encoding, mnstr_name(fp))) == NULL) 
{
-   fprintf(stderr,"Malloc failure");
+   mnstr_printf(stderr_stream,"Malloc failure");
exit(2);
}
}
@@ -2257,7 +2257,7 @@ doFile(Mapi mid, stream *fp, bool useins
bufsiz = READBLOCK;
buf = malloc(bufsiz);
if (buf == NULL) {
-   fprintf(stderr,"Malloc for doFile failed");
+   mnstr_printf(stderr_stream,"Malloc for doFile failed");
exit(2);
}
 
@@ -2285,7 +2285,7 @@ doFile(Mapi mid, stream *fp, bool useins
if (l <= 0)
break;
if (!seen_null_byte && strlen(buf + length) < (size_t) 
l) {
-   fprintf(stderr, "NULL byte in input on line %d 
of input\n", lineno);
+   mnstr_printf(stderr_stream, "NULL byte in input 
on line %d of input\n", lineno);
seen_null_byte = true;
errseen = true;
if (hdl) {
@@ -2300,7 +2300,7 @@ doFile(Mapi mid, stream *fp, bool useins
if (newbuf) {
buf = newbuf;
} else {
-   fprintf(stderr,"Malloc failure");
+   mnstr_printf(stderr_stream,"Malloc failure");
length = 0;
errseen = true;
if (hdl) {
@@ -2432,7 +2432,7 @@ doFile(Mapi mid, stream *fp, bool useins
wantsSystem = true;
break;
default:
-   fprintf(stderr, 
"unknown sub-command for \\d: %c\n", *line);
+   
mnstr_printf(stderr_stream, "unknown sub-command for \\d: %c\n", *line);
length = 0;
line[1] = '\0';
break;
@@ -2478,7 +2478,7 @@ doFile(Mapi mid, stream *fp, bool useins
}
*q = '\0';
if (escaped) {
-   fprintf(stderr, "unexpected end 
of string while "
+

MonetDB: clean-projects - rel_remove_empty_select acts on joins too

2021-02-02 Thread Pedro Ferreira
Changeset: 85dc3217a49d for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=85dc3217a49d
Modified Files:
sql/server/rel_optimizer.c
Branch: clean-projects
Log Message:

rel_remove_empty_select acts on joins too


diffs (43 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
@@ -9710,8 +9710,7 @@ optimize_rel(mvc *sql, sql_rel *rel, int
rel = rel_join_order(, rel);
rel = rel_visitor_bottomup(, rel, _push_join_down_union);
/* rel_join_order may introduce empty selects */
-   if (gp.cnt[op_select])
-   rel = rel_visitor_bottomup(, rel, 
_remove_empty_select);
+   rel = rel_visitor_bottomup(, rel, _remove_empty_select);
 
if (level <= 0)
rel = rel_visitor_bottomup(, rel, 
_join_push_exps_down);
@@ -9722,8 +9721,7 @@ optimize_rel(mvc *sql, sql_rel *rel, int
rel = rel_visitor_topdown(, rel, _push_count_down);
if (level <= 0) {
rel = rel_visitor_topdown(, rel, 
_push_select_down);
-   if (gp.cnt[op_select])
-   rel = rel_visitor_bottomup(, rel, 
_remove_empty_select);
+   rel = rel_visitor_bottomup(, rel, 
_remove_empty_select);
rel = rel_visitor_topdown(, rel, _push_join_down);
}
 
@@ -9750,8 +9748,7 @@ optimize_rel(mvc *sql, sql_rel *rel, int
   because pushing down select expressions makes rel_join_order more 
difficult */
if (gp.cnt[op_select] || gp.cnt[op_join] || gp.cnt[op_semi] || 
gp.cnt[op_anti]) {
rel = rel_visitor_topdown(, rel, _push_select_down);
-   if (gp.cnt[op_select])
-   rel = rel_visitor_bottomup(, rel, 
_remove_empty_select);
+   rel = rel_visitor_bottomup(, rel, _remove_empty_select);
}
 
if (gp.cnt[op_join] || gp.cnt[op_left] || gp.cnt[op_right] || 
gp.cnt[op_full] || gp.cnt[op_semi] || gp.cnt[op_anti]) {
@@ -9781,8 +9778,7 @@ optimize_rel(mvc *sql, sql_rel *rel, int
gp.cnt[op_semi] || gp.cnt[op_anti] || gp.cnt[op_select]) {
rel = rel_visitor_bottomup(, rel, _push_func_down);
rel = rel_visitor_topdown(, rel, _push_select_down);
-   if (gp.cnt[op_select])
-   rel = rel_visitor_bottomup(, rel, 
_remove_empty_select);
+   rel = rel_visitor_bottomup(, rel, _remove_empty_select);
}
 
if (gp.cnt[op_topn] || gp.cnt[op_sample])
___
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list


MonetDB: Jun2020 - for semijoins(basetable, R), we can replace t...

2021-02-02 Thread Niels Nes
Changeset: 55264f4d9116 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=55264f4d9116
Modified Files:
sql/backends/monet5/rel_bin.c
Branch: Jun2020
Log Message:

for semijoins(basetable, R), we can replace the 'TID' projection by the
semijoin result.


diffs (40 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
@@ -2555,13 +2555,16 @@ rel2bin_semijoin(backend *be, sql_rel *r
list *l, *sexps = NULL;
node *en = NULL, *n;
stmt *left = NULL, *right = NULL, *join = NULL, *jl, *jr, *c, *lcand = 
NULL;
-   int semijoin_only = 0;
+   int semijoin_only = 0, l_is_base = 0;
 
if (rel->op == op_anti && !list_empty(rel->exps) && 
list_length(rel->exps) == 1 && ((sql_exp*)rel->exps->h->data)->flag == 
mark_notin)
return rel2bin_antijoin(be, rel, refs);
 
-   if (rel->l) /* first construct the left sub relation */
-   left = subrel_bin(be, rel->l, refs);
+   if (rel->l) { /* first construct the left sub relation */
+   sql_rel *l = rel->l;
+   l_is_base = is_basetable(l->op);
+   left = subrel_bin(be, l, refs);
+   }
if (rel->r) /* first construct the right sub relation */
right = subrel_bin(be, rel->r, refs);
if (!left || !right)
@@ -2763,10 +2766,14 @@ rel2bin_semijoin(backend *be, sql_rel *r
 
/* project all the left columns */
for( n = left->op4.lval->h; n; n = n->next ) {
-   stmt *c = n->data;
+   stmt *c = n->data, *s;
const char *rnme = table_name(sql->sa, c);
const char *nme = column_name(sql->sa, c);
-   stmt *s = stmt_project(be, join, column(be, c));
+
+   if (l_is_base && nme[0] == '%' && strcmp(nme, TID) == 0)
+   s = join;
+   else
+   s = stmt_project(be, join, column(be, c));
 
s = stmt_alias(be, s, rnme, nme);
list_append(l, s);
___
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list