Changeset: 96fa303980e1 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/96fa303980e1
Modified Files:
        clients/mapiclient/mclient.1
        clients/mapiclient/mclient.c
        gdk/gdk_aggr.c
        gdk/gdk_batop.c
        gdk/gdk_logger.c
        gdk/gdk_logger_internals.h
        gdk/gdk_logger_old.c
        sql/backends/monet5/sql_cat.c
        sql/backends/monet5/sql_user.c
        sql/backends/monet5/vaults/fits/fits.c
        sql/server/sql_mvc.c
        sql/server/sql_privileges.c
        sql/storage/store.c
Branch: default
Log Message:

Merge with Sep2022 branch.


diffs (truncated from 1983 to 300 lines):

diff --git a/clients/ChangeLog.Sep2022 b/clients/ChangeLog.Sep2022
--- a/clients/ChangeLog.Sep2022
+++ b/clients/ChangeLog.Sep2022
@@ -1,3 +1,8 @@
 # ChangeLog file for clients
 # This file is updated with Maddlog
 
+* Mon Apr 17 2023 Sjoerd Mullender <sjo...@acm.org>
+- If the number of rows in mclient is set to 0 (using either --rows=0
+  option or \r0 on the mclient command line), the internal pager is used
+  and it then uses the height of the terminal window.
+
diff --git a/clients/mapiclient/mclient.1 b/clients/mapiclient/mclient.1
--- a/clients/mapiclient/mclient.1
+++ b/clients/mapiclient/mclient.1
@@ -320,6 +320,8 @@ query.  Remote content is retrieved by
 \fB\-\-rows=\fP\fInr\fP (\fB\-r\fP \fInr\fP)
 If specified, query results will be paged by an internal pager at the
 specified number of lines.
+If set to \fB0\fP (zero), use the height of the terminal.
+The default is \fB\-1\fP which means no pager is used.
 .TP
 \fB\-\-width=\fP\fInr\fP (\fB\-w\fP \fInr\fP)
 Specify the width of the screen.
@@ -422,7 +424,11 @@ If
 .I rows
 is
 .BR \-1 ,
-stop using the internal pager.
+stop using the internal pager, if
+.I rows
+is
+.BR 0 ,
+use the height of the terminal.
 .SS
 SQL Commands
 .TP
diff --git a/clients/mapiclient/mclient.c b/clients/mapiclient/mclient.c
--- a/clients/mapiclient/mclient.c
+++ b/clients/mapiclient/mclient.c
@@ -126,8 +126,9 @@ static char *pager = 0;             /* use external
 #ifdef HAVE_SIGACTION
 #include <signal.h>            /* to block SIGPIPE */
 #endif
-static int rowsperpage = 0;    /* for SQL pagination */
+static int rowsperpage = -1;   /* for SQL pagination */
 static int pagewidth = 0;      /* -1: take whatever is necessary, >0: limit */
+static int pageheight = 0;     /* -1: take whatever is necessary, >0: limit */
 static bool pagewidthset = false; /* whether the user set the width explicitly 
*/
 static int croppedfields = 0;  /* whatever got cropped/truncated */
 static bool firstcrop = true;  /* first time we see cropping/truncation */
@@ -1375,7 +1376,7 @@ SQLdebugRendering(MapiHdl hdl)
 }
 
 static void
-SQLpagemove(int *len, int fields, int *ps, bool *silent)
+SQLpagemove(int *len, int fields, int *ps, bool *skiprest)
 {
        char buf[512];
        ssize_t sz;
@@ -1388,11 +1389,11 @@ SQLpagemove(int *len, int fields, int *p
                if (buf[0] == 'c')
                        *ps = 0;
                if (buf[0] == 'q')
-                       *silent = true;
+                       *skiprest = true;
                while (sz > 0 && buf[sz - 1] != '\n')
                        sz = mnstr_readline(fromConsole, buf, sizeof(buf));
        }
-       if (!*silent)
+       if (!*skiprest)
                SQLseparator(len, fields, '-');
 }
 
@@ -1403,11 +1404,12 @@ SQLrenderer(MapiHdl hdl)
        int fields, rfields, printfields = 0, max = 1, graphwaste = 0;
        int *len = NULL, *hdr = NULL, *numeric = NULL;
        char **rest = NULL;
-       char buf[50];
        int ps = rowsperpage;
-       bool silent = false;
-       int64_t rows = 0;
+       bool skiprest = false;
+       int64_t rows;                           /* total number of rows */
 
+       if (ps == 0)
+               ps = pageheight;
        croppedfields = 0;
        fields = mapi_get_field_count(hdl);
        rows = mapi_get_row_count(hdl);
