Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9d6d8d7

Browse files
committed
Fix checking of index expressions in CompareIndexInfo().
This code was sloppy about comparison of index columns thatare expressions. It didn't reliably reject cases where oneindex has an expression where the other has a plain column,and it could index off the start of the attmap array, leadingto a Valgrind complaint (though an actual crash seems unlikely).I'm not sure that the expression-vs-column sloppiness leadsto any visible problem in practice, because the subsequentcomparison of the two expression lists would reject caseswhere the indexes have different numbers of expressionsoverall. Maybe we could falsely match indexes having thesame expressions in different column positions, but it'drequire unlucky contents of the word before the attmap array.It's not too surprising that no problem has been reportedfrom the field. Nonetheless, this code is clearly wrong.Per bug #18135 from Alexander Lakhin. Back-patch to allsupported branches.Discussion:https://postgr.es/m/18135-532f4a755e71e4d2@postgresql.org
1 parent9861fe2 commit9d6d8d7

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

‎src/backend/catalog/index.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2544,7 +2544,7 @@ CompareIndexInfo(IndexInfo *info1, IndexInfo *info2,
25442544

25452545
/*
25462546
* and columns match through the attribute map (actual attribute numbers
2547-
* might differ!) Note that thisimplies that index columns that are
2547+
* might differ!) Note that thischecks that index columns that are
25482548
* expressions appear in the same positions. We will next compare the
25492549
* expressions themselves.
25502550
*/
@@ -2553,13 +2553,22 @@ CompareIndexInfo(IndexInfo *info1, IndexInfo *info2,
25532553
if (attmap->maplen<info2->ii_IndexAttrNumbers[i])
25542554
elog(ERROR,"incorrect attribute map");
25552555

2556-
/* ignore expressions at this stage */
2557-
if ((info1->ii_IndexAttrNumbers[i]!=InvalidAttrNumber)&&
2558-
(attmap->attnums[info2->ii_IndexAttrNumbers[i]-1]!=
2559-
info1->ii_IndexAttrNumbers[i]))
2560-
return false;
2556+
/* ignore expressions for now (but check their collation/opfamily) */
2557+
if (!(info1->ii_IndexAttrNumbers[i]==InvalidAttrNumber&&
2558+
info2->ii_IndexAttrNumbers[i]==InvalidAttrNumber))
2559+
{
2560+
/* fail if just one index has an expression in this column */
2561+
if (info1->ii_IndexAttrNumbers[i]==InvalidAttrNumber||
2562+
info2->ii_IndexAttrNumbers[i]==InvalidAttrNumber)
2563+
return false;
2564+
2565+
/* both are columns, so check for match after mapping */
2566+
if (attmap->attnums[info2->ii_IndexAttrNumbers[i]-1]!=
2567+
info1->ii_IndexAttrNumbers[i])
2568+
return false;
2569+
}
25612570

2562-
/* collation and opfamilyis not valid forincluding columns */
2571+
/* collation and opfamilyare not valid forincluded columns */
25632572
if (i >=info1->ii_NumIndexKeyAttrs)
25642573
continue;
25652574

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp