Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does PostgreSQL determine which partition is queried when querying the partition table

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

< part_scheme->

< part_scheme->

Partnatts; iTunes +)

Recursively call gen_partprune_steps_internal- > traverse the partition scheme

(gdb) 920 Expr * partkey = linitial (rel- > partexps [I]); (gdb) 921 bool clause_is_not_null = false; (gdb) p * (Expr *) partkey$16 = {type = T_Var} (gdb) p * (Var *) partkey$17 = {xpr = {type = T_Var}, varno = 1, varattno = 1, vartype = 23, vartypmod =-1, varcollid = 0, varlevelsup = 0, varnoold = 1, varoattno = 1, location =-1}

Recursively call gen_partprune_steps_internal- > to try to match the given conditional clause with the specified partition key. The output of the match_clause_to_partition_key function is PARTCLAUSE_MATCH_CLAUSE (there is a match, and the output parameter is conditional).

(gdb) n922 PartClauseInfo * pc = NULL; (gdb) 923 List * clause_steps = NIL; (gdb) 925 switch (match_clause_to_partition_key (rel, context, (gdb) 931 Assert (pc! = NULL); (gdb) 937 if (bms_is_member (I, nullkeys)) 942 generate_opsteps = true (gdb) 943 keyclauses [I] = lappend (keyclauses [I], pc); (gdb) 944 break; (gdb) p keyclauses [I] $18 = (List *) 0x21c2b08 (gdb) p * keyclauses [I] $19 = {type = T_List, length = 1, head = 0x21c2ae0, tail = 0x21c2ae0} (gdb) p * (Node *) keyclauses [I]-> head- > data.ptr_value$20 = {type = T_Invalid}

Recursively call gen_partprune_steps_internal- > finish the condition traversal, start the production pruning step, and use the second strategy (based on the owned OpExprs generation step) to generate

(gdb) n752 foreach (lc, clauses) (gdb) n1019 if (! bms_is_empty (nullkeys) & & (gdb) 1032 else if (generate_opsteps) (gdb) 1037 step = gen_prune_steps_from_opexps (part_scheme, context, (gdb) n1039 if (step! = NULL) (gdb) p * step$21 = {type = T_PartitionPruneStepOp, step_id = 1} (gdb) n1040 result = lappend (result, step) (gdb) 1056 if (list_length (result) > 1) (gdb) p * result$22 = {type = T_List, length = 1, head = 0x21c2da0, tail = 0x21c2da0} (gdb) n1077 return result; (gdb) 1078} (gdb)

Gen_partprune_steps_internal- > Recursive call returns to complete the processing of the OR clause

(gdb) 801 if (! arg_contradictory) (gdb) 802 all_args_contradictory = false; (gdb) 804 if (argsteps! = NIL) (gdb) 808 Assert (list_length (argsteps) = = 1); (gdb) 809 step = (PartitionPruneStep *) linitial (argsteps) (gdb) 810 arg_stepids = lappend_int (arg_stepids, step- > step_id); (gdb) 791foreach (lc1, ((BoolExpr *) clause)-> args) (gdb) (gdb) 855 * contradictory = all_args_contradictory (gdb) 858 if (* contradictory) (gdb) p all_args_contradictory$23 = false (gdb) n861 if (arg_stepids! = NIL) (gdb) 865 step = gen_prune_step_combine (context, arg_stepids, (gdb) 867 result = lappend (result, step); (gdb) 869 continue (gdb) p * step$24 = {} 0x7f4522678be0 (gdb) p * result$25 = {type = T_List, length = 1, head = 0x21c2e88, tail = 0x21c2e88}

Gen_partprune_steps_internal- > complete traversal of all conditional clauses and return result

(gdb) n752 foreach (lc, clauses) (gdb) 1019 if (! bms_is_empty (nullkeys) & & (gdb) 1032 else if (generate_opsteps) (gdb) 1042 else if (bms_num_members (notnullkeys) = = part_scheme- > partnatts) (gdb) 1056 if (list_length (result) > 1) (gdb) 1077 return result; (gdb) 1078} (gdb)

Gen_partprune_steps- > go back to gen_partprune_steps and return the steps linked list

(gdb) gen_partprune_steps (rel=0x20fab08, clauses=0x21c2390, contradictory=0x7ffe1953a8d7) at partprune.c:541541 return context.steps (gdb) p * result$26 = 0'\ 000' (gdb) p context.steps$27 = (List *) 0x21c2890 (gdb) p * context.steps$28 = {type = T_List, length = 3, head = 0x21c2868, tail = 0x21c2e60} $29 = {type = T_PartitionPruneStepOp} (gdb) p * (PartitionPruneStepOp *) context.steps- > head- > data.ptr_value$30 = {step = {type = T_PartitionPruneStepOp, step_id = 0}, opstrategy = 1, exprs = 0x21c2830, cmpfns = 0x21c27d0 Nullkeys = 0x0} (gdb) p * (PartitionPruneStepOp *) context.steps- > head- > next- > data.ptr_value$31 = {step = {type = T_PartitionPruneStepOp, step_id = 1}, opstrategy = 1, exprs = 0x21c2c28, cmpfns = 0x21c2bc8, nullkeys = 0x0} (gdb) p * (PartitionPruneStepOp *) context.steps- > head- > next- > next- > data.ptr_value$32 = {step = {type = T_PartitionPruneStepCombine, step_id = 2}, opstrategy = 0, exprs = 0x21c2a10, cmpfns = 0x7e, nullkeys = nullkeys} (0x10)

Gen_partprune_steps- > back to prune_append_rel_partitions

(gdb) n542} (gdb) prune_append_rel_partitions (rel=0x20fab08) at partprune.c:574574 if (contradictory) (gdb)

Prune_append_rel_partitions- > set context

(gdb) 578 context.strategy = rel- > part_scheme- > strategy; (gdb) 579 context.partnatts = rel- > part_scheme- > partnatts;...

Prune_append_rel_partitions- > call get_matching_partitions to get the matching partition number (Indexes)

The result is 5, that is, Rel with array subscript 0 and 2 (part_rels array)

597 partindexes = get_matching_partitions (& context, pruning_steps); (gdb) 600I =-1; (gdb) p partindexes$33 = (Bitmapset *) 0x21c2ff8 (gdb) p * partindexes$34 = {nwords = 1, words = 0x21c2ffc} (gdb) p * partindexes- > words$35 = 5

Prune_append_rel_partitions- > generate Relids

The result is 40, that is, 832, that is, Rel 3 and 5.

(gdb) n601 result = NULL; (gdb) 602 while ((I = bms_next_member (partindexes, I)) > = 0) (gdb) 603 result = bms_add_member (result, rel- > part_ result [I]-> relid); (gdb) pi Qing 39 = 0 (gdb) n602 while ((I = bms_next_member (partindexes, I) > = 0) (gdb) 603 result = bms_add_member (result, rel- > part_ rels [I]-> relid) (gdb) pi Qing 40 = 2 (gdb) n602 while ((I = bms_next_member (partindexes, I)) > = 0) (gdb) 605 return result; (gdb) p result$41 = (Relids) 0x21c3018 (gdb) p * result$42 = {nwords = 1, words = 0x21c301c} (gdb) p result- > words [0] $43 = 40

Prune_append_rel_partitions- > complete the call

(gdb) set_append_rel_size (root=0x2120378, rel=0x20fab08, rti=1, rte=0x20fa3d0) at allpaths.c:922922 did_pruning = true; (gdb) Thank you for reading! On "PostgreSQL when querying the partition table how to determine which partition is queried" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, you can share it out for more people to see it!

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.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report