Changeset: 1d4b34b056bb for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=1d4b34b056bb
Modified Files:
        sql/backends/monet5/sql.c
        sql/include/sql_catalog.h
        sql/server/rel_schema.c
        sql/server/sql_mvc.c
        sql/server/sql_mvc.h
        sql/storage/sql_storage.h
        sql/storage/store.c
Branch: arrays
Log Message:

number of cells stored in sql_table


diffs (truncated from 309 to 300 lines):

diff --git a/sql/backends/monet5/sql.c b/sql/backends/monet5/sql.c
--- a/sql/backends/monet5/sql.c
+++ b/sql/backends/monet5/sql.c
@@ -440,7 +440,7 @@ create_table_or_view(mvc *sql, char *sna
        }
 
        //create a copy of the table without the changesets
-       nt = sql_trans_create_table(sql->session->tr, s, t->base.name, 
t->query, t->type, t->system, temp, t->commit_action, t->sz);
+       nt = sql_trans_create_table(sql->session->tr, s, t->base.name, 
t->query, t->type, t->system, temp, t->commit_action, t->sz, t->cellsNum);
 
        if(isArray(t)) {
                assert(t->dimensions.set); //an array should always have 
dimensional column(s)
@@ -1642,7 +1642,7 @@ mvc_create_dimension_bat(mvc *m, char *s
        sql_schema *s = NULL;
        sql_table *t = NULL;
        sql_dimension *dim = NULL;
-       long repeat1 = 0, repeat2 =0, totalElements =0;
+       long repeat1 = 0, repeat2 =0;
        long  i=0, j=0;
 
        s = mvc_bind_schema(m, sname);
@@ -1660,21 +1660,18 @@ mvc_create_dimension_bat(mvc *m, char *s
 
 #define materialiseDim(TPE, min, step, max)                     \
     do {                                \
-                       TPE it, *elements; \
-                       totalElements = floor((max - min )/ step)+1; \
+                       TPE it, *elements = NULL; \
 \
-               if((b = BATnew(TYPE_void, TYPE_##TPE, 
totalElements*repeat1*repeat2, TRANSIENT)) == NULL)   \
+               if((b = BATnew(TYPE_void, TYPE_##TPE, t->cellsNum, TRANSIENT)) 
== NULL)   \
                        return NULL;                   \
 \
                elements = (TPE*) Tloc(b, BUNfirst(b));          \
 \
-                       totalElements = 0; \
                        for(j=0; j<repeat2; j++) { \
                        for(it = min ; it <= max ; it += step) { \
                        for(i=0; i<repeat1; i++) { \
                                *elements = (TPE) it; \
                                elements++; \
-                               totalElements++; \
                        } \
                        } \
                } \
@@ -1715,7 +1712,7 @@ mvc_create_dimension_bat(mvc *m, char *s
                        fprintf(stderr, "mvc_create_dimension_bat: dimension 
type not handled\n");
        }
 
-       BATsetcount(b,totalElements);
+       BATsetcount(b,t->cellsNum);
     BATderiveProps(b,FALSE);
 
        return b;
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
@@ -470,7 +470,7 @@ typedef struct sql_dimension {
 
        lng lvl1_repeatsNum; //number of times each value of the dimension is 
repeated before being increased
        lng lvl2_repeatsNum; //number of times all values of the dimension are 
repeated as a group (including the duplicated values defined by repeatNum)
-       lng elementsNum; //the distinct number of elements in this dimension, 
i.e. the number of indices
+       lng elementsNum;
 
        struct sql_table *t;
 //     void *data; //it does not have data since it is not materialised
@@ -508,6 +508,8 @@ typedef struct sql_table {
        ca_t commit_action;     /* on commit action */
        char *query;            /* views may require some query */
        int  sz;
+       
+       lng cellsNum; //It is used when having an array. It helps when creating 
empty cells
 
        sql_ukey *pkey;
        changeset dimensions; //used only when the table is an array
diff --git a/sql/server/rel_schema.c b/sql/server/rel_schema.c
--- a/sql/server/rel_schema.c
+++ b/sql/server/rel_schema.c
@@ -952,6 +952,8 @@ int compute_repeats(mvc *sql, sql_table 
        for(i=i-1; i>=0; i--)
                dims_array[i]->lvl2_repeatsNum = 
dims_array[i+1]->lvl2_repeatsNum * dims_array[i+1]->elementsNum;
 
+       //number of cells in table
+       t->cellsNum = 
dims_array[0]->elementsNum*dims_array[0]->lvl1_repeatsNum*dims_array[0]->lvl2_repeatsNum;
        return SQL_OK;
 }
 
@@ -988,7 +990,7 @@ sql_rel* rel_create_array(mvc *sql, sql_
        } else if (temp != SQL_DECLARED_ARRAY && (!schema_privs(sql->role_id, 
s) && !(isTempSchema(s) && temp == SQL_LOCAL_TEMP))){
                return sql_error(sql, 02, "42000!CREATE ARRAY: insufficient 
privileges for user '%s' in schema '%s'", stack_get_string(sql, 
"current_user"), s->base.name);
        } else if (array_elements->token == SQL_CREATE_ARRAY) { 
-               sql_table *t = mvc_create_table(sql, s, name, tt, 0, 
SQL_DECLARED_ARRAY, commit_action, -1);
+               sql_table *t = mvc_create_array(sql, s, name, tt, 0, 
SQL_DECLARED_ARRAY, commit_action, -1, 0);
 
                dlist *columns = array_elements->data.lval;
                dnode *n;
diff --git a/sql/server/sql_mvc.c b/sql/server/sql_mvc.c
--- a/sql/server/sql_mvc.c
+++ b/sql/server/sql_mvc.c
@@ -977,6 +977,23 @@ mvc_drop_trigger(mvc *m, sql_schema *s, 
 }
 
 sql_table *
+mvc_create_array(mvc *m, sql_schema *s, const char *name, int tt, bit system, 
int persistence, int commit_action, int sz, long cellsNum)
+{
+       sql_table *t = NULL;
+
+       if (mvc_debug)
+               fprintf(stderr, "#mvc_create_table %s %s %d %d %d %d\n", 
s->base.name, name, tt, system, persistence, commit_action);
+
+       if ((persistence == SQL_DECLARED_TABLE || persistence == 
SQL_DECLARED_ARRAY) && (!s || strcmp(s->base.name, dt_schema))) {
+               t = create_sql_array(m->sa, name, tt, system, persistence, 
commit_action, cellsNum);
+               t->s = s;
+       } else {
+               t = sql_trans_create_table(m->session->tr, s, name, NULL, tt, 
system, persistence, commit_action, sz, cellsNum);
+       }
+       return t;
+}
+
+sql_table *
 mvc_create_table(mvc *m, sql_schema *s, const char *name, int tt, bit system, 
int persistence, int commit_action, int sz)
 {
        sql_table *t = NULL;
@@ -988,7 +1005,7 @@ mvc_create_table(mvc *m, sql_schema *s, 
                t = create_sql_table(m->sa, name, tt, system, persistence, 
commit_action);
                t->s = s;
        } else {
-               t = sql_trans_create_table(m->session->tr, s, name, NULL, tt, 
system, persistence, commit_action, sz);
+               t = sql_trans_create_table(m->session->tr, s, name, NULL, tt, 
system, persistence, commit_action, sz, 0);
        }
        return t;
 }
@@ -1006,7 +1023,7 @@ mvc_create_view(mvc *m, sql_schema *s, c
                t->s = s;
                t->query = sa_strdup(m->sa, sql);
        } else {
-               t = sql_trans_create_table(m->session->tr, s, name, sql, 
tt_view, system, SQL_PERSIST, 0, 0);
+               t = sql_trans_create_table(m->session->tr, s, name, sql, 
tt_view, system, SQL_PERSIST, 0, 0, 0);
        }
        return t;
 }
@@ -1024,7 +1041,7 @@ mvc_create_remote(mvc *m, sql_schema *s,
                t->s = s;
                t->query = sa_strdup(m->sa, loc);
        } else {
-               t = sql_trans_create_table(m->session->tr, s, name, loc, 
tt_remote, 0, SQL_REMOTE, 0, 0);
+               t = sql_trans_create_table(m->session->tr, s, name, loc, 
tt_remote, 0, SQL_REMOTE, 0, 0, 0);
        }
        return t;
 }
diff --git a/sql/server/sql_mvc.h b/sql/server/sql_mvc.h
--- a/sql/server/sql_mvc.h
+++ b/sql/server/sql_mvc.h
@@ -182,6 +182,7 @@ extern sql_schema *mvc_create_schema(mvc
 extern BUN mvc_clear_table(mvc *m, sql_table *t);
 extern void mvc_drop_table(mvc *c, sql_schema *s, sql_table * t, int 
drop_action);
 extern sql_table *mvc_create_table(mvc *c, sql_schema *s, const char *name, 
int tt, bit system, int persistence, int commit_action, int sz);
+extern sql_table *mvc_create_array(mvc *c, sql_schema *s, const char *name, 
int tt, bit system, int persistence, int commit_action, int sz, long cellsNum);
 extern sql_table *mvc_create_view(mvc *c, sql_schema *s, const char *name, int 
persistence, const char *sql, bit system);
 extern sql_table *mvc_create_remote(mvc *c, sql_schema *s, const char *name, 
int persistence, const char *loc);
 
diff --git a/sql/storage/sql_storage.h b/sql/storage/sql_storage.h
--- a/sql/storage/sql_storage.h
+++ b/sql/storage/sql_storage.h
@@ -323,7 +323,7 @@ extern void reset_functions(sql_trans *t
 extern sql_schema *sql_trans_create_schema(sql_trans *tr, const char *name, 
int auth_id, int owner);
 extern void sql_trans_drop_schema(sql_trans *tr, int id, int drop_action);
 
-extern sql_table *sql_trans_create_table(sql_trans *tr, sql_schema *s, const 
char *name, const char *sql, int tt, bit system, int persistence, int 
commit_action, int sz);
+extern sql_table *sql_trans_create_table(sql_trans *tr, sql_schema *s, const 
char *name, const char *sql, int tt, bit system, int persistence, int 
commit_action, int sz, long cellsNum);
 extern sql_table *sql_trans_add_table(sql_trans *tr, sql_table *mt, sql_table 
*pt);
 extern sql_table *sql_trans_del_table(sql_trans *tr, sql_table *mt, sql_table 
*pt, int drop_action);
 
@@ -382,6 +382,7 @@ extern int sql_trans_disconnect_catalog(
 extern int sql_trans_disconnect_catalog_ALL(sql_trans *tr);
 
 extern sql_table *create_sql_table(sql_allocator *sa, const char *name, sht 
type, bit system, int persistence, int commit_action);
+extern sql_table *create_sql_array(sql_allocator *sa, const char *name, sht 
type, bit system, int persistence, int commit_action, long cellsNum);
 extern sql_column *create_sql_column(sql_allocator *sa, sql_table *t, const 
char *name, sql_subtype *tpe);
 extern sql_dimension *create_sql_dimension(sql_allocator *sa, sql_table *t, 
const char *name, sql_subtype *tpe);
 extern sql_ukey *create_sql_ukey(sql_allocator *sa, sql_table *t, const char 
*nme, key_type kt);
diff --git a/sql/storage/store.c b/sql/storage/store.c
--- a/sql/storage/store.c
+++ b/sql/storage/store.c
@@ -710,6 +710,9 @@ load_table(sql_trans *tr, sql_schema *s,
        t->s = s;
        t->sz = COLSIZE;
 
+       v = table_funcs.column_find_value(tr, find_sql_column(tables, 
"cells"),rid);
+       t->cellsNum = *(long*)v;        _DELETE(v);
+
        cs_new(&t->columns, tr->sa, (fdestroy) &column_destroy);
        cs_new(&t->dimensions, tr->sa, NULL);
        cs_new(&t->idxs, tr->sa, (fdestroy) &idx_destroy);
@@ -1121,7 +1124,7 @@ insert_schemas(sql_trans *tr)
                        sql_table *t = m->data;
                        sht ca = t->commit_action;
 
-                       table_funcs.table_insert(tr, systable, &t->base.id, 
t->base.name, &s->base.id, ATOMnilptr(TYPE_str), &t->type, &t->system, &ca, 
&t->access);
+                       table_funcs.table_insert(tr, systable, &t->base.id, 
t->base.name, &s->base.id, ATOMnilptr(TYPE_str), &t->type, &t->system, &ca, 
&t->access, &t->cellsNum);
                        for (o = t->columns.set->h; o; o = o->next) {
                                sql_column *c = o->data;
 
@@ -1298,6 +1301,36 @@ create_sql_table(sql_allocator *sa, cons
        t->commit_action = (ca_t)commit_action;
        t->query = NULL;
        t->access = 0;
+       t->cellsNum = 0;
+       cs_new(&t->dimensions, sa, NULL); //dimensions are not materialised, 
thus do not need to be destroyed
+       cs_new(&t->columns, sa, (fdestroy) &column_destroy);
+       cs_new(&t->idxs, sa, (fdestroy) &idx_destroy);
+       cs_new(&t->keys, sa, (fdestroy) &key_destroy);
+       cs_new(&t->triggers, sa, (fdestroy) &trigger_destroy);
+       t->pkey = NULL;
+       t->sz = COLSIZE;
+       t->cleared = 0;
+       t->s = NULL;
+       return t;
+}
+
+sql_table *
+create_sql_array(sql_allocator *sa, const char *name, sht type, bit system, 
int persistence, int commit_action, long cellsNum)
+{
+       sql_table *t = SA_ZNEW(sa, sql_table);
+
+       assert(sa);
+       assert((persistence==SQL_PERSIST ||
+               persistence==SQL_DECLARED_TABLE || 
persistence==SQL_DECLARED_ARRAY || 
+               commit_action) && commit_action>=0);
+       base_init(sa, &t->base, next_oid(), TR_NEW, name);
+       t->type = type;
+       t->system = system;
+       t->persistence = (temp_t)persistence;
+       t->commit_action = (ca_t)commit_action;
+       t->query = NULL;
+       t->access = 0;
+       t->cellsNum = cellsNum;
        cs_new(&t->dimensions, sa, NULL); //dimensions are not materialised, 
thus do not need to be destroyed
        cs_new(&t->columns, sa, (fdestroy) &column_destroy);
        cs_new(&t->idxs, sa, (fdestroy) &idx_destroy);
@@ -1344,6 +1377,8 @@ dup_sql_table(sql_allocator *sa, sql_tab
        nt->access = t->access;
        nt->query = (t->query) ? sa_strdup(sa, t->query) : NULL;
 
+       nt->cellsNum = t->cellsNum;
+
        for (n = t->columns.set->h; n; n = n->next) 
                dup_sql_column(sa, nt, n->data);
        nt->columns.dset = NULL;
@@ -1548,6 +1583,7 @@ store_init(int debug, store_type store, 
                bootstrap_create_column(tr, t, "system", "boolean", 1);
                bootstrap_create_column(tr, t, "commit_action", "smallint", 16);
                bootstrap_create_column(tr, t, "access", "smallint", 16);
+               bootstrap_create_column(tr, t, "cells", "bigint", 64);
 
                t = bootstrap_create_table(tr, s, "_columns");
                bootstrap_create_column(tr, t, "id", "int", 32);
@@ -2116,7 +2152,6 @@ dimension_dup(sql_trans *tr, int flag, s
 
        dim->lvl1_repeatsNum = odim->lvl1_repeatsNum; 
        dim->lvl2_repeatsNum = odim->lvl2_repeatsNum; 
-       dim->elementsNum = odim->elementsNum; 
 
        dim->t = t;
 
@@ -2346,6 +2381,7 @@ table_dup(sql_trans *tr, int flag, sql_t
        t->commit_action = ot->commit_action;
        t->access = ot->access;
        t->query = (ot->query) ? sa_strdup(sa, ot->query) : NULL;
+       t->cellsNum = ot->cellsNum;
 
        cs_new(&t->columns, sa, (fdestroy) &column_destroy);
        cs_new(&t->dimensions, sa, NULL);
@@ -4316,7 +4352,7 @@ sql_trans_del_table(sql_trans *tr, sql_t
 }
 
 sql_table *
-sql_trans_create_table(sql_trans *tr, sql_schema *s, const char *name, const 
char *sql, int tt, bit system, int persistence, int commit_action, int sz)
+sql_trans_create_table(sql_trans *tr, sql_schema *s, const char *name, const 
char *sql, int tt, bit system, int persistence, int commit_action, int sz, long 
cellsNum)
 {
        sql_table *t = create_sql_table(tr->sa, name, tt, system, persistence, 
commit_action);
        sql_schema *syss = find_sql_schema(tr, isGlobal(t)?"sys":"tmp");
@@ -4333,6 +4369,8 @@ sql_trans_create_table(sql_trans *tr, sq
        t->sz = sz;
        if (sz < 0)
                t->sz = COLSIZE;
+       t->cellsNum = cellsNum;
+
        cs_add(&s->tables, t, TR_NEW);
        if (isStream(t))
                t->persistence = SQL_STREAM;
@@ -4351,7 +4389,7 @@ sql_trans_create_table(sql_trans *tr, sq
        if (!isDeclaredTable(t) && !isDeclaredArray(t))
                table_funcs.table_insert(tr, systable, &t->base.id, 
t->base.name, &s->base.id,
                        (t->query) ? t->query : ATOMnilptr(TYPE_str), &t->type,
-                       &t->system, &ca, &t->access);
+                       &t->system, &ca, &t->access, &t->cellsNum);
 
        t->base.wtime = s->base.wtime = tr->wtime = tr->wstime;
        if (isGlobal(t)) 
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to