您好,登錄后才能下訂單哦!
這篇文章主要介紹“PostgreSQL在執行邏輯優化中相關的數據結構有哪些”,在日常操作中,相信很多人在PostgreSQL在執行邏輯優化中相關的數據結構有哪些問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”PostgreSQL在執行邏輯優化中相關的數據結構有哪些”的疑惑有所幫助!接下來,請跟著小編一起來學習吧!
PostgreSQL在執行邏輯優化中相關的數據結構包括RangeSubselect/Alias/RangeVar/ResTarget/ColumnRef.
RangeSubselect
出現在FROM語句中的子查詢
/* * RangeSubselect - subquery appearing in a FROM clause * 出現在FROM語句中的子查詢 */ typedef struct RangeSubselect { NodeTag type; //是否有LATERAL? bool lateral; /* does it have LATERAL prefix? */ //未轉換的子查詢語句 Node *subquery; /* the untransformed sub-select clause */ //表別名和可選的列別名 Alias *alias; /* table alias & optional column aliases */ } RangeSubselect;
Alias
為RangeVar指定別名.別名可能同時重命名了表列.
/* * Alias - * specifies an alias for a range variable; the alias might also * specify renaming of columns within the table. * 為RangeVar指定別名.別名可能同時重命名了表列. * * 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. * 注意:colnames是Value節點(通常是字符串)鏈表. * 在與RTEs相關的Alias結構體中,可能有跟已刪除的列對應的條目. * 這些通常是空字符串("").詳細可參考parsenodes.h */ typedef struct Alias { NodeTag type; //別名 char *aliasname; /* aliased rel name (never qualified) */ //列別名鏈表 List *colnames; /* optional list of column aliases */ } Alias;
RangeVar
range variable,用于FROM語句中.
/* * RangeVar - range variable, used in FROM clauses * range variable,用于FROM語句中. * * 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. * 在工具語句中,用于表示表名,這時alias字段沒有使用. * inh用于判斷是否在子表中遞歸應用相關的操作. */ typedef struct RangeVar { NodeTag type; char *catalogname; /* the catalog (database) name, or NULL */ char *schemaname; /* the schema name, 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
結果目標列(用于先前已轉換的解析樹的目標鏈表中)
/* * ResTarget - * result target (used in target list of pre-transformed parse trees) * 結果目標列(用于先前已轉換的解析樹的目標鏈表中) * * 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. * 在SELECT的目標鏈表中, * 'name'是'AS ColumnLabel'語句中的列標簽,如無則為NULL, * 'val'是value表達式本身. * 'indirection'未使用. * * 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在target-column-names鏈表中使用ResTarget. * 這里'name'是目標列名稱,'indirection'存儲了所有與目標相關的子腳本,'val'未使用. * * 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. * 在UPDATE目標鏈表中,'name'是目標列名稱,'indirection'存儲了所有與目標相關的子腳本, * 'val'是與賦值相關的表達式. * * See A_Indirection for more info about what can appear in 'indirection'. * 詳細參見A_Indirection('indirection') */ typedef struct ResTarget { NodeTag type; //列名或NULL char *name; /* column name or NULL */ //子腳本,字段名稱,'*'或NIL List *indirection; /* subscripts, field names, and '*', or NIL */ //需要計算或賦值的值表達式 Node *val; /* the value expression to compute or assign */ //token的位置,-1表示未知 int location; /* token location, or -1 if unknown */ } ResTarget;
ColumnRef
指定對列或整個元組的引用
/* * ColumnRef - specifies a reference to a column, or possibly a whole 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"鏈表不能為空.可能包含字符串Value節點和A_Star節點(表示出現了*). * 截止到目前為止,A_Star必須出現在最后一個鏈表元素中. * * 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; //字段名稱(字符串值)鏈表或A_Star List *fields; /* field names (Value strings) or A_Star */ //token位置 int location; /* token location, or -1 if unknown */ } ColumnRef;
N/A
RangeSubselect/Alias
(gdb) p *(Node *)($stmt->fromClause->head.data->ptr_value) $15 = {type = T_RangeSubselect} #實際類型是范圍子查詢RangeSubselect (gdb) set $fromclause=(RangeSubselect *)($stmt->fromClause->head.data->ptr_value) (gdb) p *$fromclause $16 = {type = T_RangeSubselect, lateral = false, subquery = 0x1666c18, alias = 0x1666d40} (gdb) p *($fromclause->subquery) #subquery,子查詢是SelectStmt類型的節點 $17 = {type = T_SelectStmt} (gdb) p *($fromclause->alias) #alias,別名,實際值是字符串ret $18 = {type = T_Alias, aliasname = 0x1666d28 "ret", colnames = 0x0}
RangeVar
... $43 = {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 'p', 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鏈表的第1個元素是數據表,第2個元素是數據列 (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"}} ...
到此,關于“PostgreSQL在執行邏輯優化中相關的數據結構有哪些”的學習就結束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續學習更多相關知識,請繼續關注億速云網站,小編會繼續努力為大家帶來更多實用的文章!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。