Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb33a732

Browse files
committed
Improve trace_sort code to also show the total memory or disk space used.
Per request from Marc.
1 parent48f3d77 commitb33a732

File tree

3 files changed

+39
-6
lines changed

3 files changed

+39
-6
lines changed

‎src/backend/utils/sort/logtape.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
* Portions Copyright (c) 1994, Regents of the University of California
6565
*
6666
* IDENTIFICATION
67-
* $PostgreSQL: pgsql/src/backend/utils/sort/logtape.c,v 1.16 2005/10/15 02:49:37momjian Exp $
67+
* $PostgreSQL: pgsql/src/backend/utils/sort/logtape.c,v 1.17 2005/10/18 22:59:37tgl Exp $
6868
*
6969
*-------------------------------------------------------------------------
7070
*/
@@ -925,3 +925,12 @@ LogicalTapeTell(LogicalTapeSet *lts, int tapenum,
925925
*blocknum=lt->curBlockNumber;
926926
*offset=lt->pos;
927927
}
928+
929+
/*
930+
* Obtain total disk space currently used by a LogicalTapeSet, in blocks.
931+
*/
932+
long
933+
LogicalTapeSetBlocks(LogicalTapeSet*lts)
934+
{
935+
returnlts->nFileBlocks;
936+
}

‎src/backend/utils/sort/tuplesort.c

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
* Portions Copyright (c) 1994, Regents of the University of California
7979
*
8080
* IDENTIFICATION
81-
* $PostgreSQL: pgsql/src/backend/utils/sort/tuplesort.c,v 1.52 2005/10/15 02:49:37momjian Exp $
81+
* $PostgreSQL: pgsql/src/backend/utils/sort/tuplesort.c,v 1.53 2005/10/18 22:59:37tgl Exp $
8282
*
8383
*-------------------------------------------------------------------------
8484
*/
@@ -134,6 +134,7 @@ struct Tuplesortstate
134134
TupSortStatusstatus;/* enumerated value as shown above */
135135
boolrandomAccess;/* did caller request random access? */
136136
longavailMem;/* remaining memory available, in bytes */
137+
longallowedMem;/* total memory allowed, in bytes */
137138
LogicalTapeSet*tapeset;/* logtape.c object for tapes in a temp file */
138139

139140
/*
@@ -433,7 +434,8 @@ tuplesort_begin_common(int workMem, bool randomAccess)
433434

434435
state->status=TSS_INITIAL;
435436
state->randomAccess=randomAccess;
436-
state->availMem=workMem*1024L;
437+
state->allowedMem=workMem*1024L;
438+
state->availMem=state->allowedMem;
437439
state->tapeset=NULL;
438440

439441
state->memtupcount=0;
@@ -582,9 +584,24 @@ void
582584
tuplesort_end(Tuplesortstate*state)
583585
{
584586
inti;
587+
#ifdefTRACE_SORT
588+
longspaceUsed;
589+
#endif
585590

586591
if (state->tapeset)
592+
{
593+
#ifdefTRACE_SORT
594+
spaceUsed=LogicalTapeSetBlocks(state->tapeset);
595+
#endif
587596
LogicalTapeSetClose(state->tapeset);
597+
}
598+
else
599+
{
600+
#ifdefTRACE_SORT
601+
spaceUsed= (state->allowedMem-state->availMem+1023) /1024;
602+
#endif
603+
}
604+
588605
if (state->memtuples)
589606
{
590607
for (i=0;i<state->memtupcount;i++)
@@ -604,8 +621,14 @@ tuplesort_end(Tuplesortstate *state)
604621

605622
#ifdefTRACE_SORT
606623
if (trace_sort)
607-
elog(NOTICE,"sort ended: %s",
608-
pg_rusage_show(&state->ru_start));
624+
{
625+
if (state->tapeset)
626+
elog(NOTICE,"external sort ended, %ld disk blocks used: %s",
627+
spaceUsed,pg_rusage_show(&state->ru_start));
628+
else
629+
elog(NOTICE,"internal sort ended, %ld KB used: %s",
630+
spaceUsed,pg_rusage_show(&state->ru_start));
631+
}
609632
#endif
610633

611634
pfree(state);

‎src/include/utils/logtape.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
99
* Portions Copyright (c) 1994, Regents of the University of California
1010
*
11-
* $PostgreSQL: pgsql/src/include/utils/logtape.h,v 1.12 2004/12/31 22:03:46 pgsql Exp $
11+
* $PostgreSQL: pgsql/src/include/utils/logtape.h,v 1.13 2005/10/18 22:59:37 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -38,5 +38,6 @@ extern bool LogicalTapeSeek(LogicalTapeSet *lts, int tapenum,
3838
longblocknum,intoffset);
3939
externvoidLogicalTapeTell(LogicalTapeSet*lts,inttapenum,
4040
long*blocknum,int*offset);
41+
externlongLogicalTapeSetBlocks(LogicalTapeSet*lts);
4142

4243
#endif/* LOGTAPE_H */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp