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

Commit8a7f31a

Browse files
committed
Try to detect oversize tuple before corrupting relation, instead of
after...
1 parent66dbcd4 commit8a7f31a

File tree

1 file changed

+29
-16
lines changed
  • src/backend/access/heap

1 file changed

+29
-16
lines changed

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

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Id: hio.c,v 1.26 1999/07/19 07:07:18 momjian Exp $
10+
* $Id: hio.c,v 1.27 1999/11/29 04:34:55 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -107,10 +107,20 @@ RelationPutHeapTupleAtEnd(Relation relation, HeapTuple tuple)
107107
ItemIditemId;
108108
Itemitem;
109109

110+
len= (unsigned)MAXALIGN(tuple->t_len);/* be conservative */
111+
112+
/*
113+
* If we're gonna fail for oversize tuple, do it right away...
114+
* this code should go away eventually.
115+
*/
116+
if (len>MaxTupleSize)
117+
elog(ERROR,"Tuple is too big: size %d, max size %d",
118+
len,MaxTupleSize);
119+
110120
/*
111-
* Lock relation forextention. We can use LockPage here as long as in
121+
* Lock relation forextension. We can use LockPage here as long as in
112122
* all other places we use page-level locking for indices only.
113-
*Alternatevely, we could define pseudo-table as we do for
123+
*Alternatively, we could define pseudo-table as we do for
114124
* transactions with XactLockTable.
115125
*/
116126
if (!relation->rd_myxactonly)
@@ -122,17 +132,17 @@ RelationPutHeapTupleAtEnd(Relation relation, HeapTuple tuple)
122132
* relation. A good optimization would be to get this to actually
123133
* work properly.
124134
*/
125-
126135
lastblock=RelationGetNumberOfBlocks(relation);
127136

137+
/*
138+
* Get the last existing page --- may need to create the first one
139+
* if this is a virgin relation.
140+
*/
128141
if (lastblock==0)
129142
{
143+
/* what exactly is this all about??? */
130144
buffer=ReadBuffer(relation,lastblock);
131145
pageHeader= (Page)BufferGetPage(buffer);
132-
133-
/*
134-
* There was IF instead of ASSERT here ?!
135-
*/
136146
Assert(PageIsNew((PageHeader)pageHeader));
137147
buffer=ReleaseAndReadBuffer(buffer,relation,P_NEW);
138148
pageHeader= (Page)BufferGetPage(buffer);
@@ -143,13 +153,10 @@ RelationPutHeapTupleAtEnd(Relation relation, HeapTuple tuple)
143153

144154
LockBuffer(buffer,BUFFER_LOCK_EXCLUSIVE);
145155
pageHeader= (Page)BufferGetPage(buffer);
146-
len= (unsigned)MAXALIGN(tuple->t_len);/* be conservative */
147156

148157
/*
149-
* Note that this is true if the above returned a bogus page, which it
150-
* will do for a completely empty relation.
158+
* Is there room on the last existing page?
151159
*/
152-
153160
if (len>PageGetFreeSpace(pageHeader))
154161
{
155162
LockBuffer(buffer,BUFFER_LOCK_UNLOCK);
@@ -159,12 +166,18 @@ RelationPutHeapTupleAtEnd(Relation relation, HeapTuple tuple)
159166
PageInit(pageHeader,BufferGetPageSize(buffer),0);
160167

161168
if (len>PageGetFreeSpace(pageHeader))
169+
{
170+
/*
171+
* BUG: by elog'ing here, we leave the new buffer locked and not
172+
* marked dirty, which may result in an invalid page header
173+
* being left on disk. But we should not get here given the
174+
* test at the top of the routine, and the whole deal should
175+
* go away when we implement tuple splitting anyway...
176+
*/
162177
elog(ERROR,"Tuple is too big: size %d",len);
178+
}
163179
}
164180

165-
if (len>MaxTupleSize)
166-
elog(ERROR,"Tuple is too big: size %d, max size %d",len,MaxTupleSize);
167-
168181
if (!relation->rd_myxactonly)
169182
UnlockPage(relation,0,ExclusiveLock);
170183

@@ -178,7 +191,7 @@ RelationPutHeapTupleAtEnd(Relation relation, HeapTuple tuple)
178191

179192
ItemPointerSet(&((HeapTupleHeader)item)->t_ctid,lastblock,offnum);
180193

181-
/* return an accurate tuple */
194+
/* return an accurate tupleself-pointer*/
182195
ItemPointerSet(&tuple->t_self,lastblock,offnum);
183196

184197
LockBuffer(buffer,BUFFER_LOCK_UNLOCK);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp