1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-26 01:22:12 +03:00

Add TID Range Scans to support efficient scanning ranges of TIDs

This adds a new executor node named TID Range Scan.  The query planner
will generate paths for TID Range scans when quals are discovered on base
relations which search for ranges on the table's ctid column.  These
ranges may be open at either end. For example, WHERE ctid >= '(10,0)';
will return all tuples on page 10 and over.

To support this, two new optional callback functions have been added to
table AM.  scan_set_tidrange is used to set the scan range to just the
given range of TIDs.  scan_getnextslot_tidrange fetches the next tuple
in the given range.

For AMs were scanning ranges of TIDs would not make sense, these functions
can be set to NULL in the TableAmRoutine.  The query planner won't
generate TID Range Scan Paths in that case.

Author: Edmund Horner, David Rowley
Reviewed-by: David Rowley, Tomas Vondra, Tom Lane, Andres Freund, Zhihong Yu
Discussion: https://postgr.es/m/CAMyN-kB-nFTkF=VA_JPwFNo08S0d-Yk0F741S2B7LDmYAi8eyA@mail.gmail.com
This commit is contained in:
David Rowley
2021-02-27 22:59:36 +13:00
parent f4adc41c4f
commit bb437f995d
36 changed files with 1654 additions and 22 deletions

View File

@ -621,6 +621,10 @@ typedef struct PartitionSchemeData *PartitionScheme;
* to simplify matching join clauses to those lists.
*----------
*/
/* Bitmask of flags supported by table AMs */
#define AMFLAG_HAS_TID_RANGE (1 << 0)
typedef enum RelOptKind
{
RELOPT_BASEREL,
@ -710,6 +714,8 @@ typedef struct RelOptInfo
PlannerInfo *subroot; /* if subquery */
List *subplan_params; /* if subquery */
int rel_parallel_workers; /* wanted number of parallel workers */
uint32 amflags; /* Bitmask of optional features supported by
* the table AM */
/* Information about foreign tables and foreign joins */
Oid serverid; /* identifies server for the table or join */
@ -1323,6 +1329,18 @@ typedef struct TidPath
List *tidquals; /* qual(s) involving CTID = something */
} TidPath;
/*
* TidRangePath represents a scan by a continguous range of TIDs
*
* tidrangequals is an implicitly AND'ed list of qual expressions of the form
* "CTID relop pseudoconstant", where relop is one of >,>=,<,<=.
*/
typedef struct TidRangePath
{
Path path;
List *tidrangequals;
} TidRangePath;
/*
* SubqueryScanPath represents a scan of an unflattened subquery-in-FROM
*