forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitf428440
committed
Ignore invalid indexes when enforcing index rules in ALTER TABLE ATTACH PARTITION
A portion of ALTER TABLE .. ATTACH PARTITION is to ensure that thepartition being attached to the partitioned table has a correct set ofindexes, so as there is a consistent index mapping between thepartitioned table and its new-to-be partition. However, as introducedin8b08f7d, the current logic could choose an invalid index as a match,which is something that can exist when dealing with more than two levelsof partitioning, like attaching a partitioned table (that haspartitions, with an index created by CREATE INDEX ON ONLY) to anotherpartitioned table.A partitioned index with indisvalid set to false is equivalent to anincomplete partition tree, meaning that an invalid partitioned indexdoes not have indexes defined in all its partitions. Hence, choosing aninvalid partitioned index can create inconsistent partition index trees,where the parent attaching to is valid, but its partition may beinvalid.In the report from Alexander Lakhin, this showed up as an assertionfailure when validating an index. Without assertions enabled, thepartition index tree would be actually broken, as indisvalid shouldbe switched to true for a partitioned index once all its partitions arethemselves valid. With two levels of partitioning, the top partitionedtable used a valid index and was able to link to an invalid index storedon its partition, itself a partitioned table.I have studied a few options here (like the possibility to switchindisvalid to false for the parent), but came down to the conclusionthat we'd better rely on a simple rule: invalid indexes had better neverbe chosen, so as the partition attached uses and creates indexes thatthe parent expects. Some regression tests are added to provide somecoverage. Note that the existing coverage is not impacted.This is a problem since partitioned indexes exist, so backpatch all theway down to v11.Reported-by: Alexander LakhinDiscussion:https://postgr.es/14987634-43c0-0cb3-e075-94d423607e08@gmail.comBackpatch-through: 111 parentb6ab18a commitf428440
File tree
3 files changed
+58
-2
lines changed- src
- backend/commands
- test/regress
- expected
- sql
3 files changed
+58
-2
lines changedLines changed: 6 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
17080 | 17080 |
| |
17081 | 17081 |
| |
17082 | 17082 |
| |
17083 |
| - | |
17084 |
| - | |
| 17083 | + | |
| 17084 | + | |
17085 | 17085 |
| |
17086 | 17086 |
| |
17087 | 17087 |
| |
| |||
17092 | 17092 |
| |
17093 | 17093 |
| |
17094 | 17094 |
| |
| 17095 | + | |
| 17096 | + | |
| 17097 | + | |
| 17098 | + | |
17095 | 17099 |
| |
17096 | 17100 |
| |
17097 | 17101 |
| |
|
Lines changed: 30 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1420 | 1420 |
| |
1421 | 1421 |
| |
1422 | 1422 |
| |
| 1423 | + | |
| 1424 | + | |
| 1425 | + | |
| 1426 | + | |
| 1427 | + | |
| 1428 | + | |
| 1429 | + | |
| 1430 | + | |
| 1431 | + | |
| 1432 | + | |
| 1433 | + | |
| 1434 | + | |
| 1435 | + | |
| 1436 | + | |
| 1437 | + | |
| 1438 | + | |
| 1439 | + | |
| 1440 | + | |
| 1441 | + | |
| 1442 | + | |
| 1443 | + | |
| 1444 | + | |
| 1445 | + | |
| 1446 | + | |
| 1447 | + | |
| 1448 | + | |
| 1449 | + | |
| 1450 | + | |
| 1451 | + | |
| 1452 | + |
Lines changed: 22 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
760 | 760 |
| |
761 | 761 |
| |
762 | 762 |
| |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + |
0 commit comments
Comments
(0)