mirror of
https://github.com/postgres/postgres.git
synced 2025-08-21 10:42:50 +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:
@@ -566,6 +566,8 @@ extern Datum language_handler_in(PG_FUNCTION_ARGS);
|
||||
extern Datum language_handler_out(PG_FUNCTION_ARGS);
|
||||
extern Datum fdw_handler_in(PG_FUNCTION_ARGS);
|
||||
extern Datum fdw_handler_out(PG_FUNCTION_ARGS);
|
||||
extern Datum tsm_handler_in(PG_FUNCTION_ARGS);
|
||||
extern Datum tsm_handler_out(PG_FUNCTION_ARGS);
|
||||
extern Datum internal_in(PG_FUNCTION_ARGS);
|
||||
extern Datum internal_out(PG_FUNCTION_ARGS);
|
||||
extern Datum opaque_in(PG_FUNCTION_ARGS);
|
||||
@@ -1212,6 +1214,12 @@ extern Datum ginqueryarrayextract(PG_FUNCTION_ARGS);
|
||||
extern Datum ginarrayconsistent(PG_FUNCTION_ARGS);
|
||||
extern Datum ginarraytriconsistent(PG_FUNCTION_ARGS);
|
||||
|
||||
/* access/tablesample/bernoulli.c */
|
||||
extern Datum tsm_bernoulli_handler(PG_FUNCTION_ARGS);
|
||||
|
||||
/* access/tablesample/system.c */
|
||||
extern Datum tsm_system_handler(PG_FUNCTION_ARGS);
|
||||
|
||||
/* access/transam/twophase.c */
|
||||
extern Datum pg_prepared_xact(PG_FUNCTION_ARGS);
|
||||
|
||||
|
Reference in New Issue
Block a user