5983a4cff added CompactAttribute for storing commonly used fields from
FormData_pg_attribute.
5983a4cff didn't go to the trouble of adjusting
every location where we can use CompactAttribute rather than
FormData_pg_attribute, so here we change the remaining ones.
There are some locations where I've left the code using
FormData_pg_attribute. These are mostly in the ALTER TABLE code. Using
CompactAttribute here seems more risky as often the TupleDesc is being
changed and those changes may not have been flushed to the
CompactAttribute yet.
I've also left record_recv(), record_send(), record_cmp(), record_eq()
and record_image_eq() alone as it's not clear to me that accessing the
CompactAttribute is a win here due to the FormData_pg_attribute still
having to be accessed for most cases. Switching the relevant parts to
use CompactAttribute would result in having to access both for common
cases. Careful benchmarking may reveal that something can be done to
make this better, but in absence of that, the safer option is to leave
these alone.
In ReorderBufferToastReplace(), there was a check to skip attnums < 0
while looping over the TupleDesc. Doing this is redundant since
TupleDescs don't store < 0 attnums. Removing that code allows us to
move to using CompactAttribute.
The change in validateDomainCheckConstraint() just moves fetching the
FormData_pg_attribute into the ERROR path, which is cold due to calling
errstart_cold() and results in code being moved out of the common path.
Author: David Rowley <dgrowleyml@gmail.com>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Discussion: https://postgr.es/m/CAApHDvrMy90o1Lgkt31F82tcSuwRFHq3vyGewSRN=-QuSEEvyQ@mail.gmail.com
for (j = 0; j < natts; j++)
{
/* dropped columns don't count */
- if (TupleDescAttr(tupdesc, j)->attisdropped)
+ if (TupleDescCompactAttr(tupdesc, j)->attisdropped)
continue;
if (++lnum == pkattnum)
numattrs = 0;
for (i = 0; i < tupleDesc->natts; i++)
{
- Form_pg_attribute attr = TupleDescAttr(tupleDesc, i);
-
- if (attr->attisdropped)
+ if (TupleDescCompactAttr(tupleDesc, i)->attisdropped)
continue;
numattrs++;
}
first = true;
for (i = 1; i <= tupdesc->natts; i++)
{
- Form_pg_attribute attr = TupleDescAttr(tupdesc, i - 1);
-
/* Ignore dropped attributes. */
- if (attr->attisdropped)
+ if (TupleDescCompactAttr(tupdesc, i - 1)->attisdropped)
continue;
if (have_wholerow ||
foreach(lc, targetAttrs)
{
int attnum = lfirst_int(lc);
- Form_pg_attribute attr = TupleDescAttr(tupdesc, attnum - 1);
+ CompactAttribute *attr = TupleDescCompactAttr(tupdesc, attnum - 1);
if (!first)
appendStringInfoString(buf, ", ");
foreach(lc, target_attrs)
{
int attnum = lfirst_int(lc);
- Form_pg_attribute attr = TupleDescAttr(tupdesc, attnum - 1);
+ CompactAttribute *attr = TupleDescCompactAttr(tupdesc, attnum - 1);
if (!first)
appendStringInfoString(buf, ", ");
foreach(lc, targetAttrs)
{
int attnum = lfirst_int(lc);
- Form_pg_attribute attr = TupleDescAttr(tupdesc, attnum - 1);
+ CompactAttribute *attr = TupleDescCompactAttr(tupdesc, attnum - 1);
if (!first)
appendStringInfoString(buf, ", ");
&attnum, &key, &category, &nlist)) != NULL)
{
/* information about the key */
- Form_pg_attribute attr = TupleDescAttr(tdesc, (attnum - 1));
+ CompactAttribute *attr = TupleDescCompactAttr(tdesc, (attnum - 1));
/* GIN tuple and tuple length */
GinTuple *tup;
Datum d;
bool isNull;
Datum conResult;
- Form_pg_attribute attr = TupleDescAttr(tupdesc, attnum - 1);
d = slot_getattr(slot, attnum, &isNull);
if (!isNull && !DatumGetBool(conResult))
{
+ Form_pg_attribute attr = TupleDescAttr(tupdesc, attnum - 1);
+
/*
* In principle the auxiliary information for this error
* should be errdomainconstraint(), but errtablecol()
Bitmapset *attrs_used = NULL;
/* skip if not generated column */
- if (!TupleDescAttr(tupdesc, defval->adnum - 1)->attgenerated)
+ if (!TupleDescCompactAttr(tupdesc, defval->adnum - 1)->attgenerated)
continue;
/* identify columns this generated column depends on */
if (tupdesc)
{
/* Composite data type, e.g. a table's row type */
- Form_pg_attribute att_tup;
+ CompactAttribute *att;
Assert(tupdesc);
Assert(attnum - atts_done <= tupdesc->natts);
- att_tup = TupleDescAttr(tupdesc,
- attnum - atts_done - 1);
- return att_tup->attisdropped;
+ att = TupleDescCompactAttr(tupdesc,
+ attnum - atts_done - 1);
+ return att->attisdropped;
}
/* Otherwise, it can't have any dropped columns */
return false;
for (natt = 0; natt < desc->natts; natt++)
{
- Form_pg_attribute attr = TupleDescAttr(desc, natt);
+ CompactAttribute *attr = TupleDescCompactAttr(desc, natt);
ReorderBufferToastEnt *ent;
struct varlena *varlena;
dlist_iter it;
Size data_done = 0;
- /* system columns aren't toasted */
- if (attr->attnum < 0)
- continue;
-
if (attr->attisdropped)
continue;
Assert(rel->attrmap->maplen == num_phys_attrs);
for (attnum = 0; attnum < num_phys_attrs; attnum++)
{
+ CompactAttribute *cattr = TupleDescCompactAttr(desc, attnum);
Expr *defexpr;
- if (TupleDescAttr(desc, attnum)->attisdropped || TupleDescAttr(desc, attnum)->attgenerated)
+ if (cattr->attisdropped || cattr->attgenerated)
continue;
if (rel->attrmap->attnums[attnum] >= 0)
target_perminfo = list_nth(estate->es_rteperminfos, 0);
for (int i = 0; i < remoteslot->tts_tupleDescriptor->natts; i++)
{
- Form_pg_attribute att = TupleDescAttr(remoteslot->tts_tupleDescriptor, i);
+ CompactAttribute *att = TupleDescCompactAttr(remoteslot->tts_tupleDescriptor, i);
int remoteattnum = rel->attrmap->attnums[i];
if (!att->attisdropped && remoteattnum >= 0)
/* Check if there is any generated column present. */
for (int i = 0; i < desc->natts; i++)
{
- Form_pg_attribute att = TupleDescAttr(desc, i);
+ CompactAttribute *att = TupleDescCompactAttr(desc, i);
if (att->attgenerated)
{
for (i = 0; i < erh->nfields; i++)
{
if (!erh->dnulls[i] &&
- !(TupleDescAttr(tupdesc, i)->attbyval))
+ !(TupleDescCompactAttr(tupdesc, i)->attbyval))
{
char *oldValue = (char *) DatumGetPointer(erh->dvalues[i]);
Node *e = (Node *) lfirst(arg);
if (tupdesc == NULL ||
- !TupleDescAttr(tupdesc, i)->attisdropped)
+ !TupleDescCompactAttr(tupdesc, i)->attisdropped)
{
appendStringInfoString(buf, sep);
/* Whole-row Vars need special treatment here */
{
while (i < tupdesc->natts)
{
- if (!TupleDescAttr(tupdesc, i)->attisdropped)
+ if (!TupleDescCompactAttr(tupdesc, i)->attisdropped)
{
appendStringInfoString(buf, sep);
appendStringInfoString(buf, "NULL");
for (i = 0; i < nkeys; i++)
{
int attnum = attnos[i];
- Form_pg_attribute att;
/* system attribute are not supported in caches */
Assert(attnum > 0);
- att = TupleDescAttr(tupdesc, attnum - 1);
-
- if (!att->attbyval)
+ if (!TupleDescCompactAttr(tupdesc, attnum - 1)->attbyval)
pfree(DatumGetPointer(keys[i]));
}
}
idx = 0;
for (i = 0; i < desc->natts; i++)
{
- if (!TupleDescAttr(desc, i)->attisdropped)
+ if (!TupleDescCompactAttr(desc, i)->attisdropped)
idx++;
}
if (PySequence_Length(sequence) != idx)
PyObject *volatile value;
PLyObToDatum *att;
- if (TupleDescAttr(desc, i)->attisdropped)
+ if (TupleDescCompactAttr(desc, i)->attisdropped)
{
values[i] = (Datum) 0;
nulls[i] = true;