Changeset: 510285593b2d for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/510285593b2d
Modified Files:
        gdk/gdk.h
Branch: default
Log Message:

Merge with Mar2025 branch.


diffs (108 lines):

diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -1518,11 +1518,13 @@ BATsettrivprop(BAT *b)
                        b->tnil = !b->tnonil;
                        b->trevsorted = true;
                        b->tkey = b->batCount <= 1;
+                       b->tunique_est = b->batCount == 0 ? 0.0 : 1.0;
                } else {
                        b->tnonil = true;
                        b->tnil = false;
                        b->tkey = true;
                        b->trevsorted = b->batCount <= 1;
+                       b->tunique_est = (double) b->batCount;
                }
                b->tsorted = true;
        } else if (b->batCount <= 1) {
@@ -1591,11 +1593,15 @@ BATsettrivprop(BAT *b)
                b->tnokey[0] = 0;
                b->tnokey[1] = !b->tkey;
                b->tunique_est = (double) (1 + b->tkey);
-       } else if (!ATOMlinear(b->ttype)) {
-               b->tsorted = false;
-               b->trevsorted = false;
-               b->tminpos = BUN_NONE;
-               b->tmaxpos = BUN_NONE;
+       } else {
+               if (!ATOMlinear(b->ttype)) {
+                       b->tsorted = false;
+                       b->trevsorted = false;
+                       b->tminpos = BUN_NONE;
+                       b->tmaxpos = BUN_NONE;
+               }
+               if (b->tkey)
+                       b->tunique_est = (double) b->batCount;
        }
 }
 
diff --git a/gdk/gdk_batop.c b/gdk/gdk_batop.c
--- a/gdk/gdk_batop.c
+++ b/gdk/gdk_batop.c
@@ -788,7 +788,9 @@ BATappend2(BAT *b, BAT *n, BAT *s, bool 
                        b->tminpos = BUN_NONE;
                }
        }
-       if (ci.ncand > BATcount(b) / gdk_unique_estimate_keep_fraction) {
+       if (BATcount(b) == 0 && ci.ncand == ni.count)
+               b->tunique_est = ni.unique_est;
+       else if (ci.ncand > BATcount(b) / gdk_unique_estimate_keep_fraction) {
                b->tunique_est = 0;
        }
        MT_lock_unset(&b->theaplock);
diff --git a/sql/backends/monet5/sql_rank.c b/sql/backends/monet5/sql_rank.c
--- a/sql/backends/monet5/sql_rank.c
+++ b/sql/backends/monet5/sql_rank.c
@@ -198,7 +198,7 @@ SQLrow_number(Client cntxt, MalBlkPtr mb
        if (isaBatType(getArgType(mb, pci, 1))) {
                BUN cnt;
                int j, *rp, *end;
-               bit *np;
+               const bit *np;
 
                res = getArgReference_bat(stk, pci, 0);
                if (!(b = BATdescriptor(*getArgReference_bat(stk, pci, 1)))) {
@@ -209,9 +209,11 @@ SQLrow_number(Client cntxt, MalBlkPtr mb
                        msg = createException(SQL, "sql.row_number", 
SQLSTATE(HY013) MAL_MALLOC_FAIL);
                        goto bailout;
                }
-               r->tsorted = r->trevsorted = r->tkey = BATcount(b) <= 1;
+               cnt = BATcount(b);
+               r->trevsorted = cnt <= 1;
+               r->tsorted = true;
+               r->tkey = true;
 
-               cnt = BATcount(b);
                rp = (int*)Tloc(r, 0);
                if (isaBatType(getArgType(mb, pci, 2))) {
                        /* order info not used */
@@ -220,20 +222,22 @@ SQLrow_number(Client cntxt, MalBlkPtr mb
                                goto bailout;
                        }
                        BATiter pi = bat_iterator(p);
-                       np = (bit*)pi.base;
+                       np = (const bit*)pi.base;
                        end = rp + cnt;
-                       for(j=1; rp<end; j++, np++, rp++) {
-                               if (*np)
-                                       j=1;
+                       for (j = 1; rp < end; j++, np++, rp++) {
+                               if (*np) {
+                                       j = 1;
+                                       r->tkey = false;
+                                       r->tsorted = false;
+                               }
                                *rp = j;
                        }
                        bat_iterator_end(&pi);
                } else { /* single value, ie no partitions, order info not used 
*/
                        int icnt = (int) cnt;
-                       for(j=1; j<=icnt; j++, rp++)
+                       for (j = 1; j <= icnt; j++, rp++)
                                *rp = j;
-                       r->tsorted = true;
-                       r->tkey = true;
+                       r->tunique_est = (double) cnt;
                }
                BATsetcount(r, cnt);
                r->tnonil = true;
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to