Changeset: 720fc4faef9e for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/720fc4faef9e
Modified Files:
        sql/backends/monet5/sql.c
        sql/storage/bat/bat_storage.c
Branch: default
Log Message:

Merge with Jan2022 branch.


diffs (truncated from 554 to 300 lines):

diff --git a/clients/odbc/driver/SQLStatistics.c 
b/clients/odbc/driver/SQLStatistics.c
--- a/clients/odbc/driver/SQLStatistics.c
+++ b/clients/odbc/driver/SQLStatistics.c
@@ -192,7 +192,7 @@ MNDBStatistics(ODBCStmt *stmt,
                       "i.name as index_name, "
                       "case i.type when 0 then cast(%d as smallint) "
                                   "else cast(%d as smallint) end as type, "
-                      "cast(kc.nr as smallint) as ordinal_position, "
+                      "cast(kc.nr + 1 as smallint) as ordinal_position, "
                       "c.name as column_name, "
                       "cast(null as char(1)) as asc_or_desc, "
                       "cast(null as integer) as cardinality, "
@@ -209,7 +209,8 @@ MNDBStatistics(ODBCStmt *stmt,
                      "i.id = kc.id and "
                      "t.id = c.table_id and "
                      "kc.name = c.name and "
-                     "(k.type is null or k.type = 1)",
+                     "k.name = i.name and "
+                     "k.type in (0, 1)",
                stmt->Dbc->dbname,
                SQL_INDEX_HASHED, SQL_INDEX_OTHER);
        assert(pos < 1000);
diff --git a/gdk/gdk_bat.c b/gdk/gdk_bat.c
--- a/gdk/gdk_bat.c
+++ b/gdk/gdk_bat.c
@@ -579,6 +579,8 @@ BATclear(BAT *b, bool force)
                return GDK_FAIL;
        }
 
+       TRC_DEBUG(ALGO, ALGOBATFMT "\n", ALGOBATPAR(b));
+
        /* kill all search accelerators */
        HASHdestroy(b);
        IMPSdestroy(b);
