Lists: | pgsql-hackers |
---|
From: | Zdenek Kotala <Zdenek(dot)Kotala(at)Sun(dot)COM> |
---|---|
To: | PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
Subject: | race condition in pgplsql call handler? |
Date: | 2007-05-11 08:23:05 |
Message-ID: | 464427E9.6030101@sun.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
I'm looking into PG/PLSql code and following code in
plpgsql_call_handler looks strange:
/* Find or compile the function */
func = plpgsql_compile(fcinfo, false);
/* Mark the function as busy, so it can't be deleted from under
us */
func->use_count++;
I don't have deep knowledge about this part of code. But what happen if
in parallel execution "func" will be deleted between these two lines?
Zdenek
From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Zdenek Kotala <Zdenek(dot)Kotala(at)Sun(dot)COM> |
Cc: | PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: race condition in pgplsql call handler? |
Date: | 2007-05-11 13:04:19 |
Message-ID: | 17475.1178888659@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
Zdenek Kotala <Zdenek(dot)Kotala(at)Sun(dot)COM> writes:
> I'm looking into PG/PLSql code and following code in
> plpgsql_call_handler looks strange:
> /* Find or compile the function */
> func = plpgsql_compile(fcinfo, false);
> /* Mark the function as busy, so it can't be deleted from under
> us */
> func->use_count++;
> I don't have deep knowledge about this part of code. But what happen if
> in parallel execution "func" will be deleted between these two lines?
This is not a race condition because the backend is single-threaded.
(Hint: what it actually means by "function" is "the plpgsql function
cache entry I just found or built".)
regards, tom lane
From: | Zdenek Kotala <Zdenek(dot)Kotala(at)Sun(dot)COM> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: race condition in pgplsql call handler? |
Date: | 2007-05-11 13:39:50 |
Message-ID: | 46447226.1020401@sun.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
Tom Lane wrote:
> Zdenek Kotala <Zdenek(dot)Kotala(at)Sun(dot)COM> writes:
>> I'm looking into PG/PLSql code and following code in
>> plpgsql_call_handler looks strange:
>
>> /* Find or compile the function */
>> func = plpgsql_compile(fcinfo, false);
>
>> /* Mark the function as busy, so it can't be deleted from under
>> us */
>> func->use_count++;
>
>
>> I don't have deep knowledge about this part of code. But what happen if
>> in parallel execution "func" will be deleted between these two lines?
>
> This is not a race condition because the backend is single-threaded.
I see. Each backend has own function cache and use_count is for handle
recursion usage. Are my assumption correct?
thanks Zdenek
From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Zdenek Kotala <Zdenek(dot)Kotala(at)Sun(dot)COM> |
Cc: | PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: race condition in pgplsql call handler? |
Date: | 2007-05-11 13:51:25 |
Message-ID: | 18626.1178891485@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
Zdenek Kotala <Zdenek(dot)Kotala(at)Sun(dot)COM> writes:
> Tom Lane wrote:
>> This is not a race condition because the backend is single-threaded.
> I see. Each backend has own function cache and use_count is for handle
> recursion usage. Are my assumption correct?
Right. Once a function cache entry is set up, it exists unchanged until
no longer in use, no matter what happens to the underlying pg_proc row.
regards, tom lane