In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces "what are the relevant data structures of PostgreSQL in the implementation of logic optimization". In daily operations, I believe many people have doubts about the data structures related to the implementation of logic optimization in PostgreSQL. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "what are the relevant data structures of PostgreSQL in the implementation of logic optimization?" Next, please follow the editor to study!
The related data structures of PostgreSQL in performing logic optimization include RangeSubselect/Alias/RangeVar/ResTarget/ColumnRef.
I. data structure
RangeSubselect
Subqueries that appear in FROM statements
/ * * RangeSubselect-subquery appearing in a FROM clause * is there a LATERAL in the subquery * / typedef struct RangeSubselect {NodeTag type; / / that appears in the FROM statement? Bool lateral; / * does it have LATERAL prefix? * / / unconverted subquery statements Node * subquery; / * the untransformed sub-select clause * / / Table aliases and optional column aliases Alias * alias; / * table alias & optional column aliases * /} RangeSubselect
Alias
Specify an alias for RangeVar. Aliases may have renamed table columns at the same time.
/ * * Alias-* specifies an alias for a range variable; the alias might also * specify renaming of columns within the table. * specify an alias for RangeVar. Aliases may have renamed table columns at the same time. * * Note: colnames is a list of Value nodes (always strings). In Alias structs * associated with RTEs, there may be entries corresponding to dropped * columns; these are normally empty strings ("). See parsenodes.h for info. * Note: colnames is a linked list of Value nodes (usually strings). * in the Alias structure associated with RTEs, there may be entries corresponding to deleted columns. * these are usually empty strings. For more information, please see parsenodes.h * / typedef struct Alias {NodeTag type; / / aliases char * aliasname; / * aliased rel name (never qualified) * / / column aliases linked list List * colnames; / * optional list of column aliases * /} Alias
RangeVar
Range variable, used in FROM statements.
/ * * RangeVar-range variable, used in FROM clauses * range variable, used in FROM statements. * * Also used to represent table names in utility statements; there, the alias * field is not used, and inh tells whether to apply the operation * recursively to child tables. In some contexts it is also useful to carry * a TEMP table indication here. * in the tool statement, it is used to indicate the table name, when the alias field is not used. * inh is used to determine whether the relevant operation is applied recursively in the child table. * / typedef struct RangeVar {NodeTag type; char * catalogname; / * the catalog (database) name, or NULL * / char * schemaname; / * the schemaname, or NULL * / char * relname; / * the relation/sequence name * / bool inh; / * expand rel by inheritance? Recursively act * on children? * / char relpersistence; / * see RELPERSISTENCE_* in pg_class.h * / Alias * alias; / * table alias & optional column aliases * / int location; / * token location, or-1 if unknown * /} RangeVar
ResTarget
Result target column (used in the target list of the previously converted parse tree)
/ * * ResTarget-* result target (used in target list of pre-transformed parse trees) * result target column (used in the target linked list of the previously converted parse tree) * * In a SELECT target list, 'name' is the column label from an *' AS ColumnLabel' clause, or NULL if there was none, and 'val' is the * value expression itself. The 'indirection' field is not used. * in the target list of SELECT, * 'name' is the column label in the' AS ColumnLabel' statement, if none is NULL, and * 'val' is the value expression itself. * 'indirection' is not used. * * INSERT uses ResTarget in its target-column-names list. Here, 'name' is * the name of the destination column,' indirection' stores any subscripts * attached to the destination, and 'val' is not used. * INSERT uses ResTarget in target-column-names linked lists. * here 'name' is the target column name,' indirection' stores all target-related subscripts, and 'val' is not used. * * In an UPDATE target list, 'name' is the name of the destination column, *' indirection' stores any subscripts attached to the destination, and * val' is the expression to assign. * in the UPDATE target linked list, 'name' is the target column name,' indirection' stores all target-related subscripts, and * 'val' is the expression related to assignment. * * See A_Indirection for more info about what can appear in 'indirection'. * for details, see A_Indirection ('indirection') * / typedef struct ResTarget {NodeTag type; / / column name or NULL char * name; / * column name or NULL * / / subscript, field name,' *'or NIL List * indirection; / * subscripts, field names, and'*', or NIL * / / the value expression Node * val that needs to be evaluated or assigned / * the value expression to compute or assign * / / token location.-1 indicates unknown int location; / * token location, or-1 if unknown * /} ResTarget
ColumnRef
Specify a reference to a column or entire tuple
/ * * ColumnRef-specifies a reference to a column, or possibly a whole tuple * specifies a reference to a column or entire tuple * * The "fields" list must be nonempty. It can contain string Value nodes * (representing names) and A_Star nodes (representing occurrence of a'*). * Currently, A_Star must appear only as the last list element-the grammar * is responsible for enforcing this! * "fields" linked list cannot be empty. It may contain a string Value node and an A_Star node (indicating that * appears). * so far, A_Star must appear in the last linked list element. * * Note: any container subscripting or selection of fields from composite columns * is represented by an A_Indirection node above the ColumnRef. However, * for simplicity in the normal case, initial field selection from a table * name is represented within ColumnRef and not by adding A_Indirection. * / typedef struct ColumnRef {NodeTag type; / / Field name (string value) linked list or A_Star List * fields; / * field names (Value strings) or A_Star * / token location int location; / * token location, or-1 if unknown * /} ColumnRef; II, source code interpretation
N/A
Third, follow-up analysis
RangeSubselect/Alias
(gdb) p * (Node *) ($stmt- > fromClause- > head.data- > ptr_value) $15 = {type = T_RangeSubselect} # the actual type is Fan Weizi query RangeSubselect (gdb) set $fromclause= (RangeSubselect *) ($stmt- > fromClause- > head.data- > ptr_value) (gdb) p * $fromclause$16 = {type = T_RangeSubselect, lateral = false, subquery = 0x1666c18, alias = 0x1666d40} p * ($fromclause- > subquery) # subquery The subquery is a node of type SelectStmt $17 = {type = T_SelectStmt} (gdb) p * ($fromclause- > alias) # alias, alias, and the actual value is the string ret$18 = {type = T_Alias, aliasname = 0x1666d28 "ret", colnames = 0x0}
RangeVar
... = {type = T_RangeVar} (gdb) p * (RangeVar *) ((JoinExpr *) ($joinexpr- > larg))-> larg$44 = {type = T_RangeVar, catalogname = 0x0, schemaname = 0x0, relname = 0x1643380 "t_dwxx", inh = true, relpersistence = 112 'packs, alias = 0x0, location = 82}.
ResTarget
(gdb) p * (Node *) ($subquerylarg- > targetList- > head.data- > ptr_value) $26 = {type = T_ResTarget} (gdb) set $subvar= (ResTarget *) ($subquerylarg- > targetList- > head.data- > ptr_value) (gdb) p * $subvar {type = T_ResTarget, name = 0x0, indirection = 0x0, val = 0x1642c70, location = 23}.
ColumnRef
(gdb) p * $restarget- > val$25 = {type = T_ColumnRef} (gdb) p * (ColumnRef *) $restarget- > val$26 = {type = T_ColumnRef, fields = 0x1a47a08, location = 7} (gdb) p * ((ColumnRef *) $restarget- > val)-> fields$27 = {type = T_List, length = 2, head = 0x1a47a88 Tail = 0x1a479e8} (gdb) p * (Node *) (ColumnRef *) $restarget- > val)-> fields)-> head.data- > ptr_value$32 = {type = T_String} # fields linked list the first element is the data table, and the second element is the data column (gdb) p * (Value *) ((ColumnRef *) $restarget- > val)-> fields)-> head.data- > ptr_value$37 = {type = T_String, val = {ival = 27556248 Str = 0x1a47998 "t_dwxx"} (gdb) p * (Value *) (ColumnRef *) $restarget- > val)-> fields)-> tail.data- > ptr_value$38 = {type = T_String, val = {ival = 27556272, str = 0x1a479b0 "dwmc"}}. At this point, the study of "what are the relevant data structures of PostgreSQL in implementing logic optimization" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.