Changeset: 5878959602b1 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/5878959602b1
Modified Files:
        gdk/gdk.h
        gdk/gdk_join.c
        gdk/gdk_sketch.c
        monetdb5/modules/kernel/aggr.c
        sql/backends/monet5/sql_statistics.c
Branch: cnting_sketches
Log Message:

Compute sketch and update unique guess with analyze stmt.


diffs (108 lines):

diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -447,6 +447,7 @@ typedef struct BAT {
        PROPrec *tprops;        /* list of dynamic properties stored in the bat 
descriptor */
 
        uint8_t cnting_sketch[BUCKETS][CLZ_BUCKETS];
+       double unique_guess;
 
        MT_Lock theaplock;      /* lock protecting heap reference changes */
        MT_RWLock thashlock;    /* lock specifically for hash management */
@@ -1424,7 +1425,7 @@ gdk_export gdk_return BATsetstrimps(BAT 
 gdk_export void sketch_populate(BAT* n, BATiter *ni, struct canditer *nci);
 gdk_export void sketch_merge(BAT* b, BAT* n);
 gdk_export double sketch_estimator(uint8_t cnt_sketch[BUCKETS][CLZ_BUCKETS]);
-gdk_export double BATsketchestimator(BAT *b, BATiter *bi, struct canditer 
*bci);
+gdk_export double BATsketch_estimator(BAT *b, BATiter *bi, struct canditer 
*bci);
 
 /* Rtree structure functions */
 #ifdef HAVE_RTREE
diff --git a/gdk/gdk_join.c b/gdk/gdk_join.c
--- a/gdk/gdk_join.c
+++ b/gdk/gdk_join.c
@@ -3542,8 +3542,8 @@ count_unique(BAT *b, BAT *s, BUN *cnt1, 
 static double
 guess_uniques(BAT *b, struct canditer *ci)
 {
-       if (b->tunique_est)
-               return b->tunique_est;
+       if (b->unique_guess)
+               return b->unique_guess;
 
        BUN cnt1 = 0, cnt2;
        BUN max = b->twidth < SIZEOF_BUN ? (BUN) 1 << (8*b->twidth) : BUN_MAX;
@@ -3628,8 +3628,8 @@ BATguess_uniques(BAT *b, struct canditer
                return 0;
        if (b->batCount == 1 || (ci && ci->ncand == 1))
                return 1;
-       if (b->tunique_est)
-               return b->tunique_est;
+       if (b->unique_guess)
+               return b->unique_guess;
        struct canditer lci;
        if (ci == NULL) {
                canditer_init(&lci, b, NULL);
diff --git a/gdk/gdk_sketch.c b/gdk/gdk_sketch.c
--- a/gdk/gdk_sketch.c
+++ b/gdk/gdk_sketch.c
@@ -149,14 +149,23 @@ sketch_merge(BAT* b, BAT* n)
                for (size_t j = 0; j < CLZ_BUCKETS; j++)
                        if (n->cnting_sketch[i][j] > b->cnting_sketch[i][j])
                                b->cnting_sketch[i][j] = n->cnting_sketch[i][j];
-       b->tunique_est = sketch_estimator(b->cnting_sketch);
+       b->unique_guess = sketch_estimator(b->cnting_sketch);
        MT_lock_unset(&b->batIdxLock);
 }
 
 double
-BATsketchestimator(BAT *b, BATiter *bi, struct canditer *bci)
+BATsketch_estimator(BAT *b, BATiter *bi, struct canditer *bci)
 {
-       if (b->tunique_est == 0)
-               sketch_populate(b, bi, bci);
-       return sketch_estimator(b->cnting_sketch);
+       BATiter nbi;
+       struct canditer nbci;
+       if (bi == NULL) {
+               nbi = bat_iterator(b);
+               canditer_init(&nbci, b, NULL);
+       }
+       sketch_populate(b, bi ? bi : &nbi, bci ? bci : &nbci);
+       double unique_guess = sketch_estimator(b->cnting_sketch);
+       b->unique_guess = unique_guess;
+       if (bi == NULL)
+               bat_iterator_end(&nbi);
+       return unique_guess;
 }
diff --git a/monetdb5/modules/kernel/aggr.c b/monetdb5/modules/kernel/aggr.c
--- a/monetdb5/modules/kernel/aggr.c
+++ b/monetdb5/modules/kernel/aggr.c
@@ -1552,12 +1552,11 @@ AGGRcde(Client c, int *estimate, const b
 
        if (VIEWtparent(b)) {
                BAT *pb = BATdescriptor(VIEWtparent(b));
-               assert(pb);
-               printf("cnt dist est prop %f\n", pb->tunique_est);
+               printf("cnt dist est prop %f\n", pb->unique_guess);
                BBPreclaim(pb);
        }
 
-       double est = BATsketchestimator(b, &bi, &bci);
+       double est = BATsketch_estimator(b, &bi, &bci);
 
        bat_iterator_end(&bi);
        BBPreclaim(b);
diff --git a/sql/backends/monet5/sql_statistics.c 
b/sql/backends/monet5/sql_statistics.c
--- a/sql/backends/monet5/sql_statistics.c
+++ b/sql/backends/monet5/sql_statistics.c
@@ -204,6 +204,9 @@ sql_analyze(Client cntxt, MalBlkPtr mb, 
                                        /* Guess number of uniques if not 
entirely unique */
                                        (void) BATguess_uniques(b, NULL);
 
+                                       if (b->unique_guess == 0)
+                                               (void) BATsketch_estimator(b, 
NULL, NULL);
+
                                        /* Collect min and max values */
                                        mn = BATmin(b, NULL);
                                        GDKfree(mn);
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to