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

Commit3ed2005

Browse files
committed
Introduce macros for typalign and typstorage constants.
Our usual practice for "poor man's enum" catalog columns is to definemacros for the possible values and use those, not literal constants,in C code. But for some reason lost in the mists of time, this wasnever done for typalign/attalign or typstorage/attstorage. It's nevertoo late to make it better though, so let's do that.The reason I got interested in this right now is the need to duplicatesome uses of the TYPSTORAGE constants in an upcoming ALTER TYPE patch.But in general, this sort of change aids greppability and readability,so it's a good idea even without any specific motivation.I may have missed a few places that could be converted, and it's evenmore likely that pending patches will re-introduce some hard-codedreferences. But that's not fatal --- there's no expectation thatwe'd actually change any of these values. We can clean up stragglersover time.Discussion:https://postgr.es/m/16457.1583189537@sss.pgh.pa.us
1 parent0ad6f84 commit3ed2005

File tree

76 files changed

+341
-309
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+341
-309
lines changed

‎contrib/hstore/hstore_gin.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ gin_extract_hstore_query(PG_FUNCTION_ARGS)
119119
text*item;
120120

121121
deconstruct_array(query,
122-
TEXTOID,-1, false,'i',
122+
TEXTOID,-1, false,TYPALIGN_INT,
123123
&key_datums,&key_nulls,&key_count);
124124

125125
entries= (Datum*)palloc(sizeof(Datum)*key_count);

‎contrib/hstore/hstore_gist.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ ghstore_consistent(PG_FUNCTION_ARGS)
555555
inti;
556556

557557
deconstruct_array(query,
558-
TEXTOID,-1, false,'i',
558+
TEXTOID,-1, false,TYPALIGN_INT,
559559
&key_datums,&key_nulls,&key_count);
560560

561561
for (i=0;res&&i<key_count;++i)
@@ -578,7 +578,7 @@ ghstore_consistent(PG_FUNCTION_ARGS)
578578
inti;
579579

580580
deconstruct_array(query,
581-
TEXTOID,-1, false,'i',
581+
TEXTOID,-1, false,TYPALIGN_INT,
582582
&key_datums,&key_nulls,&key_count);
583583

584584
res= false;

‎contrib/hstore/hstore_io.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ hstore_from_arrays(PG_FUNCTION_ARGS)
560560
errmsg("wrong number of array subscripts")));
561561

562562
deconstruct_array(key_array,
563-
TEXTOID,-1, false,'i',
563+
TEXTOID,-1, false,TYPALIGN_INT,
564564
&key_datums,&key_nulls,&key_count);
565565

566566
/* see discussion in hstoreArrayToPairs() */
@@ -599,7 +599,7 @@ hstore_from_arrays(PG_FUNCTION_ARGS)
599599
errmsg("arrays must have same bounds")));
600600

601601
deconstruct_array(value_array,
602-
TEXTOID,-1, false,'i',
602+
TEXTOID,-1, false,TYPALIGN_INT,
603603
&value_datums,&value_nulls,&value_count);
604604

605605
Assert(key_count==value_count);
@@ -689,7 +689,7 @@ hstore_from_array(PG_FUNCTION_ARGS)
689689
}
690690

691691
deconstruct_array(in_array,
692-
TEXTOID,-1, false,'i',
692+
TEXTOID,-1, false,TYPALIGN_INT,
693693
&in_datums,&in_nulls,&in_count);
694694

695695
count=in_count /2;

‎contrib/hstore/hstore_op.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ hstoreArrayToPairs(ArrayType *a, int *npairs)
8181
j;
8282

8383
deconstruct_array(a,
84-
TEXTOID,-1, false,'i',
84+
TEXTOID,-1, false,TYPALIGN_INT,
8585
&key_datums,&key_nulls,&key_count);
8686

8787
if (key_count==0)
@@ -583,7 +583,7 @@ hstore_slice_to_array(PG_FUNCTION_ARGS)
583583
inti;
584584

585585
deconstruct_array(key_array,
586-
TEXTOID,-1, false,'i',
586+
TEXTOID,-1, false,TYPALIGN_INT,
587587
&key_datums,&key_nulls,&key_count);
588588

589589
if (key_count==0)
@@ -623,7 +623,7 @@ hstore_slice_to_array(PG_FUNCTION_ARGS)
623623
ARR_NDIM(key_array),
624624
ARR_DIMS(key_array),
625625
ARR_LBOUND(key_array),
626-
TEXTOID,-1, false,'i');
626+
TEXTOID,-1, false,TYPALIGN_INT);
627627

628628
PG_RETURN_POINTER(aout);
629629
}
@@ -720,7 +720,7 @@ hstore_akeys(PG_FUNCTION_ARGS)
720720
}
721721

722722
a=construct_array(d,count,
723-
TEXTOID,-1, false,'i');
723+
TEXTOID,-1, false,TYPALIGN_INT);
724724

725725
PG_RETURN_POINTER(a);
726726
}
@@ -767,7 +767,7 @@ hstore_avals(PG_FUNCTION_ARGS)
767767
}
768768

769769
a=construct_md_array(d,nulls,1,&count,&lb,
770-
TEXTOID,-1, false,'i');
770+
TEXTOID,-1, false,TYPALIGN_INT);
771771

772772
PG_RETURN_POINTER(a);
773773
}
@@ -819,7 +819,7 @@ hstore_to_array_internal(HStore *hs, int ndims)
819819

820820
returnconstruct_md_array(out_datums,out_nulls,
821821
ndims,out_size,lb,
822-
TEXTOID,-1, false,'i');
822+
TEXTOID,-1, false,TYPALIGN_INT);
823823
}
824824

825825
PG_FUNCTION_INFO_V1(hstore_to_array);

‎contrib/pageinspect/btreefuncs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ bt_page_print_tuples(FuncCallContext *fctx, struct user_args *uargs)
385385
nposting,
386386
TIDOID,
387387
sizeof(ItemPointerData),
388-
false,'s'));
388+
false,TYPALIGN_SHORT));
389389
pfree(tids_datum);
390390
}
391391
else

‎contrib/pageinspect/ginfuncs.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ gin_page_opaque_info(PG_FUNCTION_ARGS)
144144
values[0]=Int64GetDatum(opaq->rightlink);
145145
values[1]=Int32GetDatum(opaq->maxoff);
146146
values[2]=PointerGetDatum(construct_array(flags,nflags,
147-
TEXTOID,-1, false,'i'));
147+
TEXTOID,
148+
-1, false,TYPALIGN_INT));
148149

149150
/* Build and return the result tuple. */
150151
resultTuple=heap_form_tuple(tupdesc,values,nulls);
@@ -247,7 +248,7 @@ gin_leafpage_items(PG_FUNCTION_ARGS)
247248
ndecoded,
248249
TIDOID,
249250
sizeof(ItemPointerData),
250-
false,'s'));
251+
false,TYPALIGN_SHORT));
251252
pfree(tids_datum);
252253
pfree(tids);
253254

‎contrib/pageinspect/hashfuncs.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,14 +560,18 @@ hash_metapage_info(PG_FUNCTION_ARGS)
560560
values[j++]=PointerGetDatum(construct_array(spares,
561561
HASH_MAX_SPLITPOINTS,
562562
INT8OID,
563-
8,FLOAT8PASSBYVAL,'d'));
563+
sizeof(int64),
564+
FLOAT8PASSBYVAL,
565+
TYPALIGN_DOUBLE));
564566

565567
for (i=0;i<HASH_MAX_BITMAPS;i++)
566568
mapp[i]=Int64GetDatum((int64)metad->hashm_mapp[i]);
567569
values[j++]=PointerGetDatum(construct_array(mapp,
568570
HASH_MAX_BITMAPS,
569571
INT8OID,
570-
8,FLOAT8PASSBYVAL,'d'));
572+
sizeof(int64),
573+
FLOAT8PASSBYVAL,
574+
TYPALIGN_DOUBLE));
571575

