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

Commiteec3466

Browse files
committed
Guard against table-AM-less relations in planner.
The executor will dump core if it's asked to execute a seqscan ona relation having no table AM, such as a view. While that shouldn'treally happen, it's possible to get there via catalog corruption,such as a missing ON SELECT rule. It seems worth installing a defenseagainst that. There are multiple plausible places for such a defense,but I picked the planner's get_relation_info().Per discussion of bug #17646 from Kui Liu. Back-patch to v12 wherethe tableam APIs were introduced; in older versions you won't get aSIGSEGV, so it seems less pressing.Discussion:https://postgr.es/m/17646-70c93cfa40365776@postgresql.org
1 parentc68a183 commiteec3466

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

‎src/backend/optimizer/util/plancat.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,24 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent,
127127
*/
128128
relation=table_open(relationObjectId,NoLock);
129129

130+
/*
131+
* Relations without a table AM can be used in a query only if they are of
132+
* special-cased relkinds. This check prevents us from crashing later if,
133+
* for example, a view's ON SELECT rule has gone missing. Note that
134+
* table_open() already rejected indexes and composite types; spell the
135+
* error the same way it does.
136+
*/
137+
if (!relation->rd_tableam)
138+
{
139+
if (!(relation->rd_rel->relkind==RELKIND_FOREIGN_TABLE||
140+
relation->rd_rel->relkind==RELKIND_PARTITIONED_TABLE))
141+
ereport(ERROR,
142+
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
143+
errmsg("cannot open relation \"%s\"",
144+
RelationGetRelationName(relation)),
145+
errdetail_relkind_not_supported(relation->rd_rel->relkind)));
146+
}
147+
130148
/* Temporary and unlogged relations are inaccessible during recovery. */
131149
if (!RelationIsPermanent(relation)&&RecoveryInProgress())
132150
ereport(ERROR,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp