Changeset: 1489752de1cf for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/1489752de1cf
Modified Files:
        gdk/gdk_bat.c
        monetdb5/modules/kernel/bat5.c
        monetdb5/modules/mal/batExtensions.c
        monetdb5/modules/mal/mat.c
        sql/test/BugTracker-2016/Tests/merge_project.Bug-3955.test
Branch: Sep2022
Log Message:

No need for BATsettrivprop when only calling GDK functions.
We did need to do a little more property setting to get equivalent
results.  And this means that in one test we know a little more.


diffs (216 lines):

diff --git a/gdk/gdk_bat.c b/gdk/gdk_bat.c
--- a/gdk/gdk_bat.c
+++ b/gdk/gdk_bat.c
@@ -646,7 +646,14 @@ BATclear(BAT *b, bool force)
        BAThseqbase(b, 0);
        BATtseqbase(b, ATOMtype(b->ttype) == TYPE_oid ? 0 : oid_nil);
        b->theap->dirty = true;
-       BATsettrivprop(b);
+       b->tnonil = true;
+       b->tnil = false;
+       b->tsorted = b->trevsorted = ATOMlinear(b->ttype);
+       b->tnosorted = b->tnorevsorted = 0;
+       b->tkey = true;
+       b->tnokey[0] = b->tnokey[1] = 0;
+       b->tminpos = b->tmaxpos = BUN_NONE;
+       b->tunique_est = 0;
        MT_lock_unset(&b->theaplock);
        return GDK_SUCCEED;
 }
@@ -1166,10 +1173,57 @@ BUNappendmulti(BAT *b, const void *value
                        b->tkey = count == 1;
                        b->tnil = true;
                        b->tnonil = false;
+                       b->tunique_est = 1;
                } else {
-                       b->tsorted = b->trevsorted = b->tkey = count == 1;
+                       int c;
                        b->tnil = b->tnonil = false;
+                       switch (count) {
+                       case 1:
+                               b->tsorted = b->trevsorted = b->tkey = true;
+                               b->tunique_est = 1;
+                               break;
+                       case 2:
+                               if (b->tvheap)
+                                       c = ATOMcmp(b->ttype,
+                                                   ((void **) values)[0],
+                                                   ((void **) values)[1]);
+                               else
+                                       c = ATOMcmp(b->ttype,
+                                                   values,
+                                                   (char *) values + 
b->twidth);
+                               b->tsorted = c <= 0;
+                               b->tnosorted = !b->tsorted;
+                               b->trevsorted = c >= 0;
+                               b->tnorevsorted = !b->trevsorted;
+                               b->tkey = c != 0;
+                               b->tnokey[0] = 0;
+                               b->tnokey[1] = !b->tkey;
+                               b->tunique_est = (double) (1 + b->tkey);
+                               break;
+                       default:
+                               b->tsorted = b->trevsorted = b->tkey = false;
+                               break;
+                       }
                }
+       } else if (b->batCount == 1 && count == 1) {
+               BATiter bi = bat_iterator_nolock(b);
+               if (values != NULL) {
+                       if (b->tvheap)
+                               t = ((void **) values)[0];
+                       else
+                               t = values;
+               }
+               int c = ATOMcmp(b->ttype, BUNtail(bi, 0), t);
+               b->tsorted = c <= 0;
+               b->tnosorted = !b->tsorted;
+               b->trevsorted = c >= 0;
+               b->tnorevsorted = !b->trevsorted;
+               b->tkey = c != 0;
+               b->tnokey[0] = 0;
+               b->tnokey[1] = !b->tkey;
+               b->tunique_est = (double) (1 + b->tkey);
+               b->tnil |= values == NULL;
+               b->tnonil = false;
        } else {
                b->tnil |= values == NULL;
                b->tnonil = false;
diff --git a/monetdb5/modules/kernel/bat5.c b/monetdb5/modules/kernel/bat5.c
--- a/monetdb5/modules/kernel/bat5.c
+++ b/monetdb5/modules/kernel/bat5.c
@@ -66,7 +66,7 @@ BKCnewBAT(bat *res, const int *tt, const
        if (bn == NULL)
                throw(MAL, "bat.new", GDK_EXCEPTION);
        *res = bn->batCacheid;
-       BATsettrivprop(bn);
+       bn->tkey = true;                        /* COLnew leaves it as false */
        BBPretain(bn->batCacheid);
        BBPunfix(bn->batCacheid);
        return MAL_SUCCEED;
@@ -130,7 +130,6 @@ BKCdelete(bat *r, const bat *bid, const 
                throw(MAL, "bat.delete", GDK_EXCEPTION);
        }
        *r = b->batCacheid;
-       BATsettrivprop(b);
        BBPretain(b->batCacheid);
        BBPunfix(b->batCacheid);
        return MAL_SUCCEED;
@@ -155,7 +154,6 @@ BKCdelete_multi(bat *r, const bat *bid, 
                throw(MAL, "bat.delete", GDK_EXCEPTION);
        }
        *r = b->batCacheid;
-       BATsettrivprop(b);
        BBPretain(b->batCacheid);
        BBPunfix(b->batCacheid);
        return MAL_SUCCEED;
@@ -222,7 +220,6 @@ BKCappend_cand_force_wrap(bat *r, const 
                throw(MAL, "bat.append", GDK_EXCEPTION);
        }
        *r = b->batCacheid;
-       BATsettrivprop(b);
        BBPretain(b->batCacheid);
        BBPunfix(b->batCacheid);
        return MAL_SUCCEED;
@@ -268,7 +265,6 @@ BKCappend_val_force_wrap(bat *r, const b
                throw(MAL, "bat.append", GDK_EXCEPTION);
        }
        *r = b->batCacheid;
-       BATsettrivprop(b);
        BBPretain(b->batCacheid);
        BBPunfix(b->batCacheid);
        return MAL_SUCCEED;
@@ -293,7 +289,6 @@ BKCbun_inplace(bat *r, const bat *bid, c
                throw(MAL, "bat.inplace", GDK_EXCEPTION);
        }
        *r = b->batCacheid;
-       BATsettrivprop(b);
        BBPretain(b->batCacheid);
        BBPunfix(b->batCacheid);
        return MAL_SUCCEED;
@@ -312,7 +307,6 @@ BKCbun_inplace_force(bat *r, const bat *
                throw(MAL, "bat.inplace", GDK_EXCEPTION);
        }
        *r = b->batCacheid;
-       BATsettrivprop(b);
        BBPretain(b->batCacheid);
        BBPunfix(b->batCacheid);
        return MAL_SUCCEED;
@@ -342,7 +336,6 @@ BKCbat_inplace_force(bat *r, const bat *
                throw(MAL, "bat.inplace", GDK_EXCEPTION);
        }
        *r = b->batCacheid;
-       BATsettrivprop(b);
        BBPretain(b->batCacheid);
        BBPunfix(b->batCacheid);
        BBPunfix(p->batCacheid);
@@ -535,7 +528,6 @@ BKCsetAccess(bat *res, const bat *bid, c
        if ((b = BATsetaccess(b, m)) == NULL)
                throw(MAL, "bat.setAccess", OPERATION_FAILED);
        *res = b->batCacheid;
-       BATsettrivprop(b);
        BBPretain(b->batCacheid);
        BBPunfix(b->batCacheid);
        return MAL_SUCCEED;
diff --git a/monetdb5/modules/mal/batExtensions.c 
b/monetdb5/modules/mal/batExtensions.c
--- a/monetdb5/modules/mal/batExtensions.c
+++ b/monetdb5/modules/mal/batExtensions.c
@@ -83,7 +83,6 @@ CMDBATdup(Client cntxt, MalBlkPtr mb, Ma
        if (b == 0)
                throw(MAL,"bat.new", SQLSTATE(HY013) MAL_MALLOC_FAIL);
        *ret = b->batCacheid;
-       BATsettrivprop(b);
        BBPretain(b->batCacheid);
        BBPunfix(b->batCacheid);
        return MAL_SUCCEED;
@@ -281,7 +280,6 @@ CMDBATappend_bulk(Client cntxt, MalBlkPt
        }
 
        *r = b->batCacheid;
-       BATsettrivprop(b);
        BBPretain(b->batCacheid);
        BBPunfix(b->batCacheid);
        return MAL_SUCCEED;
diff --git a/monetdb5/modules/mal/mat.c b/monetdb5/modules/mal/mat.c
--- a/monetdb5/modules/mal/mat.c
+++ b/monetdb5/modules/mal/mat.c
@@ -166,7 +166,6 @@ MATpackIncrement(Client cntxt, MalBlkPtr
                        throw(MAL, "mat.pack", GDK_EXCEPTION);
                }
                bn->unused = (pieces-1); /* misuse "unused" field */
-               BATsettrivprop(bn);
                BBPunfix(b->batCacheid);
                if (bn->tnil && bn->tnonil) {
                        BBPreclaim(bn);
@@ -208,7 +207,6 @@ MATpackIncrement(Client cntxt, MalBlkPtr
                        throw(MAL, "mat.pack", "INTERNAL ERROR" " b->tnil or  
b->tnonil fails ");
                }
                *ret = b->batCacheid;
-               BATsettrivprop(b);
                BBPretain(b->batCacheid);
                BBPunfix(b->batCacheid);
        }
diff --git a/sql/test/BugTracker-2016/Tests/merge_project.Bug-3955.test 
b/sql/test/BugTracker-2016/Tests/merge_project.Bug-3955.test
--- a/sql/test/BugTracker-2016/Tests/merge_project.Bug-3955.test
+++ b/sql/test/BugTracker-2016/Tests/merge_project.Bug-3955.test
@@ -51,14 +51,14 @@ project (
 | | | | crossproduct (
 | | | | | project (
 | | | | | | select (
-| | | | | | | table("sys"."input_double") [ "input_double"."a1", 
"input_double"."a2" ]
-| | | | | | ) [ ("input_double"."a1") = (clob "latitude") ]
-| | | | | ) [ "input_double"."a2" as "tmp_2"."a2" ],
+| | | | | | | table("sys"."input_double") [ "input_double"."a1" UNIQUE, 
"input_double"."a2" UNIQUE ]
+| | | | | | ) [ ("input_double"."a1" UNIQUE) = (clob "latitude") ]
+| | | | | ) [ "input_double"."a2" UNIQUE as "tmp_2"."a2" ],
 | | | | | project (
 | | | | | | select (
-| | | | | | | table("sys"."input_double") [ "input_double"."a1", 
"input_double"."a2" ]
-| | | | | | ) [ ("input_double"."a1") = (clob "longitude") ]
-| | | | | ) [ "input_double"."a2" as "tmp_3"."a2" ]
+| | | | | | | table("sys"."input_double") [ "input_double"."a1" UNIQUE, 
"input_double"."a2" UNIQUE ]
+| | | | | | ) [ ("input_double"."a1" UNIQUE) = (clob "longitude") ]
+| | | | | ) [ "input_double"."a2" UNIQUE as "tmp_3"."a2" ]
 | | | | ) [  ]
 | | | ) [ "sys"."st_point"("tmp_2"."a2", "tmp_3"."a2") as "p"."a1" ]
 | | ) [  ]
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to