Re: Which data structures for the index?

From: Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com>
To: Vaibhav Kaushal <vaibhavkaushal123(at)gmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Which data structures for the index?
Date: 2010-11-18 13:40:30
Message-ID: 4CE52CCE.40009@enterprisedb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 18.11.2010 15:19, Vaibhav Kaushal wrote:
> I have a small problem: Suppose that I have a table in PostgreSQL which has
> a integer field as its Primary key and I have used the Hash indexing method
> for creating the index for the field on the table. Now I want to know the
> following details about the index (assuming the machine running PostgreSQL
> is a Linux box with DB installed at /var/lib/pgsql/data):
>
> * Which file would contain the index table data? (OR how to find them? Will
> I find them in the CATALOG tables?)

SELECT relfilenode FROM pg_class WHERE relname='index name'. The index
data is stored in a file with that name. Something like
/var/lib/pgsql/data/base/11910/<relfilenode from that query>

> * Is there some documentation available about the source apart from that on
> the website and the the one which gets compiled with the source? (specially
> about the conversions and the steps of conversion of the data from they raw
> disc reads to the structured layout in the memory just before the executor
> is started)

The source and the README files in the source tree are your best help.
And the comments in the header files are very helpful too.

> * Which file in the source tree is responsible for the scan of the index?
> (The main file in case there are two of them for the btree and hash indexes
> separately)

src/backend/access/nbtree/nbtree.c, btgettuple function
and
src/backend/access/hash/hash.c, hashgettuple function

src/backend/access/index/indexam.c is the common entry point for all
index types.

> * Which data structures are the most important ones in index scanning? (I
> will search them myself but please someone tell me the structures; there are
> just too many of them :( )

Depends on what you're interested in. IndexScanDesc is common between
all index scans, Understanding the page structure might also be helpful,
see src/include/storage/bufpage.h.

> * Are the pages of the DB file layout of the index table in someway
> different than what is discussed at
> http://www.postgresql.org/docs/9.0/interactive/storage-file-layout.html ? If
> yes then what are the differences?

No, that applies to indexes too.

> And I must say that while browsing the source, I was so pleased to read the
> comments (they really helped a lot). Thanks to the PostgreSQL coding
> conventions and of course the contributors. I am a bit clear about the
> working of the executor (thanks to ECLIPSE for support of ctags and a nice
> UI) but I am still much in a mess.
>
> Thanks in advance for the answer ;)

Good luck!

--
Heikki Linnakangas
EnterpriseDB http://www.enterprisedb.com

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Pavel Stehule 2010-11-18 13:43:22 Re: final patch - plpgsql: for-in-array
Previous Message Vaibhav Kaushal 2010-11-18 13:19:08 Which data structures for the index?