temp table problem

Lists: pgsql-hackers
From: "Abbas" <abbas(dot)butt(at)enterprisedb(dot)com>
To: <pgsql-hackers(at)postgresql(dot)org>
Subject: temp table problem
Date: 2008-07-17 03:36:39
Message-ID: 1216265799.5509.2.camel@abbas-laptop
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi,
I have come across a problem. When you try to access a temp table
created via SPI_EXEC, you get a table not found error.

SPI_EXEC("CREATE TEMP TABLE my_temp_table(first_name text, last_name
text)", UTILITY);
SPI_EXEC("REVOKE ALL ON TABLE my_temp_table FROM PUBLIC", UTILITY);

The second statement generates a table not found error, although the
first statement was successful.

After initdb the system has no temp namespace to hold
temp objects and hence the search path does not contain
any temp namespace either.
On first call to create a temp table the system first creates
a temp namespace. At this point the system calls recomputeNamespacePath
thinking that it would update search path and include the temp namespace
in it, but that does not happen beccause of override search path stack.
Hence subsquent calls to say insert into the temp table fail.

Any suggestions on how to tackle this problem?

Regards
Abbas
EnterpriseDB http://www.enterprisedb.com


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: abbas(dot)butt(at)enterprisedb(dot)com
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: temp table problem
Date: 2008-07-19 01:11:49
Message-ID: 12153.1216429909@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

"Abbas" <abbas(dot)butt(at)enterprisedb(dot)com> writes:
> I have come across a problem. When you try to access a temp table
> created via SPI_EXEC, you get a table not found error.

> SPI_EXEC("CREATE TEMP TABLE my_temp_table(first_name text, last_name
> text)", UTILITY);
> SPI_EXEC("REVOKE ALL ON TABLE my_temp_table FROM PUBLIC", UTILITY);

> The second statement generates a table not found error, although the
> first statement was successful.

Works for me ...

ret = SPI_execute("CREATE TEMP TABLE my_temp_table(first_name text, last_name text)", false, 0);

if (ret != SPI_OK_UTILITY)
elog(ERROR, "SPI_execute(CREATE) returned %d", ret);

ret = SPI_execute("REVOKE ALL ON TABLE my_temp_table FROM PUBLIC", false, 0);

if (ret != SPI_OK_UTILITY)
elog(ERROR, "SPI_execute(REVOKE) returned %d", ret);

What PG version are you testing? Maybe you need to show a complete
test case, instead of leaving us to guess at details?

regards, tom lane


From: "Robert Haas" <robertmhaas(at)gmail(dot)com>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: abbas(dot)butt(at)enterprisedb(dot)com, pgsql-hackers(at)postgresql(dot)org
Subject: Re: temp table problem
Date: 2008-07-19 02:13:37
Message-ID: 603c8f070807181913s5b28b38kfcba21bb32e24776@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

I can't help suspecting that the two statements in question were run
in different sessions (or at least different transactions?).

...Robert

On Fri, Jul 18, 2008 at 9:11 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> "Abbas" <abbas(dot)butt(at)enterprisedb(dot)com> writes:
>> I have come across a problem. When you try to access a temp table
>> created via SPI_EXEC, you get a table not found error.
>
>> SPI_EXEC("CREATE TEMP TABLE my_temp_table(first_name text, last_name
>> text)", UTILITY);
>> SPI_EXEC("REVOKE ALL ON TABLE my_temp_table FROM PUBLIC", UTILITY);
>
>> The second statement generates a table not found error, although the
>> first statement was successful.
>
> Works for me ...
>
> ret = SPI_execute("CREATE TEMP TABLE my_temp_table(first_name text, last_name text)", false, 0);
>
> if (ret != SPI_OK_UTILITY)
> elog(ERROR, "SPI_execute(CREATE) returned %d", ret);
>
> ret = SPI_execute("REVOKE ALL ON TABLE my_temp_table FROM PUBLIC", false, 0);
>
> if (ret != SPI_OK_UTILITY)
> elog(ERROR, "SPI_execute(REVOKE) returned %d", ret);
>
> What PG version are you testing? Maybe you need to show a complete
> test case, instead of leaving us to guess at details?
>
> regards, tom lane
>
> --
> Sent via pgsql-hackers mailing list (pgsql-hackers(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-hackers
>


From: "Heikki Linnakangas" <heikki(at)enterprisedb(dot)com>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: <abbas(dot)butt(at)enterprisedb(dot)com>, <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: temp table problem
Date: 2008-07-20 15:27:06
Message-ID: 4883594A.9020808@enterprisedb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Tom Lane wrote:
> What PG version are you testing? Maybe you need to show a complete
> test case, instead of leaving us to guess at details?

I think that example is bogus. Let's forget that one, and look at the
attached script.

The underlying problem is that when we do GetOverrideSearchPath() in
CreateCachedPlan, the memorized search path doesn't include pg_temp, if
the temp namespace wasn't initialized for the backend yet. When we later
need to revalidate the plan, pg_temp still isn't searched, even if it
now exists.

(On 8.3 and CVS HEAD)

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

Attachment Content-Type Size
temp-table-invisible.sql text/plain 596 bytes

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Heikki Linnakangas" <heikki(at)enterprisedb(dot)com>
Cc: abbas(dot)butt(at)enterprisedb(dot)com, pgsql-hackers(at)postgresql(dot)org
Subject: Re: temp table problem
Date: 2008-07-20 16:04:37
Message-ID: 29446.1216569877@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

"Heikki Linnakangas" <heikki(at)enterprisedb(dot)com> writes:
> The underlying problem is that when we do GetOverrideSearchPath() in
> CreateCachedPlan, the memorized search path doesn't include pg_temp, if
> the temp namespace wasn't initialized for the backend yet. When we later
> need to revalidate the plan, pg_temp still isn't searched, even if it
> now exists.

So what's the problem? The cached plan couldn't have referred to a temp
table.

regards, tom lane