TEMP table code

From: Bruce Momjian <maillist(at)candle(dot)pha(dot)pa(dot)us>
To: hackers(at)postgreSQL(dot)org (PostgreSQL-development)
Subject: TEMP table code
Date: 1999-01-28 21:38:47
Message-ID: 199901282138.QAA10091@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I am attaching a file containing changes needed for adding temp tables
to the backend code. This is not a complete patch because I am adding
new files and stuff. It is attached just for people to review.

The basic question is whether this is the proper way to do temp tables.
This implementation never adds the table to the system tables like
pg_class and pg_attribute. It does all temp table work by mapping the
user table names to system-generated unique table names using the cache
lookup code. Fortunately because of the mega-patch from August, almost
all system table access is done through the cache. Of course, a table
scan of pg_class will not show the temp table because it is not really
in pg_class, just in the cache, but there does not seem to be many cases
where this is a bad thing.

I still need to run some more tests and add a few more features, but you
get the idea. I hope to apply the patch tomorrow or Saturday.

The only other way I can think of doing temp tables is to actually
insert into the system tables, and have some flag that makes those rows
only visible to the single backend that created it. We would also have
to add a new pg_class column that contained the temp name, and modify
pg_class so it could have duplicate table names as long as the temp name
was unique. This seemed very unmodular, and would add more complexity
to the heap tuple tuple visibility code.

Here is a sample of what it does:

#$ sql test
Welcome to the POSTGRESQL interactive sql monitor:
test=> select * from test;
ERROR: test: Table does not exist.
test=> create temp table test (x int);
CREATE
test=> insert into test values (3);
INSERT 19745 1
test=> \q
#$ sql test
Welcome to the POSTGRESQL interactive sql monitor:
test=> select * from test;
ERROR: test: Table does not exist.
test=>

In this example, I create a non-temp table, then mask that with a temp
table, then destroy them both:

#$ sql test
Welcome to the POSTGRESQL interactive sql monitor:
test=> create table test (x int);
CREATE
test=> create temp table test (x int);
CREATE
test=> create temp table test (x int);
ERROR: test relation already exists
test=> drop table test;
DROP
test=> drop table test;
DROP
test=>

--
Bruce Momjian | http://www.op.net/~candle
maillist(at)candle(dot)pha(dot)pa(dot)us | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026

Attachment Content-Type Size
/tmp/junk/temptable.gz application/x-gzip 12.3 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Goran Thyni 1999-01-28 21:44:33 tough locale bug
Previous Message Tom Lane 1999-01-28 20:04:58 Re: [HACKERS] Bug or feature? COPY ignores column defaults