Skip to content

Commit 5a709b4

Browse files
committed
{173778048} bdb_count should be able to count tables w no indices
Signed-off-by: Salil Chandra <schandra107@bloomberg.net>
1 parent 78114c0 commit 5a709b4

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

bdb/bdb_cursor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ int bdb_get_lsn_context_from_timestamp(bdb_state_type *bdb_state,
199199
int bdb_get_context_from_lsn(bdb_state_type *bdb_state, void *lsnp,
200200
unsigned long long *ret_context, int *bdberr);
201201

202+
int bdb_direct_count_int(bdb_state_type *state, int ixnum, int64_t *rcnt, int parallel_count);
202203
int bdb_direct_count(bdb_cursor_ifn_t *, int ixnum, int64_t *count);
203204

204205
#endif

bdb/count.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ int bdb_count_int(bdb_state_type *bdb_state, int *bdberr)
208208
return -1;
209209
}
210210

211+
// TODO: We are not using the smallest index here, why? We are using ix0
211212
rc = bdb_state->dbp_ix[0]->cursor(bdb_state->dbp_ix[0], 0, &dbcp, 0);
212213
if (rc != 0) {
213214
myfree(buffer);
@@ -300,7 +301,12 @@ int bdb_count(bdb_state_type *bdb_state, int *bdberr)
300301
int ret;
301302
BDB_READLOCK("bdb_count");
302303

303-
ret = bdb_count_int(bdb_state, bdberr);
304+
// ret = bdb_count_int(bdb_state, bdberr);
305+
int64_t count;
306+
ret = bdb_direct_count_int(bdb_state, bdb_state->numix > 0 ? 0 : -1, &count, 0);
304307
BDB_RELLOCK();
305-
return ret;
308+
if (ret == 0)
309+
return count;
310+
*bdberr = (ret == BDBERR_DEADLOCK ? ret : BDBERR_MISC);
311+
return -1;
306312
}

bdb/cursor.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8720,19 +8720,15 @@ static void *db_count(void *varg)
87208720
return NULL;
87218721
}
87228722

8723-
int gbl_parallel_count = 0;
8724-
int bdb_direct_count(bdb_cursor_ifn_t *cur, int ixnum, int64_t *rcnt)
8723+
int bdb_direct_count_int(bdb_state_type *state, int ixnum, int64_t *rcnt, int parallel_count)
87258724
{
87268725
int64_t count = 0;
8727-
int parallel_count;
8728-
bdb_state_type *state = cur->impl->state;
87298726
DB **db;
87308727
int stripes;
87318728
pthread_attr_t attr;
87328729
if (ixnum < 0) { // data
87338730
db = state->dbp_data[0];
87348731
stripes = state->attr->dtastripe;
8735-
parallel_count = gbl_parallel_count;
87368732
Pthread_attr_init(&attr);
87378733
#ifdef PTHREAD_STACK_MIN
87388734
Pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN + 512 * 1024);
@@ -8777,3 +8773,9 @@ int bdb_direct_count(bdb_cursor_ifn_t *cur, int ixnum, int64_t *rcnt)
87778773
if (rc == 0) *rcnt = count;
87788774
return rc;
87798775
}
8776+
8777+
int gbl_parallel_count = 0;
8778+
int bdb_direct_count(bdb_cursor_ifn_t *cur, int ixnum, int64_t *rcnt)
8779+
{
8780+
return bdb_direct_count_int(cur->impl->state, ixnum, rcnt, gbl_parallel_count);
8781+
}

0 commit comments

Comments
 (0)