572576
tuple=heap_form_tuple(tupleDesc,values,nulls);
573577

‎contrib/pageinspect/heapfuncs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ heap_tuple_infomask_flags(PG_FUNCTION_ARGS)
589589

590590
/* build value */
591591
Assert(cnt <=bitcnt);
592-
a=construct_array(flags,cnt,TEXTOID,-1, false,'i');
592+
a=construct_array(flags,cnt,TEXTOID,-1, false,TYPALIGN_INT);
593593
values[0]=PointerGetDatum(a);
594594

595595
/*
@@ -611,7 +611,7 @@ heap_tuple_infomask_flags(PG_FUNCTION_ARGS)
611611
if (cnt==0)
612612
a=construct_empty_array(TEXTOID);
613613
else
614-
a=construct_array(flags,cnt,TEXTOID,-1, false,'i');
614+
a=construct_array(flags,cnt,TEXTOID,-1, false,TYPALIGN_INT);
615615
pfree(flags);
616616
values[1]=PointerGetDatum(a);
617617

‎contrib/pg_trgm/trgm_op.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -980,7 +980,7 @@ show_trgm(PG_FUNCTION_ARGS)
980980
TEXTOID,
981981
-1,
982982
false,
983-
'i');
983+
TYPALIGN_INT);
984984

985985
for (i=0;i<ARRNELEM(trg);i++)
986986
pfree(DatumGetPointer(d[i]));

‎contrib/pgcrypto/pgp-pgsql.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -787,11 +787,11 @@ parse_key_value_arrays(ArrayType *key_array, ArrayType *val_array,
787787
return0;
788788

789789
deconstruct_array(key_array,
790-
TEXTOID,-1, false,'i',
790+
TEXTOID,-1, false,TYPALIGN_INT,
791791
&key_datums,&key_nulls,&key_count);
792792

793793
deconstruct_array(val_array,
794-
TEXTOID,-1, false,'i',
794+
TEXTOID,-1, false,TYPALIGN_INT,
795795
&val_datums,&val_nulls,&val_count);
796796

797797
if (key_count!=val_count)

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* that have been put into a tuple but never sent to disk. Hopefully there
2525
* are few such places.
2626
*
27-
* Varlenas still have alignment'i' (or'd') in pg_type/pg_attribute, since
27+
* Varlenas still have alignmentINT (orDOUBLE) in pg_type/pg_attribute, since
2828
* that's the normal requirement for the untoasted format. But we ignore that
2929
* for the 1-byte-header format. This means that the actual start position
3030
* of a varlena datum may vary depending on which format it has. To determine
@@ -39,7 +39,7 @@
3939
* catalog, this is now risky: it's only safe if the preceding field is
4040
* word-aligned, so that there will never be any padding.
4141
*
42-
* We don't pack varlenas whose attstorage is'p', since the data type
42+
* We don't pack varlenas whose attstorage isPLAIN, since the data type
4343
* isn't expecting to have to detoast values. This is used in particular
4444
* by oidvector and int2vector, which are used in the system catalogs
4545
* and we'd like to still refer to them via C struct offsets.
@@ -66,10 +66,10 @@
6666

6767
/* Does att's datatype allow packing into the 1-byte-header varlena format? */
6868
#defineATT_IS_PACKABLE(att) \
69-
((att)->attlen == -1 && (att)->attstorage !='p')
69+
((att)->attlen == -1 && (att)->attstorage !=TYPSTORAGE_PLAIN)
7070
/* Use this if it's already known varlena */
7171
#defineVARLENA_ATT_IS_PACKABLE(att) \
72-
((att)->attstorage !='p')
72+
((att)->attstorage !=TYPSTORAGE_PLAIN)
7373

7474

