Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/backend/access/index/indexam.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
#include "nodes/makefuncs.h"
#include "pgstat.h"
#include "storage/bufmgr.h"
#include "storage/buf_internals.h"
#include "storage/lmgr.h"
#include "storage/predicate.h"
#include "utils/ruleutils.h"
Expand Down Expand Up @@ -114,6 +115,7 @@ static IndexScanDesc index_beginscan_internal(Relation indexRelation,
* ----------------------------------------------------------------
*/


/* ----------------
* index_open - open an index relation by relation OID
*
Expand Down Expand Up @@ -142,6 +144,41 @@ index_open(Oid relationId, LOCKMODE lockmode)
errmsg("\"%s\" is not an index",
RelationGetRelationName(r))));

/*
* NEON: support unogged indexes.
* Data of unlogged indexes is lost after compute restart so we have to reinitialize them to avoid errors.
*/
if (r->rd_rel->relpersistence == RELPERSISTENCE_UNLOGGED)
{
LOCKMODE orig_lockmode = lockmode;
while (true)
{
Buffer metapage = ReadBuffer(r, 0);
bool isNew = PageIsNew(BufferGetPage(metapage));
ReleaseBuffer(metapage);
if (isNew)
{
Relation heap;
if (lockmode != ExclusiveLock)
{
UnlockRelation(r, lockmode);
LockRelation(r, ExclusiveLock);
lockmode = ExclusiveLock;
continue;
}
DropRelFileNodesAllBuffers(&r->rd_smgr, 1);
heap = RelationIdGetRelation(r->rd_index->indrelid);
r->rd_indam->ambuild(heap, r, BuildIndexInfo(r));
RelationClose(heap);
}
break;
}
if (orig_lockmode != lockmode)
{
UnlockRelation(r, lockmode);
LockRelation(r, orig_lockmode);
}
}
return r;
}

Expand Down
39 changes: 1 addition & 38 deletions src/backend/optimizer/util/plancat.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#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"
Expand All @@ -48,8 +47,6 @@
#include "rewrite/rewriteManip.h"
#include "statistics/statistics.h"
#include "storage/bufmgr.h"
#include "storage/buf_internals.h"
#include "storage/lmgr.h"
#include "utils/builtins.h"
#include "utils/lsyscache.h"
#include "utils/partcache.h"
Expand Down Expand Up @@ -84,40 +81,6 @@ 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, LOCKMODE lmode)
{
if (!index->rd_index->indisvalid)
return false;

if (index->rd_rel->relpersistence == RELPERSISTENCE_UNLOGGED)
{
while (true)
{
Buffer metapage = ReadBuffer(index, 0);
bool isNew = PageIsNew(BufferGetPage(metapage));
ReleaseBuffer(metapage);
if (isNew)
{
Relation heap;
if (lmode != ExclusiveLock)
{
UnlockRelation(index, lmode);
LockRelation(index, ExclusiveLock);
lmode = ExclusiveLock;
continue;
}
DropRelFileNodesAllBuffers(&index->rd_smgr, 1);
heap = RelationIdGetRelation(index->rd_index->indrelid);
index->rd_indam->ambuild(heap, index, BuildIndexInfo(index));
RelationClose(heap);
}
break;
}
}
return true;
}

/*
* get_relation_info -
* Retrieves catalog information for a given relation.
Expand Down Expand Up @@ -260,7 +223,7 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent,
* still needs to insert into "invalid" indexes, if they're marked
* indisready.
*/
if (!is_index_valid(indexRelation, lmode))
if (!index->indisvalid)
{
index_close(indexRelation, NoLock);
continue;
Expand Down