mirror of
https://github.com/postgres/postgres.git
synced 2025-11-06 07:49:08 +03:00
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
This commit is contained in:
@@ -335,6 +335,26 @@ typedef struct FuncCall
|
||||
int location; /* token location, or -1 if unknown */
|
||||
} 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
|
||||
*
|
||||
@@ -535,6 +555,22 @@ typedef struct RangeFunction
|
||||
* of function returning RECORD */
|
||||
} 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)
|
||||
*
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user