1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-10 17:42:29 +03:00

Redesign tablesample method API, and do extensive code review.

The original implementation of TABLESAMPLE modeled the tablesample method
API on index access methods, which wasn't a good choice because, without
specialized DDL commands, there's no way to build an extension that can
implement a TSM.  (Raw inserts into system catalogs are not an acceptable
thing to do, because we can't undo them during DROP EXTENSION, nor will
pg_upgrade behave sanely.)  Instead adopt an API more like procedural
language handlers or foreign data wrappers, wherein the only SQL-level
support object needed is a single handler function identified by having
a special return type.  This lets us get rid of the supporting catalog
altogether, so that no custom DDL support is needed for the feature.

Adjust the API so that it can support non-constant tablesample arguments
(the original coding assumed we could evaluate the argument expressions at
ExecInitSampleScan time, which is undesirable even if it weren't outright
unsafe), and discourage sampling methods from looking at invisible tuples.
Make sure that the BERNOULLI and SYSTEM methods are genuinely repeatable
within and across queries, as required by the SQL standard, and deal more
honestly with methods that can't support that requirement.

Make a full code-review pass over the tablesample additions, and fix
assorted bugs, omissions, infelicities, and cosmetic issues (such as
failure to put the added code stanzas in a consistent ordering).
Improve EXPLAIN's output of tablesample plans, too.

Back-patch to 9.5 so that we don't have to support the original API
in production.
This commit is contained in:
Tom Lane
2015-07-25 14:39:00 -04:00
parent b26e3d660d
commit dd7a8f66ed
83 changed files with 3184 additions and 2589 deletions

View File

@@ -2290,6 +2290,18 @@ _equalRangeFunction(const RangeFunction *a, const RangeFunction *b)
return true;
}
static bool
_equalRangeTableSample(const RangeTableSample *a, const RangeTableSample *b)
{
COMPARE_NODE_FIELD(relation);
COMPARE_NODE_FIELD(method);
COMPARE_NODE_FIELD(args);
COMPARE_NODE_FIELD(repeatable);
COMPARE_LOCATION_FIELD(location);
return true;
}
static bool
_equalIndexElem(const IndexElem *a, const IndexElem *b)
{
@@ -2428,6 +2440,16 @@ _equalRangeTblFunction(const RangeTblFunction *a, const RangeTblFunction *b)
return true;
}
static bool
_equalTableSampleClause(const TableSampleClause *a, const TableSampleClause *b)
{
COMPARE_SCALAR_FIELD(tsmhandler);
COMPARE_NODE_FIELD(args);
COMPARE_NODE_FIELD(repeatable);
return true;
}
static bool
_equalWithCheckOption(const WithCheckOption *a, const WithCheckOption *b)
{
@@ -2538,36 +2560,6 @@ _equalCommonTableExpr(const CommonTableExpr *a, const CommonTableExpr *b)
return true;
}
static bool
_equalRangeTableSample(const RangeTableSample *a, const RangeTableSample *b)
{
COMPARE_NODE_FIELD(relation);
COMPARE_STRING_FIELD(method);
COMPARE_NODE_FIELD(repeatable);
COMPARE_NODE_FIELD(args);
return true;
}
static bool
_equalTableSampleClause(const TableSampleClause *a, const TableSampleClause *b)
{
COMPARE_SCALAR_FIELD(tsmid);
COMPARE_SCALAR_FIELD(tsmseqscan);
COMPARE_SCALAR_FIELD(tsmpagemode);
COMPARE_SCALAR_FIELD(tsminit);
COMPARE_SCALAR_FIELD(tsmnextblock);
COMPARE_SCALAR_FIELD(tsmnexttuple);
COMPARE_SCALAR_FIELD(tsmexaminetuple);
COMPARE_SCALAR_FIELD(tsmend);
COMPARE_SCALAR_FIELD(tsmreset);
COMPARE_SCALAR_FIELD(tsmcost);
COMPARE_NODE_FIELD(repeatable);
COMPARE_NODE_FIELD(args);
return true;
}
static bool
_equalXmlSerialize(const XmlSerialize *a, const XmlSerialize *b)
{
@@ -3260,6 +3252,9 @@ equal(const void *a, const void *b)
case T_RangeFunction:
retval = _equalRangeFunction(a, b);
break;
case T_RangeTableSample:
retval = _equalRangeTableSample(a, b);
break;
case T_TypeName:
retval = _equalTypeName(a, b);
break;
@@ -3284,6 +3279,9 @@ equal(const void *a, const void *b)
case T_RangeTblFunction:
retval = _equalRangeTblFunction(a, b);
break;
case T_TableSampleClause:
retval = _equalTableSampleClause(a, b);
break;
case T_WithCheckOption:
retval = _equalWithCheckOption(a, b);
break;
@@ -3311,12 +3309,6 @@ equal(const void *a, const void *b)
case T_CommonTableExpr:
retval = _equalCommonTableExpr(a, b);
break;
case T_RangeTableSample:
retval = _equalRangeTableSample(a, b);
break;
case T_TableSampleClause:
retval = _equalTableSampleClause(a, b);
break;
case T_FuncWithArgs:
retval = _equalFuncWithArgs(a, b);
break;