diff options
Diffstat (limited to '')
-rw-r--r-- | contrib/pageinspect/expected/hash.out | 5 | ||||
-rw-r--r-- | contrib/pageinspect/hashfuncs.c | 6 | ||||
-rw-r--r-- | contrib/pageinspect/sql/hash.sql | 5 |
3 files changed, 14 insertions, 2 deletions
diff --git a/contrib/pageinspect/expected/hash.out b/contrib/pageinspect/expected/hash.out index 5d6a518..ea387a6 100644 --- a/contrib/pageinspect/expected/hash.out +++ b/contrib/pageinspect/expected/hash.out @@ -1,6 +1,8 @@ CREATE TABLE test_hash (a int, b text); INSERT INTO test_hash VALUES (1, 'one'); CREATE INDEX test_hash_a_idx ON test_hash USING hash (a); +CREATE TABLE test_hash_part (a int, b int) PARTITION BY RANGE (a); +CREATE INDEX test_hash_part_idx ON test_hash_part USING hash(b); \x SELECT hash_page_type(get_raw_page('test_hash_a_idx', 0)); -[ RECORD 1 ]--+--------- @@ -44,6 +46,8 @@ SELECT * FROM hash_bitmap_info('test_hash_a_idx', 5); ERROR: invalid overflow block number 5 SELECT * FROM hash_bitmap_info('test_hash_a_idx', 6); ERROR: block number 6 is out of range for relation "test_hash_a_idx" +SELECT * FROM hash_bitmap_info('test_hash_part_idx', 1); -- error +ERROR: "test_hash_part_idx" is not a hash index SELECT magic, version, ntuples, bsize, bmsize, bmshift, maxbucket, highmask, lowmask, ovflpoint, firstfree, nmaps, procid, spares, mapp FROM hash_metapage_info(get_raw_page('test_hash_a_idx', 0)); @@ -203,3 +207,4 @@ SELECT hash_page_type(decode(repeat('00', :block_size), 'hex')); hash_page_type | unused DROP TABLE test_hash; +DROP TABLE test_hash_part; diff --git a/contrib/pageinspect/hashfuncs.c b/contrib/pageinspect/hashfuncs.c index 69af7b9..7c0f73f 100644 --- a/contrib/pageinspect/hashfuncs.c +++ b/contrib/pageinspect/hashfuncs.c @@ -12,6 +12,7 @@ #include "access/hash.h" #include "access/htup_details.h" +#include "access/relation.h" #include "catalog/pg_am.h" #include "catalog/pg_type.h" #include "funcapi.h" @@ -27,6 +28,7 @@ PG_FUNCTION_INFO_V1(hash_page_items); PG_FUNCTION_INFO_V1(hash_bitmap_info); PG_FUNCTION_INFO_V1(hash_metapage_info); +#define IS_INDEX(r) ((r)->rd_rel->relkind == RELKIND_INDEX) #define IS_HASH(r) ((r)->rd_rel->relam == HASH_AM_OID) /* ------------------------------------------------ @@ -417,9 +419,9 @@ hash_bitmap_info(PG_FUNCTION_ARGS) (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), errmsg("must be superuser to use raw page functions"))); - indexRel = index_open(indexRelid, AccessShareLock); + indexRel = relation_open(indexRelid, AccessShareLock); - if (!IS_HASH(indexRel)) + if (!IS_INDEX(indexRel) || !IS_HASH(indexRel)) ereport(ERROR, (errcode(ERRCODE_WRONG_OBJECT_TYPE), errmsg("\"%s\" is not a %s index", diff --git a/contrib/pageinspect/sql/hash.sql b/contrib/pageinspect/sql/hash.sql index 320fb9f..e4b9e97 100644 --- a/contrib/pageinspect/sql/hash.sql +++ b/contrib/pageinspect/sql/hash.sql @@ -2,6 +2,9 @@ CREATE TABLE test_hash (a int, b text); INSERT INTO test_hash VALUES (1, 'one'); CREATE INDEX test_hash_a_idx ON test_hash USING hash (a); +CREATE TABLE test_hash_part (a int, b int) PARTITION BY RANGE (a); +CREATE INDEX test_hash_part_idx ON test_hash_part USING hash(b); + \x SELECT hash_page_type(get_raw_page('test_hash_a_idx', 0)); @@ -21,6 +24,7 @@ SELECT * FROM hash_bitmap_info('test_hash_a_idx', 3); SELECT * FROM hash_bitmap_info('test_hash_a_idx', 4); SELECT * FROM hash_bitmap_info('test_hash_a_idx', 5); SELECT * FROM hash_bitmap_info('test_hash_a_idx', 6); +SELECT * FROM hash_bitmap_info('test_hash_part_idx', 1); -- error SELECT magic, version, ntuples, bsize, bmsize, bmshift, maxbucket, highmask, @@ -106,3 +110,4 @@ SELECT hash_page_stats(decode(repeat('00', :block_size), 'hex')); SELECT hash_page_type(decode(repeat('00', :block_size), 'hex')); DROP TABLE test_hash; +DROP TABLE test_hash_part; |