Re: Call flow of btinsert(PG_FUNCTION_ARGS) - Mailing list pgsql-hackers

From Amit Langote
Subject Re: Call flow of btinsert(PG_FUNCTION_ARGS)
Date
Msg-id CA+HiwqEBF-EPB5Tzm4_8kuTW4sV=YY_v4ZciV0DTGgp8Q6LshA@mail.gmail.com
Whole thread Raw
In response to Re: Call flow of btinsert(PG_FUNCTION_ARGS)  (Rohit Goyal <rhtgyl.87@gmail.com>)
List pgsql-hackers
On Tue, Nov 19, 2013 at 7:31 PM, Rohit Goyal <rhtgyl.87@gmail.com> wrote:
>
>
>
> On Tue, Nov 19, 2013 at 11:26 AM, Peter Geoghegan <pg@heroku.com> wrote:
>>
>> On Tue, Nov 19, 2013 at 2:22 AM, Rohit Goyal <rhtgyl.87@gmail.com> wrote:
>> >
>> > I was reading b tree index code and I wanted to the know the calling
>> > function which calls btinsert(PG_FUNCTION_ARGS) function in nbtree.c
>> > file.
>> > Moreover, my goal behind reading this function was to check how tuple is
>> > inserted in btree.
>> > I want to understand the code flow for b tree index
>>
>> Take a look at this:
>>
>> http://www.postgresql.org/docs/9.3/static/index-functions.html
>>
>>
>> --
>> Peter Geoghegan
>
> thanks for reply. :) Moreover, I am so confused about reading the nbtree
> folder c files or the file which you gave.
>
> For example, If I want to read how the data is inserted in B tree index.
> Should I read your link or the btinsert(PG_FUNCTION_ARGS) in nbtree.c file
> in nbtree folder.
>
> In future, if i want to modify btree indexing approach, then which files to
> look for.?

You could use gdb to debug a simple INSERT.

Take a look at the following also:

[http://www.postgresql.org/docs/devel/static/catalog-pg-am.html]

"The catalog pg_am stores information about index access methods.
There is one row for each index access method supported by the
system."


For example,

postgres=# \x
Expanded display (expanded) is on.
postgres=# select * from pg_am;
-[ RECORD 1 ]---+------------------
amname          | btree
amstrategies    | 5
amsupport       | 2
amcanorder      | t
amcanorderbyop  | f
amcanbackward   | t
amcanunique     | t
amcanmulticol   | t
amoptionalkey   | t
amsearcharray   | t
amsearchnulls   | t
amstorage       | f
amclusterable   | t
ampredlocks     | t
amkeytype       | 0
aminsert        | btinsert
ambeginscan     | btbeginscan
amgettuple      | btgettuple
amgetbitmap     | btgetbitmap
amrescan        | btrescan
amendscan       | btendscan
ammarkpos       | btmarkpos
amrestrpos      | btrestrpos
ambuild         | btbuild
ambuildempty    | btbuildempty
ambulkdelete    | btbulkdelete
amvacuumcleanup | btvacuumcleanup
amcanreturn     | btcanreturn
amcostestimate  | btcostestimate
amoptions       | btoptions
...
...

Likewise you could find access method (am) details for other index types.

So, if you want to study the flow for a btree insert you could set a
gdb breakpoint in btinsert (listed as 'aminsert' for btree above) to
begin with.

--
Amit



pgsql-hackers by date:

Previous
From: David Rowley
Date:
Subject: Re: CLUSTER FREEZE
Next
From: Craig Ringer
Date:
Subject: Re: Call flow of btinsert(PG_FUNCTION_ARGS)