Skip to content

Commit c4cb617

Browse files
committed
Major patch to speed up backend startup after profiling analysis.
1 parent 281ba3f commit c4cb617

File tree

9 files changed

+122
-198
lines changed

9 files changed

+122
-198
lines changed

src/backend/access/common/heaptuple.c

+14-20
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/common/heaptuple.c,v 1.19 1997/08/19 21:28:49 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/common/heaptuple.c,v 1.20 1997/08/24 23:07:26 momjian Exp $
1212
*
1313
* NOTES
1414
* The old interface functions have been converted to macros
@@ -695,26 +695,20 @@ heap_getattr(HeapTuple tup,
695695
if (attnum > (int) tup->t_natts) {
696696
*isnull = true;
697697
return ((char *) NULL);
698+
} else if (attnum > 0) {
699+
/* ----------------
700+
* take care of user defined attributes
701+
* ----------------
702+
*/
703+
return fastgetattr(tup, attnum, tupleDesc, isnull);
704+
} else {
705+
/* ----------------
706+
* take care of system attributes
707+
* ----------------
708+
*/
709+
*isnull = false;
710+
return heap_getsysattr(tup, b, attnum);
698711
}
699-
700-
/* ----------------
701-
* take care of user defined attributes
702-
* ----------------
703-
*/
704-
if (attnum > 0) {
705-
char *datum;
706-
datum = fastgetattr(tup, attnum, tupleDesc, isnull);
707-
708-
return (datum);
709-
}
710-
711-
/* ----------------
712-
* take care of system attributes
713-
* ----------------
714-
*/
715-
*isnull = false;
716-
return
717-
heap_getsysattr(tup, b, attnum);
718712
}
719713

720714
/* ----------------

src/backend/access/common/heapvalid.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/access/common/Attic/heapvalid.c,v 1.13 1997/03/28 07:03:53 scrappy Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/access/common/Attic/heapvalid.c,v 1.14 1997/08/24 23:07:26 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -22,6 +22,7 @@
2222
#include <utils/rel.h>
2323
#include <utils/tqual.h>
2424
#include <storage/bufmgr.h>
25+
#include <utils/builtins.h>
2526

2627
/* ----------------
2728
* heap_keytest
@@ -53,7 +54,9 @@ heap_keytest(HeapTuple t,
5354
return (false);
5455
}
5556

56-
if (keys->sk_flags & SK_COMMUTE)
57+
if (keys->sk_func == (func_ptr)oideq) /* optimization */
58+
test = (keys->sk_argument == atp);
59+
else if (keys->sk_flags & SK_COMMUTE)
5760
test = (long) FMGR_PTR2(keys->sk_func, keys->sk_procedure,
5861
keys->sk_argument, atp);
5962
else

src/backend/storage/ipc/s_lock.c

+38-86
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/Attic/s_lock.c,v 1.19 1997/08/20 00:50:11 scrappy Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/Attic/s_lock.c,v 1.20 1997/08/24 23:07:28 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -44,12 +44,6 @@
4444

4545
#if defined(HAS_TEST_AND_SET)
4646

47-
# if defined(__alpha__) && defined(linux)
48-
static long int tas(slock_t *lock);
49-
# else
50-
static int tas(slock_t *lock);
51-
#endif
52-
5347
#if defined (nextstep)
5448
/*
5549
* NEXTSTEP (mach)
@@ -167,6 +161,8 @@ S_LOCK_FREE(slock_t *lock)
167161
defined(sparc_solaris)
168162
/* for xxxxx_solaris, this is defined in port/.../tas.s */
169163

