In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
< aggstate->Num_hashes) {/ * * Switch to next grouping set, reinitialize, and restart the * loop. * switch to the next grouping set, reinitialize and restart the loop * / select_current_set (aggstate, nextset, true); perhash = & aggstate- > Perhash [aggstate-> current_set]; ResetTupleHashIterator (perhash- > hashtable, & perhash- > hashiter); continue } else {/ * No more hashtables, so done * / / has completed the search, set the tag, and exit aggstate- > agg_done = true; return NULL }} / * * Clear the per-output-tuple context for each group * clear the per-output-tuple context for each group * * We intentionally don't use ReScanExprContext here; if any aggs have * registered shutdown callbacks, they mustn't be called yet, since we * might not be done with that agg. * ReScanExprContext will not be used here. If there is an aggs that registers the shutdown callback, * it should not be called yet, because we may not have finished processing the agg. * / ResetExprContext (econtext); / * * Transform representative tuple back into one with the right * columns. * turn the typical tuple back to the tuple with the correct column. * / ExecStoreMinimalTuple (entry- > firstTuple, hashslot, false); slot_getallattrs (hashslot); / Clean tuples / / reset firstSlot ExecClearTuple (firstSlot); memset (firstSlot- > tts_isnull, true, firstSlot- > tts_tupleDescriptor- > natts * sizeof (bool)); for (I = 0; I
< perhash->NumhashGrpCols; iTunes +) {/ / reset firstSlot int varNumber = perhash- > hashGrpColIdxInput [I]-1; firstSlot- > tts_ values [varNumber] = hashslot- > tts_ values [I]; firstSlot- > tts_ isnull [varNumber] = hashslot- > tts_ isnull [I];} ExecStoreVirtualTuple (firstSlot); pergroup = (AggStatePerGroup) entry- > additional / * * Use the representative input tuple for any references to * non-aggregated input columns in the qual and tlist. * use typical input tuples for non-aggregate input column dependencies in qual and tlist * / econtext- > ecxt_outertuple = firstSlot; / / prepare projection slot prepare_projection_slot (aggstate, econtext- > ecxt_outertuple, aggstate- > current_set) / / final aggregation operation finalize_aggregates (aggstate, peragg, pergroup); / / projection result = project_aggregates (aggstate); if (result) return result;} / * No more groups * / No more groups is returned. } # define ScanTupleHashTable (htable, iter)\ tuplehash_iterate (htable- > hashtab, iter) / *-* ExecStoreMinimalTuple * * Like ExecStoreTuple, but insert a "minimal" tuple into the slot. * similar to ExecStoreTuple, except that a minimized tuple is inserted into the slot. * * No 'buffer' parameter since minimal tuples are never stored in relations. * the "buffer" parameter is not required because minimized tuples are not stored in relations. *-/ TupleTableSlot * ExecStoreMinimalTuple (MinimalTuple mtup, TupleTableSlot * slot, bool shouldFree) {/ * sanity checks * consistency check * / Assert (mtup! = NULL); Assert (slot! = NULL); Assert (slot- > tts_tupleDescriptor! = NULL) / * Free any old physical tuple belonging to the slot. * release the old physical tuples belonging to the slot * / if (slot- > tts_shouldFree) heap_freetuple (slot- > tts_tuple); if (slot- > tts_shouldFreeMin) heap_free_minimal_tuple (slot- > tts_mintuple); / * Drop the pin on the referenced buffer, if there is one. * clear pin tags that depend on buffer * / if (BufferIsValid (slot- > tts_buffer)) ReleaseBuffer (slot- > tts_buffer); slot- > tts_buffer = InvalidBuffer; / * * Store the new tuple into the specified slot. * store the new tuple in the specified slot * / slot- > tts_isempty = false; slot- > tts_shouldFree = false; slot- > tts_shouldFreeMin = shouldFree; slot- > tts_tuple = & slot- > tts_minhdr; slot- > tts_mintuple = mtup; slot- > tts_minhdr.t_len = mtup- > t_len + MINIMAL_TUPLE_OFFSET; slot- > tts_minhdr.t_data = (HeapTupleHeader) ((char *) mtup- MINIMAL_TUPLE_OFFSET) / * no need to set t_self or t_tableOid since we won't allow access * / / because access is not allowed, there is no need to set t_sefl or t_tableOid / * Mark extracted state invalid * / / tag extracted status invalid slot- > tts_nvalid = 0; return slot } / *-* ExecStoreVirtualTuple * Mark a slot as containing a virtual tuple. * the tag slot contains virtual tuples * * The protocol for loading a slot with virtual tuple data is: * * Call ExecClearTuple to mark the slot empty. * * Store data into the Datum/isnull arrays. * * Call ExecStoreVirtualTuple to mark the slot valid. * This is a bit unclean but it avoids one round of data copying. * the protocols for using virtual tuple data are as follows: * * call ExecClearTuple to mark slot is empty * * store data in Datum/isnull array * * call ExecStoreVirtualTuple tag slot is valid *-* / TupleTableSlot * ExecStoreVirtualTuple (TupleTableSlot * slot) {/ * * sanity checks * consistency check * / Assert (slot! = NULL) Assert (slot- > tts_tupleDescriptor! = NULL); Assert (slot- > tts_isempty); slot- > tts_isempty = false; slot- > tts_nvalid = slot- > tts_tupleDescriptor- > natts; return slot;} III, tracking analysis
Test script
-- create a data table and insert test data drop table if exists tasking aggressively simpleleading create table t_agg_simple (bh varchar (20), C1 int,c2 int,c3 int,c4 int,c5 int,c6 int); insert into t_agg_simple select 'GZ01',col,col,col,col,col,col from generate_series (1) as col;insert into t_agg_simple select' GZ02',col,col,col,col,col,col from generate_series (2) as col Insert into t_agg_simple select 'GZ03',col,col,col,col,col,col from generate_series (3) as col;insert into t_agg_simple select' GZ04',col,col,col,col,col,col from generate_series (4) as col;insert into t_agg_simple select 'GZ05',col,col,col,col,col,col from generate_series (5) as col;-- disables parallel set max_parallel_workers_per_gather=0 Select bh,avg (C1), min (C1), max (c2) from t_agg_simple group by bh
Tracking and analysis
Breakpoint 1, agg_retrieve_hash_table (aggstate=0x2929640) at nodeAgg.c:19691969 econtext = aggstate- > ss.ps.ps_ExprContext; (gdb)
Input parameters
(gdb) p * aggstate$1 = {ss = {ps = {type = T_AggState, plan = 0x2849a30, state = 0x2929428, ExecProcNode = 0x6ee438, ExecProcNodeReal = 0x6ee438, instrument = 0x0, worker_instrument = 0x0, worker_jit_instrument = 0x0, qual = 0x0, lefttree = 0x2929bb0, righttree = 0x0, initPlan = 0x0, subPlan = 0x0, chgParam = 0x0, ps_ResultTupleSlot = 0x292a7b0, ps_ExprContext = 0x2929af0, 0x2929af0 = 0x0, ps_ResultTupleSlot = 0x292a7b0, ps_ExprContext = 0x2929af0, 0x2929af0 = ps_ProjInfo, 0x292a8f0 = 0x292a8f0}, 0x292a8f0 = 0x292a8f0, scandesc =} Aggs = 0x292ae00, numaggs = 3, numtrans = 3, aggstrategy = AGG_HASHED, aggsplit = AGGSPLIT_SIMPLE, phase = 0x292aef8, numphases = 1, current_phase = 0, peragg = 0x29463e0, pertrans = 0x29483f0, hashcontext = 0x2929a30, aggcontexts = 0x2929858, tmpcontext = 0x2929878, curaggcontext = 0x2929a30, curperagg = 0x0, curpertrans = 0x2949c80, input_done = false, agg_done = false, projected_set =-1, current_set = 0, grouped_cols = 0x0, all_grouped_cols = all_grouped_cols, all_grouped_cols = 1, 0x292b090 = 0x292b090, 0x292b090 = 0x292b090 Sort_out = 0x0, sort_slot = 0x0, pergroups = 0x0, grp_firstTuple = 0x0, table_filled = true, num_hashes = 1, perhash = 0x292af50, hash_pergroup = 0x29465f8, all_pergroups = 0x29465f8, combinedproj = 0x0} (gdb)
1. Initialize relevant variables, such as context / peragg, etc.
(gdb) n 1970 peragg = aggstate- > peragg; (gdb) 1971 firstSlot = aggstate- > ss.ss_ScanTupleSlot; (gdb) 1977 perhash = & aggstate- > Perhash [aggstate-> current_set] (gdb) 1983 while (! aggstate- > agg_done) (gdb) p * peragg$2 = {aggref = 0x293a458, transno = 0, finalfn_oid = 0, finalfn = {fn_addr = 0x0, fn_oid = 0, fn_nargs = 0, fn_strict = false, fn_retset = false, fn_stats = 0'\ 000mm, fn_extra = 0x0, fn_mcxt = 0x0, fn_expr = 0x0}, numFinalArgs = 1, aggdirectargs = 0x0, resulttypeLen = 4, resulttypeByVal = true Shareable = true} (gdb) p * peragg- > aggref$3 = {xpr = {type = T_Aggref}, aggfnoid = 2116, aggtype = 23, aggcollid = 0, inputcollid = 0, aggtranstype = 23, aggargtypes = 0x293a518, aggdirectargs = 0x0, args = 0x293a628, aggorder = 0x0, aggdistinct = 0x0, aggfilter = 0x0, aggstar = false, aggvariadic = false, aggkind = 110 'nails, agglevelsup = 0, aggsplit = AGGSPLIT_SIMPLE, location = 26} (gdb) p * perhash$4 = {perhash$4 = hashtable, hashtable = {hashtable = 0, hashtable = 0, 0x2946890 = 0, 0x2946890 = 0x2946890}, 0x2946890 = Hashfunctions = 0x292b2d0, eqfuncoids = 0x2946700, numCols = 1, numhashGrpCols = 1, largestGrpColIdx = 1, hashGrpColIdxInput = 0x2946660, hashGrpColIdxHash = 0x2946680, aggnode = 0x2849a30} (gdb) p aggstate- > current_set$5 = 0 (gdb)
two。 Unfinished, cycle
2.1 getting slot from perhash data structures
(gdb) n1985 TupleTableSlot * hashslot = perhash- > hashslot; (gdb) 1988 CHECK_FOR_INTERRUPTS () (gdb) p * hashslot$6 = {type = T_TupleTableSlot, tts_isempty = false, tts_shouldFree = false, tts_shouldFreeMin = false, tts_slow = false, tts_tuple = 0x0, tts_tupleDescriptor = 0x292b120, tts_mcxt = 0x2929310, tts_buffer = 0, tts_nvalid = 1, tts_values = 0x292b298, tts_isnull = 0x292b2a0, tts_mintuple = 0x0, tts_minhdr = {t_len = 0, t_self = {ip_blkid = {bi_hi = 0, bi_lo = 0} Ip_posid = 0}, t_tableOid = 0, t_data = 0x0}, tts_off = 0, tts_fixedTupleDescriptor = true} (gdb)
2.2 call ScanTupleHashTable to get the entry
(gdb) n 1993 entry = ScanTupleHashTable (perhash- > hashtable, & perhash- > hashiter); (gdb) p perhash- > hashiter$7 = {cur = 0, end = 0, done = false} (gdb) steptuplehash_iterate (tb=0x2946720, iter=0x292af58) at.. / src/include/lib/simplehash.h:829829 while (! iter- > done) (gdb) n833 elem = & tb- > Datiter [> cur] (gdb) p * tb$8 = {size = 256, members = 5, sizemask = 255,230, data = 0x2950a00, ctx = 0x2929310, private_data = 0x2946890} (gdb) p * tb- > data$9 = {firstTuple = 0x0, additional = 0x0, status = 0, hash = 0} (gdb) p * iter$10 = {cur = 0, end = 0, done = false} (gdb) n836 iter- > cur = (iter- > cur-1) & tb- > sizemask (gdb) n838 if ((iter- > cur & tb- > sizemask) = (iter- > end & tb- > sizemask)) (gdb) p iter- > cur$11 = 255 (gdb) 12 = 255 (gdb) p iter- > cur & tb- > sizemask$13 = 255 (gdb) p iter- > end & tb- > sizemask$14 = 0 (gdb) n840 if (elem- > status = SH_STATUS_IN_USE) (gdb) p * elem$15 = {firstTuple = 0x0, additional = 0x0, status = 0 Hash = 0} (gdb) n829 while (! iter- > done) (gdb) 833 elem = & tb- > Datiter [> cur] (gdb) 836 iter- > cur = (iter- > cur-1) & tb- > sizemask (gdb) 838 if ((iter- > cur & tb- > sizemask) = (iter- > end & tb- > sizemask)) (gdb) 840 if (elem- > status = = SH_STATUS_IN_USE) (gdb) 829 while (! iter- > done) (gdb) finishRun till exit from # 0 tuplehash_iterate (tb=0x2946720) Iter=0x292af58) at.. / src/include/lib/simplehash.h:8290x00000000006eed70 in agg_retrieve_hash_table (aggstate=0x2929640) at nodeAgg.c:19931993 entry = ScanTupleHashTable (perhash- > hashtable, & perhash- > hashiter) Value returned is $16 = (TupleHashEntryData *) 0x2951d08 (gdb)
2.3 if the returned entry is NULL, switch to the next set. If the search has been completed, set the flag and exit.
2.4 if the returned entry is not NULL, then:
2.4.1 reset the inner econtext context
2.4.2 Storage minimization tuple
2.4.3 reset firstSlot to store the virtual tuple
2.4.4 prepare the projection slot and perform the final aggregation operation. If the result is not NULL after projection, the result will be returned.
(gdb) n1994 if (entry = = NULL) (gdb) 2027 ResetExprContext (econtext); (gdb) 2033 ExecStoreMinimalTuple (entry- > firstTuple, hashslot, false); (gdb) 2034 slot_getallattrs (hashslot); (gdb) 2036 ExecClearTuple (firstSlot); (gdb) 2038 firstSlot- > tts_tupleDescriptor- > natts * sizeof (bool)) (gdb) 2037 memset (firstSlot- > tts_isnull, true, (gdb) 2040 for (I = 0; I
< perhash->NumhashGrpCols T_bits0x2942a87: 0x5a470b00 0x7f7e3530 0x7f7f7f7f 0x7f7f7f7f0x2942a97: 0x0000407f 0x00000000 0x00003000 0x000000000x2942aa7: 0x9425c000 0x00000002 0x00000500 0x000000000x2942ab7: 0x7f000000 0x7f7f7f7f 0x0000057f 0x000000000x2942ac7: 0x7f000000 (gdb) x 0x7f000000 21c entry- > firstTuple- > t_bits0x2942a87: 0'\ 00011'\ v'71'G' 90'Z' 48'0' 53'5 177'0x2942a8f: 127,177' 127'\ 177' 127'\ 177' 127'\ 177' 127'\ 177' 127'\ 177' 127'\ 177' 127'\ 177' 127'\ 177'0x2942a97: 127'\ 17764'@ 0000'0'\ 0000' (gdb) n2042 int VarNumber = perhash- > hashGrpColIdxInput [I]-1 (gdb) 2044 firstSlot- > tts_ values [varNumber] = hashslot- > tts_values [I]; (gdb) 2045 firstSlot- > tts_ isnull [varNumber] = hashslot- > tts_isnull [I]; (gdb) 2040 for (I = 0; I)
< perhash->NumhashGrpCols; iTunes +) (gdb) 2047 ExecStoreVirtualTuple (firstSlot); (gdb) 2049 pergroup = (AggStatePerGroup) entry- > additional; (gdb) p * entry$1 = {firstTuple = 0x2942a78, additional = 0x2942ab0, status = 1, hash = 1229618635} (gdb) p * entry- > firstTuple$2 = {t_len = 21, mt_padding = "\ 000\ 000\ 000", t_infomask2 = 1, t_infomask = 2, t_hoff = 24'\ 0309, t_bits = 0x2942a87 "} (gdb)
Get the result
(gdb) n2055 econtext- > ecxt_outertuple = firstSlot; (gdb) p * pergroup$3 = {transValue = 5, transValueIsNull = false, noTransValue = false} (gdb) n2057 prepare_projection_slot (aggstate, (gdb) 2061 finalize_aggregates (aggstate, peragg, pergroup); (gdb) 2063 result = project_aggregates (aggstate) (gdb) 2064 if (result) (gdb) p result$4 = (TupleTableSlot *) 0x2927920 (gdb) p * result$5 = {type = T_TupleTableSlot, tts_isempty = false, tts_shouldFree = false, tts_shouldFreeMin = false, tts_slow = false, tts_tuple = 0x0, tts_tupleDescriptor = 0x2927708, tts_mcxt = 0x2926480, tts_buffer = 0, tts_nvalid = 4, tts_values = 0x2927980, tts_isnull = 0x29279a0, tts_mintuple = 0x0, tts_minhdr = {t_len = 0 T_self = {ip_blkid = {bi_hi = 0, bi_lo = 0}, ip_posid = 0}, t_tableOid = 0, t_data = 0x0}, tts_off = 0, tts_fixedTupleDescriptor = true} (gdb) p * result- > tts_values$6 = 43264648 (gdb) p * result- > tts_tupleDescriptor$7 = {natts = 4, tdtypeid = 2249, tdtypmod =-1, tdhasoid = false, tdrefcount =-1, constr = 0x0 Attrs = 0x2927728} (gdb) x result- > tts_values0x2927980: 0x88 0x2a 0x94 0x02 0x00 0x00 0x00 0x000x2927988: 0x88 0x47 0x94 0x02 0x00 0x00 0x00 0x000x2927990: 0x05 0x00 0x00 0x00 0x00 0x00 0x00 0x000x2927998: 0x05 0x00 0x00 0x00 0x00 0x00 0x00 0x00 (gdb) p * result- > tts_tupleDescriptor- > attrs$8 = {attrelid = 0, attname = {data = "bh",'\ 000'}, atttypid = 1043, attstattarget =-1 Attlen =-1, attnum = 1, attndims = 0, attcacheoff =-1, atttypmod = 24, attbyval = false, attstorage = 120'x regions, attalign = 105 'istories, attnotnull = false, atthasdef = false, atthasmissing = false, attidentity = 0'\ 00013, attisdropped = false, attislocal = true, attinhcount = 0, attcollation = 100} (gdb) p result- > tts_tupleDescriptor- > attrs [1] $9 = {attrelid = 0, attname = {data = "avg",'\ 000'}, atttypid = 1700, attstattarget =-1, attlen =-1 Attnum = 2, attndims = 0, attcacheoff =-1, atttypmod =-1, attbyval = false, attstorage = 109mm, attalign = 105i, attnotnull = false, atthasdef = false, atthasmissing = false, attidentity = 0000mm, attisdropped = false, attislocal = true, attinhcount = 0, attcollation = 0} (gdb) p result- > tts_tupleDescriptor- > attrs [2] $10 = {attrelid = 0, attname = {data = "min",'\ 000'}, atttypid = 23, attstattarget =-1, attlen = 4, attnum = 3 Attndims = 0, attcacheoff =-1, atttypmod =-1, attbyval = true, attstorage = 112 'packs, attalign = 105' ibis, attnotnull = false, atthasdef = false, atthasmissing = false, attidentity = 0'\ 000mm, attisdropped = false, attislocal = true, attinhcount = 0, attcollation = 0} (gdb) p result- > tts_tupleDescriptor- > attrs [3] $11 = {attrelid = 0, attname = {data = "max",'\ 000'}, atttypid = 23, attstattarget =-1, attlen = 4, attnum = 4, attndims = 0 Attcacheoff =-1, atttypmod =-1, attbyval = true, attstorage = 112 'pins, attalign = 105' ibis, attnotnull = false, atthasdef = false, atthasmissing = false, attidentity = 0'\ 000mm, attisdropped = false, attislocal = true, attinhcount = 0, attcollation = 0} so far I believe you have a deeper understanding of "what is the function called in PostgreSQL ExecAgg", so you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.