Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit05d13ca

Browse files
author
Hiroshi Inoue
committed
The 1st step to implement new type of scan,TidScan.
Now WHERE restriction on ctid is allowed though it issequentially scanned.
1 parent65a2c8f commit05d13ca

File tree

6 files changed

+238
-10
lines changed

6 files changed

+238
-10
lines changed

‎src/backend/access/heap/heapam.c

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.55 1999/09/24 00:23:54 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.56 1999/10/11 06:28:27 inoue Exp $
1111
*
1212
*
1313
* INTERFACE ROUTINES
@@ -1086,6 +1086,95 @@ heap_fetch(Relation relation,
10861086
}
10871087
}
10881088

1089+
/* ----------------
1090+
*heap_get_latest_tid - get the latest tid of a specified tuple
1091+
*
1092+
* ----------------
1093+
*/
1094+
ItemPointer
1095+
heap_get_latest_tid(Relationrelation,
1096+
Snapshotsnapshot,
1097+
ItemPointertid)
1098+
{
1099+
ItemIdlp;
1100+
Bufferbuffer;
1101+
PageHeaderdp;
1102+
OffsetNumberoffnum;
1103+
HeapTupleDatatp;
1104+
HeapTupleHeadert_data;
1105+
ItemPointerDatactid;
1106+
boolinvalidBlock,linkend;
1107+
1108+
/* ----------------
1109+
*get the buffer from the relation descriptor
1110+
*Note that this does a buffer pin.
1111+
* ----------------
1112+
*/
1113+
1114+
buffer=ReadBuffer(relation,ItemPointerGetBlockNumber(tid));
1115+
1116+
if (!BufferIsValid(buffer))
1117+
elog(ERROR,"heap_get_latest_tid: %s relation: ReadBuffer(%lx) failed",
1118+
&relation->rd_rel->relname, (long)tid);
1119+
1120+
LockBuffer(buffer,BUFFER_LOCK_SHARE);
1121+
1122+
/* ----------------
1123+
*get the item line pointer corresponding to the requested tid
1124+
* ----------------
1125+
*/
1126+
dp= (PageHeader)BufferGetPage(buffer);
1127+
offnum=ItemPointerGetOffsetNumber(tid);
1128+
invalidBlock= true;
1129+
if (!PageIsNew(dp))
1130+
{
1131+
lp=PageGetItemId(dp,offnum);
1132+
if (ItemIdIsUsed(lp))
1133+
invalidBlock= false;
1134+
}
1135+
if (invalidBlock)
1136+
{
1137+
LockBuffer(buffer,BUFFER_LOCK_UNLOCK);
1138+
ReleaseBuffer(buffer);
1139+
returnNULL;
1140+
}
1141+
1142+
/* ----------------
1143+
*more sanity checks
1144+
* ----------------
1145+
*/
1146+
1147+
t_data=tp.t_data= (HeapTupleHeader)PageGetItem((Page)dp,lp);
1148+
tp.t_len=ItemIdGetLength(lp);
1149+
tp.t_self=*tid;
1150+
ctid=tp.t_data->t_ctid;
1151+
1152+
/* ----------------
1153+
*check time qualification of tid
1154+
* ----------------
1155+
*/
1156+
1157+
HeapTupleSatisfies(&tp,relation,buffer,dp,
1158+
snapshot,0, (ScanKey)NULL);
1159+
1160+
linkend= true;
1161+
if ((t_data->t_infomask&HEAP_XMAX_COMMITTED)&&
1162+
!ItemPointerEquals(tid,&ctid))
1163+
linkend= false;
1164+
1165+
LockBuffer(buffer,BUFFER_LOCK_UNLOCK);
1166+
ReleaseBuffer(buffer);
1167+
1168+
if (tp.t_data==NULL)
1169+
{
1170+
if (linkend)
1171+
returnNULL;
1172+
returnheap_get_latest_tid(relation,snapshot,&ctid);
1173+
}
1174+
1175+
returntid;
1176+
}
1177+
10891178
/* ----------------
10901179
*heap_insert- insert tuple
10911180
*

‎src/backend/utils/adt/tid.c

Lines changed: 126 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/tid.c,v 1.11 1999/07/17 20:18:00 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/tid.c,v 1.12 1999/10/11 06:28:26 inoue Exp $
1111
*
1212
* NOTES
1313
* input routine largely stolen from boxin().
@@ -28,9 +28,9 @@
2828
* ----------------------------------------------------------------
2929
*/
3030
ItemPointer
31-
tidin(char*str)
31+
tidin(constchar*str)
3232
{
33-
char*p,
33+
constchar*p,
3434
*coord[NTIDARGS];
3535
inti;
3636
ItemPointerresult;
@@ -45,8 +45,12 @@ tidin(char *str)
4545
if (*p==DELIM|| (*p==LDELIM&& !i))
4646
coord[i++]=p+1;
4747

48-
if (i<NTIDARGS-1)
48+
/* if (i < NTIDARGS - 1) */
49+
if (i<NTIDARGS)
50+
{
51+
elog(ERROR,"%s invalid tid format",str);
4952
returnNULL;
53+
}
5054

5155
blockNumber= (BlockNumber)atoi(coord[0]);
5256
offsetNumber= (OffsetNumber)atoi(coord[1]);
@@ -70,6 +74,14 @@ tidout(ItemPointer itemPtr)
7074
BlockIdblockId;
7175
charbuf[32];
7276
char*str;
77+
staticchar*invalidTid="()";
78+
79+
if (!itemPtr|| !ItemPointerIsValid(itemPtr))
80+
{
81+
str=palloc(strlen(invalidTid));
82+
strcpy(str,invalidTid);
83+
returnstr;
84+
}
7385

7486
blockId=&(itemPtr->ip_blkid);
7587

@@ -83,3 +95,113 @@ tidout(ItemPointer itemPtr)
8395

8496
returnstr;
8597
}
98+
99+
/*****************************************************************************
100+
* PUBLIC ROUTINES *
101+
*****************************************************************************/
102+
103+
bool
104+
tideq(ItemPointerarg1,ItemPointerarg2)
105+
{
106+
if ((!arg1)|| (!arg2))
107+
{
108+
return false;
109+
}
110+
111+
return (BlockIdGetBlockNumber(&(arg1->ip_blkid))==
112+
BlockIdGetBlockNumber(&(arg2->ip_blkid))&&
113+
arg1->ip_posid==arg2->ip_posid );
114+
}
115+
116+
bool
117+
tidne(ItemPointerarg1,ItemPointerarg2)
118+
{
119+
if ((!arg1)|| (!arg2))
120+
{
121+
return false;
122+
}
123+
return (BlockIdGetBlockNumber(&(arg1->ip_blkid))!=
124+
BlockIdGetBlockNumber(&(arg2->ip_blkid))||
125+
arg1->ip_posid!=arg2->ip_posid );
126+
}
127+
128+
text*
129+
tid_text(ItemPointertid)
130+
{
131+
char*str;
132+
133+
if (!tid)return (text*)NULL;
134+
str=tidout(tid);
135+
136+
returntextin(str);
137+
}/* tid_text() */
138+
139+
ItemPointer
140+
text_tid(consttext*string)
141+
{
142+
ItemPointerresult;
143+
char*str;
144+
145+
if (!string)return (ItemPointer)0;
146+
147+
str=textout(string);
148+
result=tidin(str);
149+
pfree(str);
150+
151+
returnresult;
152+
}/* text_tid() */
153+
154+
155+
/*
156+
*Functions to get latest tid of a specified tuple.
157+
*Maybe these implementations is moved
158+
*to another place
159+
*/
160+
#include<utils/relcache.h>
161+
ItemPointer
162+
currtid_byreloid(Oidreloid,ItemPointertid)
163+
{
164+
ItemPointerresult=NULL,ret;
165+
Relationrel;
166+
167+
result= (ItemPointer)palloc(sizeof(ItemPointerData));
168+
ItemPointerSetInvalid(result);
169+
if (rel=heap_open(reloid,AccessShareLock),rel)
170+
{
171+
ret=heap_get_latest_tid(rel,SnapshotNow,tid);
172+
if (ret)
173+
ItemPointerCopy(ret,result);
174+
heap_close(rel,AccessShareLock);
175+
}
176+
else
177+
elog(ERROR,"Relation %u not found",reloid);
178+
179+
returnresult;
180+
}/* currtid_byreloid() */
181+
182+
ItemPointer
183+
currtid_byrelname(consttext*relname,ItemPointertid)
184+
{
185+
ItemPointerresult=NULL,ret;
186+
char*str;
187+
Relationrel;
188+
189+
if (!relname)returnresult;
190+
191+
str=textout(relname);
192+
193+
result= (ItemPointer)palloc(sizeof(ItemPointerData));
194+
ItemPointerSetInvalid(result);
195+
if (rel=heap_openr(str,AccessShareLock),rel)
196+
{
197+
ret=heap_get_latest_tid(rel,SnapshotNow,tid);
198+
if (ret)
199+
ItemPointerCopy(ret,result);
200+
heap_close(rel,AccessShareLock);
201+
}
202+
else
203+
elog(ERROR,"Relation %s not found",relname);
204+
pfree(str);
205+
206+
returnresult;
207+
}/* currtid_byrelname() */

‎src/include/access/heapam.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: heapam.h,v 1.46 1999/09/18 19:08:13 tgl Exp $
9+
* $Id: heapam.h,v 1.47 1999/10/11 06:28:29 inoue Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -256,6 +256,7 @@ extern void heap_rescan(HeapScanDesc scan, bool scanFromEnd, ScanKey key);
256256
externvoidheap_endscan(HeapScanDescscan);
257257
externHeapTupleheap_getnext(HeapScanDescscandesc,intbackw);
258258
externvoidheap_fetch(Relationrelation,Snapshotsnapshot,HeapTupletup,Buffer*userbuf);
259+
externItemPointerheap_get_latest_tid(Relationrelation,Snapshotsnapshot,ItemPointertid);
259260
externOidheap_insert(Relationrelation,HeapTupletup);
260261
externintheap_delete(Relationrelation,ItemPointertid,ItemPointerctid);
261262
externintheap_replace(Relationrelation,ItemPointerotid,HeapTupletup,

‎src/include/catalog/pg_operator.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: pg_operator.h,v 1.59 1999/09/06 21:16:18 tgl Exp $
10+
* $Id: pg_operator.h,v 1.60 1999/10/11 06:28:29 inoue Exp $
1111
*
1212
* NOTES
1313
* the genbki.sh script reads this file and generates .bki
@@ -136,6 +136,9 @@ DATA(insert OID = 399 ( "=" PGUID 0 b t f 10261026 16 399 0 00 array_e
136136
DATA(insertOID=400 ("="PGUID0btf1027102716400000array_eqeqseleqjoinsel ));
137137
DATA(insertOID=401 ("="PGUID0btf1034103416401000array_eqeqseleqjoinsel ));
138138

139+
DATA(insertOID=387 ("="PGUID0btt272716387000tideqeqseleqjoinsel ));
140+
#defineTIDEqualOperator 387
141+
139142
DATA(insertOID=410 ("="PGUID0btt202016410411412412int8eqeqseleqjoinsel ));
140143
DATA(insertOID=411 ("<>"PGUID0btf20201641141000int8neneqselneqjoinsel ));
141144
DATA(insertOID=412 ("<"PGUID0btf20201641341500int8ltintltselintltjoinsel ));

‎src/include/catalog/pg_proc.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: pg_proc.h,v 1.104 1999/09/30 14:54:23 wieck Exp $
9+
* $Id: pg_proc.h,v 1.105 1999/10/11 06:28:28 inoue Exp $
1010
*
1111
* NOTES
1212
* The script catalog/genbki.sh reads this file and generates .bki
@@ -1560,6 +1560,13 @@ DESCR("truncate _char()");
15601560
DATA(insertOID=1291 (_varcharPGUID11ftt2f1015"1015 23"10000100_varchar- ));
15611561
DESCR("truncate _varchar()");
15621562

1563+
DATA(insertOID=1292 (tideqPGUID11ftf2f16"27 27"10000100tideq- ));
1564+
DESCR("equal");
1565+
DATA(insertOID=1293 (currtidPGUID11ftf2f27"26 27"10000100currtid_byreloid- ));
1566+
DESCR("latest tid of a tuple");
1567+
DATA(insertOID=1294 (currtid2PGUID11ftf2f27"25 27"10000100currtid_byrelname- ));
1568+
DESCR("latest tid of a tuple");
1569+
15631570
DATA(insertOID=1297 (timestamp_inPGUID11ftf1f1296"0"10000100timestamp_in- ));
15641571
DESCR("(internal)");
15651572
DATA(insertOID=1298 (timestamp_outPGUID11ftf1f23"0"10000100timestamp_out- ));

‎src/include/utils/builtins.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: builtins.h,v 1.88 1999/10/03 23:55:37 tgl Exp $
9+
* $Id: builtins.h,v 1.89 1999/10/11 06:28:28 inoue Exp $
1010
*
1111
* NOTES
1212
* This should normally only be included by fmgr.h.
@@ -399,8 +399,14 @@ extern float64 gistsel(Oid operatorObjectId, Oid indrelid, AttrNumber attributeN
399399
externfloat64gistnpage(OidoperatorObjectId,Oidindrelid,AttrNumberattributeNumber,char*constValue,int32constFlag,int32nIndexKeys,Oidindexrelid);
400400

401401
/* tid.c */
402-
externItemPointertidin(char*str);
402+
externItemPointertidin(constchar*str);
403403
externchar*tidout(ItemPointeritemPtr);
404+
externbooltideq(ItemPointer,ItemPointer);
405+
externbooltidne(ItemPointer,ItemPointer);
406+
externtext*tid_text(ItemPointer);
407+
externItemPointertext_tid(consttext*);
408+
externItemPointercurrtid_byreloid(OidrelOid,ItemPointer);
409+
externItemPointercurrtid_byrelname(consttext*relName,ItemPointer);
404410

405411
/* timestamp.c */
406412
externtime_ttimestamp_in(constchar*timestamp_str);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp