码迷,mamicode.com
首页 > 其他好文 > 详细

greenplum Explicit Redistribute Motion 代码

时间:2018-01-26 20:55:44      阅读:227      评论:0      收藏:0      [点我收藏+]

标签:diff   ons   main   demo   exec   mutate   mtd   message   tab   

Explicit Redistribute Motion

The Explicit Redistribute iterator moves tuples to segments explicitly specified in the segment ID column of the tuples. This is differs from a Redistribute Motion iterator, where target segments are indirectly specified through hash expressions.

testdb=# explain delete from t1  where t1.id in (select id from t2);
                                                          QUERY PLAN                                                           
-------------------------------------------------------------------------------------------------------------------------------
 Delete (slice0; segments: 6)  (rows=4279005 width=10)
   ->  Explicit Redistribute Motion 6:6  (slice3; segments: 6)  (cost=57114.23..338731.20 rows=4279005 width=10)
         ->  Hash Join  (cost=57114.23..338731.20 rows=4279005 width=10)
               Hash Cond: t1.id = t2.id
               ->  Append-only Scan on t1  (cost=0.00..16880.00 rows=266667 width=14)
               ->  Hash  (cost=55868.87..55868.87 rows=16605 width=4)
                     ->  Broadcast Motion 6:6  (slice2; segments: 6)  (cost=52880.00..55868.87 rows=16605 width=4)
                           ->  HashAggregate  (cost=52880.00..53876.29 rows=16605 width=4)
                                 Group By: t2.id
                                 ->  Redistribute Motion 6:6  (slice1; segments: 6)  (cost=0.00..48880.00 rows=266667 width=4)
                                       Hash Key: t2.id
                                       ->  Append-only Scan on t2  (cost=0.00..16880.00 rows=266667 width=4)
 Optimizer status: legacy query optimizer
(13 rows)

 

1. 做plan时,调用preprocess_targetlist, 对update,delete,target list中加入 ctid和segment id;

(gdb) bt
#0  preprocess_targetlist (root=0x2304f58, tlist=0x0) at preptlist.c:152
#1  0x00000000007e868c in grouping_planner (root=0x2304f58, tuple_fraction=0) at planner.c:1814
#2  0x00000000007e79d7 in subquery_planner (glob=0x224cf88, parse=0x2304c00, parent_root=0x0, tuple_fraction=0, subroot=0x7ffffaf9a9d0, 
    config=0x2304f08) at planner.c:1196
#3  0x00000000007e6d94 in standard_planner (parse=0x2304c00, cursorOptions=0, boundParams=0x0) at planner.c:785
#4  0x00000000007e69d0 in resource_negotiator (parse=0x21feca8, cursorOptions=0, boundParams=0x0, resourceLife=QRL_ONCE, result=0x7ffffaf9ac08)
    at planner.c:658
#5  0x00000000007e62b4 in planner (parse=0x21feca8, cursorOptions=0, boundParams=0x0, resourceLife=QRL_ONCE) at planner.c:473
#6  0x000000000087c610 in pg_plan_query (querytree=0x21feca8, boundParams=0x0, resource_life=QRL_ONCE) at postgres.c:937
#7  0x000000000087c71b in pg_plan_queries (querytrees=0x224c560, boundParams=0x0, needSnapshot=0 \000, resource_life=QRL_ONCE) at postgres.c:1011
#8  0x000000000087db9a in exec_simple_query (query_string=0x21fdc90 "delete from t1  where t1.id in (select id from t2);", seqServerHost=0x0, 
    seqServerPort=-1) at postgres.c:1771
#9  0x0000000000885033 in exec_simple_query_message (firstchar=81 Q, input_message=0x7ffffaf9b0d0) at postgres.c:6314
#10 0x00000000008829b7 in PostgresMain (argc=4, argv=0x20c5cf8, username=0x20c5c10 "brayden") at postgres.c:4873
#11 0x000000000083615a in BackendRun (port=0x2089120) at postmaster.c:5889
#12 0x000000000083560f in BackendStartup (port=0x2089120) at postmaster.c:5484
#13 0x000000000082ff00 in ServerLoop () at postmaster.c:2163
#14 0x000000000082efcb in PostmasterMain (argc=9, argv=0x2080a40) at postmaster.c:1454
#15 0x000000000075a7ef in main (argc=9, argv=0x2080a40) at main.c:226

2. 接着plan, 加入explicit motion:

(gdb) bt
#0  request_explicit_motion (plan=0x226ad50, resultRelationsIdx=1, rtable=0x22e5be8) at cdbmutate.c:1430
#1  0x0000000000a621c7 in apply_motion (root=0x2304f58, plan=0x226ad50, query=0x2304c00) at cdbmutate.c:686
#2  0x0000000000a58c2a in cdbparallelize (root=0x2304f58, plan=0x226ad50, query=0x2304c00, cursorOptions=0, boundParams=0x0) at cdbllize.c:285
#3  0x00000000007e6f33 in standard_planner (parse=0x2304c00, cursorOptions=0, boundParams=0x0) at planner.c:834
#4  0x00000000007e69d0 in resource_negotiator (parse=0x21feca8, cursorOptions=0, boundParams=0x0, resourceLife=QRL_ONCE, result=0x7ffffaf9ac08)
    at planner.c:658
#5  0x00000000007e62b4 in planner (parse=0x21feca8, cursorOptions=0, boundParams=0x0, resourceLife=QRL_ONCE) at planner.c:473
#6  0x000000000087c610 in pg_plan_query (querytree=0x21feca8, boundParams=0x0, resource_life=QRL_ONCE) at postgres.c:937
#7  0x000000000087c71b in pg_plan_queries (querytrees=0x224c560, boundParams=0x0, needSnapshot=0 \000, resource_life=QRL_ONCE) at postgres.c:1011
#8  0x000000000087db9a in exec_simple_query (query_string=0x21fdc90 "delete from t1  where t1.id in (select id from t2);", seqServerHost=0x0, 
    seqServerPort=-1) at postgres.c:1771
#9  0x0000000000885033 in exec_simple_query_message (firstchar=81 Q, input_message=0x7ffffaf9b0d0) at postgres.c:6314
#10 0x00000000008829b7 in PostgresMain (argc=4, argv=0x20c5cf8, username=0x20c5c10 "brayden") at postgres.c:4873
#11 0x000000000083615a in BackendRun (port=0x2089120) at postmaster.c:5889
#12 0x000000000083560f in BackendStartup (port=0x2089120) at postmaster.c:5484
#13 0x000000000082ff00 in ServerLoop () at postmaster.c:2163
#14 0x000000000082efcb in PostmasterMain (argc=9, argv=0x2080a40) at postmaster.c:1454
#15 0x000000000075a7ef in main (argc=9, argv=0x2080a40) at main.c:226

3. 执行, 在做projection的时候, 记录 ctid, segment id:

(gdb) bt
#0  GetQEIndex () at identity.c:446
#1  0x00000000006f1404 in slot_getsysattr (slot=0x2bfc0f8, attnum=-8, isnull=0x2c4a0e9 "") at execTuples.c:1495
#2  0x00000000006e361a in slot_getattr (slot=0x2bfc0f8, attnum=-8, isnull=0x2c4a0e9 "") at ../../../src/include/executor/tuptable.h:320
#3  0x00000000006e4221 in ExecEvalVar (exprstate=0x2c49270, econtext=0x2bc7190, isNull=0x2c4a0e9 "", isDone=0x2c4967c) at execQual.c:674
#4  0x00000000006edd84 in ExecTargetList (targetlist=0x2c49210, econtext=0x2bc7190, values=0x2c4a0b8, isnull=0x2c4a0e8 "", itemIsDone=0x2c49678, 
    isDone=0x0) at execQual.c:5565
#5  0x00000000006ee300 in ExecProject (projInfo=0x2c495e8, isDone=0x0) at execQual.c:5762
#6  0x00000000006ee808 in ExecScan (node=0x2c48d10, accessMtd=0x6f65b4 <AppendOnlyScanNext>) at execScan.c:187
#7  0x00000000006eed3c in ExecTableScanRelation (scanState=0x2c48d10) at execScan.c:460
#8  0x000000000071e703 in ExecTableScan (node=0x2c48d10) at nodeTableScan.c:59
#9  0x00000000006e1d5e in ExecProcNode (node=0x2c48d10) at execProcnode.c:1158
#10 0x000000000070a15a in ExecHashJoinOuterGetTuple (outerNode=0x2c48d10, hjstate=0x2bc2a40, hashvalue=0x7ffda17d2264) at nodeHashjoin.c:822
#11 0x000000000070956a in ExecHashJoin (node=0x2bc2a40) at nodeHashjoin.c:362
#12 0x00000000006e1e89 in ExecProcNode (node=0x2bc2a40) at execProcnode.c:1217
#13 0x0000000000711c45 in execMotionSender (node=0x2bcc5b8) at nodeMotion.c:364
#14 0x0000000000711c03 in ExecMotion (node=0x2bcc5b8) at nodeMotion.c:331
#15 0x00000000006e1f31 in ExecProcNode (node=0x2bcc5b8) at execProcnode.c:1249
#16 0x00000000006dbba2 in ExecutePlan (estate=0x2bcaa40, planstate=0x2bcc5b8, operation=CMD_SELECT, numberTuples=0, direction=ForwardScanDirection, 
    dest=0x2c35c90) at execMain.c:3298
#17 0x00000000006d855f in ExecutorRun (queryDesc=0x2b9b210, direction=ForwardScanDirection, count=0) at execMain.c:1217
#18 0x000000000088713d in ProcessQuery (portal=0x2b990d0, stmt=0x2c21350, params=0x0, dest=0x2c35c90, completionTag=0x7ffda17d2a90 "")
    at pquery.c:327
#19 0x000000000088a0db in PortalRunMulti (portal=0x2b990d0, isTopLevel=1 \001, dest=0x2c35c90, altdest=0x2c35c90, completionTag=0x7ffda17d2a90 "")
    at pquery.c:2061
#20 0x0000000000889578 in PortalRun (portal=0x2b990d0, count=9223372036854775807, isTopLevel=1 \001, dest=0x2c35c90, altdest=0x2c35c90, 
    completionTag=0x7ffda17d2a90 "") at pquery.c:1599
#21 0x000000000087d5a4 in exec_mpp_query (query_string=0x2b750b2 "delete from t1  where t1.id in (select id from t2);", serializedQuerytree=0x0, 
    serializedQuerytreelen=0, serializedPlantree=0x2b750e6 "+2", serializedPlantreelen=2187, serializedParams=0x0, serializedParamslen=0, 
    serializedSliceInfo=0x2b75971 "\267\003", serializedSliceInfolen=302, serializedResource=0x2b75aec "P", serializedResourceLen=41, 
    seqServerHost=0x2b75b15 "192.168.3.175", seqServerPort=18040, localSlice=3) at postgres.c:1508
#22 0x0000000000883128 in PostgresMain (argc=266, argv=0x2a413b0, username=0x2a22c10 "brayden") at postgres.c:5057
#23 0x000000000083615a in BackendRun (port=0x29e2520) at postmaster.c:5889
#24 0x000000000083560f in BackendStartup (port=0x29e2520) at postmaster.c:5484
#25 0x000000000082ff00 in ServerLoop () at postmaster.c:2163
---Type <return> to continue, or q <return> to quit--- 
#26 0x000000000082efcb in PostmasterMain (argc=9, argv=0x29dda40) at postmaster.c:1454
#27 0x000000000075a7ef in main (argc=9, argv=0x29dda40) at main.c:226
(gdb) 

4. 执行, motion send tuple, 发送给对应的sement:

(gdb) bt
#0  doSendTuple (motion=0x2c21560, node=0x2bcc5b8, outerTupleSlot=0x2bfc178) at nodeMotion.c:1620
#1  0x0000000000711cbc in execMotionSender (node=0x2bcc5b8) at nodeMotion.c:400
#2  0x0000000000711c03 in ExecMotion (node=0x2bcc5b8) at nodeMotion.c:331
#3  0x00000000006e1f31 in ExecProcNode (node=0x2bcc5b8) at execProcnode.c:1249
#4  0x00000000006dbba2 in ExecutePlan (estate=0x2bcaa40, planstate=0x2bcc5b8, operation=CMD_SELECT, numberTuples=0, direction=ForwardScanDirection, 
    dest=0x2c35c90) at execMain.c:3298
#5  0x00000000006d855f in ExecutorRun (queryDesc=0x2b9b210, direction=ForwardScanDirection, count=0) at execMain.c:1217
#6  0x000000000088713d in ProcessQuery (portal=0x2b990d0, stmt=0x2c21350, params=0x0, dest=0x2c35c90, completionTag=0x7ffda17d2a90 "")
    at pquery.c:327
#7  0x000000000088a0db in PortalRunMulti (portal=0x2b990d0, isTopLevel=1 \001, dest=0x2c35c90, altdest=0x2c35c90, completionTag=0x7ffda17d2a90 "")
    at pquery.c:2061
#8  0x0000000000889578 in PortalRun (portal=0x2b990d0, count=9223372036854775807, isTopLevel=1 \001, dest=0x2c35c90, altdest=0x2c35c90, 
    completionTag=0x7ffda17d2a90 "") at pquery.c:1599
#9  0x000000000087d5a4 in exec_mpp_query (query_string=0x2b750b2 "delete from t1  where t1.id in (select id from t2);", serializedQuerytree=0x0, 
    serializedQuerytreelen=0, serializedPlantree=0x2b750e6 "+2", serializedPlantreelen=2187, serializedParams=0x0, serializedParamslen=0, 
    serializedSliceInfo=0x2b75971 "\267\003", serializedSliceInfolen=302, serializedResource=0x2b75aec "P", serializedResourceLen=41, 
    seqServerHost=0x2b75b15 "192.168.3.175", seqServerPort=18040, localSlice=3) at postgres.c:1508
#10 0x0000000000883128 in PostgresMain (argc=266, argv=0x2a413b0, username=0x2a22c10 "brayden") at postgres.c:5057
#11 0x000000000083615a in BackendRun (port=0x29e2520) at postmaster.c:5889
#12 0x000000000083560f in BackendStartup (port=0x29e2520) at postmaster.c:5484
#13 0x000000000082ff00 in ServerLoop () at postmaster.c:2163
#14 0x000000000082efcb in PostmasterMain (argc=9, argv=0x29dda40) at postmaster.c:1454
#15 0x000000000075a7ef in main (argc=9, argv=0x29dda40) at main.c:226

 

greenplum Explicit Redistribute Motion 代码

标签:diff   ons   main   demo   exec   mutate   mtd   message   tab   

原文地址:https://www.cnblogs.com/brayden/p/8360863.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!