164+
static int tas(slock_t *lock);
165+
170166
void
171167
S_LOCK(slock_t *lock)
172168
{
@@ -233,6 +229,8 @@ S_INIT_LOCK(slock_t *lock)
233229
*/
234230
static slock_t clear_lock = { -1, -1, -1, -1 };
235231

232+
static int tas(slock_t *lock);
233+
236234
void
237235
S_LOCK(slock_t *lock)
238236
{
@@ -268,6 +266,8 @@ S_LOCK_FREE(slock_t *lock)
268266

269267
#if defined(sun3)
270268

269+
static int tas(slock_t *lock);
270+
271271
void
272272
S_LOCK(slock_t *lock)
273273
{
@@ -320,6 +320,8 @@ tas_dummy()
320320
#define asm(x) __asm__(x)
321321
#endif
322322

323+
static int tas(slock_t *lock);
324+
323325
static int
324326
tas_dummy()
325327
{
@@ -383,19 +385,14 @@ S_INIT_LOCK(unsigned char *addr)
383385

384386
#if defined(NEED_I386_TAS_ASM)
385387

386-
static int
387-
tas(slock_t *m)
388-
{
389-
slock_t res;
390-
__asm__("xchgb %0,%1":"=q" (res),"=m" (*m):"0" (0x1));
391-
return(res);
392-
}
393-
394388
void
395389
S_LOCK(slock_t *lock)
396390
{
397-
while (tas(lock))
398-
;
391+
slock_t res;
392+
393+
do{
394+
__asm__("xchgb %0,%1":"=q" (res),"=m" (*lock):"0" (0x1));
395+
}while(res != 0);
399396
}
400397

401398
void
@@ -415,31 +412,26 @@ S_INIT_LOCK(slock_t *lock)
415412

416413
#if defined(__alpha__) && defined(linux)
417414

418-
static long int
419-
tas(slock_t *m)
420-
{
421-
slock_t res;
422-
__asm__(" ldq $0, %0 \n\
423-
bne $0, already_set \n\
424-
ldq_l $0, %0 \n\
425-
bne $0, already_set \n\
426-
or $31, 1, $0 \n\
427-
stq_c $0, %0 \n\
428-
beq $0, stqc_fail \n\
429-
success: bis $31, $31, %1 \n\
430-
mb \n\
431-
jmp $31, end \n\
432-
stqc_fail: or $31, 1, $0 \n\
433-
already_set: bis $0, $0, %1 \n\
434-
end: nop " : "=m" (*m), "=r" (res) :: "0" );
435-
return(res);
436-
}
437-
438415
void
439416
S_LOCK(slock_t *lock)
440417
{
441-
while (tas(lock))
442-
;
418+
slock_t res;
419+
420+
do{
421+
__asm__(" ldq $0, %0 \n\
422+
bne $0, already_set \n\
423+
ldq_l $0, %0 \n\
424+
bne $0, already_set \n\
425+
or $31, 1, $0 \n\
426+
stq_c $0, %0 \n\
427+
beq $0, stqc_fail \n\
428+
success: bis $31, $31, %1 \n\
429+
mb \n\
430+
jmp $31, end \n\
431+
stqc_fail: or $31, 1, $0 \n\
432+
already_set: bis $0, $0, %1 \n\
433+
end: nop " : "=m" (*lock), "=r" (res) :: "0" );
434+
}while(res != 0);
443435
}
444436

445437
void
@@ -459,56 +451,16 @@ S_INIT_LOCK(slock_t *lock)
459451

460452
#if defined(linux) && defined(sparc)
461453

462-
static int
463-
tas(slock_t *m)
464-
{
465-
slock_t res;
466-
__asm__("ldstub [%1], %0"
467-
: "=&r" (res)
468-
: "r" (m));
469-
return (res != 0);
470-
}
471-
472454
void
473455
S_LOCK(slock_t *lock)
474456
{
475-
while (tas(lock))
476-
;
477-
}
478-
479-
void
480-
S_UNLOCK(slock_t *lock)
481-
{
482-
*lock = 0;
483-
}
484-
485-
void
486-
S_INIT_LOCK(slock_t *lock)
487-
{
488-
S_UNLOCK(lock);
489-
}
490-
491-
#endif /* defined(linux) && defined(sparc) */
492-
493-
#if defined(NEED_NS32K_TAS_ASM)
494-
495-
static int
496-
tas(slock_t *m)
497-
{
498-
slock_t res = 0;
499-
__asm__("movd 8(fp), r1");
500-
__asm__("movqd 0, r0");
501-
__asm__("sbitd r0, 0(r1)");
502-
__asm__("sprb us, %0" : "=r" (res));
503-
res = (res >> 5) & 1;
504-
return res;
505-
}
457+
slock_t res;
506458

507-
void
508-
S_LOCK(slock_t *lock)
509-
{
510-
while (tas(lock))
511-
;
459+
do{
460+
__asm__("ldstub [%1], %0"
461+
: "=&r" (res)
462+
: "r" (lock));
463+
}while(!res != 0);
512464
}
513465

514466
void
@@ -523,7 +475,7 @@ S_INIT_LOCK(slock_t *lock)
523475
S_UNLOCK(lock);
524476
}
525477

526-
#endif /* NEED_NS32K_TAS_ASM */
478+
#endif /* defined(linux) && defined(sparc) */
527479

528480
#if defined(linux) && defined(PPC)
529481

src/backend/storage/page/bufpage.c

+1-63
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/storage/page/bufpage.c,v 1.7 1997/08/19 21:33:33 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/storage/page/bufpage.c,v 1.8 1997/08/24 23:07:30 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -31,43 +31,6 @@ static void PageIndexTupleDeleteAdjustLinePointers(PageHeader phdr,
3131

3232
static bool PageManagerShuffle = true; /* default is shuffle mode */
3333

34-
/* ----------------------------------------------------------------
35-
* Buffer support functions
36-
* ----------------------------------------------------------------
37-
*/
38-
/*
39-
* BufferGetPageSize --
40-
* Returns the page size within a buffer.
41-
*
42-
* Notes:
43-
* Assumes buffer is valid.
44-
*
45-
* The buffer can be a raw disk block and need not contain a valid
46-
* (formatted) disk page.
47-
*/
48-
Size
49-
BufferGetPageSize(Buffer buffer)
50-
{
51-
Size pageSize;
52-
53-
Assert(BufferIsValid(buffer));
54-
pageSize = BLCKSZ; /* XXX dig out of buffer descriptor */
55-
56-
Assert(PageSizeIsValid(pageSize));
57-
return (pageSize);
58-
}
59-
60-
/*
61-
* BufferGetPage --
62-
* Returns the page associated with a buffer.
63-
*/
64-
Page
65-
BufferGetPage(Buffer buffer)
66-
{
67-
return (Page) BufferGetBlock(buffer);
68-
}
69-
70-
7134
/* ----------------------------------------------------------------
7235
* Page support functions
7336
* ----------------------------------------------------------------
@@ -94,31 +57,6 @@ PageInit(Page page, Size pageSize, Size specialSize)
9457
PageSetPageSize(page, pageSize);
9558
}
9659

97-
/*
98-
* PageGetItem --
99-
* Retrieves an item on the given page.
100-
*
101-
* Note:
102-
* This does change the status of any of the resources passed.
103-
* The semantics may change in the future.
104-
*/
105-
Item
106-
PageGetItem(Page page, ItemId itemId)
107-
{
108-
Item item;
109-
110-
Assert(PageIsValid(page));
111-
/* Assert(itemId->lp_flags & LP_USED); */
112-
if(!(itemId->lp_flags & LP_USED)) {
113-
elog(NOTICE, "LP_USED assertion failed. dumping core.");
114-
abort();
115-
}
116-
117-
item = (Item)(((char *)page) + itemId->lp_off);
118-
119-
return (item);
120-
}
121-
12260
/*
12361
* PageAddItem --
12462
* Adds item to the given page.

src/backend/utils/adt/oid.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/oid.c,v 1.7 1997/07/24 20:16:17 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/oid.c,v 1.8 1997/08/24 23:07:35 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -96,6 +96,10 @@ char *oidout(Oid o)
9696
* PUBLIC ROUTINES *
9797
*****************************************************************************/
9898

99+
/*
100+
* If you change this function, change heap_keytest()
101+
* because we have hardcoded this in there as an optimization
102+
*/
99103
bool oideq(Oid arg1, Oid arg2)
100104
{
101105
return(arg1 == arg2);

0 commit comments

Comments
 (0)