@@ -1565,8 +1567,10 @@ SQLrenderer(MapiHdl hdl)
                        break;
        }
 
-       rows = SQLheader(hdl, len, printfields, fields != printfields);
+       int64_t lines;                          /* count number of lines 
printed for pager */
+       lines = SQLheader(hdl, len, printfields, fields != printfields);
 
+       int64_t nrows = 0;                      /* count number of rows printed 
*/
        while ((rfields = fetch_row(hdl)) != 0) {
                if (mnstr_errnr(toConsole) != MNSTR_NO__ERROR)
                        continue;
@@ -1576,7 +1580,7 @@ SQLrenderer(MapiHdl hdl)
                                     "got %d columns, expected %d, ignoring\n", 
rfields, fields);
                        continue;
                }
-               if (silent)
+               if (skiprest)
                        continue;
                for (i = 0; i < printfields; i++) {
                        rest[i] = mapi_fetch_field(hdl, i);
@@ -1605,22 +1609,24 @@ SQLrenderer(MapiHdl hdl)
                        }
                }
 
-               if (ps > 0 && rows >= ps && fromConsole != NULL) {
-                       SQLpagemove(len, printfields, &ps, &silent);
-                       rows = 0;
-                       if (silent) {
+               if (ps > 0 && lines >= ps && fromConsole != NULL) {
+                       SQLpagemove(len, printfields, &ps, &skiprest);
+                       lines = 0;
+                       if (skiprest) {
                                mapi_finish(hdl);
                                break;
                        }
                }
 
-               rows += SQLrow(len, numeric, rest, printfields, 2, 0);
+               nrows++;
+               lines += SQLrow(len, numeric, rest, printfields, 2, 0);
        }
-       if (fields)
+       if (fields && !skiprest)
                SQLseparator(len, printfields, '-');
-       rows = mapi_get_row_count(hdl);
-       snprintf(buf, sizeof(buf), "%" PRId64 " rows", rows);
-       mnstr_printf(toConsole, "%" PRId64 " tuple%s", rows, rows != 1 ? "s" : 
"");
+       if (skiprest)
+               mnstr_printf(toConsole, "%" PRId64 " of %" PRId64 " tuple%s", 
nrows, rows, nrows != 1 ? "s" : "");
+       else
+               mnstr_printf(toConsole, "%" PRId64 " tuple%s", rows, rows != 1 
? "s" : "");
 
        if (fields != printfields || croppedfields > 0)
                mnstr_printf(toConsole, " !");
@@ -1735,12 +1741,13 @@ setWidth(void)
 #ifdef TIOCGWINSZ
                struct winsize ws;
 
-               if (ioctl(fileno(stdout), TIOCGWINSZ, &ws) == 0 && ws.ws_col > 
0)
+               if (ioctl(fileno(stdout), TIOCGWINSZ, &ws) == 0 && ws.ws_col > 
0) {
                        pagewidth = ws.ws_col;
-               else
+                       pageheight = ws.ws_row;
+               } else
 #endif
                {
-                       pagewidth = -1;
+                       pagewidth = pageheight = -1;
                }
        }
 }
