Changeset: 03baba6c4e68 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/03baba6c4e68
Modified Files:
        sql/backends/monet5/sql.c
        sql/test/miscellaneous/Tests/simple_selects.test
Branch: sqlfuncfix
Log Message:

Merged with default


diffs (truncated from 727 to 300 lines):

diff --git a/gdk/gdk_aggr.c b/gdk/gdk_aggr.c
--- a/gdk/gdk_aggr.c
+++ b/gdk/gdk_aggr.c
@@ -3326,14 +3326,13 @@ BATgroupsize(BAT *b, BAT *g, BAT *e, BAT
                                i = canditer_next(ci) - hseq;           \
                                if (!skip_nils ||                       \
                                    !is_##TYPE##_nil(vals[i])) {        \
-                                       oids[i] = i + hseq;             \
+                                       oids[gid++] = i + hseq;         \
                                        nils--;                         \
                                }                                       \
                        }                                               \
                        TIMEOUT_CHECK(timeoffset,                       \
                                      TIMEOUT_HANDLER(BUN_NONE));       \
                } else {                                                \
-                       gid = 0; /* in case gids == NULL */             \
                        TIMEOUT_LOOP(ncand, timeoffset) {               \
                                i = canditer_next(ci) - hseq;           \
                                if (gids == NULL ||                     \
@@ -3365,7 +3364,7 @@ do_groupmin(oid *restrict oids, BATiter 
            oid min, oid max, struct canditer *restrict ci, BUN ncand,
            bool skip_nils, bool gdense)
 {
-       oid gid;
+       oid gid = 0;
        BUN i, nils;
        int t;
        const void *nil;
@@ -3423,15 +3422,16 @@ do_groupmin(oid *restrict oids, BATiter 
                                while (ncand > 0) {
                                        ncand--;
                                        i = canditer_next(ci);
-                                       oids[i - hseq] = i;
+                                       oids[gid++] = i;
                                        nils--;
                                }
                        } else {
                                while (ncand > 0) {
                                        ncand--;
                                        i = canditer_next(ci);
-                                       if (is_oid_nil(oids[i - hseq])) {
-                                               oids[i - hseq] = i;
+                                       gid = gids[i - hseq] - min;
+                                       if (is_oid_nil(oids[gid])) {
+                                               oids[gid] = i;
                                                nils--;
                                        }
                                }
@@ -3447,14 +3447,13 @@ do_groupmin(oid *restrict oids, BATiter 
                                i = canditer_next(ci) - hseq;
                                if (!skip_nils ||
                                    (*atomcmp)(BUNtail(*bi, i), nil) != 0) {
-                                       oids[i] = i + hseq;
+                                       oids[gid++] = i + hseq;
                                        nils--;
                                }
                        }
                        TIMEOUT_CHECK(timeoffset,
                                      TIMEOUT_HANDLER(BUN_NONE));
                } else {
-                       gid = 0; /* in case gids == NULL */
                        TIMEOUT_LOOP(ncand, timeoffset) {
                                i = canditer_next(ci) - hseq;
                                if (gids == NULL ||
@@ -3495,7 +3494,7 @@ do_groupmax(oid *restrict oids, BATiter 
            oid min, oid max, struct canditer *restrict ci, BUN ncand,
            bool skip_nils, bool gdense)
 {
-       oid gid;
+       oid gid = 0;
        BUN i, nils;
        int t;
        const void *nil;
@@ -3553,16 +3552,17 @@ do_groupmax(oid *restrict oids, BATiter 
                                while (ncand > 0) {
                                        ncand--;
                                        i = canditer_next(ci);
-                                       oids[i - hseq] = i;
+                                       oids[gid++] = i;
                                        nils--;
                                }
                        } else {
                                while (ncand > 0) {
                                        ncand--;
                                        i = canditer_next(ci);
-                                       if (is_oid_nil(oids[i - hseq]))
+                                       gid = gids[i - hseq] - min;
+                                       if (is_oid_nil(oids[gid]))
                                                nils--;
-                                       oids[i - hseq] = i;
+                                       oids[gid] = i;
                                }
                        }
                }
@@ -3576,14 +3576,13 @@ do_groupmax(oid *restrict oids, BATiter 
                                i = canditer_next(ci) - hseq;
                                if (!skip_nils ||
                                    (*atomcmp)(BUNtail(*bi, i), nil) != 0) {
-                                       oids[i] = i + hseq;
+                                       oids[gid++] = i + hseq;
                                        nils--;
                                }
                        }
                        TIMEOUT_CHECK(timeoffset,
                                      TIMEOUT_HANDLER(BUN_NONE));
                } else {
-                       gid = 0; /* in case gids == NULL */
                        TIMEOUT_LOOP(ncand, timeoffset) {
                                i = canditer_next(ci) - hseq;
                                if (gids == NULL ||
diff --git a/monetdb5/optimizer/opt_pipes.c b/monetdb5/optimizer/opt_pipes.c
--- a/monetdb5/optimizer/opt_pipes.c
+++ b/monetdb5/optimizer/opt_pipes.c
@@ -51,8 +51,8 @@ static struct PIPELINES {
         "optimizer.generator();"
         //"optimizer.candidates();" only for decoration in explain
         //"optimizer.mask();"
-        "optimizer.garbageCollector();",
-        "optimizer.profiler();"
+        "optimizer.garbageCollector();"
+        "optimizer.profiler();",
         "stable", NULL, 1},
        {"minimal_fast",
         "optimizer.minimalfast()",
@@ -97,8 +97,8 @@ static struct PIPELINES {
         "optimizer.postfix();"
 //      "optimizer.jit();" awaiting the new batcalc api
         "optimizer.wlc();"
-        "optimizer.garbageCollector();",
-        "optimizer.profiler();"
+        "optimizer.garbageCollector();"
+        "optimizer.profiler();",
         "stable", NULL, 1},
        {"default_fast",
         "optimizer.defaultfast()",
@@ -139,8 +139,8 @@ static struct PIPELINES {
 //      "optimizer.jit();" awaiting the new batcalc api
         "optimizer.oltp();"
         "optimizer.wlc();"
-        "optimizer.garbageCollector();",
-        "optimizer.profiler();"
+        "optimizer.garbageCollector();"
+        "optimizer.profiler();",
         "stable", NULL, 1},
 /*
  * Volcano style execution produces a sequence of blocks from the source 
relation
@@ -177,8 +177,8 @@ static struct PIPELINES {
         "optimizer.postfix();"
 //      "optimizer.jit();" awaiting the new batcalc api
         "optimizer.wlc();"
-        "optimizer.garbageCollector();",
-        "optimizer.profiler();"
+        "optimizer.garbageCollector();"
+        "optimizer.profiler();",
         "stable", NULL, 1},
 /* The no_mitosis pipe line is (and should be kept!) identical to the
  * default pipeline, except that optimizer mitosis is omitted.  It is
@@ -220,8 +220,8 @@ static struct PIPELINES {
         "optimizer.postfix();"
 //      "optimizer.jit();" awaiting the new batcalc api
         "optimizer.wlc();"
-        "optimizer.garbageCollector();",
-        "optimizer.profiler();"
+        "optimizer.garbageCollector();"
+        "optimizer.profiler();",
         "stable", NULL, 1},
 /* The sequential pipe line is (and should be kept!) identical to the
  * default pipeline, except that optimizers mitosis & dataflow are
@@ -262,8 +262,8 @@ static struct PIPELINES {
         "optimizer.postfix();"
 //      "optimizer.jit();" awaiting the new batcalc api
         "optimizer.wlc();"
-        "optimizer.garbageCollector();",
-        "optimizer.profiler();"
+        "optimizer.garbageCollector();"
+        "optimizer.profiler();",
         "stable", NULL, 1},
 /* Experimental pipelines stressing various components under
  * development.  Do not use any of these pipelines in production
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
@@ -600,6 +600,8 @@ create_table_from_emit(Client cntxt, cha
 
                if (columns[i].name && columns[i].name[0] == '%')
                        throw(SQL, "sql.catalog", SQLSTATE(42000) "CREATE 
TABLE: generated labels not allowed in column names, use an alias instead");
+               if (tpe.type->eclass == EC_ANY)
+                       throw(SQL, "sql.catalog", SQLSTATE(42000) "CREATE 
TABLE: any type (plain null value) not allowed as a column type, use an 
explicit cast");
                switch (mvc_create_column(&col, sql, t, columns[i].name, &tpe)) 
{
                        case -1:
                                throw(SQL, "sql.catalog", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
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
@@ -150,6 +150,12 @@ as_subquery(mvc *sql, sql_table *t, tabl
                        if (tt != tt_view && cname && cname[0] == '%') {
                                sql_error(sql, 01, SQLSTATE(42000) "%s: 
generated labels not allowed in column names, use an alias instead", msg);
                                return -1;
+                       } else if (!tp) {
+                               sql_error(sql, 01, SQLSTATE(42000) "%s: columns 
must have a type defined", msg);
+                               return -1;
+                       } else if (tp->type->eclass == EC_ANY) {
+                               sql_error(sql, 01, SQLSTATE(42000) "%s: any 
type (plain null value) not allowed as a column type, use an explicit cast", 
msg);
+                               return -1;
                        } else if (mvc_bind_column(sql, t, cname)) {
                                sql_error(sql, 01, SQLSTATE(42S21) "%s: 
duplicate column name %s", msg, cname);
                                return -1;
@@ -171,21 +177,24 @@ as_subquery(mvc *sql, sql_table *t, tabl
                        return -1;
                }
        } else {
-               node *m;
-
-               for (m = r->exps->h; m; m = m->next) {
+               for (node *m = r->exps->h; m; m = m->next) {
                        sql_exp *e = m->data;
                        const char *cname = exp_name(e);
                        sql_subtype *tp = exp_subtype(e);
                        sql_column *col = NULL;
 
-                       if (tt != tt_view && cname && cname[0] == '%') {
+                       if (!cname)
+                               cname = "v";
+                       if (tt != tt_view && cname[0] == '%') {
                                sql_error(sql, 01, SQLSTATE(42000) "%s: 
generated labels not allowed in column names, use an alias instead", msg);
                                return -1;
-                       }
-                       if (!cname)
-                               cname = "v";
-                       if (mvc_bind_column(sql, t, cname)) {
+                       } else if (!tp) {
+                               sql_error(sql, 01, SQLSTATE(42000) "%s: columns 
must have a type defined", msg);
+                               return -1;
+                       } else if (tp->type->eclass == EC_ANY) {
+                               sql_error(sql, 01, SQLSTATE(42000) "%s: any 
type (plain null value) not allowed as a column type, use an explicit cast", 
msg);
+                               return -1;
+                       } else if (mvc_bind_column(sql, t, cname)) {
                                sql_error(sql, 01, SQLSTATE(42S21) "%s: 
duplicate column name %s", msg, cname);
                                return -1;
                        }
@@ -343,7 +352,7 @@ column_constraint_type(mvc *sql, const c
        int res = SQL_ERR;
 
        if (isDeclared && (s->token != SQL_NULL && s->token != SQL_NOT_NULL)) {
-               (void) sql_error(sql, 02, SQLSTATE(42000) "CONSTRAINT: 
constraints on declared tables are not supported\n");
+               (void) sql_error(sql, 02, SQLSTATE(42000) "CONSTRAINT: 
constraints on declared tables are not supported");
                return res;
        }
        switch (s->token) {
@@ -351,12 +360,23 @@ column_constraint_type(mvc *sql, const c
        case SQL_PRIMARY_KEY: {
                key_type kt = (s->token == SQL_UNIQUE) ? ukey : pkey;
                sql_key *k;
+               const char *ns = name;
 
                if (kt == pkey && t->pkey) {
-                       (void) sql_error(sql, 02, SQLSTATE(42000) "CONSTRAINT 
PRIMARY KEY: a table can have only one PRIMARY KEY\n");
+                       (void) sql_error(sql, 02, SQLSTATE(42000) "CONSTRAINT 
PRIMARY KEY: a table can have only one PRIMARY KEY");
+                       return res;
+               }
+               if (!ns || !*ns) { /* add this to be safe */
+                       (void) sql_error(sql, 02, SQLSTATE(42000) "CONSTRAINT 
%s: key name name cannot be empty", (kt == pkey) ? "PRIMARY KEY" : "UNIQUE");
                        return res;
                }
-               if (name && (ol_find_name(t->keys, name) || mvc_bind_key(sql, 
ss, name))) {
+               while (isdigit((unsigned char) *ns))
+                       ns++;
+               if (!*ns) { /* if a key name just contains digit characters, 
the generated index name can be mistaken with a label */
+                       (void) sql_error(sql, 02, SQLSTATE(42000) "CONSTRAINT 
%s: key name cannot contain just digit characters (0 through 9)", (kt == pkey) 
? "PRIMARY KEY" : "UNIQUE");
+                       return res;
+               }
+               if (ol_find_name(t->keys, name) || mvc_bind_key(sql, ss, name)) 
{
                        (void) sql_error(sql, 02, SQLSTATE(42000) "CONSTRAINT 
%s: key %s already exists", (kt == pkey) ? "PRIMARY KEY" : "UNIQUE", name);
                        return res;
                }
@@ -405,6 +425,7 @@ column_constraint_type(mvc *sql, const c
                list *cols;
                sql_key *rk = NULL;
                sql_kc *kc;
+               const char *ns = name;
 
                assert(n->next->next->next->type == type_int);
                rt = find_table_or_view_on_scope(sql, ss, rsname, rtname, 
"CONSTRAINT FOREIGN KEY", false);
@@ -414,9 +435,19 @@ column_constraint_type(mvc *sql, const c
                        sql->session->status = 0;
                        rt = t;
                }
-               if (!rt) {
+               if (!rt)
                        return SQL_ERR;
-               } else if (name && (ol_find_name(t->keys, name) || 
mvc_bind_key(sql, ss, name))) {
+               if (!ns || !*ns) { /* add this to be safe */
+                       (void) sql_error(sql, 02, SQLSTATE(42000) "CONSTRAINT 
FOREIGN KEY: key name name cannot be empty");
+                       return res;
+               }
+               while (isdigit((unsigned char) *ns))
+                       ns++;
+               if (!*ns) { /* if a key name just contains digit characters, 
the generated index name can be mistaken with a label */
+                       (void) sql_error(sql, 02, SQLSTATE(42000) "CONSTRAINT 
FOREIGN KEY: key name cannot contain just digit characters (0 through 9)");
+                       return res;
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to