mirror of
https://github.com/postgres/postgres.git
synced 2025-07-03 20:02:46 +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:
27
src/backend/utils/cache/lsyscache.c
vendored
27
src/backend/utils/cache/lsyscache.c
vendored
@ -32,6 +32,7 @@
|
||||
#include "catalog/pg_range.h"
|
||||
#include "catalog/pg_statistic.h"
|
||||
#include "catalog/pg_transform.h"
|
||||
#include "catalog/pg_tablesample_method.h"
|
||||
#include "catalog/pg_type.h"
|
||||
#include "miscadmin.h"
|
||||
#include "nodes/makefuncs.h"
|
||||
@ -2996,3 +2997,29 @@ get_range_subtype(Oid rangeOid)
|
||||
else
|
||||
return InvalidOid;
|
||||
}
|
||||
|
||||
/* ---------- PG_TABLESAMPLE_METHOD CACHE ---------- */
|
||||
|
||||
/*
|
||||
* get_tablesample_method_name - given a tablesample method OID,
|
||||
* look up the name or NULL if not found
|
||||
*/
|
||||
char *
|
||||
get_tablesample_method_name(Oid tsmid)
|
||||
{
|
||||
HeapTuple tuple;
|
||||
|
||||
tuple = SearchSysCache1(TABLESAMPLEMETHODOID, ObjectIdGetDatum(tsmid));
|
||||
if (HeapTupleIsValid(tuple))
|
||||
{
|
||||
Form_pg_tablesample_method tup =
|
||||
(Form_pg_tablesample_method) GETSTRUCT(tuple);
|
||||
char *result;
|
||||
|
||||
result = pstrdup(NameStr(tup->tsmname));
|
||||
ReleaseSysCache(tuple);
|
||||
return result;
|
||||
}
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
Reference in New Issue
Block a user