Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

...
  • 2 commits
  • 1 file changed
  • 0 commit comments
  • 1 contributor
Showing with 36 additions and 26 deletions.
  1. +36 −26 src/item-bitmap.c
62 src/item-bitmap.c
View
@@ -8,6 +8,9 @@
/* allocate the memory in 1kB chunks */
#define PALLOC_CHUNK 1024
+int count_digits(int values[], int n);
+char * itoa(int value, char * str, int maxlen);
+
/* init the bitmap (allocate, set default values) */
item_bitmap * bitmap_init(int npages) {
@@ -111,20 +114,17 @@ int bitmap_add_heap_items(item_bitmap * bitmap, PageHeader header, char *raw_pag
}
/* second pass - remove the HOT chains */
+ /* FIXME this seems not to work (the checks fail after update) */
for (item = 0; item < ntuples; item++) {
if (header->pd_linp[item].lp_flags == LP_REDIRECT) {
/* walk only if not walked this HOT chain yet (skip the first item in the chain) */
- if (bitmap_get_item(bitmap, page, item)) {
- int next = item;
- do {
- next = header->pd_linp[next].lp_off;
- if (! bitmap_set_item(bitmap, page, next, false)) {
- /* FIXME this is incorrect, IMHO - the chain might be longer and the items may be
- * processed out of order */
- nerrs++;
- }
- } while (header->pd_linp[next].lp_flags != LP_REDIRECT);
+ if (bitmap_get_item(bitmap, page, header->pd_linp[item].lp_off-1)) {
+ if (! bitmap_set_item(bitmap, page, header->pd_linp[item].lp_off-1, false)) {
+ /* FIXME this is incorrect, IMHO - the chain might be longer and the items may be
+ * processed out of order */
+ nerrs++;
+ }
}
}
@@ -270,22 +270,17 @@ long bitmap_compare(item_bitmap * bitmap_a, item_bitmap * bitmap_b) {
/* TODO print details about differences (items missing in heap, items missing in index) */
void bitmap_print(item_bitmap * bitmap) {
- int i, j, k = 0;
- char page[5];
+ int i, j, bits = 0, k = 0;
char data[bitmap->nbytes*8+1];
- char * pages;
-
- pages = (char*)palloc(bitmap->npages*4+1);
+ int len = count_digits(bitmap->pages, bitmap->npages) + bitmap->npages;
+ char pages[len];
+ char *ptr = pages;
for (i = 0; i < bitmap->npages; i++) {
- if (i == 0) {
- sprintf(page, "%d", bitmap->pages[i]);
- } else {
- sprintf(page, ",%d", bitmap->pages[i]);
- }
- pages = strcat(pages, page);
+ ptr = itoa(bitmap->pages[i], ptr, len - (ptr - pages));
+ *(ptr++) = ',';
}
- pages[bitmap->npages*2] = '0';
+ *(--ptr) = '\0';
for (i = 0; i < bitmap->nbytes; i++) {
for (j = 0; j < 8; j++) {
@@ -296,10 +291,25 @@ void bitmap_print(item_bitmap * bitmap) {
}
}
}
- data[k++] = 0;
+ data[k] = '\0';
+
+ bits = bitmap_count(bitmap);
- elog(WARNING, "bitmap nbytes=%d npages=%d pages=[%s] data=[%s]", bitmap->nbytes,
- bitmap->npages, pages, data);
+ elog(WARNING, "bitmap nbytes=%d nbits=%d npages=%d pages=[%s] data=[%s]",
+ bitmap->nbytes, bits, bitmap->npages, pages, data);
- pfree(pages);
+}
+
+/* count digits to print the array (in ASCII) */
+int count_digits(int values[], int n) {
+ int i, digits = 0;
+ for (i = 0; i < n; i++) {
+ digits += (int)ceil(log(values[i]) / log(10));
+ }
+ return digits;
+}
+
+/* utility to fill an integer value in a given value */
+char * itoa(int value, char * str, int maxlen) {
+ return str + snprintf(str, maxlen, "%d", value);
}

No commit comments for this range

Something went wrong with that request. Please try again.