7575
/* ----------------------------------------------------------------
@@ -274,7 +274,7 @@ fill_val(Form_pg_attribute att,
274274
{
275275
/* cstring ... never needs alignment */
276276
*infomask |=HEAP_HASVARWIDTH;
277-
Assert(att->attalign=='c');
277+
Assert(att->attalign==TYPALIGN_CHAR);
278278
data_length=strlen(DatumGetCString(datum))+1;
279279
memcpy(data,DatumGetPointer(datum),data_length);
280280
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ index_form_tuple(TupleDesc tupleDescriptor,
100100
*/
101101
if (!VARATT_IS_EXTENDED(DatumGetPointer(untoasted_values[i]))&&
102102
VARSIZE(DatumGetPointer(untoasted_values[i]))>TOAST_INDEX_TARGET&&
103-
(att->attstorage=='x'||att->attstorage=='m'))
103+
(att->attstorage==TYPSTORAGE_EXTENDED||
104+
att->attstorage==TYPSTORAGE_MAIN))
104105
{
105106
Datumcvalue=toast_compress_datum(untoasted_values[i]);
106107

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ transformRelOptions(Datum oldOptions, List *defList, const char *namspace,
892892
intnoldoptions;
893893
inti;
894894

895-
deconstruct_array(array,TEXTOID,-1, false,'i',
895+
deconstruct_array(array,TEXTOID,-1, false,TYPALIGN_INT,
896896
&oldoptions,NULL,&noldoptions);
897897

898898
for (i=0;i<noldoptions;i++)
@@ -1060,7 +1060,7 @@ untransformRelOptions(Datum options)
10601060

10611061
array=DatumGetArrayTypeP(options);
10621062

1063-
deconstruct_array(array,TEXTOID,-1, false,'i',
1063+
deconstruct_array(array,TEXTOID,-1, false,TYPALIGN_INT,
10641064
&optiondatums,NULL,&noptions);
10651065

10661066
for (i=0;i<noptions;i++)
@@ -1201,7 +1201,7 @@ parseRelOptions(Datum options, bool validate, relopt_kind kind,
12011201
Datum*optiondatums;
12021202
intnoptions;
12031203

1204-
deconstruct_array(array,TEXTOID,-1, false,'i',
1204+
deconstruct_array(array,TEXTOID,-1, false,TYPALIGN_INT,
12051205
&optiondatums,NULL,&noptions);
12061206

12071207
for (i=0;i<noptions;i++)

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -725,32 +725,32 @@ TupleDescInitBuiltinEntry(TupleDesc desc,
725725
caseTEXTARRAYOID:
726726
att->attlen=-1;
727727
att->attbyval= false;
728-
att->attalign='i';
729-
att->attstorage='x';
728+
att->attalign=TYPALIGN_INT;
729+
att->attstorage=TYPSTORAGE_EXTENDED;
730730
att->attcollation=DEFAULT_COLLATION_OID;
731731
break;
732732

733733
caseBOOLOID:
734734
att->attlen=1;
735735
att->attbyval= true;
736-
att->attalign='c';
737-
att->attstorage='p';
736+
att->attalign=TYPALIGN_CHAR;
737+
att->attstorage=TYPSTORAGE_PLAIN;
738738
att->attcollation=InvalidOid;
739739
break;
740740

741741
caseINT4OID:
742742
att->attlen=4;
743743
att->attbyval= true;
744-
att->attalign='i';
745-
att->attstorage='p';
744+
att->attalign=TYPALIGN_INT;
745+
att->attstorage=TYPSTORAGE_PLAIN;
746746
att->attcollation=InvalidOid;
747747
break;
748748

749749
caseINT8OID:
750750
att->attlen=8;
751751
att->attbyval=FLOAT8PASSBYVAL;
752-
att->attalign='d';
753-
att->attstorage='p';
752+
att->attalign=TYPALIGN_DOUBLE;
753+
att->attstorage=TYPSTORAGE_PLAIN;
754754
att->attcollation=InvalidOid;
755755
break;
756756

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2023,7 +2023,7 @@ heapam_relation_needs_toast_table(Relation rel)
20232023
maxlength_unknown= true;
20242024
else
20252025
data_length+=maxlen;
2026-
if (att->attstorage!='p')
2026+
if (att->attstorage!=TYPSTORAGE_PLAIN)
20272027
has_toastable_attrs= true;
20282028
}
20292029
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp