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

Commitc629324

Browse files
committed
Partially flatten struct tupleDesc so that it can be used in DSM.
TupleDesc's attributes were already stored in contiguous memory after thestruct. Go one step further and get rid of the array of pointers toattributes so that they can be stored in shared memory mapped at differentaddresses in each backend. This won't work for TupleDescs with contraintsand defaults, since those point to other objects, but for many purposesonly attributes are needed.Author: Thomas MunroReviewed-By: Andres FreundDiscussion:https://postgr.es/m/CAEepm=0ZtQ-SpsgCyzzYpsXS6e=kZWqk3g5Ygn3MDV7A8dabUA@mail.gmail.com
1 parent2cd7084 commitc629324

File tree

2 files changed

+18
-57
lines changed

2 files changed

+18
-57
lines changed

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

Lines changed: 14 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ TupleDesc
4141
CreateTemplateTupleDesc(intnatts,boolhasoid)
4242
{
4343
TupleDescdesc;
44-
char*stg;
45-
intattroffset;
4644

4745
/*
4846
* sanity checks
@@ -51,38 +49,10 @@ CreateTemplateTupleDesc(int natts, bool hasoid)
5149

5250
/*
5351
* Allocate enough memory for the tuple descriptor, including the
54-
* attribute rows, and set up the attribute row pointers.
55-
*
56-
* Note: we assume that sizeof(struct tupleDesc) is a multiple of the
57-
* struct pointer alignment requirement, and hence we don't need to insert
58-
* alignment padding between the struct and the array of attribute row
59-
* pointers.
60-
*
61-
* Note: Only the fixed part of pg_attribute rows is included in tuple
62-
* descriptors, so we only need ATTRIBUTE_FIXED_PART_SIZE space per attr.
63-
* That might need alignment padding, however.
52+
* attribute rows.
6453
*/
65-
attroffset=sizeof(structtupleDesc)+natts*sizeof(Form_pg_attribute);
66-
attroffset=MAXALIGN(attroffset);
67-
stg=palloc(attroffset+natts*MAXALIGN(ATTRIBUTE_FIXED_PART_SIZE));
68-
desc= (TupleDesc)stg;
69-
70-
if (natts>0)
71-
{
72-
Form_pg_attribute*attrs;
73-
inti;
74-
75-
attrs= (Form_pg_attribute*) (stg+sizeof(structtupleDesc));
76-
desc->attrs=attrs;
77-
stg+=attroffset;
78-
for (i=0;i<natts;i++)
79-
{
80-
attrs[i]= (Form_pg_attribute)stg;
81-
stg+=MAXALIGN(ATTRIBUTE_FIXED_PART_SIZE);
82-
}
83-
}
84-
else
85-
desc->attrs=NULL;
54+
desc= (TupleDesc)palloc(offsetof(structtupleDesc,attrs)+
55+
natts*sizeof(FormData_pg_attribute));
8656

8757
/*
8858
* Initialize other fields of the tupdesc.
@@ -99,33 +69,22 @@ CreateTemplateTupleDesc(int natts, bool hasoid)
9969

10070
/*
10171
* CreateTupleDesc
102-
*This function allocates a new TupleDescpointing to a given
72+
*This function allocates a new TupleDescby copying a given
10373
*Form_pg_attribute array.
10474
*
105-
* Note: if the TupleDesc is ever freed, the Form_pg_attribute array
106-
* will not be freed thereby.
107-
*
10875
* Tuple type ID information is initially set for an anonymous record type;
10976
* caller can overwrite this if needed.
11077
*/
11178
TupleDesc
11279
CreateTupleDesc(intnatts,boolhasoid,Form_pg_attribute*attrs)
11380
{
11481
TupleDescdesc;
82+
inti;
11583

116-
/*
117-
* sanity checks
118-
*/
119-
AssertArg(natts >=0);
84+
desc=CreateTemplateTupleDesc(natts,hasoid);
12085

121-
desc= (TupleDesc)palloc(sizeof(structtupleDesc));
122-
desc->attrs=attrs;
123-
desc->natts=natts;
124-
desc->constr=NULL;
125-
desc->tdtypeid=RECORDOID;
126-
desc->tdtypmod=-1;
127-
desc->tdhasoid=hasoid;
128-
desc->tdrefcount=-1;/* assume not reference-counted */
86+
for (i=0;i<natts;++i)
87+
memcpy(TupleDescAttr(desc,i),attrs[i],ATTRIBUTE_FIXED_PART_SIZE);
12988

13089
returndesc;
13190
}
@@ -147,10 +106,12 @@ CreateTupleDescCopy(TupleDesc tupdesc)
147106

148107
for (i=0;i<desc->natts;i++)
149108
{
150-
memcpy(desc->attrs[i],tupdesc->attrs[i],ATTRIBUTE_FIXED_PART_SIZE);
151-
desc->attrs[i]->attnotnull= false;
152-
desc->attrs[i]->atthasdef= false;
153-
desc->attrs[i]->attidentity='\0';
109+
Form_pg_attributeatt=TupleDescAttr(desc,i);
110+
111+
memcpy(att,&tupdesc->attrs[i],ATTRIBUTE_FIXED_PART_SIZE);
112+
att->attnotnull= false;
113+
att->atthasdef= false;
114+
att->attidentity='\0';
154115
}
155116

156117
desc->tdtypeid=tupdesc->tdtypeid;

‎src/include/access/tupdesc.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,17 @@ typedef struct tupleConstr
7171
typedefstructtupleDesc
7272
{
7373
intnatts;/* number of attributes in the tuple */
74-
Form_pg_attribute*attrs;
75-
/* attrs[N] is a pointer to the description of Attribute Number N+1 */
76-
TupleConstr*constr;/* constraints, or NULL if none */
7774
Oidtdtypeid;/* composite type ID for tuple type */
7875
int32tdtypmod;/* typmod for tuple type */
7976
booltdhasoid;/* tuple has oid attribute in its header */
8077
inttdrefcount;/* reference count, or -1 if not counting */
78+
TupleConstr*constr;/* constraints, or NULL if none */
79+
/* attrs[N] is the description of Attribute Number N+1 */
80+
FormData_pg_attributeattrs[FLEXIBLE_ARRAY_MEMBER];
8181
}*TupleDesc;
8282

8383
/* Accessor for the i'th attribute of tupdesc. */
84-
#defineTupleDescAttr(tupdesc,i) ((tupdesc)->attrs[(i)])
84+
#defineTupleDescAttr(tupdesc,i) (&(tupdesc)->attrs[(i)])
8585

8686
externTupleDescCreateTemplateTupleDesc(intnatts,boolhasoid);
8787

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp