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

Commit60a1d96

Browse files
committed
Rework DefineIndex relkind check
Simplify coding using a switch rather than nested if tests.Author: ÁlvaroReviewed-by: Robert Haas, Amit Langote, Michaël PaquierDiscussion:https://postgr.es/m/20171013163820.pai7djcaxrntaxtn@alvherre.pgsql
1 parent5fc438f commit60a1d96

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

‎src/backend/commands/indexcmds.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -375,25 +375,24 @@ DefineIndex(Oid relationId,
375375
relationId=RelationGetRelid(rel);
376376
namespaceId=RelationGetNamespace(rel);
377377

378-
if (rel->rd_rel->relkind!=RELKIND_RELATION&&
379-
rel->rd_rel->relkind!=RELKIND_MATVIEW)
378+
/* Ensure that it makes sense to index this kind of relation */
379+
switch (rel->rd_rel->relkind)
380380
{
381-
if (rel->rd_rel->relkind==RELKIND_FOREIGN_TABLE)
382-
383-
/*
384-
* Custom error message for FOREIGN TABLE since the term is close
385-
* to a regular table and can confuse the user.
386-
*/
381+
caseRELKIND_RELATION:
382+
caseRELKIND_MATVIEW:
383+
/* OK */
384+
break;
385+
caseRELKIND_FOREIGN_TABLE:
387386
ereport(ERROR,
388387
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
389388
errmsg("cannot create index on foreign table \"%s\"",
390389
RelationGetRelationName(rel))));
391-
elseif (rel->rd_rel->relkind==RELKIND_PARTITIONED_TABLE)
390+
caseRELKIND_PARTITIONED_TABLE:
392391
ereport(ERROR,
393392
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
394393
errmsg("cannot create index on partitioned table \"%s\"",
395394
RelationGetRelationName(rel))));
396-
else
395+
default:
397396
ereport(ERROR,
398397
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
399398
errmsg("\"%s\" is not a table or materialized view",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp