In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
< state->TapeRange; tapenum++) LogicalTapeRewindForRead (state- > tapeset, tapenum, state- > read_buffer_size); for (;) {/ /-loop / * * At this point we know that tape [T] is empty. If there's just one * (real or dummy) run left on each input tape, then only one merge * pass remains. If we don't have to produce a materialized sorted * tape, we can stop at this point and do the final merge on-the-fly. * at this point, we know that tap [T] is empty. * if only a run (real or virtual) happens to be left on each input tape, there is only one merge left. * if you do not need to generate a materialized sorted tape, you can stop and perform the final merge in memory. * / if (! state- > randomAccess & &! WORKER (state)) {bool allOneRun = true; Assert (state- > tp_ runs [state-> tapeRange] = = 0); for (tapenum = 0; tapenum)
< state->TapeRange; tapenum++) {if (state- > tp_ runs [tapenum] + state- > tp_ dummy [tapenum]! = 1) {allOneRun = false; break }} if (allOneRun) {/ * Tell logtape.c we won't be writing anymore * / notifies logtape.c not to write any more. LogicalTapeSetForgetFreeSpace (state- > tapeset); / * Initialize for the final merge pass * / / prepare for final merger beginmerge (state); state- > status = TSS_FINALMERGE; return }} / * Step D5: merge runs onto tape [T] until tape [P] is empty * / / step D5: merge runs into tape [T] until tape [P] is empty while (state- > tp_ runs [state-> tapeRange-1] | | state- > tp_ dummy [state-> tapeRange-1]) {bool allDummy = true For (tapenum = 0; tapenum)
< state->TapeRange; tapenum++) {if (state- > tp_ dummy [tapenum] = 0) {allDummy = false; break;}} if (allDummy) {state- > tp_ dummy [state-> tapeRange] + + For (tapenum = 0; tapenum)
< state->TapeRange; tapenum++) state- > tp_ dummy [tapenum] -;} else mergeonerun (state);} / * Step D6: decrease level * / / step D6: summarize if (--state- > Level = = 0) break up the layer / * rewind output tape T to use as new input * / / rewind the input Tape T as the new input LogicalTapeRewindForRead (state- > tapeset, state- > tp_ tapping [state-> tapeRange], state- > read_buffer_size) / * rewind used-up input tape P, and prepare it for write pass * / / rewind the input tape P on the use and prepare LogicalTapeRewindForWrite for the write wheel (state- > tapeset, state- > tp_ tapping [state-> tapeRange-1]); state- > tp_ runs [state-> tapeRange-1] = 0; / * reassign tape units per step D6 Note we no longer care about A [] * at each step D 6, reassign the tape unit. * notice that we no longer care about A []. * / svTape = state- > tp_ tapes [state-> tapeRange]; svDummy = state- > tp_ Dummy [state-> tapeRange]; svRuns = state- > tp_ runs [state-> tapeRange]; for (tapenum = state- > tapeRange; tapenum > 0; tapenum--) {state- > tp_ tapenum [state-1]; state- > tp_ dummy [state-1] = state- > tp_ dummy [tapenum-1] State- > tp_ runs [tapenum] = state- > tp_ runs [tapenum-1];} state- > tp_tapenum [0] = svTape; state- > tp_dummy [0] = svDummy; state- > tp_runs [0] = svRuns;} / * * Done. Knuth says that the result is on TAPE [1], but since we exited * the loop without performing the last iteration of step D6, we have not * rearranged the tape unit assignment, and therefore the result is on * TAPE [T]. We need to do it this way so that we can freeze the final * output tape while rewinding it. The last iteration of step D6 would be * a waste of cycles anyway... * it is done! The result is in TAPE [1], but because the loop is exited without performing the last iteration in step D6, * there is no need to rearrange the tape unit allocation, so the result is in TAPE [T]. * by processing it once, you can freeze the result output TAPE when reversing. * the last iteration of step D 6 would be wasteful. * / state- > result_tape = state- > tp_ tapping, if (! WORKER (state)) LogicalTapeFreeze (state- > tapeset, state- > result_tape, NULL); else worker_freeze_result_tape (state); state- > status = TSS_SORTEDONTAPE; / * Release the read buffers of all the other tapes, by rewinding them. * / / release the read cache for of all other tapes (tapenum = 0; tapenum) by reversing tapes
< state->MaxTapes; tapenum++) {if (tapenum! = state- > result_tape) LogicalTapeRewindForWrite (state- > tapeset, tapenum);}} III. Tracking analysis
Test script
Select * from t_sort order by C1 and c2
Tracking and analysis
(gdb) b mergerunsBreakpoint 1 at 0xa73508: file tuplesort.c, line 2570. (gdb) Note: breakpoint 1 also set at pc 0xa73508.Breakpoint 2 at 0xa73508: file tuplesort.c, line 2570.
Input parameters
(gdb) cContinuing.Breakpoint 1, mergeruns (state=0x2b808a8) at tuplesort.c:25702570 Assert (state- > status = = TSS_BUILDRUNS) (gdb) p * state$1 = {status = TSS_BUILDRUNS, nKeys = 2, randomAccess = false, bounded = false, boundUsed = false, bound = 0, tuples = true, availMem = 3164456, allowedMem = 4194304, maxTapes = 16, tapeRange = 15, sortcontext = 0x2b80790, tuplecontext = 0x2b827a0, tapeset = 0x2b81480, comparetup = 0xa7525b, copytup = 0xa76247, writetup = 0xa76de1, readtup = 0xa76ec6, memtuples = 0x7f0cfeb14050, memtupcount = 0, memtupsize = 37448, memtupsize = growmemtuples, growmemtuples = false, false =, =, = 0, = CurrentRun = 3, mergeactive = 0x2b81350, Level = 1, destTape = 2, tp_fib = 0x2b80d58, tp_runs = 0x2b81378, tp_dummy = 0x2b813d0, tp_tapenum = 0x2b81428, activeTapes = 0, result_tape =-1, current = 0, eof_reached = false, markpos_block = 0, markpos_offset = 0, markpos_eof = false, worker =-1, shared = 0x0, nParticipants =-1, tupDesc = 0x2b67ae0, sortKeys = 0x2b80cc0, onlyKey = 0x0, abbrevNext = 10, indexInfo = 0x0, estate = estate, 0x0 = 0x0, 0x0 = 0x0 EnforceUnique = false, high_mask = 0, low_mask = 0, max_buckets = 0, datumType = 0, datumTypeLen = 0, ru_start = {tv = {tv_sec = 0, tv_usec = 0}, ru = {ru_utime = {tv_sec = 0, tv_usec = 0}, ru_stime = {tv_sec = 0, tv_usec = 0}, {ru_maxrss = 0, _ ru_maxrss_word = 0}, {ru_ixrss = 0 _ _ ru_ixrss_word = 0}, {ru_idrss = 0, _ _ ru_idrss_word = 0}, {ru_isrss = 0, _ _ ru_isrss_word = 0}, {ru_minflt = 0, _ _ ru_minflt_word = 0}, {ru_majflt = 0, _ _ ru_majflt_word = 0}, {ru_nswap = 0, _ _ ru_nswap_word = 0}, {ru_inblock = 0 _ _ ru_inblock_word = 0}, {ru_oublock = 0, _ _ ru_oublock_word = 0}, {ru_msgsnd = 0, _ _ ru_msgsnd_word = 0}, {ru_msgrcv = 0, _ _ ru_msgrcv_word = 0}, {ru_nsignals = 0, _ _ ru_nsignals_word = 0}, {ru_nvcsw = 0, _ _ ru_nvcsw_word = 0}, {ru_nivcsw = 0 _ _ ru_nivcsw_word = 0} (gdb)
Information such as sort keys
(gdb) n2571 Assert (state- > memtupcount = = 0) (gdb) 2573 if (state- > sortKeys! = NULL & & state- > sortKeys- > abbrev_converter! = NULL) (gdb) p * state- > sortKeys$2 = {ssup_cxt = 0x2b80790, ssup_collation = 0, ssup_reverse = false, ssup_nulls_first = false, ssup_attno = 2, ssup_extra = 0x0, comparator = 0x4fd4af, abbreviate = true, abbrev_converter = 0x0, abbrev_abort = 0x0, abbrev_full_comparator = 0x0} (gdb) p * state- > sortKeys- > abbrev_converterCannot access memory at address 0x0
Reset tuple memory so that large chunks of memtuples arrays are no longer needed.
(gdb) n2593 MemoryContextDelete (state- > tuplecontext); (gdb) 2594 state- > tuplecontext = NULL; (gdb) (gdb) n2600 FREEMEM (state, GetMemoryChunkSpace (state- > memtuples)); (gdb) 2601 pfree (state- > memtuples); (gdb) 2602 state- > memtuples = NULL; (gdb) 2613 if (state- > Level = = 1) (gdb)
Calculate the number of Tapes
(gdb) n2615 numInputTapes = state- > currentRun; (gdb) p state- > currentRun$3 = 3 (gdb) p state- > Level$4 = 1 (gdb) p state- > tapeRange$5 = 15 (gdb) p state- > maxTapes$6 = 16 (gdb) n2616 numTapes = numInputTapes + 1; (gdb) 2617 FREEMEM (state, (state- > maxTapes-numTapes) * TAPE_BUFFER_OVERHEAD); (gdb) 2634 if (state- > tuples) (gdb) p numInputTapes$7 = 3 (gdb) p numTapes$8 = 4 (gdb)
Initialize the slab allocator / allocate a new 'memtuples' array to the heap / rewind all output tapes ready for merge
(gdb) n2635 init_slab_allocator (state, numInputTapes + 1); (gdb) n2643 state- > memtupsize = numInputTapes; (gdb) 2644 state- > memtuples = (SortTuple *) palloc (numInputTapes * sizeof (SortTuple)); (gdb) 2645 USEMEM (state, GetMemoryChunkSpace (state- > memtuples)); (gdb) p state- > memtupsize$9 = 3 (gdb) n2662 if (trace_sort) (gdb) 2667 state- > read_buffer_size = Max (state- > availMem / numInputTapes, 0) (gdb) 2668 USEMEM (state, state- > read_buffer_size * numInputTapes); (gdb) p state- > read_buffer_size$10 = 1385762 (gdb) n2671 for (tapenum = 0; tapenum)
< state->TapeRange; tapenum++) (gdb) 2672 LogicalTapeRewindForRead (state- > tapeset, tapenum, state- > read_buffer_size); (gdb) p state- > tapeRange$11 = 15 (gdb) p state- > status$12 = TSS_BUILDRUNS (gdb)
Enter the cycle
2671 for (tapenum = 0; tapenum)
< state->TapeRange; tapenum++) (gdb) 2682 if (! state- > randomAccess & &! WORKER (state)) (gdb) 2684 bool allOneRun = true; (gdb) p state- > randomAccess$15 = false (gdb) p WORKER (state) $16 = 0 (gdb)
Loop to determine whether allOneRun is F
2687 for (tapenum = 0; tapenum)
< state->TapeRange; tapenum++) (gdb) 2695 if (allOneRun) (gdb) p allOneRun$19 = true (gdb)
Start merging, set the status, and return
(gdb) n2698 LogicalTapeSetForgetFreeSpace (state- > tapeset); (gdb) 2700 beginmerge (state); (gdb) 2701 state- > status = TSS_FINALMERGE; (gdb) 2702 return; (gdb) 2779} (gdb) tuplesort_performsort (state=0x2b808a8) at tuplesort.c:18661866 state- > eof_reached = false; (gdb)
Complete the sort
(gdb) n1867 state- > markpos_block = 0L; (gdb) 1868 state- > markpos_offset = 0; (gdb) 1869 state- > markpos_eof = false; (gdb) 1870 break; (gdb) 1878 if (trace_sort) (gdb) 1890 MemoryContextSwitchTo (oldcontext); (gdb) 1891} (gdb) ExecSort (pstate=0x2b67640) at nodeSort.c:123123 estate- > es_direction = dir; (gdb) cContinuing. At this point, the study of "how to call the mergeruns function by PostgreSQL" 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.