-
Notifications
You must be signed in to change notification settings - Fork 19
Unlogged index fix v14 #259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ | |
#include "access/xlog.h" | ||
#include "catalog/catalog.h" | ||
#include "catalog/heap.h" | ||
#include "catalog/index.h" | ||
#include "catalog/pg_am.h" | ||
#include "catalog/pg_proc.h" | ||
#include "catalog/pg_statistic_ext.h" | ||
|
@@ -46,6 +47,7 @@ | |
#include "rewrite/rewriteManip.h" | ||
#include "statistics/statistics.h" | ||
#include "storage/bufmgr.h" | ||
#include "storage/buf_internals.h" | ||
#include "utils/builtins.h" | ||
#include "utils/lsyscache.h" | ||
#include "utils/partcache.h" | ||
|
@@ -80,6 +82,28 @@ static void set_baserel_partition_key_exprs(Relation relation, | |
static void set_baserel_partition_constraint(Relation relation, | ||
RelOptInfo *rel); | ||
|
||
static bool | ||
is_index_valid(Relation index) | ||
{ | ||
if (!index->rd_index->indisvalid) | ||
return false; | ||
|
||
if (index->rd_rel->relpersistence == RELPERSISTENCE_UNLOGGED) | ||
{ | ||
Buffer metapage = ReadBuffer(index, 0); | ||
bool isNew = PageIsNew(BufferGetPage(metapage)); | ||
ReleaseBuffer(metapage); | ||
if (isNew) | ||
{ | ||
Relation heap; | ||
DropRelFileNodesAllBuffers(&index->rd_smgr, 1); | ||
heap = RelationIdGetRelation(index->rd_index->indrelid); | ||
index->rd_indam->ambuild(heap, index, BuildIndexInfo(index)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not confident we're OK to build an index without locking the base relation at a similar level as normal index creation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And perhaps index relation should be locked in AccessExclusiveLock like index_create does. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done, please check once again |
||
RelationClose(heap); | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
/* | ||
* get_relation_info - | ||
|
@@ -221,7 +245,7 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent, | |
* still needs to insert into "invalid" indexes, if they're marked | ||
* indisready. | ||
*/ | ||
if (!index->indisvalid) | ||
if (!is_index_valid(indexRelation)) | ||
{ | ||
index_close(indexRelation, NoLock); | ||
continue; | ||
|
Uh oh!
There was an error while loading. Please reload this page.