mirror of
https://github.com/postgres/postgres.git
synced 2025-11-04 20:11:56 +03:00
Separate equalRowTypes() from equalTupleDescs()
This introduces a new function equalRowTypes() that is effectively a
subset of equalTupleDescs() but only compares the number of attributes
and attribute name, type, typmod, and collation. This is enough for
most existing uses of equalTupleDescs(), which are changed to use the
new function. The only remaining callers of equalTupleDescs() are
those that really want to check the full tuple descriptor as such,
without concern about record or row or record type semantics.
The existing function hashTupleDesc() is renamed to hashRowType(),
because it now corresponds more to equalRowTypes().
The purpose of this change is to be clearer about the semantics of the
equality asked for by each caller. (At least one caller had a comment
that questioned whether equalTupleDescs() was too restrictive.) For
example, 4f622503d6 removed attstattarget from the tuple descriptor
structure. It was not fully clear at the time how this should affect
equalTupleDescs(). Now the answer is clear: By their own definitions,
equalRowTypes() does not care, and equalTupleDescs() just compares
whatever is in the tuple descriptor but does not care why it is in
there.
Reviewed-by: Tomas Vondra <tomas.vondra@enterprisedb.com>
Discussion: https://www.postgresql.org/message-id/flat/f656d6d9-6660-4518-a006-2f65cafbebd1%40eisentraut.org
This commit is contained in:
5
src/backend/utils/cache/plancache.c
vendored
5
src/backend/utils/cache/plancache.c
vendored
@@ -727,8 +727,7 @@ RevalidateCachedQuery(CachedPlanSource *plansource,
|
||||
PopActiveSnapshot();
|
||||
|
||||
/*
|
||||
* Check or update the result tupdesc. XXX should we use a weaker
|
||||
* condition than equalTupleDescs() here?
|
||||
* Check or update the result tupdesc.
|
||||
*
|
||||
* We assume the parameter types didn't change from the first time, so no
|
||||
* need to update that.
|
||||
@@ -739,7 +738,7 @@ RevalidateCachedQuery(CachedPlanSource *plansource,
|
||||
/* OK, doesn't return tuples */
|
||||
}
|
||||
else if (resultDesc == NULL || plansource->resultDesc == NULL ||
|
||||
!equalTupleDescs(resultDesc, plansource->resultDesc))
|
||||
!equalRowTypes(resultDesc, plansource->resultDesc))
|
||||
{
|
||||
/* can we give a better error message? */
|
||||
if (plansource->fixed_result)
|
||||
|
||||
10
src/backend/utils/cache/typcache.c
vendored
10
src/backend/utils/cache/typcache.c
vendored
@@ -147,7 +147,7 @@ typedef struct TypeCacheEnumData
|
||||
* We use a separate table for storing the definitions of non-anonymous
|
||||
* record types. Once defined, a record type will be remembered for the
|
||||
* life of the backend. Subsequent uses of the "same" record type (where
|
||||
* sameness means equalTupleDescs) will refer to the existing table entry.
|
||||
* sameness means equalRowTypes) will refer to the existing table entry.
|
||||
*
|
||||
* Stored record types are remembered in a linear array of TupleDescs,
|
||||
* which can be indexed quickly with the assigned typmod. There is also
|
||||
@@ -231,7 +231,7 @@ shared_record_table_compare(const void *a, const void *b, size_t size,
|
||||
else
|
||||
t2 = k2->u.local_tupdesc;
|
||||
|
||||
return equalTupleDescs(t1, t2) ? 0 : 1;
|
||||
return equalRowTypes(t1, t2) ? 0 : 1;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -249,7 +249,7 @@ shared_record_table_hash(const void *a, size_t size, void *arg)
|
||||
else
|
||||
t = k->u.local_tupdesc;
|
||||
|
||||
return hashTupleDesc(t);
|
||||
return hashRowType(t);
|
||||
}
|
||||
|
||||
/* Parameters for SharedRecordTypmodRegistry's TupleDesc table. */
|
||||
@@ -1927,7 +1927,7 @@ record_type_typmod_hash(const void *data, size_t size)
|
||||
{
|
||||
RecordCacheEntry *entry = (RecordCacheEntry *) data;
|
||||
|
||||
return hashTupleDesc(entry->tupdesc);
|
||||
return hashRowType(entry->tupdesc);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1939,7 +1939,7 @@ record_type_typmod_compare(const void *a, const void *b, size_t size)
|
||||
RecordCacheEntry *left = (RecordCacheEntry *) a;
|
||||
RecordCacheEntry *right = (RecordCacheEntry *) b;
|
||||
|
||||
return equalTupleDescs(left->tupdesc, right->tupdesc) ? 0 : 1;
|
||||
return equalRowTypes(left->tupdesc, right->tupdesc) ? 0 : 1;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user