mirror of
https://github.com/postgres/postgres.git
synced 2025-08-22 21:53:06 +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:
@@ -641,6 +641,22 @@ _copyCustomScan(const CustomScan *from)
|
||||
return newnode;
|
||||
}
|
||||
|
||||
/*
|
||||
* _copySampleScan
|
||||
*/
|
||||
static SampleScan *
|
||||
_copySampleScan(const SampleScan *from)
|
||||
{
|
||||
SampleScan *newnode = makeNode(SampleScan);
|
||||
|
||||
/*
|
||||
* copy node superclass fields
|
||||
*/
|
||||
CopyScanFields((const Scan *) from, (Scan *) newnode);
|
||||
|
||||
return newnode;
|
||||
}
|
||||
|
||||
/*
|
||||
* CopyJoinFields
|
||||
*
|
||||
@@ -2063,6 +2079,7 @@ _copyRangeTblEntry(const RangeTblEntry *from)
|
||||
COPY_SCALAR_FIELD(rtekind);
|
||||
COPY_SCALAR_FIELD(relid);
|
||||
COPY_SCALAR_FIELD(relkind);
|
||||
COPY_NODE_FIELD(tablesample);
|
||||
COPY_NODE_FIELD(subquery);
|
||||
COPY_SCALAR_FIELD(security_barrier);
|
||||
COPY_SCALAR_FIELD(jointype);
|
||||
@@ -2224,6 +2241,40 @@ _copyCommonTableExpr(const CommonTableExpr *from)
|
||||
return newnode;
|
||||
}
|
||||
|
||||
static RangeTableSample *
|
||||
_copyRangeTableSample(const RangeTableSample *from)
|
||||
{
|
||||
RangeTableSample *newnode = makeNode(RangeTableSample);
|
||||
|
||||
COPY_NODE_FIELD(relation);
|
||||
COPY_STRING_FIELD(method);
|
||||
COPY_NODE_FIELD(repeatable);
|
||||
COPY_NODE_FIELD(args);
|
||||
|
||||
return newnode;
|
||||
}
|
||||
|
||||
static TableSampleClause *
|
||||
_copyTableSampleClause(const TableSampleClause *from)
|
||||
{
|
||||
TableSampleClause *newnode = makeNode(TableSampleClause);
|
||||
|
||||
COPY_SCALAR_FIELD(tsmid);
|
||||
COPY_SCALAR_FIELD(tsmseqscan);
|
||||
COPY_SCALAR_FIELD(tsmpagemode);
|
||||
COPY_SCALAR_FIELD(tsminit);
|
||||
COPY_SCALAR_FIELD(tsmnextblock);
|
||||
COPY_SCALAR_FIELD(tsmnexttuple);
|
||||
COPY_SCALAR_FIELD(tsmexaminetuple);
|
||||
COPY_SCALAR_FIELD(tsmend);
|
||||
COPY_SCALAR_FIELD(tsmreset);
|
||||
COPY_SCALAR_FIELD(tsmcost);
|
||||
COPY_NODE_FIELD(repeatable);
|
||||
COPY_NODE_FIELD(args);
|
||||
|
||||
return newnode;
|
||||
}
|
||||
|
||||
static A_Expr *
|
||||
_copyAExpr(const A_Expr *from)
|
||||
{
|
||||
@@ -4179,6 +4230,9 @@ copyObject(const void *from)
|
||||
case T_CustomScan:
|
||||
retval = _copyCustomScan(from);
|
||||
break;
|
||||
case T_SampleScan:
|
||||
retval = _copySampleScan(from);
|
||||
break;
|
||||
case T_Join:
|
||||
retval = _copyJoin(from);
|
||||
break;
|
||||
@@ -4842,6 +4896,12 @@ copyObject(const void *from)
|
||||
case T_CommonTableExpr:
|
||||
retval = _copyCommonTableExpr(from);
|
||||
break;
|
||||
case T_RangeTableSample:
|
||||
retval = _copyRangeTableSample(from);
|
||||
break;
|
||||
case T_TableSampleClause:
|
||||
retval = _copyTableSampleClause(from);
|
||||
break;
|
||||
case T_FuncWithArgs:
|
||||
retval = _copyFuncWithArgs(from);
|
||||
break;
|
||||
|
Reference in New Issue
Block a user