Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit80c6469

Browse files
committed
Attached is a new patch which addresses this problem. (oids in
regression tests).Chris Bitmead
1 parent6fb9d2e commit80c6469

File tree

12 files changed

+599
-499
lines changed

12 files changed

+599
-499
lines changed

‎doc/src/sgml/inherit.sgml

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/Attic/inherit.sgml,v 1.10 2000/06/22 22:31:15 petere Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/Attic/inherit.sgml,v 1.11 2000/07/02 22:00:23 momjian Exp $
33
-->
44

55
<chapter id="inherit">
@@ -96,6 +96,57 @@ CREATE TABLE capitals UNDER cities (
9696
<command>UPDATE</command> and <command>DELETE</command> --
9797
support this <quote>ONLY</quote> notation.
9898
</para>
99+
100+
<para>
101+
In some cases you may wish to know which table a particular tuple
102+
originated from. There is a system attribute called
103+
<quote>TABLEOID</quote> in each table which can tell you the
104+
originating table:
105+
106+
<programlisting>
107+
SELECT c.tableoid, c.name, c.altitude
108+
FROM cities c
109+
WHERE c.altitude > 500;
110+
</programlisting>
111+
112+
which returns:
113+
114+
<programlisting>
115+
+---------+----------+----------+
116+
|tableoid |name | altitude |
117+
+---------+----------+----------+
118+
|37292 |Las Vegas | 2174 |
119+
+---------+----------+----------+
120+
|37280 |Mariposa | 1953 |
121+
+---------+----------+----------+
122+
|37280 |Madison | 845 |
123+
+---------+----------+----------+
124+
</programlisting>
125+
126+
If you do a join with pg_class you can see the actual table name:
127+
128+
<programlisting>
129+
SELECT p.relname, c.name, c.altitude
130+
FROM cities c, pg_class p
131+
WHERE c.altitude > 500 and c.tableoid = p.oid;
132+
</programlisting>
133+
134+
which returns:
135+
136+
<programlisting>
137+
+---------+----------+----------+
138+
|relname |name | altitude |
139+
+---------+----------+----------+
140+
|capitals |Las Vegas | 2174 |
141+
+---------+----------+----------+
142+
|cities |Mariposa | 1953 |
143+
+---------+----------+----------+
144+
|cities |Madison | 845 |
145+
+---------+----------+----------+
146+
</programlisting>
147+
148+
</para>
149+
99150
<note>
100151
<title>Deprecated</title>
101152
<para>

‎src/backend/access/common/heaptuple.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/access/common/heaptuple.c,v 1.62 2000/04/12 17:14:36 momjian Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/access/common/heaptuple.c,v 1.63 2000/07/02 22:00:24 momjian Exp $
1313
*
1414
* NOTES
1515
* The old interface functions have been converted to macros
@@ -169,6 +169,7 @@ heap_attisnull(HeapTuple tup, int attnum)
169169
else
170170
switch (attnum)
171171
{
172+
caseTableOidAttributeNumber:
172173
caseSelfItemPointerAttributeNumber:
173174
caseObjectIdAttributeNumber:
174175
caseMinTransactionIdAttributeNumber:
@@ -205,6 +206,8 @@ heap_sysattrlen(AttrNumber attno)
205206

206207
switch (attno)
207208
{
209+
caseTableOidAttributeNumber:
210+
returnsizeoff->t_oid;
208211
caseSelfItemPointerAttributeNumber:
209212
returnsizeoff->t_ctid;
210213
caseObjectIdAttributeNumber:
@@ -237,6 +240,9 @@ heap_sysattrbyval(AttrNumber attno)
237240

238241
switch (attno)
239242
{
243+
caseTableOidAttributeNumber:
244+
byval= true;
245+
break;
240246
caseSelfItemPointerAttributeNumber:
241247
byval= false;
242248
break;
@@ -275,7 +281,9 @@ heap_getsysattr(HeapTuple tup, Buffer b, int attnum)
275281
{
276282
switch (attnum)
277283
{
278-
caseSelfItemPointerAttributeNumber:
284+
caseTableOidAttributeNumber:
285+
return (Datum)&tup->t_tableoid;
286+
caseSelfItemPointerAttributeNumber:
279287
return (Datum)&tup->t_ctid;
280288
caseObjectIdAttributeNumber:
281289
return (Datum) (long)tup->t_oid;

‎src/backend/access/heap/heapam.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.73 2000/06/30 16:10:40 petere Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.74 2000/07/02 22:00:27 momjian Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -235,6 +235,8 @@ heapgettup(Relation relation,
235235
intlinesleft;
236236
ItemPointertid= (tuple->t_data==NULL) ?
237237
(ItemPointer)NULL :&(tuple->t_self);
238+
239+
tuple->tableOid=relation->rd_id;
238240

239241
/* ----------------
240242
*increment access statistics
@@ -621,6 +623,7 @@ heap_openr(const char *relationName, LOCKMODE lockmode)
621623

622624
Assert(lockmode >=NoLock&&lockmode<MAX_LOCKMODES);
623625

626+
624627
/* ----------------
625628
*increment access statistics
626629
* ----------------
@@ -1084,6 +1087,7 @@ heap_fetch(Relation relation,
10841087
ItemPointertid=&(tuple->t_self);
10851088
OffsetNumberoffnum;
10861089

1090+
tuple->tableOid=relation->rd_id;
10871091
/* ----------------
10881092
*increment access statistics
10891093
* ----------------
@@ -1178,6 +1182,7 @@ heap_get_latest_tid(Relation relation,
11781182
boolinvalidBlock,
11791183
linkend;
11801184

1185+
tp.tableOid=relation->rd_id;
11811186
/* ----------------
11821187
*get the buffer from the relation descriptor
11831188
*Note that this does a buffer pin.
@@ -1270,6 +1275,7 @@ heap_insert(Relation relation, HeapTuple tup)
12701275
*increment access statistics
12711276
* ----------------
12721277
*/
1278+
tup->tableOid=relation->rd_id;
12731279
IncrHeapAccessStat(local_insert);
12741280
IncrHeapAccessStat(global_insert);
12751281

@@ -1335,6 +1341,7 @@ heap_delete(Relation relation, ItemPointer tid, ItemPointer ctid)
13351341
Bufferbuffer;
13361342
intresult;
13371343

1344+
tp.tableOid=relation->rd_id;
13381345
/* increment access statistics */
13391346
IncrHeapAccessStat(local_delete);
13401347
IncrHeapAccessStat(global_delete);
@@ -1447,6 +1454,7 @@ heap_update(Relation relation, ItemPointer otid, HeapTuple newtup,
14471454
Bufferbuffer;
14481455
intresult;
14491456

1457+
newtup->tableOid=relation->rd_id;
14501458
/* increment access statistics */
14511459
IncrHeapAccessStat(local_replace);
14521460
IncrHeapAccessStat(global_replace);
@@ -1575,6 +1583,7 @@ heap_mark4update(Relation relation, HeapTuple tuple, Buffer *buffer)
15751583
PageHeaderdp;
15761584
intresult;
15771585

1586+
tuple->tableOid=relation->rd_id;
15781587
/* increment access statistics */
15791588
IncrHeapAccessStat(local_mark4update);
15801589
IncrHeapAccessStat(global_mark4update);

‎src/backend/catalog/heap.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.135 2000/07/0204:46:09 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.136 2000/07/0222:00:34 momjian Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -131,12 +131,22 @@ static FormData_pg_attribute a6 = {
131131
MaxCommandIdAttributeNumber,0,-1,-1,'\001','p','\0','i','\0','\0'
132132
};
133133

134-
staticForm_pg_attributeHeapAtt[]= {&a1,&a2,&a3,&a4,&a5,&a6};
134+
/*
135+
We decide to call this attribute "tableoid" rather than say
136+
"classoid" on the basis that in the future there may be more than one
137+
table of a particular class/type. In any case table is still the word
138+
used in SQL.
139+
*/
140+
staticFormData_pg_attributea7= {
141+
0xffffffff, {"tableoid"},OIDOID,0,sizeof(Oid),
142+
TableOidAttributeNumber,0,-1,-1,'\001','p','\0','i','\0','\0'
143+
};
144+
145+
staticForm_pg_attributeHeapAtt[]= {&a1,&a2,&a3,&a4,&a5,&a6,&a7};
135146

136147
/* ----------------------------------------------------------------
137148
*XXX END OF UGLY HARD CODED BADNESS XXX
138-
* ----------------------------------------------------------------
139-
*/
149+
* ---------------------------------------------------------------- */
140150

141151

142152
/* ----------------------------------------------------------------

‎src/backend/parser/parse_relation.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/parser/parse_relation.c,v 1.44 2000/06/20 01:41:21 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/parser/parse_relation.c,v 1.45 2000/07/02 22:00:41 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -57,6 +57,9 @@ static struct
5757
{
5858
"cmax",MaxCommandIdAttributeNumber,CIDOID
5959
},
60+
{
61+
"tableoid",TableOidAttributeNumber,OIDOID
62+
}
6063
};
6164

6265
#defineSPECIALS ((int) (sizeof(special_attr)/sizeof(special_attr[0])))

‎src/backend/utils/cache/lsyscache.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/cache/lsyscache.c,v 1.42 2000/06/08 22:37:30 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/cache/lsyscache.c,v 1.43 2000/07/02 22:00:48 momjian Exp $
1111
*
1212
* NOTES
1313
* Eventually, the index information should go through here, too.
@@ -249,6 +249,8 @@ get_attdisbursion(Oid relid, AttrNumber attnum, double min_estimate)
249249
if (attnum==ObjectIdAttributeNumber||
250250
attnum==SelfItemPointerAttributeNumber)
251251
return1.0 / (double)ntuples;
252+
if (attnum==TableOidAttributeNumber)
253+
return1.0;
252254

253255
/*
254256
* VACUUM ANALYZE has not been run for this table. Produce an estimate

‎src/include/access/heapam.h

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: heapam.h,v 1.54 2000/06/30 16:10:49 petere Exp $
10+
* $Id: heapam.h,v 1.55 2000/07/02 22:01:00 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -165,36 +165,41 @@ fastgetattr(HeapTuple tup, int attnum, TupleDesc tupleDesc,
165165
*
166166
* ----------------
167167
*/
168-
#defineheap_getattr(tup,attnum,tupleDesc,isnull)\
169-
(\
170-
AssertMacro((tup) != NULL &&\
171-
(attnum) > FirstLowInvalidHeapAttributeNumber &&\
172-
(attnum) != 0),\
173-
((attnum) > (int) (tup)->t_data->t_natts) ?\
174-
(\
175-
((isnull) ? (*(isnull) = true) : (dummyret)NULL),\
176-
(Datum)NULL\
177-
)\
178-
:\
179-
(\
180-
((attnum) > 0) ?\
181-
(\
182-
fastgetattr((tup), (attnum), (tupleDesc), (isnull))\
183-
)\
184-
:\
185-
(\
186-
((isnull) ? (*(isnull) = false) : (dummyret)NULL),\
187-
((attnum) == SelfItemPointerAttributeNumber) ?\
188-
(\
189-
(Datum)((char *)&((tup)->t_self))\
190-
)\
191-
:\
192-
(\
193-
(Datum)*(unsigned int *)\
194-
((char *)(tup)->t_data + heap_sysoffset[-(attnum)-1])\
195-
)\
196-
)\
197-
)\
168+
#defineheap_getattr(tup,attnum,tupleDesc,isnull) \
169+
( \
170+
AssertMacro((tup) != NULL && \
171+
(attnum) > FirstLowInvalidHeapAttributeNumber && \
172+
(attnum) != 0), \
173+
((attnum) > (int) (tup)->t_data->t_natts) ? \
174+
( \
175+
((isnull) ? (*(isnull) = true) : (dummyret)NULL), \
176+
(Datum)NULL \
177+
) \
178+
: \
179+
( \
180+
((attnum) > 0) ? \
181+
( \
182+
fastgetattr((tup), (attnum), (tupleDesc), (isnull)) \
183+
) \
184+
: \
185+
( \
186+
((isnull) ? (*(isnull) = false) : (dummyret)NULL), \
187+
((attnum) == SelfItemPointerAttributeNumber) ? \
188+
( \
189+
(Datum)((char *)&((tup)->t_self)) \
190+
) \
191+
: \
192+
(((attnum) == TableOidAttributeNumber) ? \
193+
( \
194+
(Datum)((tup)->tableOid) \
195+
) \
196+
: \
197+
( \
198+
(Datum)*(unsigned int *) \
199+
((char *)(tup)->t_data + heap_sysoffset[-(attnum)-1]) \
200+
)) \
201+
) \
202+
) \
198203
)
199204

200205
externHeapAccessStatisticsheap_access_stats;/* in stats.c */

‎src/include/access/htup.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: htup.h,v 1.30 2000/06/0210:20:26 vadim Exp $
10+
* $Id: htup.h,v 1.31 2000/07/0222:01:00 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -133,7 +133,8 @@ typedef struct xl_heap_move
133133
#defineMinCommandIdAttributeNumber(-4)
134134
#defineMaxTransactionIdAttributeNumber(-5)
135135
#defineMaxCommandIdAttributeNumber(-6)
136-
#defineFirstLowInvalidHeapAttributeNumber(-7)
136+
#defineTableOidAttributeNumber (-7)
137+
#defineFirstLowInvalidHeapAttributeNumber(-8)
137138

138139
/* If you make any changes above, the order off offsets in this must change */
139140
externlongheap_sysoffset[];
@@ -156,6 +157,7 @@ typedef struct HeapTupleData
156157
{
157158
uint32t_len;/* length of *t_data */
158159
ItemPointerDatat_self;/* SelfItemPointer */
160+
OidtableOid;/* */
159161
MemoryContextt_datamcxt;/* */
160162
HeapTupleHeadert_data;/* */
161163
}HeapTupleData;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp