Thread: Newbie Developer Question

Newbie Developer Question

From
"Matthew Campbell"
Date:
Hey folks, I have a newbie developer question.  I'm currently taking a course called Database Systems & Implementation at Rochester Institute of Technology and we've split up into groups and are working on extending Postgres to get some experience with a real-world DBMS (as well as the open-source initiative).  My group is working on implementing the UNIQUE functionality in indexes other than the b-tree (which is a TODO item on the postgres website).  We've been digging through the src/backend/access/hash/ and we're having a hard time figuring out the correct way to walk through items in a page.  Is this what the hashbeginscan() method is for?  If so, what should we provide for the keysz and scankey parameters?  backend/access/index/genam.c says these parameters are "key count" and "scan key" respectively, but I'm still sort of lost on what these should be and how we get them (I couldn't find any code that actually called the hashbeginscan() function to use as reference).

Bear with me...I know it's the last thing you all want to hear but I'm more a java developer than a C one, but I'm workin' on it :-D.  Is there some sort of reference equivalent of Javadocs that would show all the files, the functions, the descriptions of the parameters, etc?  As of now, we're just grepping the code to find where else specific functions are used and trying to figure it all out that way.

Thanks so much for the help (now and for the stuff in the future I'm sure I'll be bugging you all about).


-Matt

Re: Newbie Developer Question

From
Tom Lane
Date:
"Matthew Campbell" <mtthw.cmpbll@gmail.com> writes:
> ... We've been digging through the src/backend/access/hash/
> and we're having a hard time figuring out the correct way to walk through
> items in a page.  Is this what the hashbeginscan() method is for?

No, hashbeginscan doesn't do much at all except initialize state.  The
interesting stuff happens during successive hashgettuple calls ---
specifically _hash_first the first time and _hash_next on later calls.

            regards, tom lane

Re: Newbie Developer Question

From
"Matthew Campbell"
Date:
Thanks so much for the help.  _hash_first, and _hash_next all take the scan object as a parameter.  How do you create or get a scan object?  hashbeginscan looks like it sets up a scan and returns it, but it takes the number of keys and the array of scan keys.  Where do we get these arguments from?


-Matt

On 2/1/07, Tom Lane <tgl@sss.pgh.pa.us > wrote:
"Matthew Campbell" < mtthw.cmpbll@gmail.com> writes:
> ... We've been digging through the src/backend/access/hash/
> and we're having a hard time figuring out the correct way to walk through
> items in a page.  Is this what the hashbeginscan() method is for?

No, hashbeginscan doesn't do much at all except initialize state.  The
interesting stuff happens during successive hashgettuple calls ---
specifically _hash_first the first time and _hash_next on later calls.

                        regards, tom lane

Re: Newbie Developer Question

From
Tom Lane
Date:
"Matthew Campbell" <mtthw.cmpbll@gmail.com> writes:
> hashbeginscan looks like it sets up a scan and returns it, but it takes the
> number of keys and the array of scan keys.  Where do we get these arguments
> from?

You should probably go read the btree code for awhile to see how it's
done there.  The btree insertion code manufactures some scan keys from
the index tuple given to be inserted, which is what it uses to locate
the correct insertion point in the index (and, hence, any potential
conflicting entries).  But actually I'm not sure that you care about
that for hash --- all you really need is to know which bucket to look
in, and IIRC the hash insertion code calculates that already without
bothering with making scankeys.

            regards, tom lane