Introduce extensible node types.
An extensible node is always tagged T_Extensible, but the extnodename
field identifies it more specifically; it may also include arbitrary
private data. Extensible nodes can be copied, tested for equality,
serialized, and deserialized, but the core system doesn't know
anything about them otherwise. Some extensions may find it useful to
include these nodes in fdw_private or custom_private lists in lieu of
arm-wrestling their data into a format that the core code can
understand.
Along the way, so as not to burden the authors of such extensible
node types too much, expose the functions for writing serialized
tokens, and for serializing and deserializing bitmapsets.
KaiGai Kohei, per a design suggested by me. Reviewed by Andres Freund
and by me, and further edited by me.
2016-02-12 15:31:16 +01:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* extensible.h
|
2016-03-29 17:00:18 +02:00
|
|
|
* Definitions for extensible nodes and custom scans
|
Introduce extensible node types.
An extensible node is always tagged T_Extensible, but the extnodename
field identifies it more specifically; it may also include arbitrary
private data. Extensible nodes can be copied, tested for equality,
serialized, and deserialized, but the core system doesn't know
anything about them otherwise. Some extensions may find it useful to
include these nodes in fdw_private or custom_private lists in lieu of
arm-wrestling their data into a format that the core code can
understand.
Along the way, so as not to burden the authors of such extensible
node types too much, expose the functions for writing serialized
tokens, and for serializing and deserializing bitmapsets.
KaiGai Kohei, per a design suggested by me. Reviewed by Andres Freund
and by me, and further edited by me.
2016-02-12 15:31:16 +01:00
|
|
|
*
|
|
|
|
*
|
2021-01-02 19:06:25 +01:00
|
|
|
* Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group
|
Introduce extensible node types.
An extensible node is always tagged T_Extensible, but the extnodename
field identifies it more specifically; it may also include arbitrary
private data. Extensible nodes can be copied, tested for equality,
serialized, and deserialized, but the core system doesn't know
anything about them otherwise. Some extensions may find it useful to
include these nodes in fdw_private or custom_private lists in lieu of
arm-wrestling their data into a format that the core code can
understand.
Along the way, so as not to burden the authors of such extensible
node types too much, expose the functions for writing serialized
tokens, and for serializing and deserializing bitmapsets.
KaiGai Kohei, per a design suggested by me. Reviewed by Andres Freund
and by me, and further edited by me.
2016-02-12 15:31:16 +01:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
|
|
|
* src/include/nodes/extensible.h
|
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#ifndef EXTENSIBLE_H
|
|
|
|
#define EXTENSIBLE_H
|
|
|
|
|
2016-03-29 17:00:18 +02:00
|
|
|
#include "access/parallel.h"
|
|
|
|
#include "commands/explain.h"
|
|
|
|
#include "nodes/execnodes.h"
|
2019-01-29 22:49:25 +01:00
|
|
|
#include "nodes/pathnodes.h"
|
2016-03-29 17:00:18 +02:00
|
|
|
#include "nodes/plannodes.h"
|
Introduce extensible node types.
An extensible node is always tagged T_Extensible, but the extnodename
field identifies it more specifically; it may also include arbitrary
private data. Extensible nodes can be copied, tested for equality,
serialized, and deserialized, but the core system doesn't know
anything about them otherwise. Some extensions may find it useful to
include these nodes in fdw_private or custom_private lists in lieu of
arm-wrestling their data into a format that the core code can
understand.
Along the way, so as not to burden the authors of such extensible
node types too much, expose the functions for writing serialized
tokens, and for serializing and deserializing bitmapsets.
KaiGai Kohei, per a design suggested by me. Reviewed by Andres Freund
and by me, and further edited by me.
2016-02-12 15:31:16 +01:00
|
|
|
|
2016-03-29 17:00:18 +02:00
|
|
|
/* maximum length of an extensible node identifier */
|
Introduce extensible node types.
An extensible node is always tagged T_Extensible, but the extnodename
field identifies it more specifically; it may also include arbitrary
private data. Extensible nodes can be copied, tested for equality,
serialized, and deserialized, but the core system doesn't know
anything about them otherwise. Some extensions may find it useful to
include these nodes in fdw_private or custom_private lists in lieu of
arm-wrestling their data into a format that the core code can
understand.
Along the way, so as not to burden the authors of such extensible
node types too much, expose the functions for writing serialized
tokens, and for serializing and deserializing bitmapsets.
KaiGai Kohei, per a design suggested by me. Reviewed by Andres Freund
and by me, and further edited by me.
2016-02-12 15:31:16 +01:00
|
|
|
#define EXTNODENAME_MAX_LEN 64
|
|
|
|
|
|
|
|
/*
|
|
|
|
* An extensible node is a new type of node defined by an extension. The
|
|
|
|
* type is always T_ExtensibleNode, while the extnodename identifies the
|
|
|
|
* specific type of node. extnodename can be looked up to find the
|
|
|
|
* ExtensibleNodeMethods for this node type.
|
|
|
|
*/
|
|
|
|
typedef struct ExtensibleNode
|
|
|
|
{
|
|
|
|
NodeTag type;
|
|
|
|
const char *extnodename; /* identifier of ExtensibleNodeMethods */
|
|
|
|
} ExtensibleNode;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* node_size is the size of an extensible node of this type in bytes.
|
|
|
|
*
|
|
|
|
* nodeCopy is a function which performs a deep copy from oldnode to newnode.
|
|
|
|
* It does not need to copy type or extnodename, which are copied by the
|
|
|
|
* core system.
|
|
|
|
*
|
|
|
|
* nodeEqual is a function which performs a deep equality comparison between
|
|
|
|
* a and b and returns true or false accordingly. It does not need to compare
|
|
|
|
* type or extnodename, which are compared by the core system.
|
|
|
|
*
|
|
|
|
* nodeOut is a serialization function for the node type. It should use the
|
|
|
|
* output conventions typical for outfuncs.c. It does not need to output
|
|
|
|
* type or extnodename; the core system handles those.
|
|
|
|
*
|
|
|
|
* nodeRead is a deserialization function for the node type. It does not need
|
|
|
|
* to read type or extnodename; the core system handles those. It should fetch
|
|
|
|
* the next token using pg_strtok() from the current input stream, and then
|
|
|
|
* reconstruct the private fields according to the manner in readfuncs.c.
|
|
|
|
*
|
|
|
|
* All callbacks are mandatory.
|
|
|
|
*/
|
|
|
|
typedef struct ExtensibleNodeMethods
|
|
|
|
{
|
|
|
|
const char *extnodename;
|
|
|
|
Size node_size;
|
|
|
|
void (*nodeCopy) (struct ExtensibleNode *newnode,
|
|
|
|
const struct ExtensibleNode *oldnode);
|
|
|
|
bool (*nodeEqual) (const struct ExtensibleNode *a,
|
|
|
|
const struct ExtensibleNode *b);
|
|
|
|
void (*nodeOut) (struct StringInfoData *str,
|
|
|
|
const struct ExtensibleNode *node);
|
|
|
|
void (*nodeRead) (struct ExtensibleNode *node);
|
|
|
|
} ExtensibleNodeMethods;
|
|
|
|
|
|
|
|
extern void RegisterExtensibleNodeMethods(const ExtensibleNodeMethods *method);
|
|
|
|
extern const ExtensibleNodeMethods *GetExtensibleNodeMethods(const char *name,
|
|
|
|
bool missing_ok);
|
|
|
|
|
2016-03-29 17:00:18 +02:00
|
|
|
/*
|
|
|
|
* Flags for custom paths, indicating what capabilities the resulting scan
|
2021-07-07 00:10:11 +02:00
|
|
|
* will have. The flags fields of CustomPath and CustomScan nodes are
|
|
|
|
* bitmasks of these flags.
|
2016-03-29 17:00:18 +02:00
|
|
|
*/
|
|
|
|
#define CUSTOMPATH_SUPPORT_BACKWARD_SCAN 0x0001
|
|
|
|
#define CUSTOMPATH_SUPPORT_MARK_RESTORE 0x0002
|
2021-07-07 00:10:11 +02:00
|
|
|
#define CUSTOMPATH_SUPPORT_PROJECTION 0x0004
|
2016-03-29 17:00:18 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Custom path methods. Mostly, we just need to know how to convert a
|
|
|
|
* CustomPath to a plan.
|
|
|
|
*/
|
|
|
|
typedef struct CustomPathMethods
|
|
|
|
{
|
|
|
|
const char *CustomName;
|
|
|
|
|
|
|
|
/* Convert Path to a Plan */
|
|
|
|
struct Plan *(*PlanCustomPath) (PlannerInfo *root,
|
|
|
|
RelOptInfo *rel,
|
|
|
|
struct CustomPath *best_path,
|
|
|
|
List *tlist,
|
|
|
|
List *clauses,
|
|
|
|
List *custom_plans);
|
Basic partition-wise join functionality.
Instead of joining two partitioned tables in their entirety we can, if
it is an equi-join on the partition keys, join the matching partitions
individually. This involves teaching the planner about "other join"
rels, which are related to regular join rels in the same way that
other member rels are related to baserels. This can use significantly
more CPU time and memory than regular join planning, because there may
now be a set of "other" rels not only for every base relation but also
for every join relation. In most practical cases, this probably
shouldn't be a problem, because (1) it's probably unusual to join many
tables each with many partitions using the partition keys for all
joins and (2) if you do that scenario then you probably have a big
enough machine to handle the increased memory cost of planning and (3)
the resulting plan is highly likely to be better, so what you spend in
planning you'll make up on the execution side. All the same, for now,
turn this feature off by default.
Currently, we can only perform joins between two tables whose
partitioning schemes are absolutely identical. It would be nice to
cope with other scenarios, such as extra partitions on one side or the
other with no match on the other side, but that will have to wait for
a future patch.
Ashutosh Bapat, reviewed and tested by Rajkumar Raghuwanshi, Amit
Langote, Rafia Sabih, Thomas Munro, Dilip Kumar, Antonin Houska, Amit
Khandekar, and by me. A few final adjustments by me.
Discussion: http://postgr.es/m/CAFjFpRfQ8GrQvzp3jA2wnLqrHmaXna-urjm_UY9BqXj=EaDTSA@mail.gmail.com
Discussion: http://postgr.es/m/CAFjFpRcitjfrULr5jfuKWRPsGUX0LQ0k8-yG0Qw2+1LBGNpMdw@mail.gmail.com
2017-10-06 17:11:10 +02:00
|
|
|
struct List *(*ReparameterizeCustomPathByChild) (PlannerInfo *root,
|
|
|
|
List *custom_private,
|
|
|
|
RelOptInfo *child_rel);
|
2016-03-29 17:00:18 +02:00
|
|
|
} CustomPathMethods;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Custom scan. Here again, there's not much to do: we need to be able to
|
|
|
|
* generate a ScanState corresponding to the scan.
|
|
|
|
*/
|
|
|
|
typedef struct CustomScanMethods
|
|
|
|
{
|
|
|
|
const char *CustomName;
|
|
|
|
|
|
|
|
/* Create execution state (CustomScanState) from a CustomScan plan node */
|
|
|
|
Node *(*CreateCustomScanState) (CustomScan *cscan);
|
|
|
|
} CustomScanMethods;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Execution-time methods for a CustomScanState. This is more complex than
|
|
|
|
* what we need for a custom path or scan.
|
|
|
|
*/
|
|
|
|
typedef struct CustomExecMethods
|
|
|
|
{
|
|
|
|
const char *CustomName;
|
|
|
|
|
|
|
|
/* Required executor methods */
|
|
|
|
void (*BeginCustomScan) (CustomScanState *node,
|
|
|
|
EState *estate,
|
|
|
|
int eflags);
|
|
|
|
TupleTableSlot *(*ExecCustomScan) (CustomScanState *node);
|
|
|
|
void (*EndCustomScan) (CustomScanState *node);
|
|
|
|
void (*ReScanCustomScan) (CustomScanState *node);
|
|
|
|
|
|
|
|
/* Optional methods: needed if mark/restore is supported */
|
|
|
|
void (*MarkPosCustomScan) (CustomScanState *node);
|
|
|
|
void (*RestrPosCustomScan) (CustomScanState *node);
|
|
|
|
|
|
|
|
/* Optional methods: needed if parallel execution is supported */
|
|
|
|
Size (*EstimateDSMCustomScan) (CustomScanState *node,
|
|
|
|
ParallelContext *pcxt);
|
|
|
|
void (*InitializeDSMCustomScan) (CustomScanState *node,
|
|
|
|
ParallelContext *pcxt,
|
|
|
|
void *coordinate);
|
Separate reinitialization of shared parallel-scan state from ExecReScan.
Previously, the parallel executor logic did reinitialization of shared
state within the ExecReScan code for parallel-aware scan nodes. This is
problematic, because it means that the ExecReScan call has to occur
synchronously (ie, during the parent Gather node's ReScan call). That is
swimming very much against the tide so far as the ExecReScan machinery is
concerned; the fact that it works at all today depends on a lot of fragile
assumptions, such as that no plan node between Gather and a parallel-aware
scan node is parameterized. Another objection is that because ExecReScan
might be called in workers as well as the leader, hacky extra tests are
needed in some places to prevent unwanted shared-state resets.
Hence, let's separate this code into two functions, a ReInitializeDSM
call and the ReScan call proper. ReInitializeDSM is called only in
the leader and is guaranteed to run before we start new workers.
ReScan is returned to its traditional function of resetting only local
state, which means that ExecReScan's usual habits of delaying or
eliminating child rescan calls are safe again.
As with the preceding commit 7df2c1f8d, it doesn't seem to be necessary
to make these changes in 9.6, which is a good thing because the FDW and
CustomScan APIs are impacted.
Discussion: https://postgr.es/m/CAA4eK1JkByysFJNh9M349u_nNjqETuEnY_y1VUc_kJiU0bxtaQ@mail.gmail.com
2017-08-30 19:18:16 +02:00
|
|
|
void (*ReInitializeDSMCustomScan) (CustomScanState *node,
|
|
|
|
ParallelContext *pcxt,
|
|
|
|
void *coordinate);
|
2016-03-29 17:00:18 +02:00
|
|
|
void (*InitializeWorkerCustomScan) (CustomScanState *node,
|
|
|
|
shm_toc *toc,
|
|
|
|
void *coordinate);
|
2017-02-26 09:06:49 +01:00
|
|
|
void (*ShutdownCustomScan) (CustomScanState *node);
|
2016-03-29 17:00:18 +02:00
|
|
|
|
|
|
|
/* Optional: print additional information in EXPLAIN */
|
|
|
|
void (*ExplainCustomScan) (CustomScanState *node,
|
|
|
|
List *ancestors,
|
|
|
|
ExplainState *es);
|
|
|
|
} CustomExecMethods;
|
|
|
|
|
|
|
|
extern void RegisterCustomScanMethods(const CustomScanMethods *methods);
|
|
|
|
extern const CustomScanMethods *GetCustomScanMethods(const char *CustomName,
|
|
|
|
bool missing_ok);
|
|
|
|
|
Introduce extensible node types.
An extensible node is always tagged T_Extensible, but the extnodename
field identifies it more specifically; it may also include arbitrary
private data. Extensible nodes can be copied, tested for equality,
serialized, and deserialized, but the core system doesn't know
anything about them otherwise. Some extensions may find it useful to
include these nodes in fdw_private or custom_private lists in lieu of
arm-wrestling their data into a format that the core code can
understand.
Along the way, so as not to burden the authors of such extensible
node types too much, expose the functions for writing serialized
tokens, and for serializing and deserializing bitmapsets.
KaiGai Kohei, per a design suggested by me. Reviewed by Andres Freund
and by me, and further edited by me.
2016-02-12 15:31:16 +01:00
|
|
|
#endif /* EXTENSIBLE_H */
|