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

Commitf729fda

Browse files
committed
pgstattuple: Fix failure with pgstathashindex() for partitioned indexes
As coded, the function relied on index_open() when opening an indexrelation, allowing partitioned indexes to be processed bypgstathashindex(). This was leading to a "could not open file" errorbecause partitioned indexes have no physical files, or to a crash withan assertion failure (like on HEAD).This issue is fixed by applying the same checks as the other statfunctions for indexes, with a lookup at both RELKIND_INDEX and the indexAM expected.Author: Alexander LakhinDiscussion:https://postgr.es/m/18246-f4d9ff7cb3af77e6@postgresql.orgBackpatch-through: 12
1 parent7a4bdd9 commitf729fda

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

‎contrib/pgstattuple/expected/pgstattuple.out

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ ERROR: relation "test_hashidx" is not a GIN index
153153
-- check that using any of these functions with unsupported relations will fail
154154
create table test_partitioned (a int) partition by range (a);
155155
create index test_partitioned_index on test_partitioned(a);
156+
create index test_partitioned_hash_index on test_partitioned using hash(a);
156157
-- these should all fail
157158
select pgstattuple('test_partitioned');
158159
ERROR: "test_partitioned" (partitioned table) is not supported
@@ -167,7 +168,9 @@ ERROR: relation "test_partitioned" is not a btree index
167168
select pgstatginindex('test_partitioned');
168169
ERROR: relation "test_partitioned" is not a GIN index
169170
select pgstathashindex('test_partitioned');
170-
ERROR: "test_partitioned" is not an index
171+
ERROR: relation "test_partitioned" is not a hash index
172+
select pgstathashindex('test_partitioned_hash_index');
173+
ERROR: relation "test_partitioned_hash_index" is not a hash index
171174
create view test_view as select 1;
172175
-- these should all fail
173176
select pgstattuple('test_view');
@@ -181,7 +184,7 @@ ERROR: relation "test_view" is not a btree index
181184
select pgstatginindex('test_view');
182185
ERROR: relation "test_view" is not a GIN index
183186
select pgstathashindex('test_view');
184-
ERROR: "test_view" is notan index
187+
ERROR:relation"test_view" is nota hash index
185188
create foreign data wrapper dummy;
186189
create server dummy_server foreign data wrapper dummy;
187190
create foreign table test_foreign_table () server dummy_server;
@@ -197,7 +200,7 @@ ERROR: relation "test_foreign_table" is not a btree index
197200
select pgstatginindex('test_foreign_table');
198201
ERROR: relation "test_foreign_table" is not a GIN index
199202
select pgstathashindex('test_foreign_table');
200-
ERROR: "test_foreign_table" is notan index
203+
ERROR:relation"test_foreign_table" is nota hash index
201204
-- a partition of a partitioned table should work though
202205
create table test_partition partition of test_partitioned for values from (1) to (100);
203206
select pgstattuple('test_partition');
@@ -243,7 +246,7 @@ ERROR: relation "test_partition" is not a btree index
243246
select pgstatginindex('test_partition');
244247
ERROR: relation "test_partition" is not a GIN index
245248
select pgstathashindex('test_partition');
246-
ERROR: "test_partition" is notan index
249+
ERROR:relation"test_partition" is nota hash index
247250
-- an actual index of a partitioned table should work though
248251
create index test_partition_idx on test_partition(a);
249252
create index test_partition_hash_idx on test_partition using hash (a);

‎contrib/pgstattuple/pgstatindex.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -619,10 +619,9 @@ pgstathashindex(PG_FUNCTION_ARGS)
619619
float8free_percent;
620620
uint64total_space;
621621

622-
rel=index_open(relid,AccessShareLock);
622+
rel=relation_open(relid,AccessShareLock);
623623

624-
/* index_open() checks that it's an index */
625-
if (!IS_HASH(rel))
624+
if (!IS_INDEX(rel)|| !IS_HASH(rel))
626625
ereport(ERROR,
627626
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
628627
errmsg("relation \"%s\" is not a hash index",

‎contrib/pgstattuple/sql/pgstattuple.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ select pgstatginindex('test_hashidx');
6565
-- check that using any of these functions with unsupported relations will fail
6666
createtabletest_partitioned (aint) partition by range (a);
6767
createindextest_partitioned_indexon test_partitioned(a);
68+
createindextest_partitioned_hash_indexon test_partitioned using hash(a);
6869
-- these should all fail
6970
select pgstattuple('test_partitioned');
7071
select pgstattuple('test_partitioned_index');
@@ -73,6 +74,7 @@ select pg_relpages('test_partitioned');
7374
select pgstatindex('test_partitioned');
7475
select pgstatginindex('test_partitioned');
7576
select pgstathashindex('test_partitioned');
77+
select pgstathashindex('test_partitioned_hash_index');
7678

7779
createviewtest_viewasselect1;
7880
-- these should all fail

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp