Changeset: ec25669eec4d for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=ec25669eec4d
Modified Files:
        gdk/gdk_select.c
Branch: Oct2012
Log Message:

Fix off-by-one error when inserting values into result BAT.
The old code was very conservative in calculating how much to extend
the BAT.  In one case, about one third of a BAT was selected.  This
resulted in a total of 17 calls to BATextend, the last of which, 2
rows before the end, resulted in an extend by nothing: cnt/(p-r) was
close to 0.3, (q-p) was 2.  Do the maths: the result (without the new
+1024) was the same as the cnt.
With this fix, there are only two calls to BATextend in the same test.
Note that we also limit the maximum for the extend by how much is
currently in use plus how much could possibly still be needed.


diffs (47 lines):

diff --git a/gdk/gdk_select.c b/gdk/gdk_select.c
--- a/gdk/gdk_select.c
+++ b/gdk/gdk_select.c
@@ -21,19 +21,19 @@
 #include "gdk.h"
 #include "gdk_private.h"
 
-#define buninsfix(B,C,A,I,T,V,G,M,R)                                   \
-       do {                                                            \
-               if ((I) == BATcapacity((B))) {                          \
-                       BATsetcount((B), (I));                          \
-                       if (BATextend((B),                              \
-                                     MIN(BATcapacity((B)) + (G),       \
-                                         (M))) == NULL) {              \
-                               BBPreclaim((B));                        \
-                               return (R);                             \
-                       }                                               \
-                       A = (T *) C##loc((B), BUNfirst((B)));           \
-               }                                                       \
-               A[(I)] = (V);                                           \
+#define buninsfix(B,C,A,I,T,V,G,M,R)                           \
+       do {                                                    \
+               if ((I) == BATcapacity(B)) {                    \
+                       BATsetcount((B), (I));                  \
+                       if (BATextend((B),                      \
+                                     MIN(BATcapacity(B) + (G), \
+                                         (M))) == NULL) {      \
+                               BBPreclaim(B);                  \
+                               return (R);                     \
+                       }                                       \
+                       A = (T *) C##loc((B), BUNfirst(B));     \
+               }                                               \
+               A[(I)] = (V);                                   \
        } while (0)
 
 static BAT *
@@ -183,8 +183,8 @@ do {                                                        
                \
                        READ;                                           \
                        buninsfix(bn, T, dst, cnt, oid, o,              \
                                  (BUN) ((dbl) cnt / (dbl) (p-r)        \
-                                        * (dbl) (q-p) * 1.1),          \
-                                 maximum, BUN_NONE);                   \
+                                        * (dbl) (q-p) * 1.1 + 1024),   \
+                                 BATcapacity(bn) + q - p, BUN_NONE);   \
                        cnt += (TEST);                                  \
                        p++;                                            \
                }                                                       \
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to