summaryrefslogtreecommitdiff
path: root/src/backend/catalog/index.c
diff options
context:
space:
mode:
authorMichael Paquier2019-12-18 07:23:02 +0000
committerMichael Paquier2019-12-18 07:23:02 +0000
commite1551f96e643a52a035c3b35777d968bc073f7fc (patch)
tree9010890c3289462dc42a51a4d03498423359d375 /src/backend/catalog/index.c
parent04c8a69c0cccbc271e0feeb22a74c69fbd87c37e (diff)
Refactor attribute mappings used in logical tuple conversion
Tuple conversion support in tupconvert.c is able to convert rowtypes between two relations, inner and outer, which are logically equivalent but have a different ordering or even dropped columns (used mainly for inheritance tree and partitions). This makes use of attribute mappings, which are simple arrays made of AttrNumber elements with a length matching the number of attributes of the outer relation. The length of the attribute mapping has been treated as completely independent of the mapping itself until now, making it easy to pass down an incorrect mapping length. This commit refactors the code related to attribute mappings and moves it into an independent facility called attmap.c, extracted from tupconvert.c. This merges the attribute mapping with its length, avoiding to try to guess what is the length of a mapping to use as this is computed once, when the map is built. This will avoid mistakes like what has been fixed in dc816e58, which has used an incorrect mapping length by matching it with the number of attributes of an inner relation (a child partition) instead of an outer relation (a partitioned table). Author: Michael Paquier Reviewed-by: Amit Langote Discussion: https://postgr.es/m/[email protected]
Diffstat (limited to 'src/backend/catalog/index.c')
-rw-r--r--src/backend/catalog/index.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c
index 79439a0c66d..787aad636e7 100644
--- a/src/backend/catalog/index.c
+++ b/src/backend/catalog/index.c
@@ -2381,13 +2381,13 @@ BuildDummyIndexInfo(Relation index)
* Note: passing collations and opfamilies separately is a kludge. Adding
* them to IndexInfo may result in better coding here and elsewhere.
*
- * Use convert_tuples_by_name_map(index2, index1) to build the attmap.
+ * Use build_attrmap_by_name(index2, index1) to build the attmap.
*/
bool
CompareIndexInfo(IndexInfo *info1, IndexInfo *info2,
Oid *collations1, Oid *collations2,
Oid *opfamilies1, Oid *opfamilies2,
- AttrNumber *attmap, int maplen)
+ AttrMap *attmap)
{
int i;
@@ -2414,12 +2414,12 @@ CompareIndexInfo(IndexInfo *info1, IndexInfo *info2,
*/
for (i = 0; i < info1->ii_NumIndexAttrs; i++)
{
- if (maplen < info2->ii_IndexAttrNumbers[i])
+ if (attmap->maplen < info2->ii_IndexAttrNumbers[i])
elog(ERROR, "incorrect attribute map");
/* ignore expressions at this stage */
if ((info1->ii_IndexAttrNumbers[i] != InvalidAttrNumber) &&
- (attmap[info2->ii_IndexAttrNumbers[i] - 1] !=
+ (attmap->attnums[info2->ii_IndexAttrNumbers[i] - 1] !=
info1->ii_IndexAttrNumbers[i]))
return false;
@@ -2445,7 +2445,7 @@ CompareIndexInfo(IndexInfo *info1, IndexInfo *info2,
Node *mapped;
mapped = map_variable_attnos((Node *) info2->ii_Expressions,
- 1, 0, attmap, maplen,
+ 1, 0, attmap,
InvalidOid, &found_whole_row);
if (found_whole_row)
{
@@ -2469,7 +2469,7 @@ CompareIndexInfo(IndexInfo *info1, IndexInfo *info2,
Node *mapped;
mapped = map_variable_attnos((Node *) info2->ii_Predicate,
- 1, 0, attmap, maplen,
+ 1, 0, attmap,
InvalidOid, &found_whole_row);
if (found_whole_row)
{