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

Commitbd2d3c9

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 parent499342e commitbd2d3c9

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');
@@ -224,7 +227,7 @@ ERROR: relation "test_partition" is not a btree index
224227
select pgstatginindex('test_partition');
225228
ERROR: relation "test_partition" is not a GIN index
226229
select pgstathashindex('test_partition');
227-
ERROR: "test_partition" is notan index
230+
ERROR:relation"test_partition" is nota hash index
228231
-- an actual index of a partitioned table should work though
229232
create index test_partition_idx on test_partition(a);
230233
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
@@ -615,10 +615,9 @@ pgstathashindex(PG_FUNCTION_ARGS)
615615
float8free_percent;
616616
uint64total_space;
617617

618-
rel=index_open(relid,AccessShareLock);
618+
rel=relation_open(relid,AccessShareLock);
619619

620-
/* index_open() checks that it's an index */
621-
if (!IS_HASH(rel))
620+
if (!IS_INDEX(rel)|| !IS_HASH(rel))
622621
ereport(ERROR,
623622
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
624623
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