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

Commit47c6772

Browse files
committed
Clean up tupdesc.c for recent changes.
TupleDescCopy needs to have the same effects as CreateTupleDescCopy inthat, since it doesn't copy constraints, it should clear the per-attributefields associated with them. Oversight in commitcc5f813.Since TupleDescCopy has already established the presumption that itcan just flat-copy the entire attribute array in one go, propagatethat approach into CreateTupleDescCopy and CreateTupleDescCopyConstr.(I'm suspicious that this would lead to valgrind complaints if wehad any trailing padding in the struct, but we do not, and anywayfixing that seems like a job for a separate commit.)Add some better comments.Thomas Munro, reviewed by Vik Fearing, some additional hacking by meDiscussion:https://postgr.es/m/CAEepm=0NvOGZ8B6GbQyQe2C_c2m3LKJ9w=8OMBaYRLgZ_Gw6Nw@mail.gmail.com
1 parentbab2969 commit47c6772

File tree

1 file changed

+45
-7
lines changed

1 file changed

+45
-7
lines changed

‎src/backend/access/common/tupdesc.c

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ CreateTemplateTupleDesc(int natts, bool hasoid)
5252
/*
5353
* Allocate enough memory for the tuple descriptor, including the
5454
* attribute rows.
55+
*
56+
* Note: the attribute array stride is sizeof(FormData_pg_attribute),
57+
* since we declare the array elements as FormData_pg_attribute for
58+
* notational convenience. However, we only guarantee that the first
59+
* ATTRIBUTE_FIXED_PART_SIZE bytes of each entry are valid; most code that
60+
* copies tupdesc entries around copies just that much. In principle that
61+
* could be less due to trailing padding, although with the current
62+
* definition of pg_attribute there probably isn't any padding.
5563
*/
5664
desc= (TupleDesc)palloc(offsetof(structtupleDesc,attrs)+
5765
natts*sizeof(FormData_pg_attribute));
@@ -106,16 +114,25 @@ CreateTupleDescCopy(TupleDesc tupdesc)
106114

107115
desc=CreateTemplateTupleDesc(tupdesc->natts,tupdesc->tdhasoid);
108116

117+
/* Flat-copy the attribute array */
118+
memcpy(TupleDescAttr(desc,0),
119+
TupleDescAttr(tupdesc,0),
120+
desc->natts*sizeof(FormData_pg_attribute));
121+
122+
/*
123+
* Since we're not copying constraints and defaults, clear fields
124+
* associated with them.
125+
*/
109126
for (i=0;i<desc->natts;i++)
110127
{
111128
Form_pg_attributeatt=TupleDescAttr(desc,i);
112129

113-
memcpy(att,&tupdesc->attrs[i],ATTRIBUTE_FIXED_PART_SIZE);
114130
att->attnotnull= false;
115131
att->atthasdef= false;
116132
att->attidentity='\0';
117133
}
118134

135+
/* We can copy the tuple type identification, too */
119136
desc->tdtypeid=tupdesc->tdtypeid;
120137
desc->tdtypmod=tupdesc->tdtypmod;
121138

@@ -136,13 +153,12 @@ CreateTupleDescCopyConstr(TupleDesc tupdesc)
136153

137154
desc=CreateTemplateTupleDesc(tupdesc->natts,tupdesc->tdhasoid);
138155

139-
for (i=0;i<desc->natts;i++)
140-
{
141-
memcpy(TupleDescAttr(desc,i),
142-
TupleDescAttr(tupdesc,i),
143-
ATTRIBUTE_FIXED_PART_SIZE);
144-
}
156+
/* Flat-copy the attribute array */
157+
memcpy(TupleDescAttr(desc,0),
158+
TupleDescAttr(tupdesc,0),
159+
desc->natts*sizeof(FormData_pg_attribute));
145160

161+
/* Copy the TupleConstr data structure, if any */
146162
if (constr)
147163
{
148164
TupleConstr*cpy= (TupleConstr*)palloc0(sizeof(TupleConstr));
@@ -178,6 +194,7 @@ CreateTupleDescCopyConstr(TupleDesc tupdesc)
178194
desc->constr=cpy;
179195
}
180196

197+
/* We can copy the tuple type identification, too */
181198
desc->tdtypeid=tupdesc->tdtypeid;
182199
desc->tdtypmod=tupdesc->tdtypmod;
183200

@@ -195,8 +212,29 @@ CreateTupleDescCopyConstr(TupleDesc tupdesc)
195212
void
196213
TupleDescCopy(TupleDescdst,TupleDescsrc)
197214
{
215+
inti;
216+
217+
/* Flat-copy the header and attribute array */
198218
memcpy(dst,src,TupleDescSize(src));
219+
220+
/*
221+
* Since we're not copying constraints and defaults, clear fields
222+
* associated with them.
223+
*/
224+
for (i=0;i<dst->natts;i++)
225+
{
226+
Form_pg_attributeatt=TupleDescAttr(dst,i);
227+
228+
att->attnotnull= false;
229+
att->atthasdef= false;
230+
att->attidentity='\0';
231+
}
199232
dst->constr=NULL;
233+
234+
/*
235+
* Also, assume the destination is not to be ref-counted. (Copying the
236+
* source's refcount would be wrong in any case.)
237+
*/
200238
dst->tdrefcount=-1;
201239
}
202240

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp