/* Private state */ typedefstruct
{
uint64 cutoff; /* select tuples with hash less than this */
uint32 seed; /* random seed */
OffsetNumber lt; /* last tuple returned from current block */
} BernoulliSamplerData;
staticvoid bernoulli_samplescangetsamplesize(PlannerInfo *root,
RelOptInfo *baserel,
List *paramexprs,
BlockNumber *pages, double *tuples); staticvoid bernoulli_initsamplescan(SampleScanState *node, int eflags); staticvoid bernoulli_beginsamplescan(SampleScanState *node,
Datum *params, int nparams,
uint32 seed); static OffsetNumber bernoulli_nextsampletuple(SampleScanState *node,
BlockNumber blockno,
OffsetNumber maxoffset);
/* *CreateaTsmRoutinedescriptorfortheBERNOULLImethod.
*/
Datum
tsm_bernoulli_handler(PG_FUNCTION_ARGS)
{
TsmRoutine *tsm = makeNode(TsmRoutine);
/* Try to extract an estimate for the sample percentage */
pctnode = (Node *) linitial(paramexprs);
pctnode = estimate_expression_value(root, pctnode);
if (IsA(pctnode, Const) &&
!((Const *) pctnode)->constisnull)
{
samplefract = DatumGetFloat4(((Const *) pctnode)->constvalue); if (samplefract >= 0 && samplefract <= 100 && !isnan(samplefract))
samplefract /= 100.0f; else
{ /* Default samplefract if the value is bogus */
samplefract = 0.1f;
}
} else
{ /* Default samplefract if we didn't obtain a non-null Const */
samplefract = 0.1f;
}
/* We'll visit all pages of the baserel */
*pages = baserel->pages;
if (percent < 0 || percent > 100 || isnan(percent))
ereport(ERROR,
(errcode(ERRCODE_INVALID_TABLESAMPLE_ARGUMENT),
errmsg("sample percentage must be between 0 and 100")));
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.