@@ -1010,6 +1012,8 @@ BUNappendmulti(BAT *b, const void *value
        if (count == 0)
                return GDK_SUCCEED;
 
+       TRC_DEBUG(ALGO, ALGOBATFMT " appending " BUNFMT " values%s\n", 
ALGOBATPAR(b), count, values ? "" : " (all nil)");
+
        p = BUNlast(b);         /* insert at end */
        if (p == BUN_MAX || BATcount(b) + count >= BUN_MAX) {
                GDKerror("bat too large\n");
@@ -1302,6 +1306,7 @@ BUNdelete(BAT *b, oid o)
                GDKerror("cannot delete committed value\n");
                return GDK_FAIL;
        }
+       TRC_DEBUG(ALGO, ALGOBATFMT " deleting oid " OIDFMT "\n", ALGOBATPAR(b), 
o);
        b->batDirtydesc = true;
        val = BUNtail(bi, p);
        /* writing the values should be locked, reading could be done
@@ -1398,6 +1403,7 @@ BUNinplacemulti(BAT *b, const oid *posit
                         BATgetId(b));
                return GDK_FAIL;
        }
+       TRC_DEBUG(ALGO, ALGOBATFMT " replacing " BUNFMT " values\n", 
ALGOBATPAR(b), count);
        MT_lock_set(&b->theaplock);
        if (b->ttype == TYPE_void) {
                PROPdestroy(b);
@@ -2455,6 +2461,14 @@ BATmode(BAT *b, bool transient)
  * newly created and filled BAT, you may want to first make sure the
  * batCount is set correctly (e.g. by calling BATsetcount), then use
  * BATtseqbase and BATkey, and finally set the other properties.
+ *
+ * For a view, we cannot check all properties, since it is possible with
+ * the way the SQL layer works, that a parent BAT gets changed, changing
+ * the properties, while there is a view.  The view is supposed to look
+ * at only at the non-changing part of the BAT (through candidate
+ * lists), but this means that the properties of the view might not be
+ * correct.  For this reason, for views, we skip all property checking
+ * that looks at the BAT content.
  */
 
 void
@@ -2466,6 +2480,7 @@ BATassertProps(BAT *b)
        int cmp;
        const void *prev = NULL, *valp, *nilp;
        char filename[sizeof(b->theap->filename)];
+       bool isview;
 
        /* do the complete check within a lock */
        MT_lock_set(&b->theaplock);
@@ -2479,6 +2494,8 @@ BATassertProps(BAT *b)
        assert(b->hseqbase <= GDK_oid_max); /* non-nil seqbase */
        assert(b->hseqbase + BATcount(b) <= GDK_oid_max);
 
+       isview = isVIEW(b);
+
        bbpstatus = BBP_status(b->batCacheid);
        /* only at most one of BBPDELETED, BBPEXISTING, BBPNEW may be set */
        assert(((bbpstatus & BBPDELETED) != 0) +
@@ -2488,10 +2505,10 @@ BATassertProps(BAT *b)
        assert(b->ttype >= TYPE_void);
        assert(b->ttype < GDKatomcnt);
        assert(b->ttype != TYPE_bat);
-       assert(isVIEW(b) ||
+       assert(isview ||
               b->ttype == TYPE_void ||
               BBPfarms[b->theap->farmid].roles & (1 << b->batRole));
-       assert(isVIEW(b) ||
+       assert(isview ||
               b->tvheap == NULL ||
               (BBPfarms[b->tvheap->farmid].roles & (1 << b->batRole)));
 
@@ -2609,7 +2626,8 @@ BATassertProps(BAT *b)
                       (b->tnosorted > 0 &&
                        b->tnosorted < b->batCount));
                assert(!b->tsorted || b->tnosorted == 0);
-               if (!b->tsorted &&
+               if (!isview &&
+                   !b->tsorted &&
                    b->tnosorted > 0 &&
                    b->tnosorted < b->batCount)
                        assert(cmpf(BUNtail(bi, b->tnosorted - 1),
@@ -2618,7 +2636,8 @@ BATassertProps(BAT *b)
                       (b->tnorevsorted > 0 &&
                        b->tnorevsorted < b->batCount));
                assert(!b->trevsorted || b->tnorevsorted == 0);
-               if (!b->trevsorted &&
+               if (!isview &&
+                   !b->trevsorted &&
                    b->tnorevsorted > 0 &&
                    b->tnorevsorted < b->batCount)
                        assert(cmpf(BUNtail(bi, b->tnorevsorted - 1),
@@ -2626,7 +2645,7 @@ BATassertProps(BAT *b)
        }
        /* if tkey property set, both tnokey values must be 0 */
        assert(!b->tkey || (b->tnokey[0] == 0 && b->tnokey[1] == 0));
-       if (!b->tkey && (b->tnokey[0] != 0 || b->tnokey[1] != 0)) {
+       if (!isview && !b->tkey && (b->tnokey[0] != 0 || b->tnokey[1] != 0)) {
                /* if tkey not set and tnokey indicates a proof of
                 * non-key-ness, make sure the tnokey values are in
                 * range and indeed provide a proof */
@@ -2646,7 +2665,9 @@ BATassertProps(BAT *b)
                return;
        }
 
-       PROPDEBUG { /* only do a scan if property checking is requested */
+       /* only do a scan if property checking is requested and the bat
+        * is not a view */
+       if (!isview && GDKdebug & PROPMASK) {
                const void *maxval = NULL;
                const void *minval = NULL;
                bool seenmax = false, seenmin = false;
diff --git a/gdk/gdk_calc.c b/gdk/gdk_calc.c
--- a/gdk/gdk_calc.c
+++ b/gdk/gdk_calc.c
@@ -15233,7 +15233,7 @@ BATcalcifthencstelsecst(BAT *b, const Va
  */
 
 #ifdef HAVE_HGE
-static hge scales[39] = {
+static const hge scales[39] = {
        (hge) LL_CONSTANT(1),
        (hge) LL_CONSTANT(10),
        (hge) LL_CONSTANT(100),
@@ -15275,7 +15275,7 @@ static hge scales[39] = {
        (hge) LL_CONSTANT(10000000000000000000U) * 
LL_CONSTANT(10000000000000000000U)
 };
 #else
-static lng scales[19] = {
+static const lng scales[19] = {
        LL_CONSTANT(1),
        LL_CONSTANT(10),
        LL_CONSTANT(100),
diff --git a/monetdb5/modules/atoms/blob.c b/monetdb5/modules/atoms/blob.c
--- a/monetdb5/modules/atoms/blob.c
+++ b/monetdb5/modules/atoms/blob.c
@@ -36,7 +36,7 @@
 
 int TYPE_blob;
 
-static blob nullval = {
+static const blob nullval = {
        ~(size_t) 0
 };
 
diff --git a/sql/backends/monet5/dict.c b/sql/backends/monet5/dict.c
--- a/sql/backends/monet5/dict.c
+++ b/sql/backends/monet5/dict.c
@@ -233,6 +233,8 @@ DICTcompress_col(Client cntxt, MalBlkPtr
        if (!isTable(t))
                throw(SQL, "dict.compress", SQLSTATE(42000) "%s '%s' is not 
persistent",
                          TABLE_TYPE_DESCRIPTION(t->type, t->properties), 
t->base.name);
+       if (isTempTable(t))
+               throw(SQL, "dict.compress", SQLSTATE(42000) "columns from 
temporary tables cannot be compressed");
        if (t->system)
                throw(SQL, "dict.compress", SQLSTATE(42000) "columns from 
system tables cannot be compressed");
        sql_column *c = find_sql_column(t, cname);
diff --git a/sql/backends/monet5/for.c b/sql/backends/monet5/for.c
--- a/sql/backends/monet5/for.c
+++ b/sql/backends/monet5/for.c
@@ -234,6 +234,8 @@ FORcompress_col(Client cntxt, MalBlkPtr 
        if (!isTable(t))
                throw(SQL, "for.compress", SQLSTATE(42000) "%s '%s' is not 
persistent",
                          TABLE_TYPE_DESCRIPTION(t->type, t->properties), 
t->base.name);
+       if (isTempTable(t))
+               throw(SQL, "for.compress", SQLSTATE(42000) "columns from 
temporary tables cannot be compressed");
        if (t->system)
                throw(SQL, "for.compress", SQLSTATE(42000) "columns from system 
tables cannot be compressed");
        sql_column *c = find_sql_column(t, cname);
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
@@ -1850,7 +1850,7 @@ mvc_clear_table_wrap(Client cntxt, MalBl
                                if (!schema || !seq_name || !(seqs = 
find_sql_schema(tr, schema)))
                                        continue;
 
-                               assert(seqs->base.id == s->base.id);
+                               /* TODO - At the moment the sequence may not be 
stored in the same schema as the table itself */
                                if ((seq = find_sql_sequence(tr, seqs, 
seq_name))) {
                                        switch (sql_trans_sequence_restart(tr, 
seq, seq->start)) {
                                                case -1:
diff --git a/sql/backends/monet5/wlr.c b/sql/backends/monet5/wlr.c
--- a/sql/backends/monet5/wlr.c
+++ b/sql/backends/monet5/wlr.c
@@ -1129,7 +1129,7 @@ WLRclear_table(Client cntxt, MalBlkPtr m
                                if (!schema || !seq_name || !(seqs = 
find_sql_schema(tr, schema)))
                                        continue;
 
-                               assert(seqs->base.id == s->base.id);
+                               /* TODO - At the moment the sequence may not be 
stored in the same schema as the table itself */
                                if ((seq = find_sql_sequence(tr, seqs, 
seq_name))) {
                                        switch (sql_trans_sequence_restart(tr, 
seq, seq->start)) {
                                                case -1:
diff --git a/sql/server/sql_atom.c b/sql/server/sql_atom.c
--- a/sql/server/sql_atom.c
+++ b/sql/server/sql_atom.c
@@ -189,7 +189,7 @@ atom_float(sql_allocator *sa, sql_subtyp
 }
 
 #ifdef HAVE_HGE
-hge scales[39] = {
+const hge scales[39] = {
        (hge) LL_CONSTANT(1),
        (hge) LL_CONSTANT(10),
        (hge) LL_CONSTANT(100),
@@ -231,7 +231,7 @@ hge scales[39] = {
        (hge) LL_CONSTANT(10000000000000000000U) * 
LL_CONSTANT(10000000000000000000U)
 };
 #else
-lng scales[19] = {
+const lng scales[19] = {
        LL_CONSTANT(1),
        LL_CONSTANT(10),
        LL_CONSTANT(100),
diff --git a/sql/server/sql_atom.h b/sql/server/sql_atom.h
--- a/sql/server/sql_atom.h
+++ b/sql/server/sql_atom.h
@@ -61,10 +61,10 @@ extern int atom_is_zero(atom *a);
 
 #ifdef HAVE_HGE
 #define MAX_SCALE 39
-extern hge scales[MAX_SCALE];
+extern const hge scales[MAX_SCALE];
 #else
 #define MAX_SCALE 19
-extern lng scales[MAX_SCALE];
+extern const lng scales[MAX_SCALE];
 #endif
 
 extern atom *atom_zero_value(sql_allocator *sa, sql_subtype* tpe);
diff --git a/sql/server/sql_parser.y b/sql/server/sql_parser.y
--- a/sql/server/sql_parser.y
+++ b/sql/server/sql_parser.y
@@ -1761,7 +1761,7 @@ column_def:
                                sql_find_subtype(&it, "bigint", 64, 0);
                        else
                                sql_find_subtype(&it, "int", 32, 0);
-                       append_symbol(o, _symbol_create_list(SQL_TYPE, 
append_type(L(),&it)));
+                       append_symbol(o, _symbol_create_list(SQL_TYPE, 
append_type(L(),&it)));
                        append_list(l, o);
                        append_int(l, 1); /* to be dropped */
 
@@ -1770,7 +1770,7 @@ column_def:
                        } else {
                                stmts = L();
                                m->sym = _symbol_create_list(SQL_MULSTMT, 
stmts);
-                       }       
+                       }
                        append_symbol(stmts, 
_symbol_create_list(SQL_CREATE_SEQ, l));
 
                        l = L();
@@ -1864,7 +1864,7 @@ generated_column:
                } else {
                        stmts = L();
                        m->sym = _symbol_create_list(SQL_MULSTMT, stmts);
-               }       
+               }
                append_symbol(stmts, _symbol_create_list(SQL_CREATE_SEQ, l));
        }
  |     AUTO_INCREMENT
@@ -1886,7 +1886,7 @@ generated_column:
                        append_string(seqn1, m->scanner.schema);
                append_list(l, append_string(seqn1, sn));
                sql_find_subtype(&it, "int", 32, 0);
-               append_symbol(o, _symbol_create_list(SQL_TYPE, 
append_type(L(),&it)));
+               append_symbol(o, _symbol_create_list(SQL_TYPE, 
append_type(L(),&it)));
                append_list(l, o);
                append_int(l, 1); /* to be dropped */
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to