Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
f5f366e1
Commit
f5f366e1
authored
Aug 06, 1997
by
Bruce Momjian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow internal sorts to be stored in memory rather than in files.
parent
3bea7b13
Changes
11
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
630 additions
and
513 deletions
+630
-513
src/backend/executor/nodeMergejoin.c
src/backend/executor/nodeMergejoin.c
+15
-1
src/backend/executor/nodeSort.c
src/backend/executor/nodeSort.c
+70
-191
src/backend/tcop/postgres.c
src/backend/tcop/postgres.c
+15
-3
src/backend/utils/sort/lselect.c
src/backend/utils/sort/lselect.c
+46
-89
src/backend/utils/sort/psort.c
src/backend/utils/sort/psort.c
+398
-183
src/include/nodes/execnodes.h
src/include/nodes/execnodes.h
+2
-2
src/include/nodes/plannodes.h
src/include/nodes/plannodes.h
+3
-1
src/include/utils/lselect.h
src/include/utils/lselect.h
+20
-11
src/include/utils/psort.h
src/include/utils/psort.h
+49
-16
src/man/postgres.1
src/man/postgres.1
+10
-14
src/man/postmaster.1
src/man/postmaster.1
+2
-2
No files found.
src/backend/executor/nodeMergejoin.c
View file @
f5f366e1
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/nodeMergejoin.c,v 1.
5 1996/11/10 02:59:54
momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/executor/nodeMergejoin.c,v 1.
6 1997/08/06 03:41:29
momjian Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -374,6 +374,18 @@ ExecMergeTupleDump(ExprContext *econtext, MergeJoinState *mergestate)
...
@@ -374,6 +374,18 @@ ExecMergeTupleDump(ExprContext *econtext, MergeJoinState *mergestate)
printf
(
"********
\n
"
);
printf
(
"********
\n
"
);
}
}
static
void
CleanUpSort
(
Plan
*
plan
)
{
if
(
plan
==
NULL
)
return
;
if
(
plan
->
type
==
T_Sort
)
{
Sort
*
sort
=
(
Sort
*
)
plan
;
psort_end
(
sort
);
}
}
/* ----------------------------------------------------------------
/* ----------------------------------------------------------------
* ExecMergeJoin
* ExecMergeJoin
*
*
...
@@ -676,6 +688,8 @@ ExecMergeJoin(MergeJoin *node)
...
@@ -676,6 +688,8 @@ ExecMergeJoin(MergeJoin *node)
*/
*/
if
(
TupIsNull
(
outerTupleSlot
))
{
if
(
TupIsNull
(
outerTupleSlot
))
{
MJ_printf
(
"ExecMergeJoin: **** outer tuple is nil ****
\n
"
);
MJ_printf
(
"ExecMergeJoin: **** outer tuple is nil ****
\n
"
);
CleanUpSort
(
node
->
join
.
lefttree
->
lefttree
);
CleanUpSort
(
node
->
join
.
righttree
->
lefttree
);
return
NULL
;
return
NULL
;
}
}
...
...
src/backend/executor/nodeSort.c
View file @
f5f366e1
This diff is collapsed.
Click to expand it.
src/backend/tcop/postgres.c
View file @
f5f366e1
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.3
6 1997/07/29 16:14:40 thomas
Exp $
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.3
7 1997/08/06 03:41:41 momjian
Exp $
*
*
* NOTES
* NOTES
* this is the "main" module of the postgres backend and
* this is the "main" module of the postgres backend and
...
@@ -108,6 +108,7 @@ extern int lockingOff;
...
@@ -108,6 +108,7 @@ extern int lockingOff;
extern
int
NBuffers
;
extern
int
NBuffers
;
int
fsyncOff
=
0
;
int
fsyncOff
=
0
;
int
SortMem
=
512
;
int
dontExecute
=
0
;
int
dontExecute
=
0
;
static
int
ShowStats
;
static
int
ShowStats
;
...
@@ -1039,6 +1040,15 @@ PostgresMain(int argc, char *argv[])
...
@@ -1039,6 +1040,15 @@ PostgresMain(int argc, char *argv[])
flagQ
=
1
;
flagQ
=
1
;
break
;
break
;
case
'S'
:
/* ----------------
* S - amount of sort memory to use in 1k bytes
* ----------------
*/
SortMem
=
atoi
(
optarg
);
break
;
#ifdef NOT_USED
case
'S'
:
case
'S'
:
/* ----------------
/* ----------------
* S - assume stable main memory
* S - assume stable main memory
...
@@ -1048,6 +1058,7 @@ PostgresMain(int argc, char *argv[])
...
@@ -1048,6 +1058,7 @@ PostgresMain(int argc, char *argv[])
flagS
=
1
;
flagS
=
1
;
SetTransactionFlushEnabled
(
false
);
SetTransactionFlushEnabled
(
false
);
break
;
break
;
#endif
case
's'
:
case
's'
:
/* ----------------
/* ----------------
...
@@ -1173,6 +1184,7 @@ PostgresMain(int argc, char *argv[])
...
@@ -1173,6 +1184,7 @@ PostgresMain(int argc, char *argv[])
printf
(
"
\t
timings = %c
\n
"
,
ShowStats
?
't'
:
'f'
);
printf
(
"
\t
timings = %c
\n
"
,
ShowStats
?
't'
:
'f'
);
printf
(
"
\t
dates = %s
\n
"
,
EuroDates
?
"European"
:
"Normal"
);
printf
(
"
\t
dates = %s
\n
"
,
EuroDates
?
"European"
:
"Normal"
);
printf
(
"
\t
bufsize = %d
\n
"
,
NBuffers
);
printf
(
"
\t
bufsize = %d
\n
"
,
NBuffers
);
printf
(
"
\t
sortmem = %d
\n
"
,
SortMem
);
printf
(
"
\t
query echo = %c
\n
"
,
EchoQuery
?
't'
:
'f'
);
printf
(
"
\t
query echo = %c
\n
"
,
EchoQuery
?
't'
:
'f'
);
printf
(
"
\t
multiplexed backend? = %c
\n
"
,
multiplexedBackend
?
't'
:
'f'
);
printf
(
"
\t
multiplexed backend? = %c
\n
"
,
multiplexedBackend
?
't'
:
'f'
);
...
@@ -1280,7 +1292,7 @@ PostgresMain(int argc, char *argv[])
...
@@ -1280,7 +1292,7 @@ PostgresMain(int argc, char *argv[])
*/
*/
if
(
IsUnderPostmaster
==
false
)
{
if
(
IsUnderPostmaster
==
false
)
{
puts
(
"
\n
POSTGRES backend interactive interface"
);
puts
(
"
\n
POSTGRES backend interactive interface"
);
puts
(
"$Revision: 1.3
6 $ $Date: 1997/07/29 16:14:40
$"
);
puts
(
"$Revision: 1.3
7 $ $Date: 1997/08/06 03:41:41
$"
);
}
}
/* ----------------
/* ----------------
...
...
src/backend/utils/sort/lselect.c
View file @
f5f366e1
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/sort/Attic/lselect.c,v 1.
3 1997/05/20 11:35:48 vadim
Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/sort/Attic/lselect.c,v 1.
4 1997/08/06 03:41:47 momjian
Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -26,37 +26,14 @@
...
@@ -26,37 +26,14 @@
#include "utils/psort.h"
#include "utils/psort.h"
#include "utils/lselect.h"
#include "utils/lselect.h"
extern
Relation
SortRdesc
;
/* later static */
/*
* PUTTUP - writes the next tuple
* ENDRUN - mark end of run
* GETLEN - reads the length of the next tuple
* ALLOCTUP - returns space for the new tuple
* SETTUPLEN - stores the length into the tuple
* GETTUP - reads the tuple
*
* Note:
* LEN field must be a short; FP is a stream
*/
#define PUTTUP(TUP, FP) fwrite((char *)TUP, (TUP)->t_len, 1, FP)
#define PUTTUP(TUP, FP) fwrite((char *)TUP, (TUP)->t_len, 1, FP)
#define ENDRUN(FP) fwrite((char *)&shortzero, sizeof (shortzero), 1, FP)
#define GETLEN(LEN, FP) fread(&(LEN), sizeof (shortzero), 1, FP)
#define ALLOCTUP(LEN) ((HeapTuple)palloc((unsigned)LEN))
#define GETTUP(TUP, LEN, FP)\
fread((char *)(TUP) + sizeof (shortzero), 1, (LEN) - sizeof (shortzero), FP)
#define SETTUPLEN(TUP, LEN) (TUP)->t_len = LEN
/*
/*
* USEMEM - record use of memory
* USEMEM - record use of memory
* FREEMEM - record freeing of memory
* FREEMEM - record freeing of memory
* FULLMEM - 1 iff a tuple will fit
*/
*/
#define USEMEM(context,AMT) context->sortMem -= (AMT)
#define USEMEM(AMT) SortMemory -= (AMT)
#define FREEMEM(context,AMT) context->sortMem += (AMT)
#define FREEMEM(AMT) SortMemory += (AMT)
#define LACKMEM() (SortMemory <= BLCKSZ)
/* not accurate */
/*
/*
* lmerge - merges two leftist trees into one
* lmerge - merges two leftist trees into one
...
@@ -67,12 +44,12 @@ extern Relation SortRdesc; /* later static */
...
@@ -67,12 +44,12 @@ extern Relation SortRdesc; /* later static */
* speed up code significantly.
* speed up code significantly.
*/
*/
struct
leftist
*
struct
leftist
*
lmerge
(
struct
leftist
*
pt
,
struct
leftist
*
qt
)
lmerge
(
struct
leftist
*
pt
,
struct
leftist
*
qt
,
LeftistContext
context
)
{
{
register
struct
leftist
*
root
,
*
majorLeftist
,
*
minorLeftist
;
register
struct
leftist
*
root
,
*
majorLeftist
,
*
minorLeftist
;
int
dist
;
int
dist
;
if
(
tuplecmp
(
pt
->
lt_tuple
,
qt
->
lt_tuple
))
{
if
(
tuplecmp
(
pt
->
lt_tuple
,
qt
->
lt_tuple
,
context
))
{
root
=
pt
;
root
=
pt
;
majorLeftist
=
qt
;
majorLeftist
=
qt
;
}
else
{
}
else
{
...
@@ -83,7 +60,7 @@ lmerge(struct leftist *pt, struct leftist *qt)
...
@@ -83,7 +60,7 @@ lmerge(struct leftist *pt, struct leftist *qt)
root
->
lt_left
=
majorLeftist
;
root
->
lt_left
=
majorLeftist
;
else
{
else
{
if
((
minorLeftist
=
root
->
lt_right
)
!=
NULL
)
if
((
minorLeftist
=
root
->
lt_right
)
!=
NULL
)
majorLeftist
=
lmerge
(
majorLeftist
,
minorLeftist
);
majorLeftist
=
lmerge
(
majorLeftist
,
minorLeftist
,
context
);
if
((
dist
=
root
->
lt_left
->
lt_dist
)
<
majorLeftist
->
lt_dist
)
{
if
((
dist
=
root
->
lt_left
->
lt_dist
)
<
majorLeftist
->
lt_dist
)
{
root
->
lt_dist
=
1
+
dist
;
root
->
lt_dist
=
1
+
dist
;
root
->
lt_right
=
root
->
lt_left
;
root
->
lt_right
=
root
->
lt_left
;
...
@@ -97,11 +74,11 @@ lmerge(struct leftist *pt, struct leftist *qt)
...
@@ -97,11 +74,11 @@ lmerge(struct leftist *pt, struct leftist *qt)
}
}
static
struct
leftist
*
static
struct
leftist
*
linsert
(
struct
leftist
*
root
,
struct
leftist
*
new1
)
linsert
(
struct
leftist
*
root
,
struct
leftist
*
new1
,
LeftistContext
context
)
{
{
register
struct
leftist
*
left
,
*
right
;
register
struct
leftist
*
left
,
*
right
;
if
(
!
tuplecmp
(
root
->
lt_tuple
,
new1
->
lt_tuple
))
{
if
(
!
tuplecmp
(
root
->
lt_tuple
,
new1
->
lt_tuple
,
context
))
{
new1
->
lt_left
=
root
;
new1
->
lt_left
=
root
;
return
(
new1
);
return
(
new1
);
}
}
...
@@ -116,7 +93,7 @@ linsert(struct leftist *root, struct leftist *new1)
...
@@ -116,7 +93,7 @@ linsert(struct leftist *root, struct leftist *new1)
}
}
return
(
root
);
return
(
root
);
}
}
right
=
linsert
(
right
,
new1
);
right
=
linsert
(
right
,
new1
,
context
);
if
(
right
->
lt_dist
<
left
->
lt_dist
)
{
if
(
right
->
lt_dist
<
left
->
lt_dist
)
{
root
->
lt_dist
=
1
+
left
->
lt_dist
;
root
->
lt_dist
=
1
+
left
->
lt_dist
;
root
->
lt_left
=
right
;
root
->
lt_left
=
right
;
...
@@ -142,7 +119,8 @@ linsert(struct leftist *root, struct leftist *new1)
...
@@ -142,7 +119,8 @@ linsert(struct leftist *root, struct leftist *new1)
*/
*/
HeapTuple
HeapTuple
gettuple
(
struct
leftist
**
treep
,
gettuple
(
struct
leftist
**
treep
,
short
*
devnum
)
/* device from which tuple came */
short
*
devnum
,
/* device from which tuple came */
LeftistContext
context
)
{
{
register
struct
leftist
*
tp
;
register
struct
leftist
*
tp
;
HeapTuple
tup
;
HeapTuple
tup
;
...
@@ -153,9 +131,9 @@ gettuple(struct leftist **treep,
...
@@ -153,9 +131,9 @@ gettuple(struct leftist **treep,
if
(
tp
->
lt_dist
==
1
)
/* lt_left == NULL */
if
(
tp
->
lt_dist
==
1
)
/* lt_left == NULL */
*
treep
=
tp
->
lt_left
;
*
treep
=
tp
->
lt_left
;
else
else
*
treep
=
lmerge
(
tp
->
lt_left
,
tp
->
lt_right
);
*
treep
=
lmerge
(
tp
->
lt_left
,
tp
->
lt_right
,
context
);
FREEMEM
(
sizeof
(
struct
leftist
));
FREEMEM
(
context
,
sizeof
(
struct
leftist
));
FREE
(
tp
);
FREE
(
tp
);
return
(
tup
);
return
(
tup
);
}
}
...
@@ -169,14 +147,17 @@ gettuple(struct leftist **treep,
...
@@ -169,14 +147,17 @@ gettuple(struct leftist **treep,
* Note:
* Note:
* Currently never returns NULL BUG
* Currently never returns NULL BUG
*/
*/
int
void
puttuple
(
struct
leftist
**
treep
,
HeapTuple
newtuple
,
int
devnum
)
puttuple
(
struct
leftist
**
treep
,
HeapTuple
newtuple
,
short
devnum
,
LeftistContext
context
)
{
{
register
struct
leftist
*
new1
;
register
struct
leftist
*
new1
;
register
struct
leftist
*
tp
;
register
struct
leftist
*
tp
;
new1
=
(
struct
leftist
*
)
palloc
((
unsigned
)
sizeof
(
struct
leftist
));
new1
=
(
struct
leftist
*
)
palloc
((
unsigned
)
sizeof
(
struct
leftist
));
USEMEM
(
sizeof
(
struct
leftist
));
USEMEM
(
context
,
sizeof
(
struct
leftist
));
new1
->
lt_dist
=
1
;
new1
->
lt_dist
=
1
;
new1
->
lt_devnum
=
devnum
;
new1
->
lt_devnum
=
devnum
;
new1
->
lt_tuple
=
newtuple
;
new1
->
lt_tuple
=
newtuple
;
...
@@ -185,38 +166,11 @@ puttuple(struct leftist **treep, HeapTuple newtuple, int devnum)
...
@@ -185,38 +166,11 @@ puttuple(struct leftist **treep, HeapTuple newtuple, int devnum)
if
((
tp
=
*
treep
)
==
NULL
)
if
((
tp
=
*
treep
)
==
NULL
)
*
treep
=
new1
;
*
treep
=
new1
;
else
else
*
treep
=
linsert
(
tp
,
new1
);
*
treep
=
linsert
(
tp
,
new1
,
context
);
return
(
1
)
;
return
;
}
}
/*
* dumptuples - stores all the tuples in tree into file
*/
void
dumptuples
(
FILE
*
file
)
{
register
struct
leftist
*
tp
;
register
struct
leftist
*
newp
;
HeapTuple
tup
;
tp
=
Tuples
;
while
(
tp
!=
NULL
)
{
tup
=
tp
->
lt_tuple
;
if
(
tp
->
lt_dist
==
1
)
/* lt_right == NULL */
newp
=
tp
->
lt_left
;
else
newp
=
lmerge
(
tp
->
lt_left
,
tp
->
lt_right
);
FREEMEM
(
sizeof
(
struct
leftist
));
FREE
(
tp
);
PUTTUP
(
tup
,
file
);
FREEMEM
(
tup
->
t_len
);
FREE
(
tup
);
tp
=
newp
;
}
Tuples
=
NULL
;
}
/*
/*
* tuplecmp - Compares two tuples with respect CmpList
* tuplecmp - Compares two tuples with respect CmpList
*
*
...
@@ -225,7 +179,7 @@ dumptuples(FILE *file)
...
@@ -225,7 +179,7 @@ dumptuples(FILE *file)
* Assumtions:
* Assumtions:
*/
*/
int
int
tuplecmp
(
HeapTuple
ltup
,
HeapTuple
rtup
)
tuplecmp
(
HeapTuple
ltup
,
HeapTuple
rtup
,
LeftistContext
context
)
{
{
register
char
*
lattr
,
*
rattr
;
register
char
*
lattr
,
*
rattr
;
int
nkey
=
0
;
int
nkey
=
0
;
...
@@ -238,24 +192,27 @@ tuplecmp(HeapTuple ltup, HeapTuple rtup)
...
@@ -238,24 +192,27 @@ tuplecmp(HeapTuple ltup, HeapTuple rtup)
return
(
0
);
return
(
0
);
if
(
rtup
==
(
HeapTuple
)
NULL
)
if
(
rtup
==
(
HeapTuple
)
NULL
)
return
(
1
);
return
(
1
);
while
(
nkey
<
Nk
eys
&&
!
result
)
{
while
(
nkey
<
context
->
nK
eys
&&
!
result
)
{
lattr
=
heap_getattr
(
ltup
,
InvalidBuffer
,
lattr
=
heap_getattr
(
ltup
,
InvalidBuffer
,
Key
[
nkey
].
sk_attno
,
context
->
scanKeys
[
nkey
].
sk_attno
,
RelationGetTupleDescriptor
(
SortRdesc
),
context
->
tupDesc
,
&
isnull
);
&
isnull
);
if
(
isnull
)
if
(
isnull
)
return
(
0
);
return
(
0
);
rattr
=
heap_getattr
(
rtup
,
InvalidBuffer
,
rattr
=
heap_getattr
(
rtup
,
InvalidBuffer
,
Key
[
nkey
].
sk_attno
,
context
->
scanKeys
[
nkey
].
sk_attno
,
RelationGetTupleDescriptor
(
SortRdesc
)
,
context
->
tupDesc
,
&
isnull
);
&
isnull
);
if
(
isnull
)
if
(
isnull
)
return
(
1
);
return
(
1
);
if
(
Key
[
nkey
].
sk_flags
&
SK_COMMUTE
)
{
if
(
context
->
scanKeys
[
nkey
].
sk_flags
&
SK_COMMUTE
)
{
if
(
!
(
result
=
(
long
)
(
*
Key
[
nkey
].
sk_func
)
(
rattr
,
lattr
)))
if
(
!
(
result
=
result
=
-
(
long
)
(
*
Key
[
nkey
].
sk_func
)
(
lattr
,
rattr
);
(
long
)
(
*
context
->
scanKeys
[
nkey
].
sk_func
)
(
rattr
,
lattr
)))
}
else
if
(
!
(
result
=
(
long
)
(
*
Key
[
nkey
].
sk_func
)
(
lattr
,
rattr
)))
result
=
result
=
-
(
long
)
(
*
Key
[
nkey
].
sk_func
)
(
rattr
,
lattr
);
-
(
long
)
(
*
context
->
scanKeys
[
nkey
].
sk_func
)
(
lattr
,
rattr
);
}
else
if
(
!
(
result
=
(
long
)
(
*
context
->
scanKeys
[
nkey
].
sk_func
)
(
lattr
,
rattr
)))
result
=
-
(
long
)
(
*
context
->
scanKeys
[
nkey
].
sk_func
)
(
rattr
,
lattr
);
nkey
++
;
nkey
++
;
}
}
return
(
result
==
1
);
return
(
result
==
1
);
...
@@ -263,7 +220,7 @@ tuplecmp(HeapTuple ltup, HeapTuple rtup)
...
@@ -263,7 +220,7 @@ tuplecmp(HeapTuple ltup, HeapTuple rtup)
#ifdef EBUG
#ifdef EBUG
void
void
checktree
(
struct
leftist
*
tree
)
checktree
(
struct
leftist
*
tree
,
LeftistContext
context
)
{
{
int
lnodes
;
int
lnodes
;
int
rnodes
;
int
rnodes
;
...
@@ -272,8 +229,8 @@ checktree(struct leftist *tree)
...
@@ -272,8 +229,8 @@ checktree(struct leftist *tree)
puts
(
"Null tree."
);
puts
(
"Null tree."
);
return
;
return
;
}
}
lnodes
=
checktreer
(
tree
->
lt_left
,
1
);
lnodes
=
checktreer
(
tree
->
lt_left
,
1
,
context
);
rnodes
=
checktreer
(
tree
->
lt_right
,
1
);
rnodes
=
checktreer
(
tree
->
lt_right
,
1
,
context
);
if
(
lnodes
<
0
)
{
if
(
lnodes
<
0
)
{
lnodes
=
-
lnodes
;
lnodes
=
-
lnodes
;
puts
(
"0:
\t
Bad left side."
);
puts
(
"0:
\t
Bad left side."
);
...
@@ -297,24 +254,24 @@ checktree(struct leftist *tree)
...
@@ -297,24 +254,24 @@ checktree(struct leftist *tree)
}
else
if
(
tree
->
lt_dist
!=
1
+
tree
->
lt_right
->
lt_dist
)
}
else
if
(
tree
->
lt_dist
!=
1
+
tree
->
lt_right
->
lt_dist
)
puts
(
"0:
\t
Distance incorrect."
);
puts
(
"0:
\t
Distance incorrect."
);
if
(
lnodes
>
0
)
if
(
lnodes
>
0
)
if
(
tuplecmp
(
tree
->
lt_left
->
lt_tuple
,
tree
->
lt_tuple
))
if
(
tuplecmp
(
tree
->
lt_left
->
lt_tuple
,
tree
->
lt_tuple
,
context
))
printf
(
"%d:
\t
Left child < parent.
\n
"
);
printf
(
"%d:
\t
Left child < parent.
\n
"
);
if
(
rnodes
>
0
)
if
(
rnodes
>
0
)
if
(
tuplecmp
(
tree
->
lt_right
->
lt_tuple
,
tree
->
lt_tuple
))
if
(
tuplecmp
(
tree
->
lt_right
->
lt_tuple
,
tree
->
lt_tuple
,
context
))
printf
(
"%d:
\t
Right child < parent.
\n
"
);
printf
(
"%d:
\t
Right child < parent.
\n
"
);
printf
(
"Tree has %d nodes
\n
"
,
1
+
lnodes
+
rnodes
);
printf
(
"Tree has %d nodes
\n
"
,
1
+
lnodes
+
rnodes
);
}
}
int
int
checktreer
(
struct
leftist
*
tree
,
int
level
)
checktreer
(
struct
leftist
*
tree
,
int
level
,
LeftistContext
context
)
{
{
int
lnodes
,
rnodes
;
int
lnodes
,
rnodes
;
int
error
=
0
;
int
error
=
0
;
if
(
tree
==
NULL
)
if
(
tree
==
NULL
)
return
(
0
);
return
(
0
);
lnodes
=
checktreer
(
tree
->
lt_left
,
level
+
1
);
lnodes
=
checktreer
(
tree
->
lt_left
,
level
+
1
,
context
);
rnodes
=
checktreer
(
tree
->
lt_right
,
level
+
1
);
rnodes
=
checktreer
(
tree
->
lt_right
,
level
+
1
,
context
);
if
(
lnodes
<
0
)
{
if
(
lnodes
<
0
)
{
error
=
1
;
error
=
1
;
lnodes
=
-
lnodes
;
lnodes
=
-
lnodes
;
...
@@ -349,12 +306,12 @@ checktreer(struct leftist *tree, int level)
...
@@ -349,12 +306,12 @@ checktreer(struct leftist *tree, int level)
printf
(
"%d:
\t
Distance incorrect.
\n
"
,
level
);
printf
(
"%d:
\t
Distance incorrect.
\n
"
,
level
);
}
}
if
(
lnodes
>
0
)
if
(
lnodes
>
0
)
if
(
tuplecmp
(
tree
->
lt_left
->
lt_tuple
,
tree
->
lt_tuple
))
{
if
(
tuplecmp
(
tree
->
lt_left
->
lt_tuple
,
tree
->
lt_tuple
,
context
))
{
error
=
1
;
error
=
1
;
printf
(
"%d:
\t
Left child < parent.
\n
"
);
printf
(
"%d:
\t
Left child < parent.
\n
"
);
}
}
if
(
rnodes
>
0
)
if
(
rnodes
>
0
)
if
(
tuplecmp
(
tree
->
lt_right
->
lt_tuple
,
tree
->
lt_tuple
))
{
if
(
tuplecmp
(
tree
->
lt_right
->
lt_tuple
,
tree
->
lt_tuple
,
context
))
{
error
=
1
;
error
=
1
;
printf
(
"%d:
\t
Right child < parent.
\n
"
);
printf
(
"%d:
\t
Right child < parent.
\n
"
);
}
}
...
...
src/backend/utils/sort/psort.c
View file @
f5f366e1
This diff is collapsed.
Click to expand it.
src/include/nodes/execnodes.h
View file @
f5f366e1
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
*
*
* Copyright (c) 1994, Regents of the University of California
* Copyright (c) 1994, Regents of the University of California
*
*
* $Id: execnodes.h,v 1.
6 1996/11/04 08:52:54 scrappy
Exp $
* $Id: execnodes.h,v 1.
7 1997/08/06 03:42:02 momjian
Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -605,7 +605,7 @@ typedef struct SortState {
...
@@ -605,7 +605,7 @@ typedef struct SortState {
CommonScanState
csstate
;
/* its first field is NodeTag */
CommonScanState
csstate
;
/* its first field is NodeTag */
bool
sort_Flag
;
bool
sort_Flag
;
ScanKey
sort_Keys
;
ScanKey
sort_Keys
;
Relation
sort_TempRelation
;
bool
cleaned
;
}
SortState
;
}
SortState
;
/* ----------------
/* ----------------
...
...
src/include/nodes/plannodes.h
View file @
f5f366e1
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
*
*
* Copyright (c) 1994, Regents of the University of California
* Copyright (c) 1994, Regents of the University of California
*
*
* $Id: plannodes.h,v 1.
5 1996/11/05 08:18:44 scrappy
Exp $
* $Id: plannodes.h,v 1.
6 1997/08/06 03:42:04 momjian
Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -265,6 +265,8 @@ typedef struct Sort {
...
@@ -265,6 +265,8 @@ typedef struct Sort {
Oid
tempid
;
Oid
tempid
;
int
keycount
;
int
keycount
;
SortState
*
sortstate
;
SortState
*
sortstate
;
void
*
psortstate
;
bool
cleaned
;
}
Sort
;
}
Sort
;
/* ----------------
/* ----------------
...
...
src/include/utils/lselect.h
View file @
f5f366e1
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
*
*
* Copyright (c) 1994, Regents of the University of California
* Copyright (c) 1994, Regents of the University of California
*
*
* $Id: lselect.h,v 1.
3 1996/11/04 11:51:19 scrappy
Exp $
* $Id: lselect.h,v 1.
4 1997/08/06 03:42:07 momjian
Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -14,7 +14,7 @@
...
@@ -14,7 +14,7 @@
#define LSELECT_H
#define LSELECT_H
#include <stdio.h>
#include <stdio.h>
#include
<access/htup.h>
#include
"access/htup.h"
struct
leftist
{
struct
leftist
{
short
lt_dist
;
/* distance to leaf/empty node */
short
lt_dist
;
/* distance to leaf/empty node */
...
@@ -24,17 +24,26 @@ struct leftist {
...
@@ -24,17 +24,26 @@ struct leftist {
struct
leftist
*
lt_right
;
struct
leftist
*
lt_right
;
};
};
extern
struct
leftist
*
Tuples
;
/* replaces global variables in lselect.c to make it reentrant */
typedef
struct
{
TupleDesc
tupDesc
;
int
nKeys
;
ScanKey
scanKeys
;
int
sortMem
;
/* needed for psort */
}
LeftistContextData
;
typedef
LeftistContextData
*
LeftistContext
;
extern
struct
leftist
*
lmerge
(
struct
leftist
*
pt
,
struct
leftist
*
qt
);
extern
struct
leftist
*
lmerge
(
struct
leftist
*
pt
,
struct
leftist
*
qt
,
extern
HeapTuple
gettuple
(
struct
leftist
**
treep
,
short
*
devnum
);
LeftistContext
context
);
extern
int
puttuple
(
struct
leftist
**
treep
,
HeapTuple
newtuple
,
int
devnum
);
extern
HeapTuple
gettuple
(
struct
leftist
**
treep
,
short
*
devnum
,
extern
void
dumptuples
(
FILE
*
file
);
LeftistContext
context
);
extern
int
tuplecmp
(
HeapTuple
ltup
,
HeapTuple
rtup
);
extern
void
puttuple
(
struct
leftist
**
treep
,
HeapTuple
newtuple
,
short
devnum
,
LeftistContext
context
);
extern
int
tuplecmp
(
HeapTuple
ltup
,
HeapTuple
rtup
,
LeftistContext
context
);
#ifdef EBUG
#ifdef EBUG
extern
void
checktree
(
struct
leftist
*
tree
);
extern
void
checktree
(
struct
leftist
*
tree
,
LeftistContext
context
);
extern
int
checktreer
(
struct
leftist
*
tree
,
int
level
);
extern
int
checktreer
(
struct
leftist
*
tree
,
int
level
,
LeftistContext
context
);
#endif
/* EBUG */
#endif
/* EBUG */
#endif
/* LSELECT_H */
#endif
/* LSELECT_H */
src/include/utils/psort.h
View file @
f5f366e1
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
*
*
* Copyright (c) 1994, Regents of the University of California
* Copyright (c) 1994, Regents of the University of California
*
*
* $Id: psort.h,v 1.
3 1997/05/20 11:37:33 vadim
Exp $
* $Id: psort.h,v 1.
4 1997/08/06 03:42:13 momjian
Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -14,11 +14,13 @@
...
@@ -14,11 +14,13 @@
#define PSORT_H
#define PSORT_H
#include <stdio.h>
#include <stdio.h>
#include <access/relscan.h>
#include "access/relscan.h"
#include "utils/lselect.h"
#include "nodes/plannodes.h"
#define SORTMEM (1 << 18)
/* 1/4 M - any static memory */
#define SORTMEM (1 << 18)
/* 1/4 M - any static memory */
#define MAXTAPES 7
/* 7--See Fig. 70, p273 */
#define MAXTAPES 7
/* 7--See Fig. 70, p273 */
#define TAPEEXT
"pg_psort.XXXXXX"
/* TEMPDIR/TAPEEXT */
#define TAPEEXT
LEN strlen("pg_psort.xxxxx.xxx")
/* TEMPDIR/TAPEEXT */
#define FREE(x) pfree((char *) x)
#define FREE(x) pfree((char *) x)
struct
tape
{
struct
tape
{
...
@@ -35,13 +37,38 @@ struct cmplist {
...
@@ -35,13 +37,38 @@ struct cmplist {
struct
cmplist
*
cp_next
;
/* next in chain */
struct
cmplist
*
cp_next
;
/* next in chain */
};
};
extern
int
Nkeys
;
/* This structure preserves the state of psort between calls from different
extern
ScanKey
key
;
* nodes to its interface functions. Basically, it includes all of the global
extern
int
SortMemory
;
/* free memory */
* variables in psort. In case you were wondering, pointers to these structures
extern
Relation
SortRdesc
;
* are included in Sort node structures. -Rex 2.6.1995
extern
struct
leftist
*
Tuples
;
*/
typedef
struct
Psortstate
{
LeftistContextData
treeContext
;
int
TapeRange
;
int
Level
;
int
TotalDummy
;
struct
tape
Tape
[
MAXTAPES
];
int
BytesRead
;
int
BytesWritten
;
int
tupcount
;
struct
leftist
*
Tuples
;
FILE
*
psort_grab_file
;
long
psort_current
;
/* could be file offset, or array index */
long
psort_saved
;
/* could be file offset, or array index */
bool
using_tape_files
;
HeapTuple
*
memtuples
;
}
Psortstate
;
#ifdef EBUG
#ifdef EBUG
#include <stdio.h>
#include "utils/elog.h"
#include "storage/buf.h"
#include "storage/bufmgr.h"
#define PDEBUG(PROC, S1)\
#define PDEBUG(PROC, S1)\
elog(DEBUG, "%s:%d>> PROC: %s.", __FILE__, __LINE__, S1)
elog(DEBUG, "%s:%d>> PROC: %s.", __FILE__, __LINE__, S1)
...
@@ -69,15 +96,21 @@ if (1) CODE; else
...
@@ -69,15 +96,21 @@ if (1) CODE; else
#endif
#endif
/* psort.c */
/* psort.c */
extern
void
psort
(
Relation
oldrel
,
Relation
newrel
,
int
nkeys
,
ScanKey
key
);
extern
bool
psort_begin
(
Sort
*
node
,
int
nkeys
,
ScanKey
key
);
extern
void
init
psort
(
void
);
extern
void
init
tapes
(
Sort
*
node
);
extern
void
resetpsort
(
void
);
extern
void
resetpsort
(
void
);
extern
void
initialrun
(
Relation
rdesc
);
extern
void
initialrun
(
Sort
*
node
,
bool
*
empty
);
extern
bool
createrun
(
HeapScanDesc
sdesc
,
FILE
*
file
);
extern
bool
createrun
(
Sort
*
node
,
FILE
*
file
,
bool
*
empty
);
extern
HeapTuple
tuplecopy
(
HeapTuple
tup
,
Relation
rdesc
,
Buffer
b
);
extern
HeapTuple
tuplecopy
(
HeapTuple
tup
);
extern
FILE
*
mergeruns
(
void
);
extern
FILE
*
mergeruns
(
Sort
*
node
);
extern
void
merge
(
struct
tape
*
dest
);
extern
void
merge
(
Sort
*
node
,
struct
tape
*
dest
);
extern
void
endpsort
(
Relation
rdesc
,
FILE
*
file
);
extern
void
dumptuples
(
Sort
*
node
);
extern
HeapTuple
psort_grabtuple
(
Sort
*
node
);
extern
void
psort_markpos
(
Sort
*
node
);
extern
void
psort_restorepos
(
Sort
*
node
);
extern
void
psort_end
(
Sort
*
node
);
extern
FILE
*
gettape
(
void
);
extern
FILE
*
gettape
(
void
);
extern
void
resettape
(
FILE
*
file
);
extern
void
resettape
(
FILE
*
file
);
extern
void
destroytape
(
FILE
*
file
);
extern
void
destroytape
(
FILE
*
file
);
...
...
src/man/postgres.1
View file @
f5f366e1
.\" This is -*-nroff-*-
.\" This is -*-nroff-*-
.\" XXX standard disclaimer belongs here....
.\" XXX standard disclaimer belongs here....
.\" $Header: /cvsroot/pgsql/src/man/Attic/postgres.1,v 1.
5 1997/01/26 15:32:20 scrappy
Exp $
.\" $Header: /cvsroot/pgsql/src/man/Attic/postgres.1,v 1.
6 1997/08/06 03:42:18 momjian
Exp $
.TH POSTGRES95 UNIX 12/08/96 Postgres95 Postgres95
.TH POSTGRES95 UNIX 12/08/96 Postgres95 Postgres95
.SH NAME
.SH NAME
postgres \(em the Postgres backend server
postgres \(em the Postgres backend server
...
@@ -79,7 +79,10 @@ is the number of shared-memory buffers that the
...
@@ -79,7 +79,10 @@ is the number of shared-memory buffers that the
.IR "postmaster"
.IR "postmaster"
has allocated for the backend server processes that it starts. If the
has allocated for the backend server processes that it starts. If the
backend is running standalone, this specifies the number of buffers to
backend is running standalone, this specifies the number of buffers to
allocate. This value defaults to 64.
allocate. This value defaults to 64, and each buffer is 8k bytes.
.TP
.BR "-E"
Echo all queries.
.TP
.TP
.BR "-F"
.BR "-F"
Disable automatic fsync() call after each transaction.
Disable automatic fsync() call after each transaction.
...
@@ -96,8 +99,10 @@ useful for interactive use.
...
@@ -96,8 +99,10 @@ useful for interactive use.
.BR "-Q"
.BR "-Q"
Specifies \*(lqquiet\*(rq mode.
Specifies \*(lqquiet\*(rq mode.
.TP
.TP
.BR "-E"
.BR "-S"
Echo all queries.
Specifies the amount of memory to be used by internal sorts before using
disk files for sorting. This value is specified in 1k bytes, and
defaults to 512.
.TP
.TP
.BR "-e"
.BR "-e"
The
The
...
@@ -154,15 +159,6 @@ Turns off the locking system.
...
@@ -154,15 +159,6 @@ Turns off the locking system.
.BR "-N"
.BR "-N"
Disables use of newline as a query delimiter.
Disables use of newline as a query delimiter.
.TP
.TP
.BR "-S"
Indicates that the transaction system can run with the assumption of
stable main memory, thereby avoiding the necessary flushing of data
and log pages to disk at the end of each transaction system. This is
only used for performance comparisons for stable vs. non-stable
storage. Do not use this in other cases, as recovery after a system
crash may be impossible when this option is specified in the absence
of stable main memory.
.TP
.BR "-b"
.BR "-b"
Enables generation of bushy query plan trees (as opposed to left-deep
Enables generation of bushy query plan trees (as opposed to left-deep
query plans trees). These query plans are not intended for actual
query plans trees). These query plans are not intended for actual
...
...
src/man/postmaster.1
View file @
f5f366e1
.\" This is -*-nroff-*-
.\" This is -*-nroff-*-
.\" XXX standard disclaimer belongs here....
.\" XXX standard disclaimer belongs here....
.\" $Header: /cvsroot/pgsql/src/man/Attic/postmaster.1,v 1.
5 1997/02/19 01:31:30
momjian Exp $
.\" $Header: /cvsroot/pgsql/src/man/Attic/postmaster.1,v 1.
6 1997/08/06 03:42:21
momjian Exp $
.TH POSTMASTER UNIX 11/05/95 PostgreSQL PostgreSQL
.TH POSTMASTER UNIX 11/05/95 PostgreSQL PostgreSQL
.SH "NAME"
.SH "NAME"
postmaster \(em run the Postgres postmaster
postmaster \(em run the Postgres postmaster
...
@@ -60,7 +60,7 @@ understands the following command-line options:
...
@@ -60,7 +60,7 @@ understands the following command-line options:
is the number of shared-memory buffers for the
is the number of shared-memory buffers for the
.IR "postmaster"
.IR "postmaster"
to allocate and manage for the backend server processes that it
to allocate and manage for the backend server processes that it
starts. This value defaults to 64.
starts. This value defaults to 64
, and each buffer is 8k bytes
.
.TP
.TP
.BR "-D" " data_dir"
.BR "-D" " data_dir"
Specifies the directory to use as the root of the tree of database
Specifies the directory to use as the root of the tree of database
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment