From f6d208d6e51810c73f0e02c477984a6b44627f11 Mon Sep 17 00:00:00 2001 From: Simon Riggs Date: Fri, 15 May 2015 14:37:10 -0400 Subject: TABLESAMPLE, SQL Standard and extensible Add a TABLESAMPLE clause to SELECT statements that allows user to specify random BERNOULLI sampling or block level SYSTEM sampling. Implementation allows for extensible sampling functions to be written, using a standard API. Basic version follows SQLStandard exactly. Usable concrete use cases for the sampling API follow in later commits. Petr Jelinek Reviewed by Michael Paquier and Simon Riggs --- src/include/utils/sampling.h | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src/include/utils/sampling.h') diff --git a/src/include/utils/sampling.h b/src/include/utils/sampling.h index e3e7f9cf6ae..4ac208dc364 100644 --- a/src/include/utils/sampling.h +++ b/src/include/utils/sampling.h @@ -15,7 +15,12 @@ #include "storage/bufmgr.h" -extern double sampler_random_fract(void); +/* Random generator for sampling code */ +typedef unsigned short SamplerRandomState[3]; + +extern void sampler_random_init_state(long seed, + SamplerRandomState randstate); +extern double sampler_random_fract(SamplerRandomState randstate); /* Block sampling methods */ /* Data structure for Algorithm S from Knuth 3.4.2 */ @@ -25,6 +30,7 @@ typedef struct int n; /* desired sample size */ BlockNumber t; /* current block number */ int m; /* blocks selected so far */ + SamplerRandomState randstate; /* random generator state */ } BlockSamplerData; typedef BlockSamplerData *BlockSampler; @@ -35,7 +41,12 @@ extern bool BlockSampler_HasMore(BlockSampler bs); extern BlockNumber BlockSampler_Next(BlockSampler bs); /* Reservoid sampling methods */ -typedef double ReservoirStateData; +typedef struct +{ + double W; + SamplerRandomState randstate; /* random generator state */ +} ReservoirStateData; + typedef ReservoirStateData *ReservoirState; extern void reservoir_init_selection_state(ReservoirState rs, int n); -- cgit v1.2.3