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
7bb11a93
Commit
7bb11a93
authored
Dec 07, 2003
by
Tom Lane
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Speed up findObjectByCatalogId() to get rid of the other salient
bottleneck in the new pg_dump code.
parent
f8495a6b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
71 additions
and
11 deletions
+71
-11
src/bin/pg_dump/common.c
src/bin/pg_dump/common.c
+71
-11
No files found.
src/bin/pg_dump/common.c
View file @
7bb11a93
...
@@ -11,7 +11,7 @@
...
@@ -11,7 +11,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $PostgreSQL: pgsql/src/bin/pg_dump/common.c,v 1.7
8 2003/12/06 03:00:1
1 tgl Exp $
* $PostgreSQL: pgsql/src/bin/pg_dump/common.c,v 1.7
9 2003/12/07 03:14:0
1 tgl Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -37,6 +37,13 @@ static DumpableObject **dumpIdMap = NULL;
...
@@ -37,6 +37,13 @@ static DumpableObject **dumpIdMap = NULL;
static
int
allocedDumpIds
=
0
;
static
int
allocedDumpIds
=
0
;
static
DumpId
lastDumpId
=
0
;
static
DumpId
lastDumpId
=
0
;
/*
* Variables for mapping CatalogId to DumpableObject
*/
static
bool
catalogIdMapValid
=
false
;
static
DumpableObject
**
catalogIdMap
=
NULL
;
static
int
numCatalogIds
=
0
;
/*
/*
* These variables are static to avoid the notational cruft of having to pass
* These variables are static to avoid the notational cruft of having to pass
* them into findTableByOid() and friends.
* them into findTableByOid() and friends.
...
@@ -51,12 +58,13 @@ static int numFuncs;
...
@@ -51,12 +58,13 @@ static int numFuncs;
static
int
numOperators
;
static
int
numOperators
;
static
void
findParentsByOid
(
TableInfo
*
self
,
InhInfo
*
inhinfo
,
int
numInherits
);
static
void
flagInhTables
(
TableInfo
*
tbinfo
,
int
numTables
,
static
void
flagInhTables
(
TableInfo
*
tbinfo
,
int
numTables
,
InhInfo
*
inhinfo
,
int
numInherits
);
InhInfo
*
inhinfo
,
int
numInherits
);
static
void
flagInhAttrs
(
TableInfo
*
tbinfo
,
int
numTables
,
static
void
flagInhAttrs
(
TableInfo
*
tbinfo
,
int
numTables
,
InhInfo
*
inhinfo
,
int
numInherits
);
InhInfo
*
inhinfo
,
int
numInherits
);
static
int
DOCatalogIdCompare
(
const
void
*
p1
,
const
void
*
p2
);
static
void
findParentsByOid
(
TableInfo
*
self
,
InhInfo
*
inhinfo
,
int
numInherits
);
static
int
strInArray
(
const
char
*
pattern
,
char
**
arr
,
int
arr_size
);
static
int
strInArray
(
const
char
*
pattern
,
char
**
arr
,
int
arr_size
);
...
@@ -413,6 +421,9 @@ AssignDumpId(DumpableObject *dobj)
...
@@ -413,6 +421,9 @@ AssignDumpId(DumpableObject *dobj)
allocedDumpIds
=
newAlloc
;
allocedDumpIds
=
newAlloc
;
}
}
dumpIdMap
[
dobj
->
dumpId
]
=
dobj
;
dumpIdMap
[
dobj
->
dumpId
]
=
dobj
;
/* mark catalogIdMap invalid, but don't rebuild it yet */
catalogIdMapValid
=
false
;
}
}
/*
/*
...
@@ -454,25 +465,74 @@ findObjectByDumpId(DumpId dumpId)
...
@@ -454,25 +465,74 @@ findObjectByDumpId(DumpId dumpId)
*
*
* Returns NULL for unknown ID
* Returns NULL for unknown ID
*
*
* NOTE: should hash this, but just do linear search for now
* We use binary search in a sorted list that is built on first call.
* If AssignDumpId() and findObjectByCatalogId() calls were intermixed,
* the code would work, but possibly be very slow. In the current usage
* pattern that does not happen, indeed we only need to build the list once.
*/
*/
DumpableObject
*
DumpableObject
*
findObjectByCatalogId
(
CatalogId
catalogId
)
findObjectByCatalogId
(
CatalogId
catalogId
)
{
{
DumpId
i
;
DumpableObject
**
low
;
DumpableObject
**
high
;
for
(
i
=
1
;
i
<
allocedDumpIds
;
i
++
)
if
(
!
catalogIdMapValid
)
{
{
DumpableObject
*
dobj
=
dumpIdMap
[
i
];
if
(
catalogIdMap
)
free
(
catalogIdMap
);
getDumpableObjects
(
&
catalogIdMap
,
&
numCatalogIds
);
if
(
numCatalogIds
>
1
)
qsort
((
void
*
)
catalogIdMap
,
numCatalogIds
,
sizeof
(
DumpableObject
*
),
DOCatalogIdCompare
);
catalogIdMapValid
=
true
;
}
if
(
dobj
&&
/*
dobj
->
catId
.
tableoid
==
catalogId
.
tableoid
&&
* We could use bsearch() here, but the notational cruft of calling
dobj
->
catId
.
oid
==
catalogId
.
oid
)
* bsearch is nearly as bad as doing it ourselves; and the generalized
return
dobj
;
* bsearch function is noticeably slower as well.
*/
if
(
numCatalogIds
<=
0
)
return
NULL
;
low
=
catalogIdMap
;
high
=
catalogIdMap
+
(
numCatalogIds
-
1
);
while
(
low
<=
high
)
{
DumpableObject
**
middle
;
int
difference
;
middle
=
low
+
(
high
-
low
)
/
2
;
/* comparison must match DOCatalogIdCompare, below */
difference
=
oidcmp
((
*
middle
)
->
catId
.
oid
,
catalogId
.
oid
);
if
(
difference
==
0
)
difference
=
oidcmp
((
*
middle
)
->
catId
.
tableoid
,
catalogId
.
tableoid
);
if
(
difference
==
0
)
return
*
middle
;
else
if
(
difference
<
0
)
low
=
middle
+
1
;
else
high
=
middle
-
1
;
}
}
return
NULL
;
return
NULL
;
}
}
static
int
DOCatalogIdCompare
(
const
void
*
p1
,
const
void
*
p2
)
{
DumpableObject
*
obj1
=
*
(
DumpableObject
**
)
p1
;
DumpableObject
*
obj2
=
*
(
DumpableObject
**
)
p2
;
int
cmpval
;
/*
* Compare OID first since it's usually unique, whereas there will
* only be a few distinct values of tableoid.
*/
cmpval
=
oidcmp
(
obj1
->
catId
.
oid
,
obj2
->
catId
.
oid
);
if
(
cmpval
==
0
)
cmpval
=
oidcmp
(
obj1
->
catId
.
tableoid
,
obj2
->
catId
.
tableoid
);
return
cmpval
;
}
/*
/*
* Build an array of pointers to all known dumpable objects
* Build an array of pointers to all known dumpable objects
*
*
...
...
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