File: ddl-system-columns.html

package info (click to toggle)
pgadmin3 1.4.3-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 29,796 kB
  • ctags: 10,758
  • sloc: cpp: 55,356; sh: 6,164; ansic: 1,520; makefile: 576; sql: 482; xml: 100; perl: 18
file content (132 lines) | stat: -rw-r--r-- 7,115 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>5.4.System Columns</title>
<link rel="stylesheet" href="stylesheet.css" type="text/css">
<link rev="made" href="pgsql-docs@postgresql.org">
<meta name="generator" content="DocBook XSL Stylesheets V1.70.0">
<link rel="start" href="index.html" title="PostgreSQL 8.1.4 Documentation">
<link rel="up" href="ddl.html" title="Chapter5.Data Definition">
<link rel="prev" href="ddl-constraints.html" title="5.3.Constraints">
<link rel="next" href="ddl-alter.html" title="5.5.Modifying Tables">
<link rel="copyright" href="ln-legalnotice.html" title="Legal Notice">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="sect1" lang="en">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="ddl-system-columns"></a>5.4.System Columns</h2></div></div></div>
<p>   Every table has several <em class="firstterm">system columns</em> that are
   implicitly defined by the system.  Therefore, these names cannot be
   used as names of user-defined columns.  (Note that these
   restrictions are separate from whether the name is a key word or
   not; quoting a name will not allow you to escape these
   restrictions.)  You do not really need to be concerned about these
   columns, just know they exist.
  </p>
<a name="id575741"></a><div class="variablelist"><dl>
<dt><span class="term"><code class="structfield">oid</code></span></dt>
<dd><p>      <a name="id575759"></a>
      The object identifier (object ID) of a row. This column is only
      present if the table was created using <code class="literal">WITH
      OIDS</code>, or if the <a href="runtime-config-compatible.html#guc-default-with-oids">default_with_oids</a>
      configuration variable was set. This column is of type
      <code class="type">oid</code> (same name as the column); see <a href="datatype-oid.html" title="8.12.Object Identifier Types">Section8.12, &#8220;Object Identifier Types&#8221;</a> for more information about the type.
     </p></dd>
<dt><span class="term"><code class="structfield">tableoid</code></span></dt>
<dd>
<a name="id575807"></a><p>      The OID of the table containing this row.  This column is
      particularly handy for queries that select from inheritance
      hierarchies (see <a href="ddl-inherit.html" title="5.8.Inheritance">Section5.8, &#8220;Inheritance&#8221;</a>), since without it,
      it's difficult to tell which individual table a row came from.  The
      <code class="structfield">tableoid</code> can be joined against the
      <code class="structfield">oid</code> column of
      <code class="structname">pg_class</code> to obtain the table name.
     </p>
</dd>
<dt><span class="term"><code class="structfield">xmin</code></span></dt>
<dd>
<a name="id575846"></a><p>      The identity (transaction ID) of the inserting transaction for
      this row version.  (A row version is an individual state of a
      row; each update of a row creates a new row version for the same
      logical row.)
     </p>
</dd>
<dt><span class="term"><code class="structfield">cmin</code></span></dt>
<dd>
<a name="id575865"></a><p>      The command identifier (starting at zero) within the inserting
      transaction.
     </p>
</dd>
<dt><span class="term"><code class="structfield">xmax</code></span></dt>
<dd>
<a name="id575882"></a><p>      The identity (transaction ID) of the deleting transaction, or
      zero for an undeleted row version.  It is possible for this column to
      be nonzero in a visible row version. That usually indicates that the
      deleting transaction hasn't committed yet, or that an attempted
      deletion was rolled back.
     </p>
</dd>
<dt><span class="term"><code class="structfield">cmax</code></span></dt>
<dd>
<a name="id575903"></a><p>      The command identifier within the deleting transaction, or zero.
     </p>
</dd>
<dt><span class="term"><code class="structfield">ctid</code></span></dt>
<dd>
<a name="id575919"></a><p>      The physical location of the row version within its table.  Note that
      although the <code class="structfield">ctid</code> can be used to
      locate the row version very quickly, a row's
      <code class="structfield">ctid</code> will change each time it is
      updated or moved by <code class="command">VACUUM FULL</code>.  Therefore
      <code class="structfield">ctid</code> is useless as a long-term row
      identifier.  The OID, or even better a user-defined serial
      number, should be used to identify logical rows.
     </p>
</dd>
</dl></div>
<p>    OIDs are 32-bit quantities and are assigned from a single
    cluster-wide counter.  In a large or long-lived database, it is
    possible for the counter to wrap around.  Hence, it is bad
    practice to assume that OIDs are unique, unless you take steps to
    ensure that this is the case.  If you need to identify the rows in
    a table, using a sequence generator is strongly recommended.
    However, OIDs can be used as well, provided that a few additional
    precautions are taken:

    </p>
<div class="itemizedlist"><ul type="disc">
<li><p>       A unique constraint should be created on the OID column of each
       table for which the OID will be used to identify rows.  When such
       a unique constraint (or unique index) exists, the system takes
       care not to generate an OID matching an already-existing row.
       (Of course, this is only possible if the table contains fewer
       than 2<sup>32</sup> (4 billion) rows, and in practice the
       table size had better be much less than that, or performance
       may suffer.)
      </p></li>
<li><p>       OIDs should never be assumed to be unique across tables; use
       the combination of <code class="structfield">tableoid</code> and row OID if you
       need a database-wide identifier.
      </p></li>
<li><p>       The tables in question should be created using <code class="literal">WITH
       OIDS</code>.  As of <span class="productname">PostgreSQL</span> 8.1,
       <code class="literal">WITHOUT OIDS</code> is the default.
      </p></li>
</ul></div>
<p>
   </p>
<p>    Transaction identifiers are also 32-bit quantities.  In a
    long-lived database it is possible for transaction IDs to wrap
    around.  This is not a fatal problem given appropriate maintenance
    procedures; see <a href="maintenance.html" title="Chapter22.Routine Database Maintenance Tasks">Chapter22, <i>Routine Database Maintenance Tasks</i></a> for details.  It is
    unwise, however, to depend on the uniqueness of transaction IDs
    over the long term (more than one billion transactions).
   </p>
<p>    Command
    identifiers are also 32-bit quantities.  This creates a hard limit
    of 2<sup>32</sup> (4 billion) <acronym class="acronym">SQL</acronym> commands
    within a single transaction.  In practice this limit is not a
    problem [mdash ] note that the limit is on number of
    <acronym class="acronym">SQL</acronym> commands, not number of rows processed.
   </p>
</div></body>
</html>