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

Commite5f1bb9

Browse files
committed
Simplify index tuple descriptor initialization
We have two code paths for initializing the tuple descriptor for a newindex: For a normal index, we copy the tuple descriptor from the tableand reset a number of fields that are not applicable to indexes. For anexpression index, we make a blank tuple descriptor and fill in theneeded fields based on the provided expressions. As pg_attribute hasgrown over time, the number of fields that we need to reset in the firstcase is now bigger than the number of fields we actually want to copy,so it's sensible to do it the other way around: Make a blank descriptorand copy just the fields we need. This also allows more code sharingbetween the two branches, and it avoids having to touch this code foralmost every unrelated change to the pg_attribute structure.Reviewed-by: Arthur Zakirov <a.zakirov@postgrespro.ru>
1 parent7046d30 commite5f1bb9

File tree

1 file changed

+23
-34
lines changed

1 file changed

+23
-34
lines changed

‎src/backend/catalog/index.c

Lines changed: 23 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -319,9 +319,7 @@ ConstructTupleDescriptor(Relation heapRelation,
319319
indexTupDesc=CreateTemplateTupleDesc(numatts, false);
320320

321321
/*
322-
* For simple index columns, we copy the pg_attribute row from the parent
323-
* relation and modify it as necessary. For expressions we have to cons
324-
* up a pg_attribute row the hard way.
322+
* Fill in the pg_attribute row.
325323
*/
326324
for (i=0;i<numatts;i++)
327325
{
@@ -332,6 +330,19 @@ ConstructTupleDescriptor(Relation heapRelation,
332330
Form_pg_opclassopclassTup;
333331
OidkeyType;
334332

333+
MemSet(to,0,ATTRIBUTE_FIXED_PART_SIZE);
334+
to->attnum=i+1;
335+
to->attstattarget=-1;
336+
to->attcacheoff=-1;
337+
to->attislocal= true;
338+
to->attcollation= (i<numkeyatts) ?
339+
collationObjectId[i] :InvalidOid;
340+
341+
/*
342+
* For simple index columns, we copy some pg_attribute fields from the
343+
* parent relation. For expressions we have to look at the expression
344+
* result.
345+
*/
335346
if (atnum!=0)
336347
{
337348
/* Simple index column */
@@ -356,36 +367,20 @@ ConstructTupleDescriptor(Relation heapRelation,
356367
AttrNumberGetAttrOffset(atnum));
357368
}
358369

359-
/*
360-
* now that we've determined the "from", let's copy the tuple desc
361-
* data...
362-
*/
363-
memcpy(to,from,ATTRIBUTE_FIXED_PART_SIZE);
364-
365-
/*
366-
* Fix the stuff that should not be the same as the underlying
367-
* attr
368-
*/
369-
to->attnum=i+1;
370-
371-
to->attstattarget=-1;
372-
to->attcacheoff=-1;
373-
to->attnotnull= false;
374-
to->atthasdef= false;
375-
to->atthasmissing= false;
376-
to->attidentity='\0';
377-
to->attislocal= true;
378-
to->attinhcount=0;
379-
to->attcollation= (i<numkeyatts) ?
380-
collationObjectId[i] :InvalidOid;
370+
namecpy(&to->attname,&from->attname);
371+
to->atttypid=from->atttypid;
372+
to->attlen=from->attlen;
373+
to->attndims=from->attndims;
374+
to->atttypmod=from->atttypmod;
375+
to->attbyval=from->attbyval;
376+
to->attstorage=from->attstorage;
377+
to->attalign=from->attalign;
381378
}
382379
else
383380
{
384381
/* Expressional index */
385382
Node*indexkey;
386383

387-
MemSet(to,0,ATTRIBUTE_FIXED_PART_SIZE);
388-
389384
if (indexpr_item==NULL)/* shouldn't happen */
390385
elog(ERROR,"too few entries in indexprs list");
391386
indexkey= (Node*)lfirst(indexpr_item);
@@ -401,20 +396,14 @@ ConstructTupleDescriptor(Relation heapRelation,
401396
typeTup= (Form_pg_type)GETSTRUCT(tuple);
402397

403398
/*
404-
* Assign some of the attributes values. Leave the rest as 0.
399+
* Assign some of the attributes values. Leave the rest.
405400
*/
406-
to->attnum=i+1;
407401
to->atttypid=keyType;
408402
to->attlen=typeTup->typlen;
409403
to->attbyval=typeTup->typbyval;
410404
to->attstorage=typeTup->typstorage;
411405
to->attalign=typeTup->typalign;
412-
to->attstattarget=-1;
413-
to->attcacheoff=-1;
414406
to->atttypmod=exprTypmod(indexkey);
415-
to->attislocal= true;
416-
to->attcollation= (i<numkeyatts) ?
417-
collationObjectId[i] :InvalidOid;
418407

419408
ReleaseSysCache(tuple);
420409

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp