Обсуждение: PG function call

Поиск
Список
Период
Сортировка

PG function call

От
"smile khmer"
Дата:
Dear all,

Does anyone know how index searching work in PG. I've explored the
source code of PG, for btree, for searching, it will call the
functions in file btcompare.c. As I've made a printf in the functions
of the file btcompare.c. When I compile and run PG, it get into
loop,..... the messages are printed and printed .....
I want to know how the function called happen in Postgres,
it seems that it doesn't call the function directly !

I would appreciate your help
regards,

Smile


--
___________________________________________________________
Sign-up for Ads Free at Mail.com
http://promo.mail.com/adsfreejump.htm



Re: PG function call

От
Alvaro Herrera
Дата:
On Thu, Oct 06, 2005 at 09:06:59AM -0500, smile khmer wrote:
> Dear all,
> 
> Does anyone know how index searching work in PG. I've explored the 
> source code of PG, for btree, for searching, it will call the 
> functions in file btcompare.c. As I've made a printf in the functions 
> of the file btcompare.c. When I compile and run PG, it get into 
> loop,..... the messages are printed and printed .....

Not a loop -- the function may just be called a lot of times.

> I want to know how the function called happen in Postgres, 
> it seems that it doesn't call the function directly ! 

The code gets function pointers through the catalogs, so they will be
called even if you don't see a direct function call.  At some time the
code will ask for the equality function for such-and-such datatype, then
call it.

-- 
Alvaro Herrera                 http://www.amazon.com/gp/registry/CTMLCN8V17R4
"Acepta los honores y aplausos y perderás tu libertad"


How PG_FUNCTION_ARG works in PG

От
sandeep satpal
Дата:
Hi all,

Whenever a function get called it receive one parameter 
as
PG_FUNCTION_ARG ( as in nbtcompare.c )
I am not getting how it is interpreted and how it is used ??

thank u



-- 
------------------
| Sandeep Satpal |
| M.Tech Student |
| Lab 212 KReSIT |
------------------


Re: How PG_FUNCTION_ARG works in PG

От
Tom Lane
Дата:
sandeep satpal <sandeep@it.iitb.ac.in> writes:
> Whenever a function get called it receive one parameter 
> as
> PG_FUNCTION_ARG ( as in nbtcompare.c )
> I am not getting how it is interpreted and how it is used ??

It's a pointer to a struct containing the actual arguments.
You might find it helpful to read src/backend/utils/fmgr/README
which is old but still accurate.
        regards, tom lane


Re: PG function call

От
"smile khmer"
Дата:
----- Original Message -----
From: "Alvaro Herrera" <alvherre@alvh.no-ip.org>
To: "smile khmer" <khmersmile@email.com>
Subject: Re: [HACKERS] PG function call
Date: Thu, 6 Oct 2005 10:30:37 -0400

>
> On Thu, Oct 06, 2005 at 09:06:59AM -0500, smile khmer wrote:
> > Dear all,
> >
> > Does anyone know how index searching work in PG. I've explored
> > the source code of PG, for btree, for searching, it will call the
> > functions in file btcompare.c. As I've made a printf in the
> > functions of the file btcompare.c. When I compile and run PG, it
> > get into loop,..... the messages are printed and printed .....
>
> Not a loop -- the function may just be called a lot of times.

but when I write the output to file (not standard out put), it won't finish, so I interupted and
there're more than 50.000 lines,...
and during the compiling process, there's alot of messages like these :
.............................
tsort: -: input contains a loop:
tsort: fe-misc.o
tsort: fe-exec.o
tsort: -: input contains a loop:
tsort: fe-misc.o
tsort: fe-exec.o
tsort: -: input contains a loop:
tsort: fe-misc.o
tsort: fe-exec.o
...
.....

>
> > I want to know how the function called happen in Postgres, it
> > seems that it doesn't call the function directly !
>
> The code gets function pointers through the catalogs, so they will be
> called even if you don't see a direct function call.  At some time the
> code will ask for the equality function for such-and-such datatype, then
> call it.
>

then, if I want to change somepart of the code or write one function which will tell postgresql to call this function
wheneverIt compares the string or character data type. I've found "citext" project but I still don't understand where
exactlyto modified code. 

thanks,
Moni
> --
> Alvaro Herrera                 http://www.amazon.com/gp/registry/CTMLCN8V17R4
> "Acepta los honores y aplausos y perderás tu libertad"
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Have you searched our list archives?
>
>                 http://archives.postgresql.org

--
___________________________________________________________
Sign-up for Ads Free at Mail.com
http://promo.mail.com/adsfreejump.htm



Re: PG function call

От
Martijn van Oosterhout
Дата:
On Thu, Oct 06, 2005 at 10:01:55AM -0500, smile khmer wrote:
> but when I write the output to file (not standard out put), it won't finish, so I interupted and
> there're more than 50.000 lines,...

What did you expect? PostgreSQL uses indexes for everything from
looking up functions to finding tables, types, operators, etc. The
compare function will be called for eachtime it wants to do a
comparison in the index, which could be many, many times. I had a trace
that called btcompare 79 million times in a single query.

If you want to know how it got there, I suggest you attach a debugger
to the backend, put a breakpoint there and use "bt" to get a backtrace
to see where it came from.

> and during the compiling process, there's alot of messages like these :
> .............................
> tsort: -: input contains a loop:

Ignore that, not relevent.

> then, if I want to change somepart of the code or write one function
> which will tell postgresql to call this function whenever It compares
> the string or character data type. I've found "citext" project but I
> still don't understand where exactly to modified code.

Once you have created the functions and compiled them, you use CREATE
FUNCTION so the backend knows about them...
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.