* BlockSampler_Init -- prepare for random sampling of blocknumbers * * BlockSampler provides algorithm for block level sampling of a relation * as discussed on pgsql-hackers 2004-04-02 (subject "Large DB") * It selects a random sample of samplesize blocks out of * the nblocks blocks in the table. If the table has less than * samplesize blocks, all blocks are selected. * * Since we know the
| 36 | * Returns the number of blocks that BlockSampler_Next will return. |
| 37 | */ |
| 38 | BlockNumber |
| 39 | BlockSampler_Init(BlockSampler bs, BlockNumber nblocks, int samplesize, |
| 40 | long randseed) |
| 41 | { |
| 42 | bs->N = nblocks; /* measured table size */ |
| 43 | |
| 44 | /* |
| 45 | * If we decide to reduce samplesize for tables that have less or not much |
| 46 | * more than samplesize blocks, here is the place to do it. |
| 47 | */ |
| 48 | bs->n = samplesize; |
| 49 | bs->t = 0; /* blocks scanned so far */ |
| 50 | bs->m = 0; /* blocks selected so far */ |
| 51 | |
| 52 | sampler_random_init_state(randseed, bs->randstate); |
| 53 | |
| 54 | return Min(bs->n, bs->N); |
| 55 | } |
| 56 | |
| 57 | bool |
| 58 | BlockSampler_HasMore(BlockSampler bs) |
no test coverage detected