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

Commitca90252

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 parentabed06f commitca90252

File tree

6 files changed

+60
-2
lines changed

6 files changed

+60
-2
lines changed

‎contrib/pageinspect/expected/page.out

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

233233
(1 row)
234234

235+
-- tests for sequences
236+
create temporary sequence test_sequence;
237+
select tuple_data_split('test_sequence'::regclass, t_data, t_infomask, t_infomask2, t_bits)
238+
from heap_page_items(get_raw_page('test_sequence', 0));
239+
tuple_data_split
240+
-------------------------------------------------------
241+
{"\\x0100000000000000","\\x0000000000000000","\\x00"}
242+
(1 row)
243+

‎contrib/pageinspect/heapfuncs.c

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

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

‎contrib/pageinspect/sql/page.sql

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

‎contrib/pgstattuple/expected/pgstattuple.out

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,30 @@ select pgstathashindex('test_partition_hash_idx');
244244
(4,8,0,1,0,0,0,100)
245245
(1 row)
246246

247+
-- these should work for sequences
248+
create sequence test_sequence;
249+
select count(*) from pgstattuple('test_sequence');
250+
count
251+
-------
252+
1
253+
(1 row)
254+
255+
select pg_relpages('test_sequence');
256+
pg_relpages
257+
-------------
258+
1
259+
(1 row)
260+
261+
-- these should fail for sequences
262+
select pgstatindex('test_sequence');
263+
ERROR: relation "test_sequence" is not a btree index
264+
select pgstatginindex('test_sequence');
265+
ERROR: relation "test_sequence" is not a GIN index
266+
select pgstathashindex('test_sequence');
267+
ERROR: relation "test_sequence" is not a hash index
268+
select pgstattuple_approx('test_sequence');
269+
ERROR: "test_sequence" is not a table or materialized view
270+
drop sequence test_sequence;
247271
drop table test_partitioned;
248272
drop view test_view;
249273
drop foreign table test_foreign_table;

‎contrib/pgstattuple/pgstattuple.c

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

338-
if (rel->rd_rel->relam!=HEAP_TABLE_AM_OID)
338+
/*
339+
* Sequences always use heap AM, but they don't show that in the catalogs.
340+
*/
341+
if (rel->rd_rel->relkind!=RELKIND_SEQUENCE&&
342+
rel->rd_rel->relam!=HEAP_TABLE_AM_OID)
339343
ereport(ERROR,
340344
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
341345
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
@@ -114,6 +114,18 @@ create index test_partition_hash_idx on test_partition using hash (a);
114114
select pgstatindex('test_partition_idx');
115115
select pgstathashindex('test_partition_hash_idx');
116116

117+
-- these should work for sequences
118+
createsequencetest_sequence;
119+
selectcount(*)from pgstattuple('test_sequence');
120+
select pg_relpages('test_sequence');
121+
122+
-- these should fail for sequences
123+
select pgstatindex('test_sequence');
124+
select pgstatginindex('test_sequence');
125+
select pgstathashindex('test_sequence');
126+
select pgstattuple_approx('test_sequence');
127+
128+
dropsequence test_sequence;
117129
droptable test_partitioned;
118130
dropview test_view;
119131
drop foreign table test_foreign_table;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp