[prev] 47 [next]

Insertion in Heaps (cont)

PostgreSQL's tuple insertion:

heap_insert(Relation relation,    // relation desc
            HeapTuple newtup,     // new tuple data
            CommandId cid, ...)   // SQL statement

  • finds page which has enough free space for newtup
  • ensures page loaded into buffer pool and locked
  • copies tuple data into page buffer, sets xmin, etc.
  • marks buffer as dirty
  • writes details of insertion into transaction log
  • returns OID of new tuple if relation has OIDs