Skip to content

Commit bef5fcc

Browse files
committed
pgstatindex, pageinspect: handle partitioned indexes
Commit 8b08f7d failed to update these modules to at least give non-broken error messages for partitioned indexes. Add appropriate error support to them. Peter G. was complaining about a problem of unfriendly error messages; while we haven't fixed that yet, subsequent discussion let to discovery of these unhandled cases. Author: Michaël Paquier Reported-by: Peter Geoghegan Discussion: https://postgr.es/m/CAH2-WzkOKptQiE51Bh4_xeEHhaBwHkZkGtKizrFMgEkfUuRRQg@mail.gmail.com
1 parent c8478f4 commit bef5fcc

File tree

7 files changed

+22
-3
lines changed

7 files changed

+22
-3
lines changed

contrib/pageinspect/expected/page.out

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,14 @@ SELECT * FROM fsm_page_contents(get_raw_page('test1', 'fsm', 0));
8383
(1 row)
8484

8585
DROP TABLE test1;
86-
-- check that using any of these functions with a partitioned table would fail
86+
-- check that using any of these functions with a partitioned table or index
87+
-- would fail
8788
create table test_partitioned (a int) partition by range (a);
89+
create index test_partitioned_index on test_partitioned (a);
8890
select get_raw_page('test_partitioned', 0); -- error about partitioned table
8991
ERROR: cannot get raw page from partitioned table "test_partitioned"
92+
select get_raw_page('test_partitioned_index', 0); -- error about partitioned index
93+
ERROR: cannot get raw page from partitioned index "test_partitioned_index"
9094
-- a regular table which is a member of a partition set should work though
9195
create table test_part1 partition of test_partitioned for values from ( 1 ) to (100);
9296
select get_raw_page('test_part1', 0); -- get farther and error about empty table

contrib/pageinspect/rawpage.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@ get_raw_page_internal(text *relname, ForkNumber forknum, BlockNumber blkno)
128128
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
129129
errmsg("cannot get raw page from partitioned table \"%s\"",
130130
RelationGetRelationName(rel))));
131+
if (rel->rd_rel->relkind == RELKIND_PARTITIONED_INDEX)
132+
ereport(ERROR,
133+
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
134+
errmsg("cannot get raw page from partitioned index \"%s\"",
135+
RelationGetRelationName(rel))));
131136

132137
/*
133138
* Reject attempts to read non-local temporary relations; we would be

contrib/pageinspect/sql/page.sql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,12 @@ SELECT * FROM fsm_page_contents(get_raw_page('test1', 'fsm', 0));
3333

3434
DROP TABLE test1;
3535

36-
-- check that using any of these functions with a partitioned table would fail
36+
-- check that using any of these functions with a partitioned table or index
37+
-- would fail
3738
create table test_partitioned (a int) partition by range (a);
39+
create index test_partitioned_index on test_partitioned (a);
3840
select get_raw_page('test_partitioned', 0); -- error about partitioned table
41+
select get_raw_page('test_partitioned_index', 0); -- error about partitioned index
3942

4043
-- a regular table which is a member of a partition set should work though
4144
create table test_part1 partition of test_partitioned for values from ( 1 ) to (100);

contrib/pgstattuple/expected/pgstattuple.out

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,12 @@ select pgstatginindex('test_hashidx');
152152
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);
155+
create index test_partitioned_index on test_partitioned(a);
155156
-- these should all fail
156157
select pgstattuple('test_partitioned');
157158
ERROR: "test_partitioned" (partitioned table) is not supported
159+
select pgstattuple('test_partitioned_index');
160+
ERROR: "test_partitioned_index" (partitioned index) is not supported
158161
select pgstattuple_approx('test_partitioned');
159162
ERROR: "test_partitioned" is not a table or materialized view
160163
select pg_relpages('test_partitioned');

contrib/pgstattuple/pgstatindex.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,6 @@ pgstathashindex(PG_FUNCTION_ARGS)
604604
errmsg("relation \"%s\" is not a hash index",
605605
RelationGetRelationName(rel))));
606606

607-
608607
/*
609608
* Reject attempts to read non-local temporary relations; we would be
610609
* likely to get wrong data since we have no visibility into the owning

contrib/pgstattuple/pgstattuple.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,9 @@ pgstat_relation(Relation rel, FunctionCallInfo fcinfo)
296296
case RELKIND_PARTITIONED_TABLE:
297297
err = "partitioned table";
298298
break;
299+
case RELKIND_PARTITIONED_INDEX:
300+
err = "partitioned index";
301+
break;
299302
default:
300303
err = "unknown";
301304
break;

contrib/pgstattuple/sql/pgstattuple.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,10 @@ select pgstatginindex('test_hashidx');
6464

6565
-- check that using any of these functions with unsupported relations will fail
6666
create table test_partitioned (a int) partition by range (a);
67+
create index test_partitioned_index on test_partitioned(a);
6768
-- these should all fail
6869
select pgstattuple('test_partitioned');
70+
select pgstattuple('test_partitioned_index');
6971
select pgstattuple_approx('test_partitioned');
7072
select pg_relpages('test_partitioned');
7173
select pgstatindex('test_partitioned');

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy