Howto add a field to each postgresql tuple

From: "Maurice Gittens" <mgittens(at)gits(dot)nl>
To: "PostgreSQL-development" <hackers(at)postgreSQL(dot)org>
Subject: Howto add a field to each postgresql tuple
Date: 1998-02-27 08:57:11
Message-ID: 001801bd435d$b1537c60$fcf3b2c2@caleb..gits.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Ok,

As part of my "learning postgresql project" I've been hacking yesterday
and I've found out how to add a system attribute to each tuple in
postgresql.

I added a system attribute which maintains the relation between the
oid of a heaptuple and the oid of the relation to which the tuple
belongs.

In OO speak each instance now knows to which class it belongs.
(Like runtime type idenfication in C++ and other languages).

The operation required the following changes.

* in htup.h
- add the new attribute to the HeapTupleData structure. Remember to
add a symbolic constant with the index of the system attribute.
also remember to Adjust the FirstLowInvalidHeapAttribute constant
accordingly.

* in heaptuple.c
- add offsetof new fields to the heap_sysoffset table
- update the functions heap_attisnull, heap_sysattrlen, heap_sysattrbyval,
heap_getsysattr to support the new system attribute

* in heapam.c
- for example in the function heap_insert initialize the new field.
In my case I want the field to carry the oid of the relation into which
the tuple is being inserted.

* in heap.c
- update the static array of AttributeTupleForms called HeapAtt with
information about the new systemattribute.
Make sure the name of your systemattribute isn't a postgresql
reserve word -:).

* in index.c
- update the static array of FormData_pg_attribute called sysatts with
information about the new systemattribute

After making these modifcations the system passes all regression tests
and seems to give the expected results.
Of course it was tested using inheritance (since this is the only context
in which the functionality offered makes any sense).

Now my next goal is polymorphism.
I want triggers to be more like polymorphic functions in OO languages.
So that the definition of the trigger used only depend on the relation
but also on the context which it is used.
So it more closely follows the semantics of polymorphic methods.

Don't worry I will try to ensure that poeple who don't like OO will not
notice any difference in the semantics of the postgresql system.

Thanks for your patience,
Maurice

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Meskes 1998-02-27 09:48:42 common area
Previous Message Vadim B. Mikheev 1998-02-27 07:30:08 permission issue