Changeset: 88c3392da908 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=88c3392da908
Modified Files:
        ctest/tools/monetdbe/example_decimals.c
        sql/backends/monet5/sql_result.c
        sql/include/sql_catalog.h
        sql/storage/bat/res_table.c
Branch: default
Log Message:

small improvement of result set (ie keep nr_rows)


diffs (150 lines):

diff --git a/ctest/tools/monetdbe/example_decimals.c 
b/ctest/tools/monetdbe/example_decimals.c
--- a/ctest/tools/monetdbe/example_decimals.c
+++ b/ctest/tools/monetdbe/example_decimals.c
@@ -60,7 +60,10 @@ main(void)
                                        if (col->data[r] == col->null_value) {
                                                printf("NULL");
                                        } else {
-                                               printf("%d", col->data[r]);
+                                               if (col->scale)
+                                                       printf("%d.%02d", 
col->data[r]/(int)col->scale, col->data[r]%(int)col->scale);
+                                               else
+                                                       printf("%d", 
col->data[r]);
                                        }
                                        break;
                                }
@@ -78,7 +81,10 @@ main(void)
                                        if (col->data[r] == col->null_value) {
                                                printf("NULL");
                                        } else {
-                                               printf("%" PRId64, 
col->data[r]);
+                                               if (col->scale)
+                                                       printf("%" PRId64 
".%03" PRId64, col->data[r]/(int64_t)col->scale, 
col->data[r]%(int64_t)col->scale);
+                                               else
+                                                       printf("%" PRId64, 
col->data[r]);
                                        }
                                        break;
                                }
diff --git a/sql/backends/monet5/sql_result.c b/sql/backends/monet5/sql_result.c
--- a/sql/backends/monet5/sql_result.c
+++ b/sql/backends/monet5/sql_result.c
@@ -2150,7 +2150,6 @@ mvc_export_head_prot10(backend *b, strea
        size_t i = 0;
        BUN count = 0;
        res_table *t = res_tables_find(m->results, res_id);
-       BAT *order = NULL;
        int fres = 0;
 
        if (!t || !s) {
@@ -2160,11 +2159,7 @@ mvc_export_head_prot10(backend *b, strea
        /* tuple count */
        if (only_header) {
                if (t->order) {
-                       order = BBPquickdesc(t->order, false);
-                       if (!order)
-                               return -1;
-
-                       count = BATcount(order);
+                       count = t->nr_rows;
                } else
                        count = 1;
        }
@@ -2312,7 +2307,6 @@ mvc_export_head(backend *b, stream *s, i
        int i, res = 0;
        BUN count = 0;
        res_table *t = res_tables_find(m->results, res_id);
-       BAT *order = NULL;
 
        if (!s || !t)
                return 0;
@@ -2334,13 +2328,10 @@ mvc_export_head(backend *b, stream *s, i
        /* tuple count */
        if (only_header) {
                if (t->order) {
-                       order = BBPquickdesc(t->order, false);
-                       if (!order)
-                               return -1;
-
-                       count = BATcount(order);
-               } else
+                       count = t->nr_rows;
+               } else {
                        count = 1;
+               }
        }
        m->rowcnt = count;
        sqlvar_set_number(find_global_var(m, mvc_bind_schema(m, "sys"), 
"rowcnt"), m->rowcnt);
@@ -2467,7 +2458,7 @@ mvc_export_file(backend *b, stream *s, r
                order = BATdescriptor(t->order);
                if (!order)
                        return -1;
-               count = BATcount(order);
+               count = t->nr_rows;
 
                res = mvc_export_table(b, s, t, order, 0, count, "", t->tsep, 
t->rsep, t->ssep, t->ns);
                BBPunfix(order->batCacheid);
@@ -2514,8 +2505,8 @@ mvc_export_result(backend *b, stream *s,
                return -1;
 
        count = m->reply_size;
-       if (m->reply_size != -2 && (count <= 0 || count >= BATcount(order))) {
-               count = BATcount(order);
+       if (m->reply_size != -2 && (count <= 0 || count >= t->nr_rows)) {
+               count = t->nr_rows;
                clean = 1;
        }
        if (json) {
@@ -2565,11 +2556,11 @@ mvc_export_chunk(backend *b, stream *s, 
                return -1;
        cnt = nr;
        if (cnt == 0)
-               cnt = BATcount(order);
-       if (offset >= BATcount(order))
+               cnt = t->nr_rows;
+       if (offset >= t->nr_rows)
                cnt = 0;
-       if (cnt == BUN_NONE || offset + cnt > BATcount(order))
-               cnt = BATcount(order) - offset;
+       if (cnt == BUN_NONE || offset + cnt > t->nr_rows)
+               cnt = t->nr_rows - offset;
 
        if (b->client->protocol != PROTOCOL_10) {
                /* query type: Q_BLOCK */
diff --git a/sql/include/sql_catalog.h b/sql/include/sql_catalog.h
--- a/sql/include/sql_catalog.h
+++ b/sql/include/sql_catalog.h
@@ -683,6 +683,7 @@ typedef struct res_table {
        oid query_id;
        mapi_query_t query_type;
        int nr_cols;
+       BUN nr_rows;
        int cur_col;
        const char *tsep;
        const char *rsep;
diff --git a/sql/storage/bat/res_table.c b/sql/storage/bat/res_table.c
--- a/sql/storage/bat/res_table.c
+++ b/sql/storage/bat/res_table.c
@@ -35,6 +35,7 @@ res_table_create(sql_trans *tr, int res_
        t->query_id = query_id;
        t->query_type = type;
        t->nr_cols = nr_cols;
+       t->nr_rows = 0;
        t->cur_col = 0;
        t->cols = NEW_ARRAY(res_col, nr_cols);
        if(!t->cols) {
@@ -49,6 +50,7 @@ res_table_create(sql_trans *tr, int res_
        if (order) {
                t->order = order->batCacheid;
                bat_incref(t->order);
+               t->nr_rows = BATcount(order);
        } 
        t->next = next;
        return t;
@@ -98,6 +100,7 @@ res_col_create(sql_trans *tr, res_table 
                                return NULL;
                        }
                        t->order = o->batCacheid;
+                       t->nr_rows = 1;
                        BBPkeepref(t->order);
                }
        }
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to