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

Commitc398300

Browse files
committed
Combine cmin and cmax fields of HeapTupleHeaders into a single field, by
keeping private state in each backend that has inserted and deleted the sametuple during its current top-level transaction. This is sufficient sincethere is no need to be able to determine the cmin/cmax from any othertransaction. This gets us back down to 23-byte headers, removing a penaltypaid in 8.0 to support subtransactions. Patch by Heikki Linnakangas, withminor revisions by moi, following a design hashed out awhile back on thepghackers list.
1 parentacb3416 commitc398300

File tree

21 files changed

+799
-127
lines changed

21 files changed

+799
-127
lines changed

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
*
1818
* IDENTIFICATION
19-
* $PostgreSQL: pgsql/src/backend/access/common/heaptuple.c,v 1.114 2007/01/0922:00:59 momjian Exp $
19+
* $PostgreSQL: pgsql/src/backend/access/common/heaptuple.c,v 1.115 2007/02/0903:35:33 tgl Exp $
2020
*
2121
*-------------------------------------------------------------------------
2222
*/
@@ -582,14 +582,18 @@ heap_getsysattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
582582
caseMinTransactionIdAttributeNumber:
583583
result=TransactionIdGetDatum(HeapTupleHeaderGetXmin(tup->t_data));
584584
break;
585-
caseMinCommandIdAttributeNumber:
586-
result=CommandIdGetDatum(HeapTupleHeaderGetCmin(tup->t_data));
587-
break;
588585
caseMaxTransactionIdAttributeNumber:
589586
result=TransactionIdGetDatum(HeapTupleHeaderGetXmax(tup->t_data));
590587
break;
588+
caseMinCommandIdAttributeNumber:
591589
caseMaxCommandIdAttributeNumber:
592-
result=CommandIdGetDatum(HeapTupleHeaderGetCmax(tup->t_data));
590+
/*
591+
* cmin and cmax are now both aliases for the same field,
592+
* which can in fact also be a combo command id. XXX perhaps we
593+
* should return the "real" cmin or cmax if possible, that is
594+
* if we are inside the originating transaction?
595+
*/
596+
result=CommandIdGetDatum(HeapTupleHeaderGetRawCommandId(tup->t_data));
593597
break;
594598
caseTableOidAttributeNumber:
595599
result=ObjectIdGetDatum(tup->t_tableOid);

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

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.227 2007/02/05 04:22:18 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.228 2007/02/09 03:35:33 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -1407,8 +1407,7 @@ heap_insert(Relation relation, HeapTuple tup, CommandId cid,
14071407
tup->t_data->t_infomask |=HEAP_XMAX_INVALID;
14081408
HeapTupleHeaderSetXmin(tup->t_data,xid);
14091409
HeapTupleHeaderSetCmin(tup->t_data,cid);
1410-
HeapTupleHeaderSetXmax(tup->t_data,0);/* zero out Datum fields */
1411-
HeapTupleHeaderSetCmax(tup->t_data,0);/* for cleanliness */
1410+
HeapTupleHeaderSetXmax(tup->t_data,0);/* for cleanliness */
14121411
tup->t_tableOid=RelationGetRelid(relation);
14131412

14141413
/*
@@ -1585,6 +1584,7 @@ heap_delete(Relation relation, ItemPointer tid,
15851584
PageHeaderdp;
15861585
Bufferbuffer;
15871586
boolhave_tuple_lock= false;
1587+
booliscombo;
15881588

15891589
Assert(ItemPointerIsValid(tid));
15901590

@@ -1724,6 +1724,9 @@ heap_delete(Relation relation, ItemPointer tid,
17241724
returnresult;
17251725
}
17261726

1727+
/* replace cid with a combo cid if necessary */
1728+
HeapTupleHeaderAdjustCmax(tp.t_data,&cid,&iscombo);
1729+
17271730
START_CRIT_SECTION();
17281731

17291732
/* store transaction information of xact deleting the tuple */
@@ -1733,7 +1736,7 @@ heap_delete(Relation relation, ItemPointer tid,
17331736
HEAP_IS_LOCKED |
17341737
HEAP_MOVED);
17351738
HeapTupleHeaderSetXmax(tp.t_data,xid);
1736-
HeapTupleHeaderSetCmax(tp.t_data,cid);
1739+
HeapTupleHeaderSetCmax(tp.t_data,cid,iscombo);
17371740
/* Make sure there is no forward chain link in t_ctid */
17381741
tp.t_data->t_ctid=tp.t_self;
17391742

@@ -1893,6 +1896,7 @@ heap_update(Relation relation, ItemPointer otid, HeapTuple newtup,
18931896
Sizenewtupsize,
18941897
pagefree;
18951898
boolhave_tuple_lock= false;
1899+
booliscombo;
18961900

18971901
Assert(ItemPointerIsValid(otid));
18981902

@@ -2058,8 +2062,13 @@ heap_update(Relation relation, ItemPointer otid, HeapTuple newtup,
20582062
newtup->t_data->t_infomask |= (HEAP_XMAX_INVALID |HEAP_UPDATED);
20592063
HeapTupleHeaderSetXmin(newtup->t_data,xid);
20602064
HeapTupleHeaderSetCmin(newtup->t_data,cid);
2061-
HeapTupleHeaderSetXmax(newtup->t_data,0);/* zero out Datum fields */
2062-
HeapTupleHeaderSetCmax(newtup->t_data,0);/* for cleanliness */
2065+
HeapTupleHeaderSetXmax(newtup->t_data,0);/* for cleanliness */
2066+
2067+
/*
2068+
* Replace cid with a combo cid if necessary. Note that we already put
2069+
* the plain cid into the new tuple.
2070+
*/
2071+
HeapTupleHeaderAdjustCmax(oldtup.t_data,&cid,&iscombo);
20632072

20642073
/*
20652074
* If the toaster needs to be activated, OR if the new tuple will not fit
@@ -2088,7 +2097,7 @@ heap_update(Relation relation, ItemPointer otid, HeapTuple newtup,
20882097
HEAP_IS_LOCKED |
20892098
HEAP_MOVED);
20902099
HeapTupleHeaderSetXmax(oldtup.t_data,xid);
2091-
HeapTupleHeaderSetCmax(oldtup.t_data,cid);
2100+
HeapTupleHeaderSetCmax(oldtup.t_data,cid,iscombo);
20922101
/* temporarily make it look not-updated */
20932102
oldtup.t_data->t_ctid=oldtup.t_self;
20942103
already_marked= true;
@@ -2183,7 +2192,7 @@ heap_update(Relation relation, ItemPointer otid, HeapTuple newtup,
21832192
HEAP_IS_LOCKED |
21842193
HEAP_MOVED);
21852194
HeapTupleHeaderSetXmax(oldtup.t_data,xid);
2186-
HeapTupleHeaderSetCmax(oldtup.t_data,cid);
2195+
HeapTupleHeaderSetCmax(oldtup.t_data,cid,iscombo);
21872196
}
21882197

21892198
/* record address of new tuple in t_ctid of old one */
@@ -2687,12 +2696,11 @@ heap_lock_tuple(Relation relation, HeapTuple tuple, Buffer *buffer,
26872696
/*
26882697
* Store transaction information of xact locking the tuple.
26892698
*
2690-
* Note:our CIDis meaninglessif storing a MultiXactId, but no harm in
2691-
*storing it anyway.
2699+
* Note:Cmaxis meaninglessin this context, so don't set it; this
2700+
*avoids possibly generating a useless combo CID.
26922701
*/
26932702
tuple->t_data->t_infomask=new_infomask;
26942703
HeapTupleHeaderSetXmax(tuple->t_data,xid);
2695-
HeapTupleHeaderSetCmax(tuple->t_data,cid);
26962704
/* Make sure there is no forward chain link in t_ctid */
26972705
tuple->t_data->t_ctid=*tid;
26982706

@@ -3443,7 +3451,7 @@ heap_xlog_delete(XLogRecPtr lsn, XLogRecord *record)
34433451
HEAP_IS_LOCKED |
34443452
HEAP_MOVED);
34453453
HeapTupleHeaderSetXmax(htup,record->xl_xid);
3446-
HeapTupleHeaderSetCmax(htup,FirstCommandId);
3454+
HeapTupleHeaderSetCmax(htup,FirstCommandId, false);
34473455
/* Make sure there is no forward chain link in t_ctid */
34483456
htup->t_ctid=xlrec->target.tid;
34493457
PageSetLSN(page,lsn);
@@ -3608,7 +3616,7 @@ heap_xlog_update(XLogRecPtr lsn, XLogRecord *record, bool move)
36083616
HEAP_IS_LOCKED |
36093617
HEAP_MOVED);
36103618
HeapTupleHeaderSetXmax(htup,record->xl_xid);
3611-
HeapTupleHeaderSetCmax(htup,FirstCommandId);
3619+
HeapTupleHeaderSetCmax(htup,FirstCommandId, false);
36123620
/* Set forward chain link in t_ctid */
36133621
htup->t_ctid=xlrec->newtid;
36143622
}
@@ -3761,7 +3769,7 @@ heap_xlog_lock(XLogRecPtr lsn, XLogRecord *record)
37613769
else
37623770
htup->t_infomask |=HEAP_XMAX_EXCL_LOCK;
37633771
HeapTupleHeaderSetXmax(htup,xlrec->locking_xid);
3764-
HeapTupleHeaderSetCmax(htup,FirstCommandId);
3772+
HeapTupleHeaderSetCmax(htup,FirstCommandId, false);
37653773
/* Make sure there is no forward chain link in t_ctid */
37663774
htup->t_ctid=xlrec->target.tid;
37673775
PageSetLSN(page,lsn);

‎src/backend/access/transam/xact.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.233 2007/02/07 23:11:29 tgl Exp $
13+
* $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.234 2007/02/09 03:35:33 tgl Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -38,11 +38,12 @@
3838
#include"storage/lmgr.h"
3939
#include"storage/procarray.h"
4040
#include"storage/smgr.h"
41+
#include"utils/combocid.h"
4142
#include"utils/flatfiles.h"
43+
#include"utils/guc.h"
4244
#include"utils/inval.h"
4345
#include"utils/memutils.h"
4446
#include"utils/relcache.h"
45-
#include"utils/guc.h"
4647

4748

4849
/*
@@ -1628,6 +1629,7 @@ CommitTransaction(void)
16281629
AtEOXact_Namespace(true);
16291630
/* smgrcommit already done */
16301631
AtEOXact_Files();
1632+
AtEOXact_ComboCid();
16311633
pgstat_clear_snapshot();
16321634
pgstat_count_xact_commit();
16331635
pgstat_report_txn_timestamp(0);
@@ -1845,6 +1847,7 @@ PrepareTransaction(void)
18451847
AtEOXact_Namespace(true);
18461848
/* smgrcommit already done */
18471849
AtEOXact_Files();
1850+
AtEOXact_ComboCid();
18481851
pgstat_clear_snapshot();
18491852

