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

Commit88a658a

Browse files
committed
amcheck: Improve error message for partitioned index target.
Previously, amcheck could produce misleading error message whena partitioned index was passed to functions like bt_index_check().For example, bt_index_check() with a partitioned btree index produced: ERROR: expected "btree" index as targets for verification DETAIL: Relation ... is a btree index.Reporting "expected btree index as targets" even when the specifiedindex was a btree was confusing. In this case, the function should failsince the partitioned index specified is not valid target. This commitimproves the error reporting to better reflect this actual issue. Now,bt_index_check() with a partitioned index, the error message is: ERROR: expected index as targets for verification DETAIL: This operation is not supported for partitioned indexes.This commit also applies the following minor changes:- Simplifies index_checkable() by using get_am_name() to retrieve the access method name.- Changes index_checkable() from extern to static, as it is only used in verify_common.c.- Updates the error code for invalid indexes to ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE, aligning with usage in similar modules like pgstattuple.Author: Masahiro Ikeda <ikedamsh@oss.nttdata.com>Reviewed-by: Fujii Masao <masao.fujii@gmail.com>Discussion:https://postgr.es/m/8829854bbfc8635ddecd0846bb72dfda@oss.nttdata.com
1 parent6b1c4d3 commit88a658a

File tree

4 files changed

+27
-14
lines changed

4 files changed

+27
-14
lines changed

‎contrib/amcheck/expected/check_btree.out

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ SELECT bt_index_parent_check('bttest_a_brin_idx');
6060
ERROR: expected "btree" index as targets for verification
6161
DETAIL: Relation "bttest_a_brin_idx" is a brin index.
6262
ROLLBACK;
63+
-- verify partitioned indexes are rejected (error)
64+
BEGIN;
65+
CREATE TABLE bttest_partitioned (a int, b int) PARTITION BY list (a);
66+
CREATE INDEX bttest_btree_partitioned_idx ON bttest_partitioned USING btree (b);
67+
SELECT bt_index_parent_check('bttest_btree_partitioned_idx');
68+
ERROR: expected index as targets for verification
69+
DETAIL: This operation is not supported for partitioned indexes.
70+
ROLLBACK;
6371
-- normal check outside of xact
6472
SELECT bt_index_check('bttest_a_idx');
6573
bt_index_check

‎contrib/amcheck/sql/check_btree.sql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ CREATE INDEX bttest_a_brin_idx ON bttest_a USING brin(id);
5252
SELECT bt_index_parent_check('bttest_a_brin_idx');
5353
ROLLBACK;
5454

55+
-- verify partitioned indexes are rejected (error)
56+
BEGIN;
57+
CREATETABLEbttest_partitioned (aint, bint) PARTITION BY list (a);
58+
CREATEINDEXbttest_btree_partitioned_idxON bttest_partitioned USING btree (b);
59+
SELECT bt_index_parent_check('bttest_btree_partitioned_idx');
60+
ROLLBACK;
61+
5562
-- normal check outside of xact
5663
SELECT bt_index_check('bttest_a_idx');
5764
-- more expansive tests

‎contrib/amcheck/verify_common.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@
1818
#include"verify_common.h"
1919
#include"catalog/index.h"
2020
#include"catalog/pg_am.h"
21+
#include"commands/defrem.h"
2122
#include"commands/tablecmds.h"
2223
#include"utils/guc.h"
2324
#include"utils/syscache.h"
2425

2526
staticboolamcheck_index_mainfork_expected(Relationrel);
27+
staticboolindex_checkable(Relationrel,Oidam_id);
2628

2729

2830
/*
@@ -155,23 +157,21 @@ amcheck_lock_relation_and_check(Oid indrelid,
155157
* callable by non-superusers. If granted, it's useful to be able to check a
156158
* whole cluster.
157159
*/
158-
bool
160+
staticbool
159161
index_checkable(Relationrel,Oidam_id)
160162
{
161-
if (rel->rd_rel->relkind!=RELKIND_INDEX||
162-
rel->rd_rel->relam!=am_id)
163-
{
164-
HeapTupleamtup;
165-
HeapTupleamtuprel;
163+
if (rel->rd_rel->relkind!=RELKIND_INDEX)
164+
ereport(ERROR,
165+
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
166+
errmsg("expected index as targets for verification"),
167+
errdetail_relkind_not_supported(rel->rd_rel->relkind)));
166168

167-
amtup=SearchSysCache1(AMOID,ObjectIdGetDatum(am_id));
168-
amtuprel=SearchSysCache1(AMOID,ObjectIdGetDatum(rel->rd_rel->relam));
169+
if (rel->rd_rel->relam!=am_id)
169170
ereport(ERROR,
170171
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
171-
errmsg("expected \"%s\" index as targets for verification",NameStr(((Form_pg_am)GETSTRUCT(amtup))->amname)),
172+
errmsg("expected \"%s\" index as targets for verification",get_am_name(am_id)),
172173
errdetail("Relation \"%s\" is a %s index.",
173-
RelationGetRelationName(rel),NameStr(((Form_pg_am)GETSTRUCT(amtuprel))->amname))));
174-
}
174+
RelationGetRelationName(rel),get_am_name(rel->rd_rel->relam))));
175175

176176
if (RELATION_IS_OTHER_TEMP(rel))
177177
ereport(ERROR,
@@ -182,7 +182,7 @@ index_checkable(Relation rel, Oid am_id)
182182

183183
if (!rel->rd_index->indisvalid)
184184
ereport(ERROR,
185-
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
185+
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
186186
errmsg("cannot check index \"%s\"",
187187
RelationGetRelationName(rel)),
188188
errdetail("Index is not valid.")));

‎contrib/amcheck/verify_common.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,3 @@ extern void amcheck_lock_relation_and_check(Oid indrelid,
2626
Oidam_id,
2727
IndexDoCheckCallbackcheck,
2828
LOCKMODElockmode,void*state);
29-
30-
externboolindex_checkable(Relationrel,Oidam_id);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp