aboutsummaryrefslogtreecommitdiff
path: root/src/backend/optimizer/prep/prepunion.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2018-01-12 15:46:37 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2018-01-12 15:46:37 -0500
commit680d540502609b422d378a1b8e0c10cac3c60084 (patch)
treed8790680d7cb56b0a1d47d39eeaeb493118852c6 /src/backend/optimizer/prep/prepunion.c
parent90947674fc984f5639e3b1bf013435a023aa713b (diff)
downloadpostgresql-680d540502609b422d378a1b8e0c10cac3c60084.tar.gz
postgresql-680d540502609b422d378a1b8e0c10cac3c60084.zip
Avoid unnecessary failure in SELECT concurrent with ALTER NO INHERIT.
If a query against an inheritance tree runs concurrently with an ALTER TABLE that's disinheriting one of the tree members, it's possible to get a "could not find inherited attribute" error because after obtaining lock on the removed member, make_inh_translation_list sees that its columns have attinhcount=0 and decides they aren't the columns it's looking for. An ideal fix, perhaps, would avoid including such a just-removed member table in the query at all; but there seems no way to accomplish that without adding expensive catalog rechecks or creating a likelihood of deadlocks. Instead, let's just drop the check on attinhcount. In this way, a query that's included a just-disinherited child will still succeed, which is not a completely unreasonable behavior. This problem has existed for a long time, so back-patch to all supported branches. Also add an isolation test verifying related behaviors. Patch by me; the new isolation test is based on Kyotaro Horiguchi's work. Discussion: https://postgr.es/m/20170626.174612.23936762.horiguchi.kyotaro@lab.ntt.co.jp
Diffstat (limited to 'src/backend/optimizer/prep/prepunion.c')
-rw-r--r--src/backend/optimizer/prep/prepunion.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/backend/optimizer/prep/prepunion.c b/src/backend/optimizer/prep/prepunion.c
index e8eeabdc889..7ef391ffeb4 100644
--- a/src/backend/optimizer/prep/prepunion.c
+++ b/src/backend/optimizer/prep/prepunion.c
@@ -1832,7 +1832,7 @@ make_inh_translation_list(Relation oldrelation, Relation newrelation,
*/
if (old_attno < newnatts &&
(att = TupleDescAttr(new_tupdesc, old_attno)) != NULL &&
- !att->attisdropped && att->attinhcount != 0 &&
+ !att->attisdropped &&
strcmp(attname, NameStr(att->attname)) == 0)
new_attno = old_attno;
else
@@ -1840,7 +1840,7 @@ make_inh_translation_list(Relation oldrelation, Relation newrelation,
for (new_attno = 0; new_attno < newnatts; new_attno++)
{
att = TupleDescAttr(new_tupdesc, new_attno);
- if (!att->attisdropped && att->attinhcount != 0 &&
+ if (!att->attisdropped &&
strcmp(attname, NameStr(att->attname)) == 0)
break;
}