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

Commit05036a3

Browse files
Reintroduce support for sequences in pgstattuple and pageinspect.
Commit4b82664 restricted a number of functions provided bycontrib modules to only relations that use the "heap" table accessmethod. Sequences always use this table access method, but they donot advertise as such in the pg_class system catalog, so theaforementioned commit also (presumably unintentionally) removedsupport for sequences from some of these functions. This commitreintroduces said support for sequences to these functions and addsa couple of relevant tests.Co-authored-by: Ayush VatsaReviewed-by: Robert Haas, Michael Paquier, Matthias van de MeentDiscussion:https://postgr.es/m/CACX%2BKaP3i%2Bi9tdPLjF5JCHVv93xobEdcd_eB%2B638VDvZ3i%3DcQA%40mail.gmail.comBackpatch-through: 12
1 parentb0c3061 commit05036a3

File tree

6 files changed

+61
-2
lines changed

6 files changed

+61
-2
lines changed

‎contrib/pageinspect/expected/page.out

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,3 +239,12 @@ SELECT page_checksum(decode(repeat('00', :block_size), 'hex'), 1);
239239

240240
(1 row)
241241

242+
-- tests for sequences
243+
create temporary sequence test_sequence;
244+
select tuple_data_split('test_sequence'::regclass, t_data, t_infomask, t_infomask2, t_bits)
245+
from heap_page_items(get_raw_page('test_sequence', 0));
246+
tuple_data_split
247+
-------------------------------------------------------
248+
{"\\x0100000000000000","\\x0000000000000000","\\x00"}
249+
(1 row)
250+

‎contrib/pageinspect/heapfuncs.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,11 @@ tuple_data_split_internal(Oid relid, char *tupdata,
320320
raw_attrs=initArrayResult(BYTEAOID,CurrentMemoryContext, false);
321321
nattrs=tupdesc->natts;
322322

323-
if (rel->rd_rel->relam!=HEAP_TABLE_AM_OID)
323+
/*
324+
* Sequences always use heap AM, but they don't show that in the catalogs.
325+
*/
326+
if (rel->rd_rel->relkind!=RELKIND_SEQUENCE&&
327+
rel->rd_rel->relam!=HEAP_TABLE_AM_OID)
324328
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
325329
errmsg("only heap AM is supported")));
326330

‎contrib/pageinspect/sql/page.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,8 @@ SHOW block_size \gset
9898
SELECT fsm_page_contents(decode(repeat('00', :block_size),'hex'));
9999
SELECT page_header(decode(repeat('00', :block_size),'hex'));
100100
SELECT page_checksum(decode(repeat('00', :block_size),'hex'),1);
101+
102+
-- tests for sequences
103+
create temporary sequence test_sequence;
104+
select tuple_data_split('test_sequence'::regclass, t_data, t_infomask, t_infomask2, t_bits)
105+
from heap_page_items(get_raw_page('test_sequence',0));

‎contrib/pgstattuple/expected/pgstattuple.out

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,31 @@ select pgstathashindex('test_partition_hash_idx');
273273
(4,8,0,1,0,0,0,100)
274274
(1 row)
275275

276+
-- these should work for sequences
277+
create sequence test_sequence;
278+
select count(*) from pgstattuple('test_sequence');
279+
count
280+
-------
281+
1
282+
(1 row)
283+
284+
select pg_relpages('test_sequence');
285+
pg_relpages
286+
-------------
287+
1
288+
(1 row)
289+
290+
-- these should fail for sequences
291+
select pgstatindex('test_sequence');
292+
ERROR: relation "test_sequence" is not a btree index
293+
select pgstatginindex('test_sequence');
294+
ERROR: relation "test_sequence" is not a GIN index
295+
select pgstathashindex('test_sequence');
296+
ERROR: relation "test_sequence" is not a hash index
297+
select pgstattuple_approx('test_sequence');
298+
ERROR: relation "test_sequence" is of wrong relation kind
299+
DETAIL: This operation is not supported for sequences.
300+
drop sequence test_sequence;
276301
drop table test_partitioned;
277302
drop view test_view;
278303
drop foreign table test_foreign_table;

‎contrib/pgstattuple/pgstattuple.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,11 @@ pgstat_heap(Relation rel, FunctionCallInfo fcinfo)
323323
pgstattuple_typestat= {0};
324324
SnapshotDataSnapshotDirty;
325325

326-
if (rel->rd_rel->relam!=HEAP_TABLE_AM_OID)
326+
/*
327+
* Sequences always use heap AM, but they don't show that in the catalogs.
328+
*/
329+
if (rel->rd_rel->relkind!=RELKIND_SEQUENCE&&
330+
rel->rd_rel->relam!=HEAP_TABLE_AM_OID)
327331
ereport(ERROR,
328332
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
329333
errmsg("only heap AM is supported")));

‎contrib/pgstattuple/sql/pgstattuple.sql

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,18 @@ create index test_partition_hash_idx on test_partition using hash (a);
119119
select pgstatindex('test_partition_idx');
120120
select pgstathashindex('test_partition_hash_idx');
121121

122+
-- these should work for sequences
123+
createsequencetest_sequence;
124+
selectcount(*)from pgstattuple('test_sequence');
125+
select pg_relpages('test_sequence');
126+
127+
-- these should fail for sequences
128+
select pgstatindex('test_sequence');
129+
select pgstatginindex('test_sequence');
130+
select pgstathashindex('test_sequence');
131+
select pgstattuple_approx('test_sequence');
132+
133+
dropsequence test_sequence;
122134
droptable test_partitioned;
123135
dropview test_view;
124136
drop foreign table test_foreign_table;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp