Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
postgres-lambda-diff
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jakob Huber
postgres-lambda-diff
Commits
604f54cd
Commit
604f54cd
authored
23 years ago
by
Tom Lane
Browse files
Options
Downloads
Patches
Plain Diff
Some minor tweaks of REINDEX processing: grab exclusive lock a little
earlier, make error checks more uniform.
parent
fb726283
No related branches found
Branches containing commit
Tags
REL7_2_BETA3
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/backend/catalog/index.c
+32
-15
32 additions, 15 deletions
src/backend/catalog/index.c
src/backend/commands/indexcmds.c
+5
-3
5 additions, 3 deletions
src/backend/commands/indexcmds.c
src/backend/tcop/utility.c
+11
-2
11 additions, 2 deletions
src/backend/tcop/utility.c
with
48 additions
and
20 deletions
src/backend/catalog/index.c
+
32
−
15
View file @
604f54cd
...
...
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.1
69
2001/11/
05 17:46:24 momjian
Exp $
* $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.1
70
2001/11/
20 02:46:13 tgl
Exp $
*
*
* INTERFACE ROUTINES
...
...
@@ -1874,10 +1874,27 @@ reindex_index(Oid indexId, bool force, bool inplace)
* REINDEX within a transaction block is dangerous, because if the
* transaction is later rolled back we have no way to undo truncation
* of the index's physical file. Disallow it.
*
* XXX if we're not doing an inplace rebuild, wouldn't this be okay?
*/
if
(
IsTransactionBlock
())
elog
(
ERROR
,
"REINDEX cannot run inside a transaction block"
);
/*
* Open our index relation and get an exclusive lock on it.
*
* Note: doing this before opening the parent heap relation means
* there's a possibility for deadlock failure against another xact
* that is doing normal accesses to the heap and index. However,
* it's not real clear why you'd be needing to do REINDEX on a table
* that's in active use, so I'd rather have the protection of making
* sure the index is locked down.
*/
iRel
=
index_open
(
indexId
);
if
(
iRel
==
NULL
)
elog
(
ERROR
,
"reindex_index: can't open index relation"
);
LockRelation
(
iRel
,
AccessExclusiveLock
);
old
=
SetReindexProcessing
(
true
);
/* Scan pg_index to find the index's pg_index entry */
...
...
@@ -1898,22 +1915,17 @@ reindex_index(Oid indexId, bool force, bool inplace)
heap_endscan
(
scan
);
heap_close
(
indexRelation
,
AccessShareLock
);
/* Open
our index
relation */
/* Open
the parent heap
relation */
heapRelation
=
heap_open
(
heapId
,
ExclusiveLock
);
if
(
heapRelation
==
NULL
)
elog
(
ERROR
,
"reindex_index: can't open heap relation"
);
iRel
=
index_open
(
indexId
);
if
(
iRel
==
NULL
)
elog
(
ERROR
,
"reindex_index: can't open index relation"
);
if
(
!
inplace
)
{
inplace
=
iRel
->
rd_rel
->
relisshared
;
if
(
!
inplace
)
setNewRelfilenode
(
iRel
);
}
/* Obtain exclusive lock on it, just to be sure */
LockRelation
(
iRel
,
AccessExclusiveLock
);
/*
* Force inplace processing if it's a shared index. Necessary because
* we have no way to update relfilenode in other databases.
*/
if
(
iRel
->
rd_rel
->
relisshared
)
inplace
=
true
;
if
(
inplace
)
{
...
...
@@ -1928,6 +1940,13 @@ reindex_index(Oid indexId, bool force, bool inplace)
iRel
->
rd_nblocks
=
0
;
iRel
->
rd_targblock
=
InvalidBlockNumber
;
}
else
{
/*
* We'll build a new physical relation for the index.
*/
setNewRelfilenode
(
iRel
);
}
/* Initialize the index and rebuild */
index_build
(
heapRelation
,
iRel
,
indexInfo
);
...
...
@@ -1982,11 +2001,9 @@ reindex_relation(Oid relid, bool force)
HeapTuple
indexTuple
;
bool
old
,
reindexed
;
bool
deactivate_needed
,
overwrite
,
upd_pg_class_inplace
;
Relation
rel
;
overwrite
=
upd_pg_class_inplace
=
deactivate_needed
=
false
;
...
...
This diff is collapsed.
Click to expand it.
src/backend/commands/indexcmds.c
+
5
−
3
View file @
604f54cd
...
...
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.6
0
2001/1
0
/2
5
0
5
:4
9:25 momjian
Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.6
1
2001/1
1
/2
0
0
2
:4
6:13 tgl
Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -637,6 +637,9 @@ ReindexDatabase(const char *dbname, bool force, bool all)
ALLOCSET_DEFAULT_INITSIZE
,
ALLOCSET_DEFAULT_MAXSIZE
);
/*
* Scan pg_class to build a list of the relations we need to reindex.
*/
relationRelation
=
heap_openr
(
RelationRelationName
,
AccessShareLock
);
scan
=
heap_beginscan
(
relationRelation
,
false
,
SnapshotNow
,
0
,
NULL
);
relcnt
=
relalc
=
0
;
...
...
@@ -646,8 +649,6 @@ ReindexDatabase(const char *dbname, bool force, bool all)
{
if
(
!
IsSystemRelationName
(
NameStr
(((
Form_pg_class
)
GETSTRUCT
(
tuple
))
->
relname
)))
continue
;
if
(((
Form_pg_class
)
GETSTRUCT
(
tuple
))
->
relhasrules
)
continue
;
}
if
(((
Form_pg_class
)
GETSTRUCT
(
tuple
))
->
relkind
==
RELKIND_RELATION
)
{
...
...
@@ -670,6 +671,7 @@ ReindexDatabase(const char *dbname, bool force, bool all)
heap_endscan
(
scan
);
heap_close
(
relationRelation
,
AccessShareLock
);
/* Now reindex each rel in a separate transaction */
CommitTransactionCommand
();
for
(
i
=
0
;
i
<
relcnt
;
i
++
)
{
...
...
This diff is collapsed.
Click to expand it.
src/backend/tcop/utility.c
+
11
−
2
View file @
604f54cd
...
...
@@ -10,7 +10,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.12
2
2001/1
0
/2
5
0
5
:4
9:43 momjian
Exp $
* $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.12
3
2001/1
1
/2
0
0
2
:4
6:13 tgl
Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -865,7 +865,7 @@ ProcessUtility(Node *parsetree,
relname
=
(
char
*
)
stmt
->
name
;
if
(
IsSystemRelationName
(
relname
))
{
if
(
!
allowSystemTableMods
&&
IsSystemRelationName
(
relname
)
)
if
(
!
allowSystemTableMods
)
elog
(
ERROR
,
"
\"
%s
\"
is a system index. call REINDEX under standalone postgres with -O -P options"
,
relname
);
if
(
!
IsIgnoringSystemIndexes
())
...
...
@@ -878,6 +878,15 @@ ProcessUtility(Node *parsetree,
break
;
case
TABLE
:
relname
=
(
char
*
)
stmt
->
name
;
if
(
IsSystemRelationName
(
relname
))
{
if
(
!
allowSystemTableMods
)
elog
(
ERROR
,
"
\"
%s
\"
is a system table. call REINDEX under standalone postgres with -O -P options"
,
relname
);
if
(
!
IsIgnoringSystemIndexes
())
elog
(
ERROR
,
"
\"
%s
\"
is a system table. call REINDEX under standalone postgres with -P -O options"
,
relname
);
}
if
(
!
pg_ownercheck
(
GetUserId
(),
relname
,
RELNAME
))
elog
(
ERROR
,
"%s: %s"
,
relname
,
aclcheck_error_strings
[
ACLCHECK_NOT_OWNER
]);
ReindexTable
(
relname
,
stmt
->
force
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment