mirror of
https://github.com/postgres/postgres.git
synced 2025-07-18 17:42:25 +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:
@ -591,6 +591,14 @@ _outCustomScan(StringInfo str, const CustomScan *node)
|
||||
node->methods->TextOutCustomScan(str, node);
|
||||
}
|
||||
|
||||
static void
|
||||
_outSampleScan(StringInfo str, const SampleScan *node)
|
||||
{
|
||||
WRITE_NODE_TYPE("SAMPLESCAN");
|
||||
|
||||
_outScanInfo(str, (const Scan *) node);
|
||||
}
|
||||
|
||||
static void
|
||||
_outJoin(StringInfo str, const Join *node)
|
||||
{
|
||||
@ -2444,6 +2452,36 @@ _outCommonTableExpr(StringInfo str, const CommonTableExpr *node)
|
||||
WRITE_NODE_FIELD(ctecolcollations);
|
||||
}
|
||||
|
||||
static void
|
||||
_outRangeTableSample(StringInfo str, const RangeTableSample *node)
|
||||
{
|
||||
WRITE_NODE_TYPE("RANGETABLESAMPLE");
|
||||
|
||||
WRITE_NODE_FIELD(relation);
|
||||
WRITE_STRING_FIELD(method);
|
||||
WRITE_NODE_FIELD(repeatable);
|
||||
WRITE_NODE_FIELD(args);
|
||||
}
|
||||
|
||||
static void
|
||||
_outTableSampleClause(StringInfo str, const TableSampleClause *node)
|
||||
{
|
||||
WRITE_NODE_TYPE("TABLESAMPLECLAUSE");
|
||||
|
||||
WRITE_OID_FIELD(tsmid);
|
||||
WRITE_BOOL_FIELD(tsmseqscan);
|
||||
WRITE_BOOL_FIELD(tsmpagemode);
|
||||
WRITE_OID_FIELD(tsminit);
|
||||
WRITE_OID_FIELD(tsmnextblock);
|
||||
WRITE_OID_FIELD(tsmnexttuple);
|
||||
WRITE_OID_FIELD(tsmexaminetuple);
|
||||
WRITE_OID_FIELD(tsmend);
|
||||
WRITE_OID_FIELD(tsmreset);
|
||||
WRITE_OID_FIELD(tsmcost);
|
||||
WRITE_NODE_FIELD(repeatable);
|
||||
WRITE_NODE_FIELD(args);
|
||||
}
|
||||
|
||||
static void
|
||||
_outSetOperationStmt(StringInfo str, const SetOperationStmt *node)
|
||||
{
|
||||
@ -2474,6 +2512,7 @@ _outRangeTblEntry(StringInfo str, const RangeTblEntry *node)
|
||||
case RTE_RELATION:
|
||||
WRITE_OID_FIELD(relid);
|
||||
WRITE_CHAR_FIELD(relkind);
|
||||
WRITE_NODE_FIELD(tablesample);
|
||||
break;
|
||||
case RTE_SUBQUERY:
|
||||
WRITE_NODE_FIELD(subquery);
|
||||
@ -2973,6 +3012,9 @@ _outNode(StringInfo str, const void *obj)
|
||||
case T_CustomScan:
|
||||
_outCustomScan(str, obj);
|
||||
break;
|
||||
case T_SampleScan:
|
||||
_outSampleScan(str, obj);
|
||||
break;
|
||||
case T_Join:
|
||||
_outJoin(str, obj);
|
||||
break;
|
||||
@ -3319,6 +3361,12 @@ _outNode(StringInfo str, const void *obj)
|
||||
case T_CommonTableExpr:
|
||||
_outCommonTableExpr(str, obj);
|
||||
break;
|
||||
case T_RangeTableSample:
|
||||
_outRangeTableSample(str, obj);
|
||||
break;
|
||||
case T_TableSampleClause:
|
||||
_outTableSampleClause(str, obj);
|
||||
break;
|
||||
case T_SetOperationStmt:
|
||||
_outSetOperationStmt(str, obj);
|
||||
break;
|
||||
|
Reference in New Issue
Block a user