mirror of
https://github.com/postgres/postgres.git
synced 2025-11-04 20:11:56 +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:
@@ -7,7 +7,7 @@
|
||||
* Copyright (c) 2000-2020, PostgreSQL Global Development Group
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* src/backend/access/common/toast_helper.c
|
||||
* src/backend/access/table/toast_helper.c
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -18,6 +18,8 @@
|
||||
#include "access/table.h"
|
||||
#include "access/toast_helper.h"
|
||||
#include "access/toast_internals.h"
|
||||
#include "catalog/pg_type_d.h"
|
||||
|
||||
|
||||
/*
|
||||
* Prepare to TOAST a tuple.
|
||||
@@ -120,7 +122,7 @@ toast_tuple_init(ToastTupleContext *ttc)
|
||||
/*
|
||||
* If the table's attribute says PLAIN always, force it so.
|
||||
*/
|
||||
if (att->attstorage == 'p')
|
||||
if (att->attstorage == TYPSTORAGE_PLAIN)
|
||||
ttc->ttc_attr[i].tai_colflags |= TOASTCOL_IGNORE;
|
||||
|
||||
/*
|
||||
@@ -134,7 +136,7 @@ toast_tuple_init(ToastTupleContext *ttc)
|
||||
if (VARATT_IS_EXTERNAL(new_value))
|
||||
{
|
||||
ttc->ttc_attr[i].tai_oldexternal = new_value;
|
||||
if (att->attstorage == 'p')
|
||||
if (att->attstorage == TYPSTORAGE_PLAIN)
|
||||
new_value = detoast_attr(new_value);
|
||||
else
|
||||
new_value = detoast_external_attr(new_value);
|
||||
@@ -165,8 +167,8 @@ toast_tuple_init(ToastTupleContext *ttc)
|
||||
* for_compression flag is passed as true, it must also not be marked
|
||||
* TOASTCOL_INCOMPRESSIBLE.
|
||||
*
|
||||
* The column must have attstorage 'e' or 'x' if check_main is false, and
|
||||
* must have attstorage 'm' if check_main is true.
|
||||
* The column must have attstorage EXTERNAL or EXTENDED if check_main is
|
||||
* false, and must have attstorage MAIN if check_main is true.
|
||||
*
|
||||
* The column must have a minimum size of MAXALIGN(TOAST_POINTER_SIZE);
|
||||
* if not, no benefit is to be expected by compressing it.
|
||||
@@ -195,13 +197,14 @@ toast_tuple_find_biggest_attribute(ToastTupleContext *ttc,
|
||||
if ((ttc->ttc_attr[i].tai_colflags & skip_colflags) != 0)
|
||||
continue;
|
||||
if (VARATT_IS_EXTERNAL(DatumGetPointer(ttc->ttc_values[i])))
|
||||
continue; /* can't happen, toast_action would be 'p' */
|
||||
continue; /* can't happen, toast_action would be PLAIN */
|
||||
if (for_compression &&
|
||||
VARATT_IS_COMPRESSED(DatumGetPointer(ttc->ttc_values[i])))
|
||||
continue;
|
||||
if (check_main && att->attstorage != 'm')
|
||||
if (check_main && att->attstorage != TYPSTORAGE_MAIN)
|
||||
continue;
|
||||
if (!check_main && att->attstorage != 'x' && att->attstorage != 'e')
|
||||
if (!check_main && att->attstorage != TYPSTORAGE_EXTENDED &&
|
||||
att->attstorage != TYPSTORAGE_EXTERNAL)
|
||||
continue;
|
||||
|
||||
if (ttc->ttc_attr[i].tai_size > biggest_size)
|
||||
|
||||
Reference in New Issue
Block a user