Re: The number of bytes is stored in index_size of pgstatindex() ?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: 大塚憲司 <otsuka(dot)kenji(at)nttcom(dot)co(dot)jp>
Cc: pgsql-docs(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org
Subject: Re: The number of bytes is stored in index_size of pgstatindex() ?
Date: 2016-02-18 17:40:48
Message-ID: 31925.1455817248@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs pgsql-hackers

=?UTF-8?B?5aSn5aGa5oay5Y+4?= <otsuka(dot)kenji(at)nttcom(dot)co(dot)jp> writes:
> It seems that description of index_size that is returned by pgstatindex() is wrong.
> The document says "Total number of pages in index".
> But it looks like the number of bytes is stored in index_size.

Hmm, you're right, because what the code does is

values[j++] = psprintf(INT64_FORMAT,
(indexStat.root_pages +
indexStat.leaf_pages +
indexStat.internal_pages +
indexStat.deleted_pages +
indexStat.empty_pages) * BLCKSZ);

so the result is clearly measured in bytes not pages.

I was going to just change the docs to say "Total index size in bytes",
but then I noticed that this number is not that either: it does not
count the metapage and therefore is BLCKSZ less than the true file
size. As an example:

regression=# select * from pgstatindex('tenk1_unique1');
version | tree_level | index_size | root_block_no | internal_pages | leaf_pages
| empty_pages | deleted_pages | avg_leaf_density | leaf_fragmentation
---------+------------+------------+---------------+----------------+-----------
-+-------------+---------------+------------------+--------------------
2 | 1 | 237568 | 3 | 0 | 28
| 0 | 0 | 87.91 | 0
(1 row)

regression=# select relfilenode from pg_class where relname = 'tenk1_unique1';
relfilenode
-------------
27449
(1 row)

$ ls -l 27449
-rw-------. 1 postgres postgres 245760 Feb 17 18:58 27449

I think this is a bug and we ought to fix the code to include the
metapage in the reported index_size. Thoughts?

regards, tom lane

In response to

Responses

Browse pgsql-docs by date

  From Date Subject
Next Message Peter Geoghegan 2016-02-18 17:50:20 Re: [HACKERS] The number of bytes is stored in index_size of pgstatindex() ?
Previous Message 大塚憲司 2016-02-18 12:02:15 The number of bytes is stored in index_size of pgstatindex() ?

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Geoghegan 2016-02-18 17:50:20 Re: [HACKERS] The number of bytes is stored in index_size of pgstatindex() ?
Previous Message Kevin Wooten 2016-02-18 17:33:13 Re: JDBC behaviour