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

Commit1d4ee0c

Browse files
Jan WieckJan Wieck
Jan Wieck
authored and
Jan Wieck
committed
Turned high-frequently called pgstat functions into macros
for speed.Jan
1 parentf889b12 commit1d4ee0c

File tree

2 files changed

+61
-242
lines changed

2 files changed

+61
-242
lines changed

‎src/backend/postmaster/pgstat.c

Lines changed: 1 addition & 225 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*
2020
*Copyright (c) 2001, PostgreSQL Global Development Group
2121
*
22-
*$Id: pgstat.c,v 1.1 2001/06/22 19:18:35 wieck Exp $
22+
*$Id: pgstat.c,v 1.2 2001/06/29 16:29:37 wieck Exp $
2323
* ----------
2424
*/
2525
#include<stdio.h>
@@ -757,230 +757,6 @@ pgstat_initstats(PgStat_Info *stats, Relation rel)
757757
}
758758

759759

760-
/* ----------
761-
* pgstat_reset_heap_scan() -
762-
*
763-
*Called from heap_rescan() to reset the heap_scan_counted flag.
764-
*Since the optimizer usually does a beginscan()/endscan() without
765-
*really doing a scan, we cannot count those calls. We have to wait
766-
*if after a beginscan() or rescan() really a call to the getnext()
767-
*function happens.
768-
* ----------
769-
*/
770-
void
771-
pgstat_reset_heap_scan(PgStat_Info*stats)
772-
{
773-
if (stats->tabentry==NULL)
774-
return;
775-
776-
stats->heap_scan_counted= FALSE;
777-
}
778-
779-
780-
/* ----------
781-
* pgstat_count_heap_scan() -
782-
*
783-
*Called from heap_getnext() to tell us that now the relation
784-
*really is scanned.
785-
* ----------
786-
*/
787-
void
788-
pgstat_count_heap_scan(PgStat_Info*stats)
789-
{
790-
if (stats->tabentry==NULL)
791-
return;
792-
793-
if (!stats->heap_scan_counted)
794-
{
795-
((PgStat_TableEntry*)(stats->tabentry))->t_numscans++;
796-
stats->heap_scan_counted= TRUE;
797-
}
798-
}
799-
800-
801-
/* ----------
802-
* pgstat_count_heap_getnext() -
803-
*
804-
*Called from heap_getnext() whenever a valid tuple is returned
805-
*from a sequential scan. The above cannot get combined into this,
806-
*because if a heap scan didn't return any tuples, the scan itself
807-
*would be missing in the stats.
808-
* ----------
809-
*/
810-
void
811-
pgstat_count_heap_getnext(PgStat_Info*stats)
812-
{
813-
if (stats->tabentry==NULL)
814-
return;
815-
816-
((PgStat_TableEntry*)(stats->tabentry))->t_tuples_returned++;
817-
}
818-
819-
820-
/* ----------
821-
* pgstat_count_heap_fetch() -
822-
*
823-
*Called from heap_fetch() if this is caused by a heap lookup
824-
*for an actually done index scan.
825-
* ----------
826-
*/
827-
void
828-
pgstat_count_heap_fetch(PgStat_Info*stats)
829-
{
830-
if (stats->tabentry==NULL)
831-
return;
832-
833-
((PgStat_TableEntry*)(stats->tabentry))->t_tuples_fetched++;
834-
}
835-
836-
837-
/* ----------
838-
* pgstat_count_heap_insert() -
839-
*
840-
*Called from heap_insert().
841-
* ----------
842-
*/
843-
void
844-
pgstat_count_heap_insert(PgStat_Info*stats)
845-
{
846-
if (stats->tabentry==NULL)
847-
return;
848-
849-
((PgStat_TableEntry*)(stats->tabentry))->t_tuples_inserted++;
850-
}
851-
852-
853-
/* ----------
854-
* pgstat_count_heap_update() -
855-
*
856-
*Called from heap_update().
857-
* ----------
858-
*/
859-
void
860-
pgstat_count_heap_update(PgStat_Info*stats)
861-
{
862-
if (stats->tabentry==NULL)
863-
return;
864-
865-
((PgStat_TableEntry*)(stats->tabentry))->t_tuples_updated++;
866-
}
867-
868-
869-
/* ----------
870-
* pgstat_count_heap_delete() -
871-
*
872-
*Called from heap_delete().
873-
* ----------
874-
*/
875-
void
876-
pgstat_count_heap_delete(PgStat_Info*stats)
877-
{
878-
if (stats->tabentry==NULL)
879-
return;
880-
881-
((PgStat_TableEntry*)(stats->tabentry))->t_tuples_deleted++;
882-
}
883-
884-
885-
/* ----------
886-
* pgstat_reset_index_scan() -
887-
*
888-
*See pgstat_reset_heap_scan().
889-
* ----------
890-
*/
891-
void
892-
pgstat_reset_index_scan(PgStat_Info*stats)
893-
{
894-
if (stats->tabentry==NULL)
895-
return;
896-
897-
stats->index_scan_counted= FALSE;
898-
}
899-
900-
901-
/* ----------
902-
* pgstat_count_index_scan() -
903-
*
904-
*See pgstat_count_heap_scan().
905-
* ----------
906-
*/
907-
void
908-
pgstat_count_index_scan(PgStat_Info*stats)
909-
{
910-
if (stats->tabentry==NULL)
911-
return;
912-
913-
if (!stats->index_scan_counted)
914-
{
915-
((PgStat_TableEntry*)(stats->tabentry))->t_numscans++;
916-
stats->index_scan_counted= TRUE;
917-
}
918-
}
919-
920-
921-
/* ----------
922-
* pgstat_reset_index_getnext() -
923-
*
924-
*See pgstat_count_heap_getnext().
925-
* ----------
926-
*/
927-
void
928-
pgstat_count_index_getnext(PgStat_Info*stats)
929-
{
930-
if (stats->tabentry==NULL)
931-
return;
932-
933-
((PgStat_TableEntry*)(stats->tabentry))->t_tuples_returned++;
934-
}
935-
936-
937-
/* ----------
938-
* pgstat_count_buffer_read() -
939-
*
940-
*Called from bufmgr.c when a buffer is looked up in the shared buffer
941-
*cache. The real number of buffers read from the disk (or at least the
942-
*OSs or drives cache) is this minus buffer_hit_count below.
943-
* ----------
944-
*/
945-
void
946-
pgstat_count_buffer_read(PgStat_Info*stats,Relationrel)
947-
{
948-
if (stats->tabentry==NULL)
949-
{
950-
if (stats->no_stats)
951-
return;
952-
pgstat_initstats(stats,rel);
953-
if (stats->tabentry==NULL)
954-
return;
955-
}
956-
957-
((PgStat_TableEntry*)(stats->tabentry))->t_blocks_fetched++;
958-
}
959-
960-
961-
/* ----------
962-
* pgstat_count_buffer_hit() -
963-
*
964-
*Counts how many buffer per relation (or index) have been found
965-
*in the buffer cache.
966-
* ----------
967-
*/
968-
void
969-
pgstat_count_buffer_hit(PgStat_Info*stats,Relationrel)
970-
{
971-
if (stats->tabentry==NULL)
972-
{
973-
if (stats->no_stats)
974-
return;
975-
pgstat_initstats(stats,rel);
976-
if (stats->tabentry==NULL)
977-
return;
978-
}
979-
980-
((PgStat_TableEntry*)(stats->tabentry))->t_blocks_hit++;
981-
}
982-
983-
984760
/* ----------
985761
* pgstat_count_xact_commit() -
986762
*

‎src/include/pgstat.h

Lines changed: 60 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
*Copyright (c) 2001, PostgreSQL Global Development Group
77
*
8-
* $Id: pgstat.h,v 1.1 2001/06/22 19:18:36 wieck Exp $
8+
* $Id: pgstat.h,v 1.2 2001/06/29 16:29:37 wieck Exp $
99
* ----------
1010
*/
1111
#ifndefPGSTAT_H
@@ -347,22 +347,65 @@ extern voidpgstat_reset_counters(void);
347347

