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

extended the catalog with the additional values used by the arrays


diffs (254 lines):

diff --git a/sql/backends/monet5/sql.mx b/sql/backends/monet5/sql.mx
--- a/sql/backends/monet5/sql.mx
+++ b/sql/backends/monet5/sql.mx
@@ -1877,12 +1877,11 @@ create_table_or_view( mvc *sql, char *sn
                }
        }
 
-       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->fixed, 
&t->ndims);
 
        for (n = t->columns.set->h; n; n = n->next) {
                sql_column *c = n->data;
                mvc_copy_column(sql, nt, c);
-               if (c->dim) nt->ndims++;
        }
        if (t->idxs.set) {
                for (n = t->idxs.set->h; n; n = n->next) {
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
@@ -425,7 +425,7 @@ typedef struct sql_table {
        int drop_action;        /* only needed for alter drop table */
 
        int cleared;            /* cleared in the current transaction */
-       int fixed; /* for arrays: fixed or unbounded */
+       bit fixed; /* for arrays: fixed or unbounded */
        int ndims; /* for arrays: number of dimensions */
 
        void *data;
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
@@ -87,6 +87,8 @@ mvc_init(char *dbname, int debug, store_
                mvc_create_column_(m, t, "system", "boolean", 1);
                mvc_create_column_(m, t, "commit_action", "smallint", 16);
                mvc_create_column_(m, t, "readonly", "boolean", 1);
+               mvc_create_column_(m, t, "fixed", "boolean", 1);
+               mvc_create_column_(m, t, "nr_dimensions", "int", 32);
                mvc_create_column_(m, t, "temporary", "smallint", 16);
 
                if (catalog_version) {
@@ -109,7 +111,7 @@ mvc_init(char *dbname, int debug, store_
                mvc_create_column_(m, t, "number", "int", 32);
                mvc_create_column_(m, t, "storage_type", "int", 32);
 
-               t = mvc_create_view(m, s, "arrays", SQL_PERSIST, "SELECT * FROM 
(SELECT p.*, 0 AS \"temporary\" FROM \"sys\".\"_tables\" AS p WHERE type = 6 
UNION ALL SELECT t.*, 1 AS \"temporary\" FROM \"tmp\".\"_tables\" AS t WHERE 
type = 6) AS arrays;", 1);
+               t = mvc_create_view(m, s, "arrays", SQL_PERSIST, "SELECT * FROM 
(SELECT p.*, 0 AS \"temporary\" FROM \"sys\".\"_tables\" AS p WHERE 
nr_dimensions > 0 UNION ALL SELECT t.*, 1 AS \"temporary\" FROM 
\"tmp\".\"_tables\" AS t WHERE nr_dimensions > 0) AS arrays;", 1);
                mvc_create_column_(m, t, "id", "int", 32);
                mvc_create_column_(m, t, "name", "varchar", 1024);
                mvc_create_column_(m, t, "schema_id", "int", 32);
@@ -118,6 +120,8 @@ mvc_init(char *dbname, int debug, store_
                mvc_create_column_(m, t, "system", "boolean", 1);
                mvc_create_column_(m, t, "commit_action", "smallint", 16);
                mvc_create_column_(m, t, "readonly", "boolean", 1);
+               mvc_create_column_(m, t, "fixed", "boolean", 1);
+               mvc_create_column_(m, t, "nr_dimensions", "int", 32);
                mvc_create_column_(m, t, "temporary", "smallint", 16);
                if (catalog_version) {
                        int pub = ROLE_PUBLIC;
@@ -130,13 +134,21 @@ mvc_init(char *dbname, int debug, store_
                t = mvc_create_view(m, s, "dimensions", SQL_PERSIST, "SELECT * 
FROM (SELECT pc.*, \"pd\".\"start\", pd.step, pd.stop FROM \"sys\".\"_columns\" 
AS pc, \"sys\".\"_dimensions\" AS pd WHERE pc.id = pd.column_id UNION ALL 
SELECT tc.*, \"td\".\"start\", td.step, td.stop FROM \"tmp\".\"_columns\" AS 
tc, \"tmp\".\"_dimensions\" AS td WHERE tc.id = td.column_id) AS dimensions;", 
1);
                mvc_create_column_(m, t, "id", "int", 32);
                mvc_create_column_(m, t, "name", "varchar", 1024);
-               mvc_create_column_(m, t, "schema_id", "int", 32);
-               mvc_create_column_(m, t, "query", "varchar", 2048);
-               mvc_create_column_(m, t, "type", "smallint", 16);
-               mvc_create_column_(m, t, "system", "boolean", 1);
-               mvc_create_column_(m, t, "commit_action", "smallint", 16);
-               mvc_create_column_(m, t, "readonly", "boolean", 1);
-               mvc_create_column_(m, t, "temporary", "smallint", 16);
+               mvc_create_column_(m, t, "type", "varchar", 1024);
+               mvc_create_column_(m, t, "type_digits", "int", 32);
+               mvc_create_column_(m, t, "type_scale", "int", 32);
+               mvc_create_column_(m, t, "table_id", "int", 32);
+               mvc_create_column_(m, t, "default", "varchar", 2048);
+               mvc_create_column_(m, t, "null", "boolean", 1);
+               mvc_create_column_(m, t, "number", "int", 32);
+               mvc_create_column_(m, t, "storage", "varchar", 2048);
+               //mvc_create_column_(m, t, "schema_id", "int", 32);
+               //mvc_create_column_(m, t, "query", "varchar", 2048);
+               //mvc_create_column_(m, t, "type", "smallint", 16);
+               //mvc_create_column_(m, t, "system", "boolean", 1);
+               //mvc_create_column_(m, t, "commit_action", "smallint", 16);
+               //mvc_create_column_(m, t, "readonly", "boolean", 1);
+               //mvc_create_column_(m, t, "temporary", "smallint", 16);
                mvc_create_column_(m, t, "start", "varchar", 2048);
                mvc_create_column_(m, t, "step", "varchar", 2048);
                mvc_create_column_(m, t, "stop", "varchar", 2048);
@@ -1009,12 +1021,13 @@ mvc_create_table(mvc *m, sql_schema *s, 
                                tt == tt_table? "TABLE":(tt == tt_array? 
"ARRAY":"OTHER_TT"),
                                s->base.name, name, tt, system, persistence, 
commit_action);
 
+       /* FIXME: are the NULLs correct values for 'fixed' and 'ndims'? */
        if (persistence == SQL_DECLARED_TABLE) {
                /* declared tables should not end up in the catalog */
-               t = create_sql_table(m->sa, name, tt, system, persistence, 
commit_action);
+               t = create_sql_table(m->sa, name, tt, system, persistence, 
commit_action, NULL, NULL);
                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, NULL, NULL);
        }
        return t;
 }
@@ -1028,11 +1041,11 @@ mvc_create_view(mvc *m, sql_schema *s, c
                fprintf(stderr, "#mvc_create_view %s %s %s\n", s->base.name, 
name, sql);
 
        if (persistence == SQL_DECLARED_TABLE) {
-               t = create_sql_table(m->sa, name, tt_view, system, persistence, 
0);
+               t = create_sql_table(m->sa, name, tt_view, system, persistence, 
0, NULL, NULL);
                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, NULL, NULL);
        }
        return t;
 }
@@ -1046,11 +1059,11 @@ mvc_create_remote(mvc *m, sql_schema *s,
                fprintf(stderr, "#mvc_create_remote %s %s %s\n", s->base.name, 
name, loc);
 
        if (persistence == SQL_DECLARED_TABLE) {
-               t = create_sql_table(m->sa, name, tt_remote, 0, persistence, 0);
+               t = create_sql_table(m->sa, name, tt_remote, 0, persistence, 0, 
NULL, NULL);
                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, NULL, NULL);
        }
        return t;
 }
@@ -1063,7 +1076,7 @@ mvc_create_generated(mvc *m, sql_schema 
        if (mvc_debug)
                fprintf(stderr, "#mvc_create_generated %s %s %s\n", 
s->base.name, name, sql);
 
-       t = sql_trans_create_table(m->session->tr, s, name, sql, tt_generated, 
system, SQL_PERSIST, 0, 0);
+       t = sql_trans_create_table(m->session->tr, s, name, sql, tt_generated, 
system, SQL_PERSIST, 0, 0, NULL, NULL);
        return t;
 }
 
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
@@ -314,7 +314,7 @@ extern void reset_functions(sql_trans *t
 extern sql_schema *sql_trans_create_schema(sql_trans *tr, 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, char 
*name, 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, char 
*name, char *sql, int tt, bit system, int persistence, int commit_action, int 
sz, bit *fixed, int *ndims);
 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);
 
@@ -368,7 +368,7 @@ extern int sql_trans_connect_catalog(sql
 extern int sql_trans_disconnect_catalog(sql_trans *tr, char *db_alias);
 extern int sql_trans_disconnect_catalog_ALL(sql_trans *tr);
 
-extern sql_table *create_sql_table(sql_allocator *sa, char *name, sht type, 
bit system, int persistence, int commit_action);
+extern sql_table *create_sql_table(sql_allocator *sa, char *name, sht type, 
bit system, int persistence, int commit_action, bit *fixed, int *ndims);
 extern sql_column *create_sql_column(sql_allocator *sa, sql_table *t, char 
*name, sql_subtype *tpe);
 extern sql_ukey *create_sql_ukey(sql_allocator *sa, sql_table *t, char *nme, 
key_type kt);
 extern sql_fkey *create_sql_fkey(sql_allocator *sa, sql_table *t, char *nme, 
key_type kt, sql_key *rkey, int on_delete, int on_update );
diff --git a/sql/storage/store.c b/sql/storage/store.c
--- a/sql/storage/store.c
+++ b/sql/storage/store.c
@@ -616,6 +616,10 @@ load_table(sql_trans *tr, sql_schema *s,
        t->cleared = 0;
        v = table_funcs.column_find_value(tr, find_sql_column(tables, 
"readonly"),rid);
        t->readonly = *(bit *)v;        _DELETE(v);
+       v = table_funcs.column_find_value(tr, find_sql_column(tables, 
"fixed"),rid);
+       t->fixed = *(bit *)v;   _DELETE(v);
+       v = table_funcs.column_find_value(tr, find_sql_column(tables, 
"nr_dimensions"),rid);
+       t->ndims = *(int *)v;   _DELETE(v);
 
        t->pkey = NULL;
        t->s = s;
@@ -1018,7 +1022,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->readonly);
+                       table_funcs.table_insert(tr, systable, &t->base.id, 
t->base.name, &s->base.id, ATOMnilptr(TYPE_str), &t->type, &t->system, &ca, 
&t->readonly, &t->fixed, &t->ndims);
                        for (o = t->columns.set->h; o; o = o->next) {
                                sql_column *c = o->data;
 
@@ -1158,7 +1162,7 @@ bootstrap_create_column(sql_trans *tr, s
 }
 
 sql_table *
-create_sql_table(sql_allocator *sa, char *name, sht type, bit system, int 
persistence, int commit_action)
+create_sql_table(sql_allocator *sa, char *name, sht type, bit system, int 
persistence, int commit_action, bit *fixed, int *ndims)
 {
        sql_table *t = (sa)?SA_ZNEW(sa, sql_table):ZNEW(sql_table);
 
@@ -1179,8 +1183,9 @@ create_sql_table(sql_allocator *sa, char
        t->pkey = NULL;
        t->sz = COLSIZE;
        t->cleared = 0;
-       t->fixed = 1; /* This is ONLY for arrays, should be set to 0 if an 
unbounded dimension is found. */
-       t->ndims = 0; /* This is ONLY for arrays */
+       /* 'fixed' and 'ndims' are ONLY used for arrays.  Pass NULLs to get 
their defaults. */
+       t->fixed = fixed ? *fixed : 1; /* should be set to 0 if an unbounded 
dimension is found. */
+       t->ndims = ndims ? *ndims : 0;
        t->s = NULL;
        return t;
 }
@@ -1217,7 +1222,7 @@ sql_table *
 dup_sql_table(sql_allocator *sa, sql_table *t)
 {
        node *n;
-       sql_table *nt = create_sql_table(sa, t->base.name, t->type, t->system, 
SQL_DECLARED_TABLE, t->commit_action);
+       sql_table *nt = create_sql_table(sa, t->base.name, t->type, t->system, 
SQL_DECLARED_TABLE, t->commit_action, &t->fixed, &t->ndims);
 
        for (n = t->columns.set->h; n; n = n->next) 
                dup_sql_column(sa, nt, n->data);
@@ -1252,7 +1257,7 @@ bootstrap_create_table(sql_trans *tr, sq
        int istmp = isTempSchema(s);
        int persistence = istmp?SQL_GLOBAL_TEMP:SQL_PERSIST;
        sht commit_action = istmp?CA_PRESERVE:CA_COMMIT;
-       sql_table *t = create_sql_table(NULL, name, tt_table, 1, persistence, 
commit_action);
+       sql_table *t = create_sql_table(NULL, name, tt_table, 1, persistence, 
commit_action, NULL, NULL /* we never have arrays here */);
 
        if (bs_debug)
                fprintf(stderr, "#bootstrap_create_table %s\n", name );
@@ -1438,6 +1443,8 @@ 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, "readonly", "boolean", 1);
+               bootstrap_create_column(tr, t, "fixed", "boolean", 1);
+               bootstrap_create_column(tr, t, "nr_dimensions", "int", 32);
 
                t = bootstrap_create_table(tr, s, "_columns");
                bootstrap_create_column(tr, t, "id", "int", 32);
@@ -3847,9 +3854,9 @@ sql_trans_del_table(sql_trans *tr, sql_t
 }
 
 sql_table *
-sql_trans_create_table(sql_trans *tr, sql_schema *s, char *name, char *sql, 
int tt, bit system, int persistence, int commit_action, int sz)
+sql_trans_create_table(sql_trans *tr, sql_schema *s, char *name, char *sql, 
int tt, bit system, int persistence, int commit_action, int sz, bit *fixed, int 
*ndims)
 {
-       sql_table *t = create_sql_table(NULL, name, tt, system, persistence, 
commit_action);
+       sql_table *t = create_sql_table(NULL, name, tt, system, persistence, 
commit_action, fixed, ndims);
        sql_schema *syss = find_sql_schema(tr, isGlobal(t)?"sys":"tmp");
        sql_table *systable = find_sql_table(syss, "_tables");
        sht ca;
@@ -3877,7 +3884,7 @@ sql_trans_create_table(sql_trans *tr, sq
        if (!isDeclaredTable(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->readonly);
+                       &t->system, &ca, &t->readonly, &t->fixed, &t->ndims);
 
        t->base.wtime = s->base.wtime = tr->wtime = tr->stime;
        if (isGlobal(t)) 
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to