473,671 Members | 2,384 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Missing OID rant

<rant>

Please can someone explain why Postgres cannot recognize that objects
(referenced by pl/pgsql functions) whose OID no longer exists could in
fact be found (as new objects) if the function was reparsed and compiled
again.

Here's an example:

Create table t1 (f1 integer);
insert into t1 values (1);

CREATE OR REPLACE FUNCTION GetOne() RETURNS integer AS '
DECLARE
i integer;
BEGIN
select f1 into i from t1 limit 1;
return i;
END;
' LANGUAGE 'plpgsql';

select GetOne(); <-- WORKS OK

drop table t1;
Create table t1 (f1 integer);
insert into t1 values (1);

select GetOne(); <-- ERROR: relation with OID xxxxxx does not exist

Now I know why this is happening, but it is really crap.

Here's a solution (similar to what Oracle does (I believe):

Whenever you delete an object, you locate any functions (or other objects)
referencing that object's OID, and you mark them as invalid, and any
subsequent objects that now refer to the newly invalidated object(s).

When a function is invoked which is marked invalid, then it is first
parsed/compiled again - if that is successful then the function executes
as before. If compiling is unsuccessful, then the standard "relation with
OID xxxxxx does not exist" error could be returned (or perhaps an even
better error message detailing the actual name of the missing object, God
forbid!).

Where else would this be useful? How about the following scenario when you
want to make use of a temporary table in a pl/pgsql function:

-- This will not work
....
CREATE TEMP TABLE foo AS SELECT ....;
FOR r IN SELECT * FROM foo
LOOP
.....
END LOOP;
DROP TABLE foo;

-- You have to do this
....
CREATE TEMP TABLE foo AS SELECT ....;
FOR r IN EXECUTE "SELECT * FROM foo"
LOOP
.....
END LOOP;
DROP TABLE foo;
....

This might even make rebuilding databases easier because you could refer
to objects (during the rebuild) that don't yet exist (haven't been
inserted yet), but that would be validated the first time the object was
actually accessed.

There are loads of instances (db in flux, move table to another schema
etc) why you might want/need to drop a table, and recreate it. But in
Postgres, you have to reapply all DDL statements to the db that referenced
that dropped/recreated object - this is just not fun!

I don't know, but cannot believe that it would be hard to implement this,
and although many might not think that it is worth it, it is a really NICE
feature in Oracle. And when you're used to it, it is a royal pain in the
ass not having it.

</rant>

BTW, I still love postgres - I just want it to be better!

John Sidney-Woollett

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddres sHere" to ma*******@postg resql.org)

Nov 23 '05 #1
12 2035
Alvaro Herrera said:
Actually, in your example the only thing you need to do is close the
connection and reconnect. I agree it would be nice to recompile the
function automatically, but it's not as bad as you put it.


Thanks, I wasn't aware of that.

John Sidney-Woollett

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 23 '05 #2
Alvaro Herrera said:
Actually, in your example the only thing you need to do is close the
connection and reconnect. I agree it would be nice to recompile the
function automatically, but it's not as bad as you put it.


Thanks, I wasn't aware of that.

John Sidney-Woollett

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 23 '05 #3
Tom Lane said:
"John Sidney-Woollett" <jo****@wardbro ok.com> writes:
Please can someone explain why Postgres cannot recognize that objects
(referenced by pl/pgsql functions) whose OID no longer exists could in
fact be found (as new objects) if the function was reparsed and compiled
again.


Criticism in the form of a patch would be useful.


I know but I don't have the expertise to do that - I was only trying to
raise the issue... :)
Whenever you delete an object, you locate any functions (or other
objects)
referencing that object's OID, and you mark them as invalid, and any
subsequent objects that now refer to the newly invalidated object(s).


Yup, this is on the TODO list, and has been for awhile:

* Flush cached query plans when their underlying catalog data changes


Is the query plan cached for the life of the session, or the life of the
cache/database/postmaster session?

Isn't removing the plan from the cache, and marking objects invalid two
separate although related issues?
I don't know, but cannot believe that it would be hard to implement
this,


Step right up ...


Believe you me, you don't want my code - it's been quite a few years since
I've done any C programming, a patch I produced might set Postgres back 5
years!!

BTW, I was only highlighting the issue because the missing OID message bit
me in the ass again today, and I didn't realise that it existed as an
outstanding todo item.

I guess that there are other missing features like exception handling and
nested transactions which are more important and need attention more
urgently...

John Sidney-Woollett

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postg resql.org

Nov 23 '05 #4
Tom Lane said:
"John Sidney-Woollett" <jo****@wardbro ok.com> writes:
Please can someone explain why Postgres cannot recognize that objects
(referenced by pl/pgsql functions) whose OID no longer exists could in
fact be found (as new objects) if the function was reparsed and compiled
again.


Criticism in the form of a patch would be useful.


I know but I don't have the expertise to do that - I was only trying to
raise the issue... :)
Whenever you delete an object, you locate any functions (or other
objects)
referencing that object's OID, and you mark them as invalid, and any
subsequent objects that now refer to the newly invalidated object(s).


Yup, this is on the TODO list, and has been for awhile:

* Flush cached query plans when their underlying catalog data changes


Is the query plan cached for the life of the session, or the life of the
cache/database/postmaster session?

Isn't removing the plan from the cache, and marking objects invalid two
separate although related issues?
I don't know, but cannot believe that it would be hard to implement
this,


Step right up ...


Believe you me, you don't want my code - it's been quite a few years since
I've done any C programming, a patch I produced might set Postgres back 5
years!!

BTW, I was only highlighting the issue because the missing OID message bit
me in the ass again today, and I didn't realise that it existed as an
outstanding todo item.

I guess that there are other missing features like exception handling and
nested transactions which are more important and need attention more
urgently...

John Sidney-Woollett

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postg resql.org

Nov 23 '05 #5
On Thu, Apr 22, 2004 at 02:07:39PM +0100, John Sidney-Woollett wrote:
There are loads of instances (db in flux, move table to another schema
etc) why you might want/need to drop a table, and recreate it. But in
Postgres, you have to reapply all DDL statements to the db that referenced
that dropped/recreated object - this is just not fun!


Actually, in your example the only thing you need to do is close the
connection and reconnect. I agree it would be nice to recompile the
function automatically, but it's not as bad as you put it.

--
Alvaro Herrera (<alvherre[a]dcc.uchile.cl>)
"Sallah, I said NO camels! That's FIVE camels; can't you count?"
(Indiana Jones)

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddres sHere" to ma*******@postg resql.org)

Nov 23 '05 #6
On Thu, Apr 22, 2004 at 02:07:39PM +0100, John Sidney-Woollett wrote:
There are loads of instances (db in flux, move table to another schema
etc) why you might want/need to drop a table, and recreate it. But in
Postgres, you have to reapply all DDL statements to the db that referenced
that dropped/recreated object - this is just not fun!


Actually, in your example the only thing you need to do is close the
connection and reconnect. I agree it would be nice to recompile the
function automatically, but it's not as bad as you put it.

--
Alvaro Herrera (<alvherre[a]dcc.uchile.cl>)
"Sallah, I said NO camels! That's FIVE camels; can't you count?"
(Indiana Jones)

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddres sHere" to ma*******@postg resql.org)

Nov 23 '05 #7
"John Sidney-Woollett" <jo****@wardbro ok.com> writes:
Please can someone explain why Postgres cannot recognize that objects
(referenced by pl/pgsql functions) whose OID no longer exists could in
fact be found (as new objects) if the function was reparsed and compiled
again.
Criticism in the form of a patch would be useful.
Whenever you delete an object, you locate any functions (or other objects)
referencing that object's OID, and you mark them as invalid, and any
subsequent objects that now refer to the newly invalidated object(s).
Yup, this is on the TODO list, and has been for awhile:

* Flush cached query plans when their underlying catalog data changes
I don't know, but cannot believe that it would be hard to implement this,


Step right up ...

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddres sHere" to ma*******@postg resql.org)

Nov 23 '05 #8
"John Sidney-Woollett" <jo****@wardbro ok.com> writes:
Please can someone explain why Postgres cannot recognize that objects
(referenced by pl/pgsql functions) whose OID no longer exists could in
fact be found (as new objects) if the function was reparsed and compiled
again.
Criticism in the form of a patch would be useful.
Whenever you delete an object, you locate any functions (or other objects)
referencing that object's OID, and you mark them as invalid, and any
subsequent objects that now refer to the newly invalidated object(s).
Yup, this is on the TODO list, and has been for awhile:

* Flush cached query plans when their underlying catalog data changes
I don't know, but cannot believe that it would be hard to implement this,


Step right up ...

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddres sHere" to ma*******@postg resql.org)

Nov 23 '05 #9
Jan Wieck said:
Exactly, and because of that we want you to do the easy stuff with the
cache invalidation, so that we have the time to think about the others.


Might be easy for you... I shudder when I try to imagine the size of the
mountain that that simple task would represent for me ;)

John Sidney-Woollett

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 23 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
2252
by: Bart Nessux | last post by:
How can one view the contents of a queue? I'd like to verify that the queue has the same number of objects as the list that has been put into it. Also, should one think of a queue as static or dynamic (on the put side)? Do you put stuff in it once and then get from it until it's empty or do you put stuff in it a bit at a time? Or, can you do both? Also, does the queue actually get smaller as the threads feed from it or does it stay the...
0
1184
by: Trevor Best | last post by:
<rant> Spent an hour yesterday figuring that one out in my sp, on an insert statement that used a join for the source. Even rebooted the server in desperation. It wasn't until I took that join and made a view and used that as a source it pointed out the real error, mismatched number of columns between insert into and select statements. D'OH! </rant> -- A)bort, R)etry, I)nfluence with large hammer.
0
431
by: John Sidney-Woollett | last post by:
<rant> Please can someone explain why Postgres cannot recognize that objects (referenced by pl/pgsql functions) whose OID no longer exists could in fact be found (as new objects) if the function was reparsed and compiled again. Here's an example: Create table t1 (f1 integer);
67
7684
by: PC Datasheet | last post by:
Transaction data is given with date ranges: Beginning End 4/1/06 4/4/06 4/7/06 4/11/06 4/14/06 4/17/06 4/18/06 4/21/06 426/06 4/30/06 I am looking for suggestions on how to find the date ranges where there were no transactions.
8
1428
by: Jamie | last post by:
Hello Newsgroup: This is my little rant about security and why we have home directories. You may choose to ignore it or disagree with it, that is your perogative and I won't care, but... this little rant needs to be said in the 21'st century, as we seem to have forgotten about it. Many PHP packages and cgi scripts ask you to store database settings and passwords in web space.
41
3364
by: rick | last post by:
Why can't Python have a reverse() function/method like Ruby? Python: x = 'a_string' # Reverse the string print x Ruby: x = 'a_string' # Reverse the string
0
1060
by: =?Utf-8?B?Z3V5?= | last post by:
<Rant> Why is it so hard to use a GridView? I have spent 2 weeks writing an app and it is fine. I have spent 1 week of this time trying to find out how to either a) set column widths for an autogenerated GridView or b) find the column widths that have been automatically generated. The only thing that is stopping the app going live is the B**dy GridView. It is a really basic thing to want to do, why is it impossible?
60
2436
by: DuncanIdaho | last post by:
Hello This is a rant. If you don't want to read it then don't, simple really. I usually spend my working life buried away in the back ends (fnar) of business systems. Serverside stuff over presentation stuff. I've managed to steer clear of Microsoft stuff for most of my working life, not really by design, it's just the way it turned out. Recently I was given the task of setting up a website from scratch
17
1735
by: Christoph Zwerschke | last post by:
I'm just reading PEP 3107 (function annotations) and wonder why exceptions are not mentioned there. I think it would be helpful if one could specify which exceptions can be raised by a function, similarly to how it is possible in C++ using the "throw" clause. The syntax would be something like this: def foo(a: expr, b: expr = 5) raises expr -expr: The expr in that "raises" clause should be a list of Exceptions.
0
8481
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8400
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8602
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8672
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7441
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6234
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
2
2058
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1814
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.