aboutsummaryrefslogtreecommitdiff
path: root/src/include/utils/sampling.h
diff options
context:
space:
mode:
authorSimon Riggs <simon@2ndQuadrant.com>2015-05-15 04:02:54 +0200
committerSimon Riggs <simon@2ndQuadrant.com>2015-05-15 04:02:54 +0200
commit83e176ec18d2a91dbea1d0d1bd94c38dc47cd77c (patch)
tree6c92ec7402b4ac14a585c41d960e35bd283a878b /src/include/utils/sampling.h
parent5a3022fde018aca9b23b7f7506233b437d943de2 (diff)
downloadpostgresql-83e176ec18d2a91dbea1d0d1bd94c38dc47cd77c.tar.gz
postgresql-83e176ec18d2a91dbea1d0d1bd94c38dc47cd77c.zip
Separate block sampling functions
Refactoring ahead of tablesample patch Requested and reviewed by Michael Paquier Petr Jelinek
Diffstat (limited to 'src/include/utils/sampling.h')
-rw-r--r--src/include/utils/sampling.h44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/include/utils/sampling.h b/src/include/utils/sampling.h
new file mode 100644
index 00000000000..e3e7f9cf6ae
--- /dev/null
+++ b/src/include/utils/sampling.h
@@ -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 */