@@ -741,9 +741,7 @@ pgss_shmem_shutdown(int code, Datum arg)
741741 FILE * file ;
742742 char * qbuffer = NULL ;
743743 Size qbuffer_size = 0 ;
744- HASH_SEQ_STATUS hash_seq ;
745744 int32 num_entries ;
746- pgssEntry * entry ;
747745
748746 /* Don't try to dump during a crash. */
749747 if (code )
@@ -777,8 +775,7 @@ pgss_shmem_shutdown(int code, Datum arg)
777775 * When serializing to disk, we store query texts immediately after their
778776 * entry data. Any orphaned query texts are thereby excluded.
779777 */
780- hash_seq_init (& hash_seq , pgss_hash );
781- while ((entry = hash_seq_search (& hash_seq )) != NULL )
778+ foreach_hash (pgssEntry , entry , pgss_hash )
782779 {
783780 int len = entry -> query_len ;
784781 char * qstr = qtext_fetch (entry -> query_offset , len ,
@@ -790,8 +787,8 @@ pgss_shmem_shutdown(int code, Datum arg)
790787 if (fwrite (entry , sizeof (pgssEntry ), 1 , file ) != 1 ||
791788 fwrite (qstr , 1 , len + 1 , file ) != len + 1 )
792789 {
793- /* note: we assume hash_seq_term won't change errno */
794- hash_seq_term ( & hash_seq );
790+ /* note: we assume foreach_hash_term won't change errno */
791+ foreach_hash_term ( entry );
795792 goto error ;
796793 }
797794 }
@@ -1695,8 +1692,6 @@ pg_stat_statements_internal(FunctionCallInfo fcinfo,
16951692 Size qbuffer_size = 0 ;
16961693 Size extent = 0 ;
16971694 int gc_count = 0 ;
1698- HASH_SEQ_STATUS hash_seq ;
1699- pgssEntry * entry ;
17001695
17011696 /*
17021697 * Superusers or roles with the privileges of pg_read_all_stats members
@@ -1825,8 +1820,7 @@ pg_stat_statements_internal(FunctionCallInfo fcinfo,
18251820 }
18261821 }
18271822
1828- hash_seq_init (& hash_seq , pgss_hash );
1829- while ((entry = hash_seq_search (& hash_seq )) != NULL )
1823+ foreach_hash (pgssEntry , entry , pgss_hash )
18301824 {
18311825 Datum values [PG_STAT_STATEMENTS_COLS ];
18321826 bool nulls [PG_STAT_STATEMENTS_COLS ];
@@ -2170,9 +2164,7 @@ entry_cmp(const void *lhs, const void *rhs)
21702164static void
21712165entry_dealloc (void )
21722166{
2173- HASH_SEQ_STATUS hash_seq ;
21742167 pgssEntry * * entries ;
2175- pgssEntry * entry ;
21762168 int nvictims ;
21772169 int i ;
21782170 Size tottextlen ;
@@ -2196,8 +2188,7 @@ entry_dealloc(void)
21962188 tottextlen = 0 ;
21972189 nvalidtexts = 0 ;
21982190
2199- hash_seq_init (& hash_seq , pgss_hash );
2200- while ((entry = hash_seq_search (& hash_seq )) != NULL )
2191+ foreach_hash (pgssEntry , entry , pgss_hash )
22012192 {
22022193 entries [i ++ ] = entry ;
22032194 /* "Sticky" entries get a different usage decay rate. */
@@ -2509,8 +2500,6 @@ gc_qtexts(void)
25092500 char * qbuffer ;
25102501 Size qbuffer_size ;
25112502 FILE * qfile = NULL ;
2512- HASH_SEQ_STATUS hash_seq ;
2513- pgssEntry * entry ;
25142503 Size extent ;
25152504 int nentries ;
25162505
@@ -2552,8 +2541,7 @@ gc_qtexts(void)
25522541 extent = 0 ;
25532542 nentries = 0 ;
25542543
2555- hash_seq_init (& hash_seq , pgss_hash );
2556- while ((entry = hash_seq_search (& hash_seq )) != NULL )
2544+ foreach_hash (pgssEntry , entry , pgss_hash )
25572545 {
25582546 int query_len = entry -> query_len ;
25592547 char * qry = qtext_fetch (entry -> query_offset ,
@@ -2576,7 +2564,7 @@ gc_qtexts(void)
25762564 (errcode_for_file_access (),
25772565 errmsg ("could not write file \"%s\": %m" ,
25782566 PGSS_TEXT_FILE )));
2579- hash_seq_term ( & hash_seq );
2567+ foreach_hash_term ( entry );
25802568 goto gc_fail ;
25812569 }
25822570
@@ -2643,8 +2631,7 @@ gc_qtexts(void)
26432631 * Since the contents of the external file are now uncertain, mark all
26442632 * hashtable entries as having invalid texts.
26452633 */
2646- hash_seq_init (& hash_seq , pgss_hash );
2647- while ((entry = hash_seq_search (& hash_seq )) != NULL )
2634+ foreach_hash (pgssEntry , entry , pgss_hash )
26482635 {
26492636 entry -> query_offset = 0 ;
26502637 entry -> query_len = -1 ;
@@ -2708,8 +2695,6 @@ if (e) { \
27082695static TimestampTz
27092696entry_reset (Oid userid , Oid dbid , int64 queryid , bool minmax_only )
27102697{
2711- HASH_SEQ_STATUS hash_seq ;
2712- pgssEntry * entry ;
27132698 FILE * qfile ;
27142699 int64 num_entries ;
27152700 int64 num_remove = 0 ;
@@ -2729,6 +2714,8 @@ entry_reset(Oid userid, Oid dbid, int64 queryid, bool minmax_only)
27292714 if (userid != 0 && dbid != 0 && queryid != INT64CONST (0 ))
27302715 {
27312716 /* If all the parameters are available, use the fast path. */
2717+ pgssEntry * entry ;
2718+
27322719 memset (& key , 0 , sizeof (pgssHashKey ));
27332720 key .userid = userid ;
27342721 key .dbid = dbid ;
@@ -2752,8 +2739,7 @@ entry_reset(Oid userid, Oid dbid, int64 queryid, bool minmax_only)
27522739 else if (userid != 0 || dbid != 0 || queryid != INT64CONST (0 ))
27532740 {
27542741 /* Reset entries corresponding to valid parameters. */
2755- hash_seq_init (& hash_seq , pgss_hash );
2756- while ((entry = hash_seq_search (& hash_seq )) != NULL )
2742+ foreach_hash (pgssEntry , entry , pgss_hash )
27572743 {
27582744 if ((!userid || entry -> key .userid == userid ) &&
27592745 (!dbid || entry -> key .dbid == dbid ) &&
@@ -2766,8 +2752,7 @@ entry_reset(Oid userid, Oid dbid, int64 queryid, bool minmax_only)
27662752 else
27672753 {
27682754 /* Reset all entries. */
2769- hash_seq_init (& hash_seq , pgss_hash );
2770- while ((entry = hash_seq_search (& hash_seq )) != NULL )
2755+ foreach_hash (pgssEntry , entry , pgss_hash )
27712756 {
27722757 SINGLE_ENTRY_RESET (entry );
27732758 }
0 commit comments