mirror of
https://github.com/postgres/postgres.git
synced 2025-05-12 16:21:30 +03:00
additional argument specifying the kind of lock to acquire/release (or 'NoLock' to do no lock processing). Ensure that all relations are locked with some appropriate lock level before being examined --- this ensures that relevant shared-inval messages have been processed and should prevent problems caused by concurrent VACUUM. Fix several bugs having to do with mismatched increment/decrement of relation ref count and mismatched heap_open/close (which amounts to the same thing). A bogus ref count on a relation doesn't matter much *unless* a SI Inval message happens to arrive at the wrong time, which is probably why we got away with this sloppiness for so long. Repair missing grab of AccessExclusiveLock in DROP TABLE, ALTER/RENAME TABLE, etc, as noted by Hiroshi. Recommend 'make clean all' after pulling this update; I modified the Relation struct layout slightly. Will post further discussion to pghackers list shortly.
124 lines
2.9 KiB
C
124 lines
2.9 KiB
C
/*-------------------------------------------------------------------------
|
|
*
|
|
* not_in.c
|
|
* Executes the "not_in" operator for any data type
|
|
*
|
|
* Copyright (c) 1994, Regents of the University of California
|
|
*
|
|
*
|
|
* IDENTIFICATION
|
|
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/not_in.c,v 1.21 1999/09/18 19:07:49 tgl Exp $
|
|
*
|
|
*-------------------------------------------------------------------------
|
|
*/
|
|
/*
|
|
*
|
|
* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
|
|
* X HACK WARNING!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! X
|
|
* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
|
|
*
|
|
* This code is the OLD not-in code that is HACKED
|
|
* into place until operators that can have arguments as
|
|
* columns are ******REALLY****** implemented!!!!!!!!!!!
|
|
*
|
|
*/
|
|
|
|
#include "postgres.h"
|
|
#include "access/heapam.h"
|
|
#include "utils/builtins.h"
|
|
|
|
static int my_varattno(Relation rd, char *a);
|
|
|
|
/* ----------------------------------------------------------------
|
|
*
|
|
* ----------------------------------------------------------------
|
|
*/
|
|
bool
|
|
int4notin(int32 not_in_arg, char *relation_and_attr)
|
|
{
|
|
Relation relation_to_scan;
|
|
int32 integer_value;
|
|
HeapTuple current_tuple;
|
|
HeapScanDesc scan_descriptor;
|
|
bool dummy,
|
|
retval;
|
|
int attrid;
|
|
char *relation,
|
|
*attribute;
|
|
char my_copy[NAMEDATALEN * 2 + 2];
|
|
Datum value;
|
|
|
|
strncpy(my_copy, relation_and_attr, sizeof(my_copy));
|
|
my_copy[sizeof(my_copy) - 1] = '\0';
|
|
|
|
relation = (char *) strtok(my_copy, ".");
|
|
attribute = (char *) strtok(NULL, ".");
|
|
if (attribute == NULL)
|
|
elog(ERROR, "int4notin: must provide relationname.attributename");
|
|
|
|
/* Open the relation and get a relation descriptor */
|
|
|
|
relation_to_scan = heap_openr(relation, AccessShareLock);
|
|
|
|
/* Find the column to search */
|
|
|
|
attrid = my_varattno(relation_to_scan, attribute);
|
|
if (attrid < 0)
|
|
{
|
|
elog(ERROR, "int4notin: unknown attribute %s for relation %s",
|
|
attribute, relation);
|
|
}
|
|
|
|
scan_descriptor = heap_beginscan(relation_to_scan, false, SnapshotNow,
|
|
0, (ScanKey) NULL);
|
|
|
|
retval = true;
|
|
|
|
/* do a scan of the relation, and do the check */
|
|
while (HeapTupleIsValid(current_tuple = heap_getnext(scan_descriptor, 0)))
|
|
{
|
|
value = heap_getattr(current_tuple,
|
|
(AttrNumber) attrid,
|
|
RelationGetDescr(relation_to_scan),
|
|
&dummy);
|
|
integer_value = DatumGetInt32(value);
|
|
if (not_in_arg == integer_value)
|
|
{
|
|
retval = false;
|
|
break; /* can stop scanning now */
|
|
}
|
|
}
|
|
|
|
/* close the relation */
|
|
heap_endscan(scan_descriptor);
|
|
heap_close(relation_to_scan, AccessShareLock);
|
|
|
|
return retval;
|
|
}
|
|
|
|
bool
|
|
oidnotin(Oid the_oid, char *compare)
|
|
{
|
|
if (the_oid == InvalidOid)
|
|
return false;
|
|
return int4notin(the_oid, compare);
|
|
}
|
|
|
|
/*
|
|
* XXX
|
|
* If varattno (in parser/catalog_utils.h) ever is added to
|
|
* cinterface.a, this routine should go away
|
|
*/
|
|
static int
|
|
my_varattno(Relation rd, char *a)
|
|
{
|
|
int i;
|
|
|
|
for (i = 0; i < rd->rd_rel->relnatts; i++)
|
|
{
|
|
if (!namestrcmp(&rd->rd_att->attrs[i]->attname, a))
|
|
return i + 1;
|
|
}
|
|
return -1;
|
|
}
|