diff options
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/access/heapam.h | 4 | ||||
-rw-r--r-- | src/include/access/relscan.h | 1 | ||||
-rw-r--r-- | src/include/access/tablesample.h | 60 | ||||
-rw-r--r-- | src/include/catalog/indexing.h | 5 | ||||
-rw-r--r-- | src/include/catalog/pg_proc.h | 27 | ||||
-rw-r--r-- | src/include/catalog/pg_tablesample_method.h | 78 | ||||
-rw-r--r-- | src/include/executor/nodeSamplescan.h | 24 | ||||
-rw-r--r-- | src/include/nodes/execnodes.h | 9 | ||||
-rw-r--r-- | src/include/nodes/nodes.h | 4 | ||||
-rw-r--r-- | src/include/nodes/parsenodes.h | 37 | ||||
-rw-r--r-- | src/include/nodes/plannodes.h | 6 | ||||
-rw-r--r-- | src/include/optimizer/cost.h | 1 | ||||
-rw-r--r-- | src/include/optimizer/pathnode.h | 2 | ||||
-rw-r--r-- | src/include/parser/kwlist.h | 1 | ||||
-rw-r--r-- | src/include/parser/parse_func.h | 5 | ||||
-rw-r--r-- | src/include/port.h | 4 | ||||
-rw-r--r-- | src/include/utils/lsyscache.h | 1 | ||||
-rw-r--r-- | src/include/utils/rel.h | 1 | ||||
-rw-r--r-- | src/include/utils/sampling.h | 15 | ||||
-rw-r--r-- | src/include/utils/syscache.h | 2 |
20 files changed, 284 insertions, 3 deletions
diff --git a/src/include/access/heapam.h b/src/include/access/heapam.h index 49c8ca4d66e..eec7c95b218 100644 --- a/src/include/access/heapam.h +++ b/src/include/access/heapam.h @@ -114,8 +114,12 @@ extern HeapScanDesc heap_beginscan_strat(Relation relation, Snapshot snapshot, bool allow_strat, bool allow_sync); extern HeapScanDesc heap_beginscan_bm(Relation relation, Snapshot snapshot, int nkeys, ScanKey key); +extern HeapScanDesc heap_beginscan_sampling(Relation relation, + Snapshot snapshot, int nkeys, ScanKey key, + bool allow_strat, bool allow_pagemode); extern void heap_setscanlimits(HeapScanDesc scan, BlockNumber startBlk, BlockNumber endBlk); +extern void heapgetpage(HeapScanDesc scan, BlockNumber page); extern void heap_rescan(HeapScanDesc scan, ScanKey key); extern void heap_endscan(HeapScanDesc scan); extern HeapTuple heap_getnext(HeapScanDesc scan, ScanDirection direction); diff --git a/src/include/access/relscan.h b/src/include/access/relscan.h index 5a0d724aca5..1b9b2993957 100644 --- a/src/include/access/relscan.h +++ b/src/include/access/relscan.h @@ -29,6 +29,7 @@ typedef struct HeapScanDescData int rs_nkeys; /* number of scan keys */ ScanKey rs_key; /* array of scan key descriptors */ bool rs_bitmapscan; /* true if this is really a bitmap scan */ + bool rs_samplescan; /* true if this is really a sample scan */ bool rs_pageatatime; /* verify visibility page-at-a-time? */ bool rs_allow_strat; /* allow or disallow use of access strategy */ bool rs_allow_sync; /* allow or disallow use of syncscan */ diff --git a/src/include/access/tablesample.h b/src/include/access/tablesample.h new file mode 100644 index 00000000000..222fa8d5561 --- /dev/null +++ b/src/include/access/tablesample.h @@ -0,0 +1,60 @@ +/*------------------------------------------------------------------------- + * + * tablesample.h + * Public header file for TABLESAMPLE clause interface + * + * + * Portions Copyright (c) 1996-2015, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/tablesample.h + * + *------------------------------------------------------------------------- + */ +#ifndef TABLESAMPLE_H +#define TABLESAMPLE_H + +#include "access/relscan.h" +#include "executor/executor.h" + +typedef struct TableSampleDesc { + HeapScanDesc heapScan; + TupleDesc tupDesc; /* Mostly useful for tsmexaminetuple */ + + void *tsmdata; /* private method data */ + + /* These point to he function of the TABLESAMPLE Method. */ + FmgrInfo tsminit; + FmgrInfo tsmnextblock; + FmgrInfo tsmnexttuple; + FmgrInfo tsmexaminetuple; + FmgrInfo tsmreset; + FmgrInfo tsmend; +} TableSampleDesc; + + +extern TableSampleDesc *tablesample_init(SampleScanState *scanstate, + TableSampleClause *tablesample); +extern HeapTuple tablesample_getnext(TableSampleDesc *desc); +extern void tablesample_reset(TableSampleDesc *desc); +extern void tablesample_end(TableSampleDesc *desc); +extern HeapTuple tablesample_source_getnext(TableSampleDesc *desc); +extern HeapTuple tablesample_source_gettup(TableSampleDesc *desc, ItemPointer tid, + bool *visible); + +extern Datum tsm_system_init(PG_FUNCTION_ARGS); +extern Datum tsm_system_nextblock(PG_FUNCTION_ARGS); +extern Datum tsm_system_nexttuple(PG_FUNCTION_ARGS); +extern Datum tsm_system_end(PG_FUNCTION_ARGS); +extern Datum tsm_system_reset(PG_FUNCTION_ARGS); +extern Datum tsm_system_cost(PG_FUNCTION_ARGS); + +extern Datum tsm_bernoulli_init(PG_FUNCTION_ARGS); +extern Datum tsm_bernoulli_nextblock(PG_FUNCTION_ARGS); +extern Datum tsm_bernoulli_nexttuple(PG_FUNCTION_ARGS); +extern Datum tsm_bernoulli_end(PG_FUNCTION_ARGS); +extern Datum tsm_bernoulli_reset(PG_FUNCTION_ARGS); +extern Datum tsm_bernoulli_cost(PG_FUNCTION_ARGS); + + +#endif diff --git a/src/include/catalog/indexing.h b/src/include/catalog/indexing.h index 71e0010a6f8..f20567ed5f5 100644 --- a/src/include/catalog/indexing.h +++ b/src/include/catalog/indexing.h @@ -316,6 +316,11 @@ DECLARE_UNIQUE_INDEX(pg_replication_origin_roiident_index, 6001, on pg_replicati DECLARE_UNIQUE_INDEX(pg_replication_origin_roname_index, 6002, on pg_replication_origin using btree(roname varchar_pattern_ops)); #define ReplicationOriginNameIndex 6002 +DECLARE_UNIQUE_INDEX(pg_tablesample_method_name_index, 3331, on pg_tablesample_method using btree(tsmname name_ops)); +#define TableSampleMethodNameIndexId 3331 +DECLARE_UNIQUE_INDEX(pg_tablesample_method_oid_index, 3332, on pg_tablesample_method using btree(oid oid_ops)); +#define TableSampleMethodOidIndexId 3332 + /* last step of initialization script: build the indexes declared above */ BUILD_INDICES diff --git a/src/include/catalog/pg_proc.h b/src/include/catalog/pg_proc.h index 1c9edbc3b37..c2185bd9add 100644 --- a/src/include/catalog/pg_proc.h +++ b/src/include/catalog/pg_proc.h @@ -5297,6 +5297,33 @@ DESCR("get an individual replication origin's replication progress"); DATA(insert OID = 6014 ( pg_show_replication_origin_status PGNSP PGUID 12 1 100 0 0 f f f f f t v 0 0 2249 "" "{26,25,3220,3220}" "{o,o,o,o}" "{local_id, external_id, remote_lsn, local_lsn}" _null_ _null_ pg_show_replication_origin_status _null_ _null_ _null_ )); DESCR("get progress for all replication origins"); +/* tablesample */ +DATA(insert OID = 3335 ( tsm_system_init PGNSP PGUID 12 1 0 0 0 f f f f t f v 3 0 2278 "2281 23 700" _null_ _null_ _null_ _null_ _null_ tsm_system_init _null_ _null_ _null_ )); +DESCR("tsm_system_init(internal)"); +DATA(insert OID = 3336 ( tsm_system_nextblock PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 23 "2281 16" _null_ _null_ _null_ _null_ _null_ tsm_system_nextblock _null_ _null_ _null_ )); +DESCR("tsm_system_nextblock(internal)"); +DATA(insert OID = 3337 ( tsm_system_nexttuple PGNSP PGUID 12 1 0 0 0 f f f f t f v 4 0 21 "2281 23 21 16" _null_ _null_ _null_ _null_ _null_ tsm_system_nexttuple _null_ _null_ _null_ )); +DESCR("tsm_system_nexttuple(internal)"); +DATA(insert OID = 3338 ( tsm_system_end PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "2281" _null_ _null_ _null_ _null_ _null_ tsm_system_end _null_ _null_ _null_ )); +DESCR("tsm_system_end(internal)"); +DATA(insert OID = 3339 ( tsm_system_reset PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "2281" _null_ _null_ _null_ _null_ _null_ tsm_system_reset _null_ _null_ _null_ )); +DESCR("tsm_system_reset(internal)"); +DATA(insert OID = 3340 ( tsm_system_cost PGNSP PGUID 12 1 0 0 0 f f f f t f v 7 0 2278 "2281 2281 2281 2281 2281 2281 2281" _null_ _null_ _null_ _null_ _null_ tsm_system_cost _null_ _null_ _null_ )); +DESCR("tsm_system_cost(internal)"); + +DATA(insert OID = 3341 ( tsm_bernoulli_init PGNSP PGUID 12 1 0 0 0 f f f f t f v 3 0 2278 "2281 23 700" _null_ _null_ _null_ _null_ _null_ tsm_bernoulli_init _null_ _null_ _null_ )); +DESCR("tsm_bernoulli_init(internal)"); +DATA(insert OID = 3342 ( tsm_bernoulli_nextblock PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 23 "2281 16" _null_ _null_ _null_ _null_ _null_ tsm_bernoulli_nextblock _null_ _null_ _null_ )); +DESCR("tsm_bernoulli_nextblock(internal)"); +DATA(insert OID = 3343 ( tsm_bernoulli_nexttuple PGNSP PGUID 12 1 0 0 0 f f f f t f v 4 0 21 "2281 23 21 16" _null_ _null_ _null_ _null_ _null_ tsm_bernoulli_nexttuple _null_ _null_ _null_ )); +DESCR("tsm_bernoulli_nexttuple(internal)"); +DATA(insert OID = 3344 ( tsm_bernoulli_end PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "2281" _null_ _null_ _null_ _null_ _null_ tsm_bernoulli_end _null_ _null_ _null_ )); +DESCR("tsm_bernoulli_end(internal)"); +DATA(insert OID = 3345 ( tsm_bernoulli_reset PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "2281" _null_ _null_ _null_ _null_ _null_ tsm_bernoulli_reset _null_ _null_ _null_ )); +DESCR("tsm_bernoulli_reset(internal)"); +DATA(insert OID = 3346 ( tsm_bernoulli_cost PGNSP PGUID 12 1 0 0 0 f f f f t f v 7 0 2278 "2281 2281 2281 2281 2281 2281 2281" _null_ _null_ _null_ _null_ _null_ tsm_bernoulli_cost _null_ _null_ _null_ )); +DESCR("tsm_bernoulli_cost(internal)"); + /* * Symbolic values for provolatile column: these indicate whether the result * of a function is dependent *only* on the values of its explicit arguments, diff --git a/src/include/catalog/pg_tablesample_method.h b/src/include/catalog/pg_tablesample_method.h new file mode 100644 index 00000000000..968d1e696ab --- /dev/null +++ b/src/include/catalog/pg_tablesample_method.h @@ -0,0 +1,78 @@ +/*------------------------------------------------------------------------- + * + * pg_tablesample_method.h + * definition of the table scan methods. + * + * + * Portions Copyright (c) 1996-2014, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_tablesample_method.h + * + * + *------------------------------------------------------------------------- + */ +#ifndef PG_TABLESAMPLE_METHOD_H +#define PG_TABLESAMPLE_METHOD_H + +#include "catalog/genbki.h" +#include "catalog/objectaddress.h" + +/* ---------------- + * pg_tablesample_method definition. cpp turns this into + * typedef struct FormData_pg_tablesample_method + * ---------------- + */ +#define TableSampleMethodRelationId 3330 + +CATALOG(pg_tablesample_method,3330) +{ + NameData tsmname; /* tablesample method name */ + bool tsmseqscan; /* does this method scan whole table sequentially? */ + bool tsmpagemode; /* does this method scan page at a time? */ + regproc tsminit; /* init scan function */ + regproc tsmnextblock; /* function returning next block to sample + or InvalidBlockOffset if finished */ + regproc tsmnexttuple; /* function returning next tuple offset from current block + or InvalidOffsetNumber if end of the block was reacher */ + regproc tsmexaminetuple; /* optional function which can examine tuple contents and + decide if tuple should be returned or not */ + regproc tsmend; /* end scan function*/ + regproc tsmreset; /* reset state - used by rescan */ + regproc tsmcost; /* costing function */ +} FormData_pg_tablesample_method; + +/* ---------------- + * Form_pg_tablesample_method corresponds to a pointer to a tuple with + * the format of pg_tablesample_method relation. + * ---------------- + */ +typedef FormData_pg_tablesample_method *Form_pg_tablesample_method; + +/* ---------------- + * compiler constants for pg_tablesample_method + * ---------------- + */ +#define Natts_pg_tablesample_method 10 +#define Anum_pg_tablesample_method_tsmname 1 +#define Anum_pg_tablesample_method_tsmseqscan 2 +#define Anum_pg_tablesample_method_tsmpagemode 3 +#define Anum_pg_tablesample_method_tsminit 4 +#define Anum_pg_tablesample_method_tsmnextblock 5 +#define Anum_pg_tablesample_method_tsmnexttuple 6 +#define Anum_pg_tablesample_method_tsmexaminetuple 7 +#define Anum_pg_tablesample_method_tsmend 8 +#define Anum_pg_tablesample_method_tsmreset 9 +#define Anum_pg_tablesample_method_tsmcost 10 + +/* ---------------- + * initial contents of pg_tablesample_method + * ---------------- + */ + +DATA(insert OID = 3333 ( system false true tsm_system_init tsm_system_nextblock tsm_system_nexttuple - tsm_system_end tsm_system_reset tsm_system_cost )); +DESCR("SYSTEM table sampling method"); +DATA(insert OID = 3334 ( bernoulli true false tsm_bernoulli_init tsm_bernoulli_nextblock tsm_bernoulli_nexttuple - tsm_bernoulli_end tsm_bernoulli_reset tsm_bernoulli_cost )); +DESCR("BERNOULLI table sampling method"); + +#endif /* PG_TABLESAMPLE_METHOD_H */ diff --git a/src/include/executor/nodeSamplescan.h b/src/include/executor/nodeSamplescan.h new file mode 100644 index 00000000000..4b769daec8b --- /dev/null +++ b/src/include/executor/nodeSamplescan.h @@ -0,0 +1,24 @@ +/*------------------------------------------------------------------------- + * + * nodeSamplescan.h + * + * + * + * Portions Copyright (c) 1996-2014, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeSamplescan.h + * + *------------------------------------------------------------------------- + */ +#ifndef NODESAMPLESCAN_H +#define NODESAMPLESCAN_H + +#include "nodes/execnodes.h" + +extern SampleScanState *ExecInitSampleScan(SampleScan *node, EState *estate, int eflags); +extern TupleTableSlot *ExecSampleScan(SampleScanState *node); +extern void ExecEndSampleScan(SampleScanState *node); +extern void ExecReScanSampleScan(SampleScanState *node); + +#endif /* NODESAMPLESCAN_H */ diff --git a/src/include/nodes/execnodes.h b/src/include/nodes/execnodes.h index fcfe1107f92..972368019a9 100644 --- a/src/include/nodes/execnodes.h +++ b/src/include/nodes/execnodes.h @@ -1238,6 +1238,15 @@ typedef struct ScanState typedef ScanState SeqScanState; /* + * SampleScan + */ +typedef struct SampleScanState +{ + ScanState ss; + struct TableSampleDesc *tsdesc; +} SampleScanState; + +/* * These structs store information about index quals that don't have simple * constant right-hand sides. See comments for ExecIndexBuildScanKeys() * for discussion. diff --git a/src/include/nodes/nodes.h b/src/include/nodes/nodes.h index 768f413a451..8b275f6e263 100644 --- a/src/include/nodes/nodes.h +++ b/src/include/nodes/nodes.h @@ -61,6 +61,7 @@ typedef enum NodeTag T_ValuesScan, T_CteScan, T_WorkTableScan, + T_SampleScan, T_ForeignScan, T_CustomScan, T_Join, @@ -97,6 +98,7 @@ typedef enum NodeTag T_BitmapOrState, T_ScanState, T_SeqScanState, + T_SampleScanState, T_IndexScanState, T_IndexOnlyScanState, T_BitmapIndexScanState, @@ -419,6 +421,8 @@ typedef enum NodeTag T_OnConflictClause, T_CommonTableExpr, T_RoleSpec, + T_RangeTableSample, + T_TableSampleClause, /* * TAGS FOR REPLICATION GRAMMAR PARSE NODES (replnodes.h) diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h index 053f1b01213..6723f46f3f1 100644 --- a/src/include/nodes/parsenodes.h +++ b/src/include/nodes/parsenodes.h @@ -336,6 +336,26 @@ typedef struct FuncCall } FuncCall; /* + * TableSampleClause - a sampling method information + */ +typedef struct TableSampleClause +{ + NodeTag type; + Oid tsmid; + bool tsmseqscan; + bool tsmpagemode; + Oid tsminit; + Oid tsmnextblock; + Oid tsmnexttuple; + Oid tsmexaminetuple; + Oid tsmend; + Oid tsmreset; + Oid tsmcost; + Node *repeatable; + List *args; +} TableSampleClause; + +/* * A_Star - '*' representing all columns of a table or compound field * * This can appear within ColumnRef.fields, A_Indirection.indirection, and @@ -536,6 +556,22 @@ typedef struct RangeFunction } RangeFunction; /* + * RangeTableSample - represents <table> TABLESAMPLE <method> (<params>) REPEATABLE (<num>) + * + * SQL Standard specifies only one parameter which is percentage. But we allow + * custom tablesample methods which may need different input arguments so we + * accept list of arguments. + */ +typedef struct RangeTableSample +{ + NodeTag type; + RangeVar *relation; + char *method; /* sampling method */ + Node *repeatable; + List *args; /* arguments for sampling method */ +} RangeTableSample; + +/* * ColumnDef - column definition (used in various creates) * * If the column has a default value, we may have the value expression @@ -772,6 +808,7 @@ typedef struct RangeTblEntry */ Oid relid; /* OID of the relation */ char relkind; /* relation kind (see pg_class.relkind) */ + TableSampleClause *tablesample; /* sampling method and parameters */ /* * Fields valid for a subquery RTE (else NULL): diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h index 65f71d81705..4e655b0e6c1 100644 --- a/src/include/nodes/plannodes.h +++ b/src/include/nodes/plannodes.h @@ -287,6 +287,12 @@ typedef struct Scan typedef Scan SeqScan; /* ---------------- + * table sample scan node + * ---------------- + */ +typedef Scan SampleScan; + +/* ---------------- * index scan node * * indexqualorig is an implicitly-ANDed list of index qual expressions, each diff --git a/src/include/optimizer/cost.h b/src/include/optimizer/cost.h index 9c2000b15aa..24003ae3591 100644 --- a/src/include/optimizer/cost.h +++ b/src/include/optimizer/cost.h @@ -68,6 +68,7 @@ extern double index_pages_fetched(double tuples_fetched, BlockNumber pages, double index_pages, PlannerInfo *root); extern void cost_seqscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info); +extern void cost_samplescan(Path *path, PlannerInfo *root, RelOptInfo *baserel); extern void cost_index(IndexPath *path, PlannerInfo *root, double loop_count); extern void cost_bitmap_heap_scan(Path *path, PlannerInfo *root, RelOptInfo *baserel, diff --git a/src/include/optimizer/pathnode.h b/src/include/optimizer/pathnode.h index 9923f0eb3ea..89c8deda95c 100644 --- a/src/include/optimizer/pathnode.h +++ b/src/include/optimizer/pathnode.h @@ -32,6 +32,8 @@ extern bool add_path_precheck(RelOptInfo *parent_rel, extern Path *create_seqscan_path(PlannerInfo *root, RelOptInfo *rel, Relids required_outer); +extern Path *create_samplescan_path(PlannerInfo *root, RelOptInfo *rel, + Relids required_outer); extern IndexPath *create_index_path(PlannerInfo *root, IndexOptInfo *index, List *indexclauses, diff --git a/src/include/parser/kwlist.h b/src/include/parser/kwlist.h index faea99108c4..7d5f857ae59 100644 --- a/src/include/parser/kwlist.h +++ b/src/include/parser/kwlist.h @@ -368,6 +368,7 @@ PG_KEYWORD("sysid", SYSID, UNRESERVED_KEYWORD) PG_KEYWORD("system", SYSTEM_P, UNRESERVED_KEYWORD) PG_KEYWORD("table", TABLE, RESERVED_KEYWORD) PG_KEYWORD("tables", TABLES, UNRESERVED_KEYWORD) +PG_KEYWORD("tablesample", TABLESAMPLE, TYPE_FUNC_NAME_KEYWORD) PG_KEYWORD("tablespace", TABLESPACE, UNRESERVED_KEYWORD) PG_KEYWORD("temp", TEMP, UNRESERVED_KEYWORD) PG_KEYWORD("template", TEMPLATE, UNRESERVED_KEYWORD) diff --git a/src/include/parser/parse_func.h b/src/include/parser/parse_func.h index 32646918e20..40c007c35fc 100644 --- a/src/include/parser/parse_func.h +++ b/src/include/parser/parse_func.h @@ -33,6 +33,11 @@ typedef enum extern Node *ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs, FuncCall *fn, int location); +extern TableSampleClause *ParseTableSample(ParseState *pstate, + char *samplemethod, + Node *repeatable, List *args, + int location); + extern FuncDetailCode func_get_detail(List *funcname, List *fargs, List *fargnames, int nargs, Oid *argtypes, diff --git a/src/include/port.h b/src/include/port.h index 3787cbfb761..71113c03944 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -357,6 +357,10 @@ extern off_t ftello(FILE *stream); #endif #endif +#define RAND48_SEED_0 (0x330e) +#define RAND48_SEED_1 (0xabcd) +#define RAND48_SEED_2 (0x1234) + extern double pg_erand48(unsigned short xseed[3]); extern long pg_lrand48(void); extern void pg_srand48(long seed); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index ffbaa61e5e2..e2e5734ea7b 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -156,6 +156,7 @@ extern void free_attstatsslot(Oid atttype, extern char *get_namespace_name(Oid nspid); extern char *get_namespace_name_or_temp(Oid nspid); extern Oid get_range_subtype(Oid rangeOid); +extern char *get_tablesample_method_name(Oid tsmid); #define type_is_array(typid) (get_element_type(typid) != InvalidOid) /* type_is_array_domain accepts both plain arrays and domains over arrays */ diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index 9e17d87413d..fd40366bcda 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -63,7 +63,6 @@ typedef struct RelationAmInfo FmgrInfo amcanreturn; } RelationAmInfo; - /* * Here are the contents of a relation cache entry. */ 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); diff --git a/src/include/utils/syscache.h b/src/include/utils/syscache.h index 6634099cbe2..2dbd38488b6 100644 --- a/src/include/utils/syscache.h +++ b/src/include/utils/syscache.h @@ -81,6 +81,8 @@ enum SysCacheIdentifier REPLORIGNAME, RULERELNAME, STATRELATTINH, + TABLESAMPLEMETHODNAME, + TABLESAMPLEMETHODOID, TABLESPACEOID, TRFOID, TRFTYPELANG, |