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

Add a reverse-translation column number array to struct AppendRelInfo.

This provides for cheaper mapping of child columns back to parent
columns.  The one existing use-case in examine_simple_variable()
would hardly justify this by itself; but an upcoming bug fix will
make use of this array in a mainstream code path, and it seems
likely that we'll find other uses for it as we continue to build
out the partitioning infrastructure.

Discussion: https://postgr.es/m/12424.1575168015@sss.pgh.pa.us
This commit is contained in:
Tom Lane
2019-12-02 18:05:29 -05:00
parent 4526951d56
commit ce76c0ba53
8 changed files with 61 additions and 39 deletions

View File

@ -2151,17 +2151,13 @@ struct SpecialJoinInfo
* "append relation" (essentially, a list of child RTEs), we build an
* AppendRelInfo for each child RTE. The list of AppendRelInfos indicates
* which child RTEs must be included when expanding the parent, and each node
* carries information needed to translate Vars referencing the parent into
* Vars referencing that child.
* carries information needed to translate between columns of the parent and
* columns of the child.
*
* These structs are kept in the PlannerInfo node's append_rel_list.
* Note that we just throw all the structs into one list, and scan the
* whole list when desiring to expand any one parent. We could have used
* a more complex data structure (eg, one list per parent), but this would
* be harder to update during operations such as pulling up subqueries,
* and not really any easier to scan. Considering that typical queries
* will not have many different append parents, it doesn't seem worthwhile
* to complicate things.
* These structs are kept in the PlannerInfo node's append_rel_list, with
* append_rel_array[] providing a convenient lookup method for the struct
* associated with a particular child relid (there can be only one, though
* parent rels may have many entries in append_rel_list).
*
* Note: after completion of the planner prep phase, any given RTE is an
* append parent having entries in append_rel_list if and only if its
@ -2218,6 +2214,15 @@ typedef struct AppendRelInfo
*/
List *translated_vars; /* Expressions in the child's Vars */
/*
* This array simplifies translations in the reverse direction, from
* child's column numbers to parent's. The entry at [ccolno - 1] is the
* 1-based parent column number for child column ccolno, or zero if that
* child column is dropped or doesn't exist in the parent.
*/
int num_child_cols; /* length of array */
AttrNumber *parent_colnos; /* array of parent attnos, or zeroes */
/*
* We store the parent table's OID here for inheritance, or InvalidOid for
* UNION ALL. This is only needed to help in generating error messages if