1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-02 09:02:37 +03:00

The 1st step to implement new type of scan,TidScan.

Now WHERE restriction on ctid is allowed though it is
sequentially scanned.
This commit is contained in:
Hiroshi Inoue
1999-10-11 06:28:29 +00:00
parent 65a2c8f5b8
commit 05d13cad28
6 changed files with 238 additions and 10 deletions

View File

@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/tid.c,v 1.11 1999/07/17 20:18:00 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/tid.c,v 1.12 1999/10/11 06:28:26 inoue Exp $
*
* NOTES
* input routine largely stolen from boxin().
@ -28,9 +28,9 @@
* ----------------------------------------------------------------
*/
ItemPointer
tidin(char *str)
tidin(const char *str)
{
char *p,
const char *p,
*coord[NTIDARGS];
int i;
ItemPointer result;
@ -45,8 +45,12 @@ tidin(char *str)
if (*p == DELIM || (*p == LDELIM && !i))
coord[i++] = p + 1;
if (i < NTIDARGS - 1)
/* if (i < NTIDARGS - 1) */
if (i < NTIDARGS)
{
elog(ERROR, "%s invalid tid format", str);
return NULL;
}
blockNumber = (BlockNumber) atoi(coord[0]);
offsetNumber = (OffsetNumber) atoi(coord[1]);
@ -70,6 +74,14 @@ tidout(ItemPointer itemPtr)
BlockId blockId;
char buf[32];
char *str;
static char *invalidTid = "()";
if (!itemPtr || !ItemPointerIsValid(itemPtr))
{
str = palloc(strlen(invalidTid));
strcpy(str, invalidTid);
return str;
}
blockId = &(itemPtr->ip_blkid);
@ -83,3 +95,113 @@ tidout(ItemPointer itemPtr)
return str;
}
/*****************************************************************************
* PUBLIC ROUTINES *
*****************************************************************************/
bool
tideq(ItemPointer arg1, ItemPointer arg2)
{
if ((!arg1) || (!arg2))
{
return false;
}
return ( BlockIdGetBlockNumber(&(arg1->ip_blkid)) ==
BlockIdGetBlockNumber(&(arg2->ip_blkid)) &&
arg1->ip_posid == arg2->ip_posid );
}
bool
tidne(ItemPointer arg1, ItemPointer arg2)
{
if ((!arg1) || (!arg2))
{
return false;
}
return ( BlockIdGetBlockNumber(&(arg1->ip_blkid)) !=
BlockIdGetBlockNumber(&(arg2->ip_blkid)) ||
arg1->ip_posid != arg2->ip_posid );
}
text *
tid_text(ItemPointer tid)
{
char *str;
if (!tid) return (text *)NULL;
str = tidout(tid);
return textin(str);
} /* tid_text() */
ItemPointer
text_tid(const text *string)
{
ItemPointer result;
char *str;
if (!string) return (ItemPointer)0;
str = textout(string);
result = tidin(str);
pfree(str);
return result;
} /* text_tid() */
/*
* Functions to get latest tid of a specified tuple.
* Maybe these implementations is moved
* to another place
*/
#include <utils/relcache.h>
ItemPointer
currtid_byreloid(Oid reloid, ItemPointer tid)
{
ItemPointer result = NULL, ret;
Relation rel;
result = (ItemPointer) palloc(sizeof(ItemPointerData));
ItemPointerSetInvalid(result);
if (rel = heap_open(reloid, AccessShareLock), rel)
{
ret = heap_get_latest_tid(rel, SnapshotNow, tid);
if (ret)
ItemPointerCopy(ret, result);
heap_close(rel, AccessShareLock);
}
else
elog(ERROR, "Relation %u not found", reloid);
return result;
} /* currtid_byreloid() */
ItemPointer
currtid_byrelname(const text *relname, ItemPointer tid)
{
ItemPointer result = NULL, ret;
char *str;
Relation rel;
if (!relname) return result;
str = textout(relname);
result = (ItemPointer) palloc(sizeof(ItemPointerData));
ItemPointerSetInvalid(result);
if (rel = heap_openr(str, AccessShareLock), rel)
{
ret = heap_get_latest_tid(rel, SnapshotNow, tid);
if (ret)
ItemPointerCopy(ret, result);
heap_close(rel, AccessShareLock);
}
else
elog(ERROR, "Relation %s not found", relname);
pfree(str);
return result;
} /* currtid_byrelname() */