mirror of
https://github.com/postgres/postgres.git
synced 2025-08-28 18:48:04 +03:00
Introduce macros for typalign and typstorage constants.
Our usual practice for "poor man's enum" catalog columns is to define macros for the possible values and use those, not literal constants, in C code. But for some reason lost in the mists of time, this was never done for typalign/attalign or typstorage/attstorage. It's never too late to make it better though, so let's do that. The reason I got interested in this right now is the need to duplicate some 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 even more likely that pending patches will re-introduce some hard-coded references. But that's not fatal --- there's no expectation that we'd actually change any of these values. We can clean up stragglers over time. Discussion: https://postgr.es/m/16457.1583189537@sss.pgh.pa.us
This commit is contained in:
@@ -2023,7 +2023,7 @@ heapam_relation_needs_toast_table(Relation rel)
|
||||
maxlength_unknown = true;
|
||||
else
|
||||
data_length += maxlen;
|
||||
if (att->attstorage != 'p')
|
||||
if (att->attstorage != TYPSTORAGE_PLAIN)
|
||||
has_toastable_attrs = true;
|
||||
}
|
||||
}
|
||||
|
@@ -159,11 +159,12 @@ heap_toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup,
|
||||
/* ----------
|
||||
* Compress and/or save external until data fits into target length
|
||||
*
|
||||
* 1: Inline compress attributes with attstorage 'x', and store very
|
||||
* large attributes with attstorage 'x' or 'e' external immediately
|
||||
* 2: Store attributes with attstorage 'x' or 'e' external
|
||||
* 3: Inline compress attributes with attstorage 'm'
|
||||
* 4: Store attributes with attstorage 'm' external
|
||||
* 1: Inline compress attributes with attstorage EXTENDED, and store very
|
||||
* large attributes with attstorage EXTENDED or EXTERNAL external
|
||||
* immediately
|
||||
* 2: Store attributes with attstorage EXTENDED or EXTERNAL external
|
||||
* 3: Inline compress attributes with attstorage MAIN
|
||||
* 4: Store attributes with attstorage MAIN external
|
||||
* ----------
|
||||
*/
|
||||
|
||||
@@ -176,8 +177,9 @@ heap_toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup,
|
||||
maxDataLen = RelationGetToastTupleTarget(rel, TOAST_TUPLE_TARGET) - hoff;
|
||||
|
||||
/*
|
||||
* Look for attributes with attstorage 'x' to compress. Also find large
|
||||
* attributes with attstorage 'x' or 'e', and store them external.
|
||||
* Look for attributes with attstorage EXTENDED to compress. Also find
|
||||
* large attributes with attstorage EXTENDED or EXTERNAL, and store them
|
||||
* external.
|
||||
*/
|
||||
while (heap_compute_data_size(tupleDesc,
|
||||
toast_values, toast_isnull) > maxDataLen)
|
||||
@@ -189,13 +191,16 @@ heap_toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup,
|
||||
break;
|
||||
|
||||
/*
|
||||
* Attempt to compress it inline, if it has attstorage 'x'
|
||||
* Attempt to compress it inline, if it has attstorage EXTENDED
|
||||
*/
|
||||
if (TupleDescAttr(tupleDesc, biggest_attno)->attstorage == 'x')
|
||||
if (TupleDescAttr(tupleDesc, biggest_attno)->attstorage == TYPSTORAGE_EXTENDED)
|
||||
toast_tuple_try_compression(&ttc, biggest_attno);
|
||||
else
|
||||
{
|
||||
/* has attstorage 'e', ignore on subsequent compression passes */
|
||||
/*
|
||||
* has attstorage EXTERNAL, ignore on subsequent compression
|
||||
* passes
|
||||
*/
|
||||
toast_attr[biggest_attno].tai_colflags |= TOASTCOL_INCOMPRESSIBLE;
|
||||
}
|
||||
|
||||
@@ -213,9 +218,9 @@ heap_toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup,
|
||||
}
|
||||
|
||||
/*
|
||||
* Second we look for attributes of attstorage 'x' or 'e' that are still
|
||||
* inline, and make them external. But skip this if there's no toast
|
||||
* table to push them to.
|
||||
* Second we look for attributes of attstorage EXTENDED or EXTERNAL that
|
||||
* are still inline, and make them external. But skip this if there's no
|
||||
* toast table to push them to.
|
||||
*/
|
||||
while (heap_compute_data_size(tupleDesc,
|
||||
toast_values, toast_isnull) > maxDataLen &&
|
||||
@@ -230,7 +235,7 @@ heap_toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup,
|
||||
}
|
||||
|
||||
/*
|
||||
* Round 3 - this time we take attributes with storage 'm' into
|
||||
* Round 3 - this time we take attributes with storage MAIN into
|
||||
* compression
|
||||
*/
|
||||
while (heap_compute_data_size(tupleDesc,
|
||||
@@ -246,8 +251,8 @@ heap_toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup,
|
||||
}
|
||||
|
||||
/*
|
||||
* Finally we store attributes of type 'm' externally. At this point we
|
||||
* increase the target tuple size, so that 'm' attributes aren't stored
|
||||
* Finally we store attributes of type MAIN externally. At this point we
|
||||
* increase the target tuple size, so that MAIN attributes aren't stored
|
||||
* externally unless really necessary.
|
||||
*/
|
||||
maxDataLen = TOAST_TUPLE_TARGET_MAIN - hoff;
|
||||
|
Reference in New Issue
Block a user