1996-07-09 08:22:35 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* hashscan.c
|
1997-09-07 07:04:48 +02:00
|
|
|
* manage scans on hash tables
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
2007-01-05 23:20:05 +01:00
|
|
|
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
Wording cleanup for error messages. Also change can't -> cannot.
Standard English uses "may", "can", and "might" in different ways:
may - permission, "You may borrow my rake."
can - ability, "I can lift that log."
might - possibility, "It might rain today."
Unfortunately, in conversational English, their use is often mixed, as
in, "You may use this variable to do X", when in fact, "can" is a better
choice. Similarly, "It may crash" is better stated, "It might crash".
2007-02-01 20:10:30 +01:00
|
|
|
* $PostgreSQL: pgsql/src/backend/access/hash/hashscan.c,v 1.42 2007/02/01 19:10:25 momjian Exp $
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
1999-07-16 01:04:24 +02:00
|
|
|
#include "postgres.h"
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1999-07-16 01:04:24 +02:00
|
|
|
#include "access/hash.h"
|
2004-07-17 05:32:14 +02:00
|
|
|
#include "utils/resowner.h"
|
1996-10-21 07:45:21 +02:00
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct HashScanListData
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
IndexScanDesc hashsl_scan;
|
2004-07-17 05:32:14 +02:00
|
|
|
ResourceOwner hashsl_owner;
|
1997-09-07 07:04:48 +02:00
|
|
|
struct HashScanListData *hashsl_next;
|
1997-09-08 23:56:23 +02:00
|
|
|
} HashScanListData;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef HashScanListData *HashScanList;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
2004-01-07 19:56:30 +01:00
|
|
|
static HashScanList HashScans = NULL;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
Restructure index AM interface for index building and index tuple deletion,
per previous discussion on pghackers. Most of the duplicate code in
different AMs' ambuild routines has been moved out to a common routine
in index.c; this means that all index types now do the right things about
inserting recently-dead tuples, etc. (I also removed support for EXTEND
INDEX in the ambuild routines, since that's about to go away anyway, and
it cluttered the code a lot.) The retail indextuple deletion routines have
been replaced by a "bulk delete" routine in which the indexscan is inside
the access method. I haven't pushed this change as far as it should go yet,
but it should allow considerable simplification of the internal bookkeeping
for deletions. Also, add flag columns to pg_am to eliminate various
hardcoded tests on AM OIDs, and remove unused pg_am columns.
Fix rtree and gist index types to not attempt to store NULLs; before this,
gist usually crashed, while rtree managed not to crash but computed wacko
bounding boxes for NULL entries (which might have had something to do with
the performance problems we've heard about occasionally).
Add AtEOXact routines to hash, rtree, and gist, all of which have static
state that needs to be reset after an error. We discovered this need long
ago for btree, but missed the other guys.
Oh, one more thing: concurrent VACUUM is now the default.
2001-07-16 00:48:19 +02:00
|
|
|
|
|
|
|
/*
|
2004-07-17 05:32:14 +02:00
|
|
|
* ReleaseResources_hash() --- clean up hash subsystem resources.
|
Restructure index AM interface for index building and index tuple deletion,
per previous discussion on pghackers. Most of the duplicate code in
different AMs' ambuild routines has been moved out to a common routine
in index.c; this means that all index types now do the right things about
inserting recently-dead tuples, etc. (I also removed support for EXTEND
INDEX in the ambuild routines, since that's about to go away anyway, and
it cluttered the code a lot.) The retail indextuple deletion routines have
been replaced by a "bulk delete" routine in which the indexscan is inside
the access method. I haven't pushed this change as far as it should go yet,
but it should allow considerable simplification of the internal bookkeeping
for deletions. Also, add flag columns to pg_am to eliminate various
hardcoded tests on AM OIDs, and remove unused pg_am columns.
Fix rtree and gist index types to not attempt to store NULLs; before this,
gist usually crashed, while rtree managed not to crash but computed wacko
bounding boxes for NULL entries (which might have had something to do with
the performance problems we've heard about occasionally).
Add AtEOXact routines to hash, rtree, and gist, all of which have static
state that needs to be reset after an error. We discovered this need long
ago for btree, but missed the other guys.
Oh, one more thing: concurrent VACUUM is now the default.
2001-07-16 00:48:19 +02:00
|
|
|
*
|
|
|
|
* This is here because it needs to touch this module's static var HashScans.
|
|
|
|
*/
|
|
|
|
void
|
2004-07-17 05:32:14 +02:00
|
|
|
ReleaseResources_hash(void)
|
2004-07-01 02:52:04 +02:00
|
|
|
{
|
|
|
|
HashScanList l;
|
|
|
|
HashScanList prev;
|
|
|
|
HashScanList next;
|
|
|
|
|
|
|
|
/*
|
2005-10-15 04:49:52 +02:00
|
|
|
* Note: this should be a no-op during normal query shutdown. However, in
|
|
|
|
* an abort situation ExecutorEnd is not called and so there may be open
|
|
|
|
* index scans to clean up.
|
2004-07-01 02:52:04 +02:00
|
|
|
*/
|
|
|
|
prev = NULL;
|
|
|
|
|
|
|
|
for (l = HashScans; l != NULL; l = next)
|
|
|
|
{
|
|
|
|
next = l->hashsl_next;
|
2004-07-17 05:32:14 +02:00
|
|
|
if (l->hashsl_owner == CurrentResourceOwner)
|
2004-07-01 02:52:04 +02:00
|
|
|
{
|
|
|
|
if (prev == NULL)
|
|
|
|
HashScans = next;
|
|
|
|
else
|
|
|
|
prev->hashsl_next = next;
|
|
|
|
|
|
|
|
pfree(l);
|
|
|
|
/* prev does not change */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
prev = l;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
/*
|
1997-09-07 07:04:48 +02:00
|
|
|
* _Hash_regscan() -- register a new scan.
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
_hash_regscan(IndexScanDesc scan)
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
HashScanList new_el;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
new_el = (HashScanList) palloc(sizeof(HashScanListData));
|
|
|
|
new_el->hashsl_scan = scan;
|
2004-07-17 05:32:14 +02:00
|
|
|
new_el->hashsl_owner = CurrentResourceOwner;
|
1997-09-07 07:04:48 +02:00
|
|
|
new_el->hashsl_next = HashScans;
|
|
|
|
HashScans = new_el;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1997-09-07 07:04:48 +02:00
|
|
|
* _hash_dropscan() -- drop a scan from the scan list
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
_hash_dropscan(IndexScanDesc scan)
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
HashScanList chk,
|
|
|
|
last;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2004-01-07 19:56:30 +01:00
|
|
|
last = NULL;
|
1997-09-07 07:04:48 +02:00
|
|
|
for (chk = HashScans;
|
2004-01-07 19:56:30 +01:00
|
|
|
chk != NULL && chk->hashsl_scan != scan;
|
1997-09-07 07:04:48 +02:00
|
|
|
chk = chk->hashsl_next)
|
|
|
|
last = chk;
|
|
|
|
|
2004-01-07 19:56:30 +01:00
|
|
|
if (chk == NULL)
|
Wording cleanup for error messages. Also change can't -> cannot.
Standard English uses "may", "can", and "might" in different ways:
may - permission, "You may borrow my rake."
can - ability, "I can lift that log."
might - possibility, "It might rain today."
Unfortunately, in conversational English, their use is often mixed, as
in, "You may use this variable to do X", when in fact, "can" is a better
choice. Similarly, "It may crash" is better stated, "It might crash".
2007-02-01 20:10:30 +01:00
|
|
|
elog(ERROR, "hash scan list trashed; cannot find 0x%p", (void *) scan);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2004-01-07 19:56:30 +01:00
|
|
|
if (last == NULL)
|
1997-09-07 07:04:48 +02:00
|
|
|
HashScans = chk->hashsl_next;
|
|
|
|
else
|
|
|
|
last->hashsl_next = chk->hashsl_next;
|
|
|
|
|
|
|
|
pfree(chk);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
2003-09-05 00:06:27 +02:00
|
|
|
/*
|
|
|
|
* Is there an active scan in this bucket?
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
_hash_has_active_scan(Relation rel, Bucket bucket)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
2003-09-05 00:06:27 +02:00
|
|
|
Oid relid = RelationGetRelid(rel);
|
1997-09-08 04:41:22 +02:00
|
|
|
HashScanList l;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2003-09-05 00:06:27 +02:00
|
|
|
for (l = HashScans; l != NULL; l = l->hashsl_next)
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
2002-05-21 01:51:44 +02:00
|
|
|
if (relid == l->hashsl_scan->indexRelation->rd_id)
|
2003-09-05 00:06:27 +02:00
|
|
|
{
|
|
|
|
HashScanOpaque so = (HashScanOpaque) l->hashsl_scan->opaque;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
2003-09-05 00:06:27 +02:00
|
|
|
if (so->hashso_bucket_valid &&
|
|
|
|
so->hashso_bucket == bucket)
|
|
|
|
return true;
|
|
|
|
}
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
|
|
|
|
2003-09-05 00:06:27 +02:00
|
|
|
return false;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|