diff --git a/src/backend/storage/smgr/smgr.c b/src/backend/storage/smgr/smgr.c index 0c0bba4ab3..02a5d5cdda 100644 --- a/src/backend/storage/smgr/smgr.c +++ b/src/backend/storage/smgr/smgr.c @@ -259,7 +259,12 @@ static void add_to_unowned_list(SMgrRelation reln) { /* place it at head of the list (to make smgrsetowner cheap) */ + reln->prev_unowned_reln = NULL; reln->next_unowned_reln = first_unowned_reln; + + if (first_unowned_reln) + first_unowned_reln->prev_unowned_reln = reln; + first_unowned_reln = reln; } @@ -279,20 +284,20 @@ add_to_unowned_list(SMgrRelation reln) static void remove_from_unowned_list(SMgrRelation reln) { - SMgrRelation *link; - SMgrRelation cur; + SMgrRelation prev; + SMgrRelation next; - for (link = &first_unowned_reln, cur = *link; - cur != NULL; - link = &cur->next_unowned_reln, cur = *link) - { - if (cur == reln) - { - *link = cur->next_unowned_reln; - cur->next_unowned_reln = NULL; - break; - } - } + prev = reln->prev_unowned_reln; + next = reln->next_unowned_reln; + + if (prev) + prev->next_unowned_reln = reln->next_unowned_reln; + + if (next) + next->prev_unowned_reln = reln->prev_unowned_reln; + + if (reln == first_unowned_reln) + first_unowned_reln = next; } /* diff --git a/src/include/storage/smgr.h b/src/include/storage/smgr.h index 820d08ed4e..ed6c4421eb 100644 --- a/src/include/storage/smgr.h +++ b/src/include/storage/smgr.h @@ -72,6 +72,7 @@ typedef struct SMgrRelationData struct _MdfdVec *md_seg_fds[MAX_FORKNUM + 1]; /* if unowned, list link in list of all unowned SMgrRelations */ + struct SMgrRelationData *prev_unowned_reln; struct SMgrRelationData *next_unowned_reln; } SMgrRelationData;