18501853
CurrentResourceOwner=NULL;
@@ -1997,6 +2000,7 @@ AbortTransaction(void)
19972000
AtEOXact_Namespace(false);
19982001
smgrabort();
19992002
AtEOXact_Files();
2003+
AtEOXact_ComboCid();
20002004
pgstat_clear_snapshot();
20012005
pgstat_count_xact_rollback();
20022006
pgstat_report_txn_timestamp(0);

‎src/backend/utils/fmgr/fmgr.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/fmgr/fmgr.c,v 1.103 2007/01/05 22:19:43 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/fmgr/fmgr.c,v 1.104 2007/02/09 03:35:34 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -64,7 +64,7 @@ typedef struct
6464
/* fn_oid is the hash key and so must be first! */
6565
Oidfn_oid;/* OID of an external C function */
6666
TransactionIdfn_xmin;/* for checking up-to-dateness */
67-
CommandIdfn_cmin;
67+
ItemPointerDatafn_tid;
6868
PGFunctionuser_fn;/* the function's address */
6969
constPg_finfo_record*inforec;/* address of its info record */
7070
}CFuncHashTabEntry;
@@ -483,7 +483,7 @@ lookup_C_func(HeapTuple procedureTuple)
483483
if (entry==NULL)
484484
returnNULL;/* no such entry */
485485
if (entry->fn_xmin==HeapTupleHeaderGetXmin(procedureTuple->t_data)&&
486-
entry->fn_cmin==HeapTupleHeaderGetCmin(procedureTuple->t_data))
486+
ItemPointerEquals(&entry->fn_tid,&procedureTuple->t_self))
487487
returnentry;/* OK */
488488
returnNULL;/* entry is out of date */
489489
}
@@ -521,7 +521,7 @@ record_C_func(HeapTuple procedureTuple,
521521
&found);
522522
/* OID is already filled in */
523523
entry->fn_xmin=HeapTupleHeaderGetXmin(procedureTuple->t_data);
524-
entry->fn_cmin=HeapTupleHeaderGetCmin(procedureTuple->t_data);
524+
entry->fn_tid=procedureTuple->t_self;
525525
entry->user_fn=user_fn;
526526
entry->inforec=inforec;
527527
}

‎src/backend/utils/time/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@
44
# Makefile for utils/time
55
#
66
# IDENTIFICATION
7-
# $PostgreSQL: pgsql/src/backend/utils/time/Makefile,v 1.11 2007/01/20 17:16:15 petere Exp $
7+
# $PostgreSQL: pgsql/src/backend/utils/time/Makefile,v 1.12 2007/02/09 03:35:34 tgl Exp $
88
#
99
#-------------------------------------------------------------------------
1010

1111
subdir = src/backend/utils/time
1212
top_builddir = ../../../..
1313
include$(top_builddir)/src/Makefile.global
1414

15-
OBJS = tqual.o
15+
OBJS =combocid.otqual.o
1616

1717
all: SUBSYS.o
1818

1919
SUBSYS.o:$(OBJS)
2020
$(LD)$(LDREL)$(LDOUT) SUBSYS.o$(OBJS)
2121

22-
clean:
22+
clean:
2323
rm -f SUBSYS.o$(OBJS)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp