diff options
| author | Simon Riggs <simon@2ndQuadrant.com> | 2015-05-15 14:37:10 -0400 |
|---|---|---|
| committer | Simon Riggs <simon@2ndQuadrant.com> | 2015-05-15 14:37:10 -0400 |
| commit | f6d208d6e51810c73f0e02c477984a6b44627f11 (patch) | |
| tree | 99d540d0b7bda73ff60479f15444f554403d4679 /src/include/nodes | |
| parent | 11a83bbedd73800db70f6f2af5a8eb10d15d39d7 (diff) | |
| download | postgresql-f6d208d6e51810c73f0e02c477984a6b44627f11.tar.gz | |
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
Diffstat (limited to 'src/include/nodes')
| -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 |
4 files changed, 56 insertions, 0 deletions
diff --git a/src/include/nodes/execnodes.h b/src/include/nodes/execnodes.h index fcfe1107f9..972368019a 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 768f413a45..8b275f6e26 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 053f1b0121..6723f46f3f 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 65f71d8170..4e655b0e6c 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 |
