pgsql: Redesign tablesample method API, and do extensive code review. - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Redesign tablesample method API, and do extensive code review.
Date
Msg-id E1ZJ4ML-0001xP-TM@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
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.

Branch
------
REL9_5_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/6fcb337fa507723d6940ed8e5658d3da1fac6195

Modified Files
--------------
contrib/pg_stat_statements/pg_stat_statements.c    |   10 +
contrib/tsm_system_rows/Makefile                   |    4 +-
.../tsm_system_rows/expected/tsm_system_rows.out   |   96 ++++-
contrib/tsm_system_rows/sql/tsm_system_rows.sql    |   41 +-
contrib/tsm_system_rows/tsm_system_rows--1.0.sql   |   43 +-
contrib/tsm_system_rows/tsm_system_rows.c          |  445 ++++++++++++-------
contrib/tsm_system_rows/tsm_system_rows.control    |    2 +-
contrib/tsm_system_time/Makefile                   |    4 +-
.../tsm_system_time/expected/tsm_system_time.out   |  138 ++++--
contrib/tsm_system_time/sql/tsm_system_time.sql    |   53 ++-
contrib/tsm_system_time/tsm_system_time--1.0.sql   |   38 +-
contrib/tsm_system_time/tsm_system_time.c          |  453 +++++++++++---------
contrib/tsm_system_time/tsm_system_time.control    |    2 +-
doc/src/sgml/catalogs.sgml                         |  120 ------
doc/src/sgml/datatype.sgml                         |   11 +-
doc/src/sgml/postgres.sgml                         |    2 +-
doc/src/sgml/ref/select.sgml                       |  126 +++---
doc/src/sgml/tablesample-method.sgml               |  322 ++++++++++----
doc/src/sgml/tsm-system-rows.sgml                  |   39 +-
doc/src/sgml/tsm-system-time.sgml                  |   42 +-
src/backend/access/heap/heapam.c                   |   61 ++-
src/backend/access/tablesample/Makefile            |    6 +-
src/backend/access/tablesample/bernoulli.c         |  326 +++++++-------
src/backend/access/tablesample/system.c            |  312 +++++++++-----
src/backend/access/tablesample/tablesample.c       |  355 +--------------
src/backend/catalog/Makefile                       |    5 +-
src/backend/catalog/dependency.c                   |    8 +
src/backend/commands/explain.c                     |  107 +++--
src/backend/executor/execAmi.c                     |    7 +-
src/backend/executor/nodeSamplescan.c              |  437 +++++++++++++++++--
src/backend/nodes/copyfuncs.c                      |  115 +++--
src/backend/nodes/equalfuncs.c                     |   64 ++-
src/backend/nodes/nodeFuncs.c                      |   75 ++--
src/backend/nodes/outfuncs.c                       |   88 ++--
src/backend/nodes/readfuncs.c                      |   61 +--
src/backend/optimizer/path/allpaths.c              |  100 ++++-
src/backend/optimizer/path/costsize.c              |   57 +--
src/backend/optimizer/plan/createplan.c            |   34 +-
src/backend/optimizer/plan/initsplan.c             |    4 +-
src/backend/optimizer/plan/planner.c               |   19 +-
src/backend/optimizer/plan/setrefs.c               |   18 +-
src/backend/optimizer/plan/subselect.c             |    7 +-
src/backend/optimizer/prep/prepjointree.c          |   13 +-
src/backend/optimizer/util/pathnode.c              |    8 +-
src/backend/parser/gram.y                          |   27 +-
src/backend/parser/parse_clause.c                  |  190 +++++---
src/backend/parser/parse_func.c                    |  144 -------
src/backend/rewrite/rewriteHandler.c               |    4 +
src/backend/utils/adt/pseudotypes.c                |   27 ++
src/backend/utils/adt/ruleutils.c                  |   94 ++--
src/backend/utils/cache/lsyscache.c                |   27 --
src/backend/utils/cache/syscache.c                 |   23 -
src/backend/utils/errcodes.txt                     |    2 +
src/backend/utils/misc/sampling.c                  |    2 +-
src/bin/psql/tab-complete.c                        |   10 +-
src/include/access/heapam.h                        |    4 +-
src/include/access/tablesample.h                   |   61 ---
src/include/access/tsmapi.h                        |   81 ++++
src/include/catalog/catversion.h                   |    2 +-
src/include/catalog/indexing.h                     |    5 -
src/include/catalog/pg_proc.h                      |   37 +-
src/include/catalog/pg_tablesample_method.h        |   81 ----
src/include/catalog/pg_type.h                      |    2 +
src/include/executor/nodeSamplescan.h              |    2 +-
src/include/nodes/execnodes.h                      |   15 +-
src/include/nodes/nodes.h                          |    9 +-
src/include/nodes/parsenodes.h                     |   59 ++-
src/include/nodes/plannodes.h                      |    7 +-
src/include/optimizer/cost.h                       |    3 +-
src/include/parser/parse_func.h                    |    5 -
src/include/port.h                                 |    4 -
src/include/utils/builtins.h                       |    8 +
src/include/utils/lsyscache.h                      |    1 -
src/include/utils/syscache.h                       |    2 -
src/port/erand48.c                                 |    3 +
src/test/regress/expected/rowsecurity.out          |   24 +-
src/test/regress/expected/rules.out                |    4 +
src/test/regress/expected/sanity_check.out         |    1 -
src/test/regress/expected/tablesample.out          |  284 +++++++-----
src/test/regress/output/misc.source                |    5 +-
src/test/regress/serial_schedule                   |    2 +-
src/test/regress/sql/rowsecurity.sql               |    8 +-
src/test/regress/sql/tablesample.sql               |   90 ++--
83 files changed, 3116 insertions(+), 2521 deletions(-)


pgsql-committers by date:

Previous
From: Tom Lane
Date:
Subject: pgsql: Redesign tablesample method API, and do extensive code review.
Next
From: Tom Lane
Date:
Subject: pgsql: Update oidjoins regression test for 9.5.