1
0
mirror of https://github.com/postgres/postgres.git synced 2025-12-21 05:21:08 +03:00

Separate block sampling functions

Refactoring ahead of tablesample patch

Requested and reviewed by Michael Paquier

Petr Jelinek
This commit is contained in:
Simon Riggs
2015-05-15 04:02:54 +02:00
parent 5a3022fde0
commit 83e176ec18
7 changed files with 287 additions and 232 deletions

View File

@@ -0,0 +1,44 @@
/*-------------------------------------------------------------------------
*
* sampling.h
* definitions for sampling functions
*
* Portions Copyright (c) 1996-2014, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* src/include/utils/sampling.h
*
*-------------------------------------------------------------------------
*/
#ifndef SAMPLING_H
#define SAMPLING_H
#include "storage/bufmgr.h"
extern double sampler_random_fract(void);
/* Block sampling methods */
/* Data structure for Algorithm S from Knuth 3.4.2 */
typedef struct
{
BlockNumber N; /* number of blocks, known in advance */
int n; /* desired sample size */
BlockNumber t; /* current block number */
int m; /* blocks selected so far */
} BlockSamplerData;
typedef BlockSamplerData *BlockSampler;
extern void BlockSampler_Init(BlockSampler bs, BlockNumber nblocks,
int samplesize, long randseed);
extern bool BlockSampler_HasMore(BlockSampler bs);
extern BlockNumber BlockSampler_Next(BlockSampler bs);
/* Reservoid sampling methods */
typedef double ReservoirStateData;
typedef ReservoirStateData *ReservoirState;
extern void reservoir_init_selection_state(ReservoirState rs, int n);
extern double reservoir_get_next_S(ReservoirState rs, double t, int n);
#endif /* SAMPLING_H */