diff --git a/gdk/gdk_aggr.c b/gdk/gdk_aggr.c
--- a/gdk/gdk_aggr.c
+++ b/gdk/gdk_aggr.c
@@ -3611,98 +3611,127 @@ BATmin_skipnil(BAT *b, void *aggr, bit s
                Heap *oidxh = NULL;
                bool usepoidx = false;
 
-               if (BATcheckorderidx(b)) {
-                       MT_lock_set(&b->batIdxLock);
-                       oidxh = b->torderidx;
-                       if (oidxh != NULL)
-                               HEAPincref(oidxh);
-                       MT_lock_unset(&b->batIdxLock);
-               }
-               if (oidxh == NULL &&
-                   pb != NULL &&
-                   BATcheckorderidx(pb)) {
-                       /* no lock on b needed since it's a view */
-                       MT_lock_set(&pb->batIdxLock);
-                       MT_lock_set(&pb->theaplock);
-                       if (pb->tbaseoff == bi.baseoff &&
-                           BATcount(pb) == bi.count &&
-                           pb->hseqbase == b->hseqbase &&
-                           (oidxh = pb->torderidx) != NULL) {
-                               HEAPincref(oidxh);
-                               usepoidx = true;
+               if (BATordered(b)) {
+                       if (skipnil && !bi.nonil) {
+                               pos = binsearch(NULL, 0, bi.type, bi.base,
+                                               bi.vh ? bi.vh->base : NULL,
+                                               bi.width, 0, bi.count,
+                                               ATOMnilptr(bi.type), 1, 1);
+                               if (pos == bi.count)
+                                       pos = oid_nil;
+                               else
+                                       pos += b->hseqbase;
+                       } else {
+                               pos = b->hseqbase;
                        }
-                       MT_lock_unset(&pb->batIdxLock);
-                       MT_lock_unset(&pb->theaplock);
-               }
-               if (oidxh != NULL) {
-                       const oid *ords = (const oid *) oidxh->base + 
ORDERIDXOFF;
-                       BUN r;
-                       if (!bi.nonil) {
-                               MT_thread_setalgorithm(usepoidx ? "binsearch on 
parent oidx" : "binsearch on oidx");
-                               r = binsearch(ords, 0, bi.type, bi.base,
-                                             bi.vh ? bi.vh->base : NULL,
-                                             bi.width, 0, bi.count,
-                                             ATOMnilptr(bi.type), 1, 1);
-                               if (r == 0) {
-                                       /* there are no nils, record that */
-                                       MT_lock_set(&b->theaplock);
-                                       if (b->batCount == bi.count) {
-                                               b->tnonil = true;
-                                       }
-                                       MT_lock_unset(&b->theaplock);
-                               }
-                               bat_iterator_end(&bi);
+               } else if (BATordered_rev(b)) {
+                       if (skipnil && !bi.nonil) {
+                               pos = binsearch(NULL, 0, bi.type, bi.base,
+                                               bi.vh ? bi.vh->base : NULL,
+                                               bi.width, 0, bi.count,
+                                               ATOMnilptr(bi.type), -1, 1);
+                               if (pos == 0)
+                                       pos = oid_nil;
+                               else
+                                       pos = pos + b->hseqbase - 1;
                        } else {
-                               r = 0;
+                               pos = bi.count + b->hseqbase - 1;
                        }
-                       if (r == bi.count) {
-                               /* no non-nil values */
-                               pos = oid_nil;
-                       } else {
-                               MT_thread_setalgorithm(usepoidx ? "using parent 
oidx" : "using oidx");
-                               pos = ords[r];
-                       }
-                       HEAPdecref(oidxh, false);
                } else {
-                       Imprints *imprints = NULL;
-                       if ((pb == NULL || bi.count == BATcount(pb)) &&
-                           BATcheckimprints(b)) {
-                               if (pb != NULL) {
-                                       MT_lock_set(&pb->batIdxLock);
-                                       imprints = pb->timprints;
-                                       if (imprints != NULL)
-                                               IMPSincref(imprints);
-                                       else
-                                               imprints = NULL;
-                                       MT_lock_unset(&pb->batIdxLock);
+                       if (BATcheckorderidx(b)) {
+                               MT_lock_set(&b->batIdxLock);
+                               oidxh = b->torderidx;
+                               if (oidxh != NULL)
+                                       HEAPincref(oidxh);
+                               MT_lock_unset(&b->batIdxLock);
+                       }
+                       if (oidxh == NULL &&
+                           pb != NULL &&
+                           BATcheckorderidx(pb)) {
+                               /* no lock on b needed since it's a view */
+                               MT_lock_set(&pb->batIdxLock);
+                               MT_lock_set(&pb->theaplock);
+                               if (pb->tbaseoff == bi.baseoff &&
+                                   BATcount(pb) == bi.count &&
+                                   pb->hseqbase == b->hseqbase &&
+                                   (oidxh = pb->torderidx) != NULL) {
+                                       HEAPincref(oidxh);
+                                       usepoidx = true;
+                               }
+                               MT_lock_unset(&pb->batIdxLock);
+                               MT_lock_unset(&pb->theaplock);
+                       }
+                       if (oidxh != NULL) {
+                               const oid *ords = (const oid *) oidxh->base + 
ORDERIDXOFF;
+                               BUN r;
+                               if (!bi.nonil) {
+                                       MT_thread_setalgorithm(usepoidx ? 
"binsearch on parent oidx" : "binsearch on oidx");
+                                       r = binsearch(ords, 0, bi.type, bi.base,
+                                                     bi.vh ? bi.vh->base : 
NULL,
+                                                     bi.width, 0, bi.count,
+                                                     ATOMnilptr(bi.type), 1, 
1);
+                                       if (r == 0) {
+                                               /* there are no nils, record 
that */
+                                               MT_lock_set(&b->theaplock);
+                                               if (b->batCount == bi.count) {
+                                                       b->tnonil = true;
+                                               }
+                                               MT_lock_unset(&b->theaplock);
+                                       }
+                                       bat_iterator_end(&bi);
                                } else {
-                                       MT_lock_set(&b->batIdxLock);
-                                       imprints = b->timprints;
_______________________________________________
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org

Reply via email to