348348
externvoidpgstat_initstats(PgStat_Info*stats,Relationrel);
349349

350-
externvoidpgstat_reset_heap_scan(PgStat_Info*stats);
351-
externvoidpgstat_count_heap_scan(PgStat_Info*stats);
352-
externvoidpgstat_count_heap_getnext(PgStat_Info*stats);
353-
externvoidpgstat_count_heap_fetch(PgStat_Info*stats);
354-
externvoidpgstat_count_heap_insert(PgStat_Info*stats);
355-
externvoidpgstat_count_heap_update(PgStat_Info*stats);
356-
externvoidpgstat_count_heap_delete(PgStat_Info*stats);
357-
358-
externvoidpgstat_reset_index_scan(PgStat_Info*stats);
359-
externvoidpgstat_count_index_scan(PgStat_Info*stats);
360-
externvoidpgstat_count_index_getnext(PgStat_Info*stats);
361-
362-
externvoidpgstat_count_buffer_read(PgStat_Info*stats,
363-
Relationrel);
364-
externvoidpgstat_count_buffer_hit(PgStat_Info*stats,
365-
Relationrel);
350+
351+
#definepgstat_reset_heap_scan(s)\
352+
if ((s)->tabentry != NULL)\
353+
(s)->heap_scan_counted = FALSE
354+
#definepgstat_count_heap_scan(s)\
355+
if ((s)->tabentry != NULL && !(s)->heap_scan_counted) {\
356+
((PgStat_TableEntry *)((s)->tabentry))->t_numscans++;\
357+
(s)->heap_scan_counted = TRUE;\
358+
}
359+
#definepgstat_count_heap_getnext(s)\
360+
if ((s)->tabentry != NULL)\
361+
((PgStat_TableEntry *)((s)->tabentry))->t_tuples_returned++
362+
#definepgstat_count_heap_fetch(s)\
363+
if ((s)->tabentry != NULL)\
364+
((PgStat_TableEntry *)((s)->tabentry))->t_tuples_fetched++
365+
#definepgstat_count_heap_insert(s)\
366+
if ((s)->tabentry != NULL)\
367+
((PgStat_TableEntry *)((s)->tabentry))->t_tuples_inserted++
368+
#definepgstat_count_heap_update(s)\
369+
if ((s)->tabentry != NULL)\
370+
((PgStat_TableEntry *)((s)->tabentry))->t_tuples_updated++
371+
#definepgstat_count_heap_delete(s)\
372+
if ((s)->tabentry != NULL)\
373+
((PgStat_TableEntry *)((s)->tabentry))->t_tuples_deleted++
374+
375+
#definepgstat_reset_index_scan(s)\
376+
if ((s)->tabentry != NULL)\
377+
(s)->index_scan_counted = FALSE
378+
#definepgstat_count_index_scan(s)\
379+
if ((s)->tabentry != NULL && !(s)->index_scan_counted) {\
380+
((PgStat_TableEntry *)((s)->tabentry))->t_numscans++;\
381+
(s)->index_scan_counted = TRUE;\
382+
}
383+
#definepgstat_count_index_getnext(s)\
384+
if ((s)->tabentry != NULL)\
385+
((PgStat_TableEntry *)((s)->tabentry))->t_tuples_returned++
386+
387+
#definepgstat_count_buffer_read(s,r)\
388+
if ((s)->tabentry != NULL)\
389+
((PgStat_TableEntry *)((s)->tabentry))->t_blocks_fetched++;\
390+
else {\
391+
if (!(s)->no_stats) {\
392+
pgstat_initstats((s), (r));\
393+
if ((s)->tabentry != NULL)\
394+
((PgStat_TableEntry *)((s)->tabentry))->t_blocks_fetched++; \
395+
}\
396+
}
397+
#definepgstat_count_buffer_hit(s,r)\
398+
if ((s)->tabentry != NULL)\
399+
((PgStat_TableEntry *)((s)->tabentry))->t_blocks_hit++;\
400+
else {\
401+
if (!(s)->no_stats) {\
402+
pgstat_initstats((s), (r));\
403+
if ((s)->tabentry != NULL)\
404+
((PgStat_TableEntry *)((s)->tabentry))->t_blocks_hit++;\
405+
}\
406+
}
407+
408+
366409
externvoidpgstat_count_xact_commit(void);
367410
externvoidpgstat_count_xact_rollback(void);
368411

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp