1
/*-------------------------------------------------------------------------
4
* manage scans on hash tables
6
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
7
* Portions Copyright (c) 1994, Regents of the University of California
11
* $PostgreSQL: pgsql/src/backend/access/hash/hashscan.c,v 1.38 2004-12-31 21:59:13 pgsql Exp $
13
*-------------------------------------------------------------------------
18
#include "access/hash.h"
19
#include "utils/resowner.h"
22
typedef struct HashScanListData
24
IndexScanDesc hashsl_scan;
25
ResourceOwner hashsl_owner;
26
struct HashScanListData *hashsl_next;
29
typedef HashScanListData *HashScanList;
31
static HashScanList HashScans = NULL;
35
* ReleaseResources_hash() --- clean up hash subsystem resources.
37
* This is here because it needs to touch this module's static var HashScans.
40
ReleaseResources_hash(void)
47
* Note: this should be a no-op during normal query shutdown. However,
48
* in an abort situation ExecutorEnd is not called and so there may be
49
* open index scans to clean up.
53
for (l = HashScans; l != NULL; l = next)
55
next = l->hashsl_next;
56
if (l->hashsl_owner == CurrentResourceOwner)
61
prev->hashsl_next = next;
64
/* prev does not change */
72
* _Hash_regscan() -- register a new scan.
75
_hash_regscan(IndexScanDesc scan)
79
new_el = (HashScanList) palloc(sizeof(HashScanListData));
80
new_el->hashsl_scan = scan;
81
new_el->hashsl_owner = CurrentResourceOwner;
82
new_el->hashsl_next = HashScans;
87
* _hash_dropscan() -- drop a scan from the scan list
90
_hash_dropscan(IndexScanDesc scan)
97
chk != NULL && chk->hashsl_scan != scan;
98
chk = chk->hashsl_next)
102
elog(ERROR, "hash scan list trashed; can't find 0x%p", (void *) scan);
105
HashScans = chk->hashsl_next;
107
last->hashsl_next = chk->hashsl_next;
113
* Is there an active scan in this bucket?
116
_hash_has_active_scan(Relation rel, Bucket bucket)
118
Oid relid = RelationGetRelid(rel);
121
for (l = HashScans; l != NULL; l = l->hashsl_next)
123
if (relid == l->hashsl_scan->indexRelation->rd_id)
125
HashScanOpaque so = (HashScanOpaque) l->hashsl_scan->opaque;
127
if (so->hashso_bucket_valid &&
128
so->hashso_bucket == bucket)