Changeset: 76573b37b432 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/76573b37b432
Modified Files:
        gdk/gdk_bbp.c
        gdk/gdk_private.h
        gdk/gdk_select.c
        testing/Mz.py.in
Branch: default
Log Message:

Merged with Jul2021


diffs (truncated from 1155 to 300 lines):

diff --git a/gdk/gdk_bbp.c b/gdk/gdk_bbp.c
--- a/gdk/gdk_bbp.c
+++ b/gdk/gdk_bbp.c
@@ -3492,7 +3492,8 @@ BBPsync(int cnt, bat *restrict subcommit
                                MT_lock_set(&GDKswapLock(i));
                        /* set flag that we're syncing, i.e. that we'll
                         * be between moving heap to backup dir and
-                        * saving the new version */
+                        * saving the new version, in other words, the
+                        * heap may not exist in the usual location */
                        BBP_status_on(i, BBPSYNCING);
                        /* wait until unloading is finished before
                         * attempting to make a backup */
@@ -3510,38 +3511,46 @@ BBPsync(int cnt, bat *restrict subcommit
                                break;
                        }
                        if (BBP_status(i) & BBPEXISTING) {
-                               if (b != NULL && BBPbackup(b, subcommit != 
NULL) != GDK_SUCCEED) {
-                                       BBP_status_off(i, BBPSYNCING);
-                                       if (lock)
-                                               MT_lock_unset(&GDKswapLock(i));
-                                       break;
-                               }
-                       } else if (subcommit && (b = BBP_desc(i)) && 
BBP_status(i) & BBPDELETED) {
-                               char o[10];
-                               char *f;
-                               snprintf(o, sizeof(o), "%o", (unsigned) 
b->batCacheid);
-                               f = GDKfilepath(b->theap->farmid, BAKDIR, o, 
gettailname(b));
-                               if (f == NULL) {
+                               if (b != NULL) {
+                                       if (BBPbackup(b, subcommit != NULL) != 
GDK_SUCCEED) {
+                                               BBP_status_off(i, BBPSYNCING);
+                                               if (lock)
+                                                       
MT_lock_unset(&GDKswapLock(i));
+                                               break;
+                                       }
+                               } else {
+                                       /* file has not been moved to
+                                        * backup dir, so no need for
+                                        * other threads to wait */
                                        BBP_status_off(i, BBPSYNCING);
-                                       if (lock)
-                                               MT_lock_unset(&GDKswapLock(i));
-                                       ret = GDK_FAIL;
-                                       goto bailout;
                                }
-                               if (MT_access(f, F_OK) == 0)
-                                       file_move(b->theap->farmid, BAKDIR, 
SUBDIR, o, gettailname(b));
-                               GDKfree(f);
-                               f = GDKfilepath(b->theap->farmid, BAKDIR, o, 
"theap");
-                               if (f == NULL) {
-                                       BBP_status_off(i, BBPSYNCING);
-                                       if (lock)
-                                               MT_lock_unset(&GDKswapLock(i));
-                                       ret = GDK_FAIL;
-                                       goto bailout;
+                       } else {
+                               BBP_status_off(i, BBPSYNCING);
+                               if (subcommit && (b = BBP_desc(i)) && 
BBP_status(i) & BBPDELETED) {
+                                       char o[10];
+                                       char *f;
+                                       snprintf(o, sizeof(o), "%o", (unsigned) 
b->batCacheid);
+                                       f = GDKfilepath(b->theap->farmid, 
BAKDIR, o, gettailname(b));
+                                       if (f == NULL) {
+                                               if (lock)
+                                                       
MT_lock_unset(&GDKswapLock(i));
+                                               ret = GDK_FAIL;
+                                               goto bailout;
+                                       }
+                                       if (MT_access(f, F_OK) == 0)
+                                               file_move(b->theap->farmid, 
BAKDIR, SUBDIR, o, gettailname(b));
+                                       GDKfree(f);
+                                       f = GDKfilepath(b->theap->farmid, 
BAKDIR, o, "theap");
+                                       if (f == NULL) {
+                                               if (lock)
+                                                       
MT_lock_unset(&GDKswapLock(i));
+                                               ret = GDK_FAIL;
+                                               goto bailout;
+                                       }
+                                       if (MT_access(f, F_OK) == 0)
+                                               file_move(b->theap->farmid, 
BAKDIR, SUBDIR, o, "theap");
+                                       GDKfree(f);
                                }
-                               if (MT_access(f, F_OK) == 0)
-                                       file_move(b->theap->farmid, BAKDIR, 
SUBDIR, o, "theap");
-                               GDKfree(f);
                        }
                        if (lock)
                                MT_lock_unset(&GDKswapLock(i));
diff --git a/gdk/gdk_imprints.c b/gdk/gdk_imprints.c
--- a/gdk/gdk_imprints.c
+++ b/gdk/gdk_imprints.c
@@ -447,18 +447,7 @@ BATimprints(BAT *b)
        lng t0 = GDKusec();
 
        /* we only create imprints for types that look like types we know */
-       switch (ATOMbasetype(b->ttype)) {
-       case TYPE_bte:
-       case TYPE_sht:
-       case TYPE_int:
-       case TYPE_lng:
-#ifdef HAVE_HGE
-       case TYPE_hge:
-#endif
-       case TYPE_flt:
-       case TYPE_dbl:
-               break;
-       default:                /* type not supported */
+       if (!imprintable(b->ttype)) {
                /* doesn't look enough like base type: do nothing */
                GDKerror("unsupported type\n");
                return GDK_FAIL;
diff --git a/gdk/gdk_private.h b/gdk/gdk_private.h
--- a/gdk/gdk_private.h
+++ b/gdk/gdk_private.h
@@ -273,6 +273,25 @@ void VIEWdestroy(BAT *b)
 BAT *virtualize(BAT *bn)
        __attribute__((__visibility__("hidden")));
 
+static inline bool
+imprintable(int tpe)
+{
+       switch (ATOMbasetype(tpe)) {
+       case TYPE_bte:
+       case TYPE_sht:
+       case TYPE_int:
+       case TYPE_lng:
+#ifdef HAVE_HGE
+       case TYPE_hge:
+#endif
+       case TYPE_flt:
+       case TYPE_dbl:
+               return true;
+       default:                /* type not supported */
+               return false;
+       }
+}
+
 /* calculate the integer 2 logarithm (i.e. position of highest set
  * bit) of the argument (with a slight twist: 0 gives 0, 1 gives 1,
  * 0x8 to 0xF give 4, etc.) */
diff --git a/gdk/gdk_select.c b/gdk/gdk_select.c
--- a/gdk/gdk_select.c
+++ b/gdk/gdk_select.c
@@ -1943,14 +1943,14 @@ BATselect(BAT *b, BAT *s, const void *tl
                 * iii) is not var-sized.
                 */
                tmp = NULL;
-               bool use_imprints = !equi &&
-                       !b->tvarsized &&
-                       (!b->batTransient ||
-                        (parent != 0 &&
-                         (tmp = BBP_cache(parent)) != NULL &&
-                         !tmp->batTransient));
                Imprints *imprints = NULL;
-               if (use_imprints && BATimprints(b) == GDK_SUCCEED) {
+               if (!equi &&
+                   imprintable(b->ttype) &&
+                   (!b->batTransient ||
+                    (parent != 0 &&
+                     (tmp = BBP_cache(parent)) != NULL &&
+                     !tmp->batTransient)) &&
+                   BATimprints(b) == GDK_SUCCEED) {
                        if (tmp != NULL) {
                                MT_lock_set(&tmp->batIdxLock);
                                imprints = tmp->timprints;
@@ -1969,6 +1969,7 @@ BATselect(BAT *b, BAT *s, const void *tl
                                MT_lock_unset(&b->batIdxLock);
                        }
                }
+               GDKclrerr();
                bn = scanselect(b, &bi, &ci, bn, tl, th, li, hi, equi, anti,
                                lval, hval, lnil, maximum, imprints, &algo);
                if (imprints)
@@ -2302,6 +2303,7 @@ rangejoin(BAT *r1, BAT *r2, BAT *l, BAT 
                cnt = BATcount(r1);
                assert(r2 == NULL || BATcount(r1) == BATcount(r2));
        } else if (!anti && !symmetric &&
+                  imprintable(l->ttype) &&
                   (BATcount(rl) > 2 ||
                    !l->batTransient ||
                    (VIEWtparent(l) != 0 &&
diff --git a/sql/storage/bat/bat_storage.c b/sql/storage/bat/bat_storage.c
--- a/sql/storage/bat/bat_storage.c
+++ b/sql/storage/bat/bat_storage.c
@@ -303,6 +303,24 @@ segs_end( segments *segs, sql_trans *tr,
        return cnt;
 }
 
+static size_t
+segs_end_include_deleted( segments *segs, sql_trans *tr, sql_table *table)
+{
+       size_t cnt = 0;
+
+       lock_table(tr->store, table->base.id);
+       segment *s = segs->h, *l = NULL;
+
+       for(;s; s = s->next) {
+               if (s->ts == tr->tid || SEG_IS_VALID(s, tr))
+                               l = s;
+       }
+       if (l)
+               cnt = l->end;
+       unlock_table(tr->store, table->base.id);
+       return cnt;
+}
+
 static int
 segments2cs(sql_trans *tr, segments *segs, column_storage *cs, sql_table *t)
 {
@@ -313,9 +331,9 @@ segments2cs(sql_trans *tr, segments *seg
                return LOG_ERR;
        segment *s = segs->h;
 
-       size_t nr = segs_end(segs, tr, t);
+       size_t nr = segs_end_include_deleted(segs, tr, t);
        size_t rounded_nr = ((nr+31)&~31);
-       if (rounded_nr >= BATcapacity(b) && BATextend(b, rounded_nr) != 
GDK_SUCCEED) {
+       if (rounded_nr > BATcapacity(b) && BATextend(b, rounded_nr) != 
GDK_SUCCEED) {
                bat_destroy(b);
                return LOG_ERR;
        }
diff --git a/sql/storage/store.c b/sql/storage/store.c
--- a/sql/storage/store.c
+++ b/sql/storage/store.c
@@ -5710,10 +5710,12 @@ sql_trans_drop_column(sql_trans *tr, sql
                        oid rid;
                        next->colnr--;
 
-                       rid = store->table_api.column_find_row(tr, cid, 
&next->base.id, NULL);
-                       assert(!is_oid_nil(rid));
-                       if ((res = store->table_api.column_update_value(tr, 
cnr, rid, &next->colnr)))
-                               return res;
+                       if (!isDeclaredTable(t)) {
+                               rid = store->table_api.column_find_row(tr, cid, 
&next->base.id, NULL);
+                               assert(!is_oid_nil(rid));
+                               if ((res = 
store->table_api.column_update_value(tr, cnr, rid, &next->colnr)))
+                                       return res;
+                       }
                }
        }
 
diff --git a/sql/test/BugTracker-2019/Tests/alter_table_drop_column.Bug-6749.py 
b/sql/test/BugTracker-2019/Tests/alter_table_drop_column.Bug-6749.py
--- a/sql/test/BugTracker-2019/Tests/alter_table_drop_column.Bug-6749.py
+++ b/sql/test/BugTracker-2019/Tests/alter_table_drop_column.Bug-6749.py
@@ -63,29 +63,29 @@ with tempfile.TemporaryDirectory() as fa
                         stderr=process.PIPE) as s:
         client1 = pymonetdb.connect(database='db1', port=myport, 
autocommit=True)
         cur1 = client1.cursor()
-        cur1.execute('select count(*) from sys.objects inner join 
sys.dependencies on objects.id = dependencies.depend_id inner join sys.columns 
on dependencies.id = columns.id inner join sys.tables on columns.table_id = 
tables.id where tables.name = \'t\';')
+        cur1.execute("select count(*) from sys.objects inner join 
sys.dependencies on objects.id = dependencies.depend_id inner join sys.columns 
on dependencies.id = columns.id inner join sys.tables on columns.table_id = 
tables.id where tables.name = 't';")
         if cur1.fetchall() != [(2,)]:
             sys.stderr.write("2 expected")
-        cur1.execute('select count(*) from sys.dependencies inner join 
sys.columns on dependencies.id = columns.id inner join sys.tables on 
columns.table_id = tables.id where tables.name = \'t\';')
+        cur1.execute("select count(*) from sys.dependencies inner join 
sys.columns on dependencies.id = columns.id inner join sys.tables on 
columns.table_id = tables.id where tables.name = 't';")
         if cur1.fetchall() != [(2,)]:
             sys.stderr.write("2 expected")
-        cur1.execute('select keys.type, keys.name, keys.rkey, keys.action from 
sys.keys inner join sys.tables on tables.id = keys.table_id where tables.name = 
\'t\';')
+        cur1.execute("select keys.type, keys.name, keys.rkey, keys.action from 
sys.keys inner join sys.tables on tables.id = keys.table_id where tables.name = 
't';")
         if cur1.fetchall() != [(1,"t_b_unique",-1,-1)]:
-            sys.stderr.write('[(1,\"t_b_unique\",-1,-1)] expected')
-        cur1.execute('select idxs.type, idxs.name from sys.idxs inner join 
tables on tables.id = idxs.table_id where tables.name = \'t\';')
+            sys.stderr.write('[(1,"t_b_unique",-1,-1)] expected')
+        cur1.execute("select idxs.type, idxs.name from sys.idxs inner join 
tables on tables.id = idxs.table_id where tables.name = 't';")
         if cur1.fetchall() != [(0,"t_b_unique")]:
             sys.stderr.write('[(0,"t_b_unique")] expected')
         cur1.execute('alter table t drop column b cascade;')
-        cur1.execute('select count(*) from sys.objects inner join 
sys.dependencies on objects.id = dependencies.depend_id inner join sys.columns 
on dependencies.id = columns.id inner join sys.tables on columns.table_id = 
tables.id where tables.name = \'t\';')
+        cur1.execute("select count(*) from sys.objects inner join 
sys.dependencies on objects.id = dependencies.depend_id inner join sys.columns 
on dependencies.id = columns.id inner join sys.tables on columns.table_id = 
tables.id where tables.name = 't';")
         if cur1.fetchall() != [(0,)]:
             sys.stderr.write("0 expected")
-        cur1.execute('select count(*) from sys.dependencies inner join 
sys.columns on dependencies.id = columns.id inner join sys.tables on 
columns.table_id = tables.id where tables.name = \'t\';')
+        cur1.execute("select count(*) from sys.dependencies inner join 
sys.columns on dependencies.id = columns.id inner join sys.tables on 
columns.table_id = tables.id where tables.name = 't';")
         if cur1.fetchall() != [(0,)]:
             sys.stderr.write("0 expected")
-        cur1.execute('select keys.type, keys.name, keys.rkey, keys.action from 
sys.keys inner join sys.tables on tables.id = keys.table_id where tables.name = 
\'t\';')
+        cur1.execute("select keys.type, keys.name, keys.rkey, keys.action from 
sys.keys inner join sys.tables on tables.id = keys.table_id where tables.name = 
't';")
         if cur1.fetchall() != []:
             sys.stderr.write('[] expected')
-        cur1.execute('select idxs.type, idxs.name from sys.idxs inner join 
tables on tables.id = idxs.table_id where tables.name = \'t\';')
+        cur1.execute("select idxs.type, idxs.name from sys.idxs inner join 
tables on tables.id = idxs.table_id where tables.name = 't';")
         if cur1.fetchall() != []:
             sys.stderr.write('[] expected')
         cur1.close()
@@ -107,29 +107,29 @@ with tempfile.TemporaryDirectory() as fa
         cur1.execute('select * from t;')
         if cur1.fetchall() != []:
             sys.stderr.write('[] expected')
-        cur1.execute('select count(*) from sys.objects inner join 
sys.dependencies on objects.id = dependencies.depend_id inner join sys.columns 
on dependencies.id = columns.id inner join sys.tables on columns.table_id = 
tables.id where tables.name = \'t\';')
+        cur1.execute("select count(*) from sys.objects inner join 
sys.dependencies on objects.id = dependencies.depend_id inner join sys.columns 
on dependencies.id = columns.id inner join sys.tables on columns.table_id = 
tables.id where tables.name = 't';")
         if cur1.fetchall() != [(2,)]:
             sys.stderr.write("2 expected")
-        cur1.execute('select count(*) from sys.dependencies inner join 
sys.columns on dependencies.id = columns.id inner join sys.tables on 
columns.table_id = tables.id where tables.name = \'t\';')
+        cur1.execute("select count(*) from sys.dependencies inner join 
sys.columns on dependencies.id = columns.id inner join sys.tables on 
columns.table_id = tables.id where tables.name = 't';")
         if cur1.fetchall() != [(2,)]:
             sys.stderr.write("2 expected")
-        cur1.execute('select keys.type, keys.name, keys.rkey, keys.action from 
sys.keys inner join sys.tables on tables.id = keys.table_id where tables.name = 
\'t\';')
+        cur1.execute("select keys.type, keys.name, keys.rkey, keys.action from 
sys.keys inner join sys.tables on tables.id = keys.table_id where tables.name = 
't';")
         if cur1.fetchall() != [(1,"t_b_unique",-1,-1)]:
-            sys.stderr.write('[(1,\"t_b_unique\",-1,-1)] expected')
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to