1a966c69948e950c7eb06797a961ae4df5856c95 angie Tue Oct 1 09:49:43 2013 -0700 Fixing corner case: if we hit the end of rowBuf in nextRowFromBuffer,then discover in asdDoQueryChunking that we don't need to query again, then we need to reset rowBuf because when we return to nextRowFromBuffer, we check rowBuf->size which should be 0. We could also check self->eof, but I think it's cleaner to have the correct rowBuf state. diff --git src/hg/lib/annoStreamDb.c src/hg/lib/annoStreamDb.c index 759ca10..df19d75 100644 --- src/hg/lib/annoStreamDb.c +++ src/hg/lib/annoStreamDb.c @@ -227,32 +227,35 @@ rowBuf->buf[ix++] = lmCloneRow(rowBuf->lm, row, sSelf->numCols+self->omitBin); } // Set rowBuf->size to the number of rows we actually stored. rowBuf->size = ix; sqlFreeResult(&sr); updateNextChunkState(self, queryMaxItems); } static void asdDoQueryChunking(struct annoStreamDb *self, char *minChrom, uint minEnd) /* Return a sqlResult for a query on table items in position range. * If doing a whole genome query. just 'select * from' table. */ { struct annoStreamer *sSelf = &(self->streamer); struct dyString *query = sqlDyStringCreate("select * from %s ", self->table); if (sSelf->chrom != NULL && self->rowBuf.size > 0 && !self->doNextChunk) + { // We're doing a region query, we already got some rows, and don't need another chunk: + resetRowBuf(&self->rowBuf); self->eof = TRUE; + } if (self->useMaxOutRows) { self->maxOutRows -= self->rowBuf.size; if (self->maxOutRows <= 0) self->eof = TRUE; } if (self->eof) return; int queryMaxItems = ASD_CHUNK_SIZE; if (self->useMaxOutRows && self->maxOutRows < queryMaxItems) queryMaxItems = self->maxOutRows; if (self->hasBin) { // Results will be in bin order, but we can restore chromStart order by // accumulating initial coarse-bin items and merge-sorting them with