Commit 94f282b1 authored by Paras Garg's avatar Paras Garg

changed Makefile and added conf file

parent 3ecce2f2
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/home/paras/git/postgres/install/include/server"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu17",
"cppStandard": "gnu++14",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}
\ No newline at end of file
......@@ -5,17 +5,13 @@ PGFILEDESC = "lsm tree index based on existing btree index"
EXTENSION = lsm
DATA = lsm--1.0.sql
REGRESS = test
REGRESS_OPTS = --temp-config $(top_srcdir)/contrib/lsm3/lsm3.conf
#REGRESS = test
#REGRESS_OPTS = --temp-config $(top_srcdir)/contrib/lsm3/lsm3.conf
ifdef USE_PGXS
PG_CONFIG ?= pg_config
# postgres build stuff
PG_CONFIG = pg_config
PGXS := $(shell $(PG_CONFIG) --pgxs)
include $(PGXS)
else
subdir = contrib/lsm3
top_builddir = ../..
include $(top_builddir)/src/Makefile.global
include $(top_srcdir)/contrib/contrib-global.mk
endif
......@@ -31,47 +31,47 @@
#include "storage/lmgr.h"
#include "storage/procarray.h"
#include "lsm3.h"
#include "lsm.h"
#ifdef PG_MODULE_MAGIC
PG_MODULE_MAGIC;
#endif
PG_FUNCTION_INFO_V1(lsm3_handler);
PG_FUNCTION_INFO_V1(lsm3_btree_wrapper);
PG_FUNCTION_INFO_V1(lsm3_get_merge_count);
PG_FUNCTION_INFO_V1(lsm3_start_merge);
PG_FUNCTION_INFO_V1(lsm3_wait_merge_completion);
PG_FUNCTION_INFO_V1(lsm3_top_index_size);
PG_FUNCTION_INFO_V1(lsm_handler);
PG_FUNCTION_INFO_V1(lsm_btree_wrapper);
PG_FUNCTION_INFO_V1(lsm_get_merge_count);
PG_FUNCTION_INFO_V1(lsm_start_merge);
PG_FUNCTION_INFO_V1(lsm_wait_merge_completion);
PG_FUNCTION_INFO_V1(lsm_top_index_size);
extern void _PG_init(void);
extern void _PG_fini(void);
extern void lsm3_merger_main(Datum arg);
extern void lsm_merger_main(Datum arg);
/* Lsm3 dictionary (hashtable with control data for all indexes) */
static Lsm3DictEntry* Lsm3Entry;
static HTAB* Lsm3Dict;
static LWLock* Lsm3DictLock;
static List* Lsm3ReleasedLocks;
/* lsm dictionary (hashtable with control data for all indexes) */
static lsmDictEntry* lsmEntry;
static HTAB* lsmDict;
static LWLock* lsmDictLock;
static List* lsmReleasedLocks;
/* Kind of relation optioms for Lsm3 index */
static relopt_kind Lsm3ReloptKind;
/* Kind of relation optioms for lsm index */
static relopt_kind lsmReloptKind;
/* Lsm3 kooks */
/* lsm kooks */
static ProcessUtility_hook_type PreviousProcessUtilityHook = NULL;
static shmem_startup_hook_type PreviousShmemStartupHook = NULL;
static ExecutorFinish_hook_type PreviousExecutorFinish = NULL;
/* Lsm3 GUCs */
static int Lsm3MaxIndexes;
static int Lsm3TopIndexSize;
/* lsm GUCs */
static int lsmMaxIndexes;
static int lsmTopIndexSize;
/* Background worker termination flag */
static volatile bool Lsm3Cancel;
static volatile bool lsmCancel;
static void
lsm3_shmem_startup(void)
lsm_shmem_startup(void)
{
HASHCTL info;
......@@ -81,17 +81,17 @@ lsm3_shmem_startup(void)
}
memset(&info, 0, sizeof(info));
info.keysize = sizeof(Oid);
info.entrysize = sizeof(Lsm3DictEntry);
Lsm3Dict = ShmemInitHash("lsm3 hash",
Lsm3MaxIndexes, Lsm3MaxIndexes,
info.entrysize = sizeof(lsmDictEntry);
lsmDict = ShmemInitHash("lsm hash",
lsmMaxIndexes, lsmMaxIndexes,
&info,
HASH_ELEM | HASH_BLOBS);
Lsm3DictLock = &(GetNamedLWLockTranche("lsm3"))->lock;
lsmDictLock = &(GetNamedLWLockTranche("lsm"))->lock;
}
/* Initialize Lsm3 control data entry */
/* Initialize lsm control data entry */
static void
lsm3_init_entry(Lsm3DictEntry* entry, Relation index)
lsm_init_entry(lsmDictEntry* entry, Relation index)
{
SpinLockInit(&entry->spinlock);
entry->active_index = 0;
......@@ -105,12 +105,12 @@ lsm3_init_entry(Lsm3DictEntry* entry, Relation index)
entry->heap = index->rd_index->indrelid;
entry->db_id = MyDatabaseId;
entry->user_id = GetUserId();
entry->top_index_size = index->rd_options ? ((Lsm3Options*)index->rd_options)->top_index_size : 0;
entry->top_index_size = index->rd_options ? ((lsmOptions*)index->rd_options)->top_index_size : 0;
}
/* Get B-Tree index size (number of blocks) */
static BlockNumber
lsm3_get_index_size(Oid relid)
lsm_get_index_size(Oid relid)
{
Relation index = index_open(relid, AccessShareLock);
BlockNumber size = RelationGetNumberOfBlocks(index);
......@@ -118,66 +118,66 @@ lsm3_get_index_size(Oid relid)
return size;
}
/* Lookup or create Lsm3 control data for this index */
static Lsm3DictEntry*
lsm3_get_entry(Relation index)
/* Lookup or create lsm control data for this index */
static lsmDictEntry*
lsm_get_entry(Relation index)
{
Lsm3DictEntry* entry;
lsmDictEntry* entry;
bool found = true;
LWLockAcquire(Lsm3DictLock, LW_SHARED);
entry = (Lsm3DictEntry*)hash_search(Lsm3Dict, &RelationGetRelid(index), HASH_FIND, &found);
LWLockAcquire(lsmDictLock, LW_SHARED);
entry = (lsmDictEntry*)hash_search(lsmDict, &RelationGetRelid(index), HASH_FIND, &found);
if (entry == NULL)
{
/* We need exclusive lock to create new entry */
LWLockRelease(Lsm3DictLock);
LWLockAcquire(Lsm3DictLock, LW_EXCLUSIVE);
entry = (Lsm3DictEntry*)hash_search(Lsm3Dict, &RelationGetRelid(index), HASH_ENTER, &found);
LWLockRelease(lsmDictLock);
LWLockAcquire(lsmDictLock, LW_EXCLUSIVE);
entry = (lsmDictEntry*)hash_search(lsmDict, &RelationGetRelid(index), HASH_ENTER, &found);
}
if (!found)
{
char* relname = RelationGetRelationName(index);
lsm3_init_entry(entry, index);
lsm_init_entry(entry, index);
for (int i = 0; i < 2; i++)
{
char* topidxname = psprintf("%s_top%d", relname, i);
entry->top[i] = get_relname_relid(topidxname, RelationGetNamespace(index));
if (entry->top[i] == InvalidOid)
{
elog(ERROR, "Lsm3: failed to lookup %s index", topidxname);
elog(ERROR, "lsm: failed to lookup %s index", topidxname);
}
}
entry->active_index = lsm3_get_index_size(entry->top[0]) >= lsm3_get_index_size(entry->top[1]) ? 0 : 1;
entry->active_index = lsm_get_index_size(entry->top[0]) >= lsm_get_index_size(entry->top[1]) ? 0 : 1;
}
LWLockRelease(Lsm3DictLock);
LWLockRelease(lsmDictLock);
return entry;
}
/* Launch merger bgworker */
static void
lsm3_launch_bgworker(Lsm3DictEntry* entry)
lsm_launch_bgworker(lsmDictEntry* entry)
{
BackgroundWorker worker;
BackgroundWorkerHandle *handle;
pid_t bgw_pid;
MemSet(&worker, 0, sizeof(worker));
snprintf(worker.bgw_name, sizeof(worker.bgw_name), "lsm3-merger-%d", entry->base);
snprintf(worker.bgw_type, sizeof(worker.bgw_type), "lsm3-merger-%d", entry->base);
snprintf(worker.bgw_name, sizeof(worker.bgw_name), "lsm-merger-%d", entry->base);
snprintf(worker.bgw_type, sizeof(worker.bgw_type), "lsm-merger-%d", entry->base);
worker.bgw_flags = BGWORKER_SHMEM_ACCESS | BGWORKER_BACKEND_DATABASE_CONNECTION;
worker.bgw_start_time = BgWorkerStart_ConsistentState;
worker.bgw_restart_time = BGW_NEVER_RESTART;
strcpy(worker.bgw_function_name, "lsm3_merger_main");
strcpy(worker.bgw_library_name, "lsm3");
strcpy(worker.bgw_function_name, "lsm_merger_main");
strcpy(worker.bgw_library_name, "lsm");
worker.bgw_main_arg = PointerGetDatum(entry);
worker.bgw_notify_pid = MyProcPid;
if (!RegisterDynamicBackgroundWorker(&worker, &handle))
{
elog(ERROR, "Lsm3: failed to start background worker");
elog(ERROR, "lsm: failed to start background worker");
}
if (WaitForBackgroundWorkerStartup(handle, &bgw_pid) != BGWH_STARTED)
{
elog(ERROR, "Lsm3: startup of background worker is failed");
elog(ERROR, "lsm: startup of background worker is failed");
}
entry->merger = BackendPidGetProc(bgw_pid);
for (int n_attempts = 0; entry->merger == NULL || n_attempts < 100; n_attempts++)
......@@ -187,27 +187,27 @@ lsm3_launch_bgworker(Lsm3DictEntry* entry)
}
if (entry->merger == NULL)
{
elog(ERROR, "Lsm3: background worker %d is crashed", bgw_pid);
elog(ERROR, "lsm: background worker %d is crashed", bgw_pid);
}
}
/* Cancel merger bgwroker */
static void
lsm3_merge_cancel(int sig)
lsm_merge_cancel(int sig)
{
Lsm3Cancel = true;
lsmCancel = true;
SetLatch(MyLatch);
}
/* Truncate top index */
static void
lsm3_truncate_index(Oid index_oid, Oid heap_oid)
lsm_truncate_index(Oid index_oid, Oid heap_oid)
{
Relation index = index_open(index_oid, AccessExclusiveLock);
Relation heap = table_open(heap_oid, AccessShareLock); /* heap is actually not used, because we will not load data to top indexes */
IndexInfo* indexInfo = BuildDummyIndexInfo(index);
RelationTruncate(index, 0);
elog(LOG, "Lsm3: truncate index %s", RelationGetRelationName(index));
elog(LOG, "lsm: truncate index %s", RelationGetRelationName(index));
index_build(heap, index, indexInfo, true, false);
index_close(index, AccessExclusiveLock);
table_close(heap, AccessShareLock);
......@@ -215,7 +215,7 @@ lsm3_truncate_index(Oid index_oid, Oid heap_oid)
/* Merge top index into base index */
static void
lsm3_merge_indexes(Oid dst_oid, Oid src_oid, Oid heap_oid)
lsm_merge_indexes(Oid dst_oid, Oid src_oid, Oid heap_oid)
{
Relation top_index = index_open(src_oid, AccessShareLock);
Relation heap = table_open(heap_oid, AccessShareLock);
......@@ -224,7 +224,7 @@ lsm3_merge_indexes(Oid dst_oid, Oid src_oid, Oid heap_oid)
bool ok;
Oid save_am = base_index->rd_rel->relam;
elog(LOG, "Lsm3: merge top index %s with size %d blocks", RelationGetRelationName(top_index), RelationGetNumberOfBlocks(top_index));
elog(LOG, "lsm: merge top index %s with size %d blocks", RelationGetRelationName(top_index), RelationGetNumberOfBlocks(top_index));
base_index->rd_rel->relam = BTREE_AM_OID;
scan = index_beginscan(heap, top_index, SnapshotAny, 0, 0);
......@@ -247,14 +247,14 @@ lsm3_merge_indexes(Oid dst_oid, Oid src_oid, Oid heap_oid)
unsigned short save_info = itup->t_info;
itup->t_info = (save_info & ~(INDEX_SIZE_MASK | INDEX_ALT_TID_MASK)) + BTreeTupleGetPostingOffset(itup);
itup->t_tid = scan->xs_heaptid;
_bt_doinsert(base_index, itup, false, heap); /* lsm3 index is not unique so need not to heck for duplica
_bt_doinsert(base_index, itup, false, heap); /* lsm index is not unique so need not to heck for duplica
tes */
itup->t_tid = save_tid;
itup->t_info = save_info;
}
else
{
_bt_doinsert(base_index, itup, false, heap); /* lsm3 index is not unique so need not to heck for duplica
_bt_doinsert(base_index, itup, false, heap); /* lsm index is not unique so need not to heck for duplica
tes */
}
}
......@@ -265,10 +265,10 @@ tes */
table_close(heap, AccessShareLock);
}
/* Lsm3 index options.
/* lsm index options.
*/
static bytea *
lsm3_options(Datum reloptions, bool validate)
lsm_options(Datum reloptions, bool validate)
{
static const relopt_parse_elt tab[] = {
{"fillfactor", RELOPT_TYPE_INT, offsetof(BTOptions, fillfactor)},
......@@ -276,41 +276,41 @@ lsm3_options(Datum reloptions, bool validate)
offsetof(BTOptions, vacuum_cleanup_index_scale_factor)},
{"deduplicate_items", RELOPT_TYPE_BOOL,
offsetof(BTOptions, deduplicate_items)},
{"top_index_size", RELOPT_TYPE_INT, offsetof(Lsm3Options, top_index_size)},
{"unique", RELOPT_TYPE_BOOL, offsetof(Lsm3Options, unique)}
{"top_index_size", RELOPT_TYPE_INT, offsetof(lsmOptions, top_index_size)},
{"unique", RELOPT_TYPE_BOOL, offsetof(lsmOptions, unique)}
};
return (bytea *) build_reloptions(reloptions, validate, Lsm3ReloptKind,
sizeof(Lsm3Options), tab, lengthof(tab));
return (bytea *) build_reloptions(reloptions, validate, lsmReloptKind,
sizeof(lsmOptions), tab, lengthof(tab));
}
/* Main function of merger bgwroker */
void
lsm3_merger_main(Datum arg)
lsm_merger_main(Datum arg)
{
Lsm3DictEntry* entry = (Lsm3DictEntry*)DatumGetPointer(arg);
lsmDictEntry* entry = (lsmDictEntry*)DatumGetPointer(arg);
char *appname;
pqsignal(SIGINT, lsm3_merge_cancel);
pqsignal(SIGQUIT, lsm3_merge_cancel);
pqsignal(SIGTERM, lsm3_merge_cancel);
pqsignal(SIGINT, lsm_merge_cancel);
pqsignal(SIGQUIT, lsm_merge_cancel);
pqsignal(SIGTERM, lsm_merge_cancel);
/* We're now ready to receive signals */
BackgroundWorkerUnblockSignals();
BackgroundWorkerInitializeConnectionByOid(entry->db_id, entry->user_id, 0);
appname = psprintf("lsm3 merger for %d", entry->base);
appname = psprintf("lsm merger for %d", entry->base);
pgstat_report_appname(appname);
pfree(appname);
while (!Lsm3Cancel)
while (!lsmCancel)
{
int merge_index= -1;
int wr;
pgstat_report_activity(STATE_IDLE, "waiting");
wr = WaitLatch(MyLatch, WL_LATCH_SET | WL_EXIT_ON_PM_DEATH, -1L, PG_WAIT_EXTENSION);
if ((wr & WL_POSTMASTER_DEATH) || Lsm3Cancel)
if ((wr & WL_POSTMASTER_DEATH) || lsmCancel)
{
break;
}
......@@ -331,10 +331,10 @@ lsm3_merger_main(Datum arg)
StartTransactionCommand();
{
pgstat_report_activity(STATE_RUNNING, "merging");
lsm3_merge_indexes(entry->base, entry->top[merge_index], entry->heap);
lsm_merge_indexes(entry->base, entry->top[merge_index], entry->heap);
pgstat_report_activity(STATE_RUNNING, "truncate");
lsm3_truncate_index(entry->top[merge_index], entry->heap);
lsm_truncate_index(entry->top[merge_index], entry->heap);
}
CommitTransactionCommand();
......@@ -348,7 +348,7 @@ lsm3_merger_main(Datum arg)
/* Build index tuple comparator context */
static SortSupport
lsm3_build_sortkeys(Relation index)
lsm_build_sortkeys(Relation index)
{
int keysz = IndexRelationGetNumberOfKeyAttributes(index);
SortSupport sortKeys = (SortSupport) palloc0(keysz * sizeof(SortSupportData));
......@@ -384,7 +384,7 @@ lsm3_build_sortkeys(Relation index)
/* Compare index tuples */
static int
lsm3_compare_index_tuples(IndexScanDesc scan1, IndexScanDesc scan2, SortSupport sortKeys)
lsm_compare_index_tuples(IndexScanDesc scan1, IndexScanDesc scan2, SortSupport sortKeys)
{
int n_keys = IndexRelationGetNumberOfKeyAttributes(scan1->indexRelation);
......@@ -408,20 +408,20 @@ lsm3_compare_index_tuples(IndexScanDesc scan1, IndexScanDesc scan2, SortSupport
}
/*
* Lsm3 access methods implementation
* lsm access methods implementation
*/
static IndexBuildResult *
lsm3_build(Relation heap, Relation index, IndexInfo *indexInfo)
lsm_build(Relation heap, Relation index, IndexInfo *indexInfo)
{
Oid save_am = index->rd_rel->relam;
IndexBuildResult * result;
bool found;
LWLockAcquire(Lsm3DictLock, LW_EXCLUSIVE); /* Obtain exclusive lock on dictionary: it will be released in utility hook */
Lsm3Entry = hash_search(Lsm3Dict, &RelationGetRelid(index), HASH_ENTER, &found); /* Setting Lsm3Entry indicates to utility hook that Lsm3 index was created */
LWLockAcquire(lsmDictLock, LW_EXCLUSIVE); /* Obtain exclusive lock on dictionary: it will be released in utility hook */
lsmEntry = hash_search(lsmDict, &RelationGetRelid(index), HASH_ENTER, &found); /* Setting lsmEntry indicates to utility hook that lsm index was created */
if (!found)
{
lsm3_init_entry(Lsm3Entry, index);
lsm_init_entry(lsmEntry, index);
}
index->rd_rel->relam = BTREE_AM_OID;
result = btbuild(heap, index, indexInfo);
......@@ -432,19 +432,19 @@ lsm3_build(Relation heap, Relation index, IndexInfo *indexInfo)
/* Insert in active top index, on overflow swap active indexes and initiate merge to base index */
static bool
lsm3_insert(Relation rel, Datum *values, bool *isnull,
lsm_insert(Relation rel, Datum *values, bool *isnull,
ItemPointer ht_ctid, Relation heapRel,
IndexUniqueCheck checkUnique,
IndexInfo *indexInfo)
{
Lsm3DictEntry* entry = lsm3_get_entry(rel);
lsmDictEntry* entry = lsm_get_entry(rel);
int active_index;
uint64 n_merges; /* used to check if merge was initiated by somebody else */
Relation index;
Oid save_am;
bool overflow;
int top_index_size = entry->top_index_size ? entry->top_index_size : Lsm3TopIndexSize;
int top_index_size = entry->top_index_size ? entry->top_index_size : lsmTopIndexSize;
/* Obtain current active index and increment access counter under spinlock */
SpinLockAcquire(&entry->spinlock);
......@@ -462,7 +462,7 @@ lsm3_insert(Relation rel, Datum *values, bool *isnull,
index->rd_rel->relam = save_am;
overflow = !entry->merge_in_progress /* do not check for overflow if merge was already initiated */
&& (entry->n_inserts % LSM3_CHECK_TOP_INDEX_SIZE_PERIOD) == 0 /* perform check only each N-th insert */
&& (entry->n_inserts % lsm_CHECK_TOP_INDEX_SIZE_PERIOD) == 0 /* perform check only each N-th insert */
&& RelationGetNumberOfBlocks(index)*(BLCKSZ/1024) > top_index_size;
SpinLockAcquire(&entry->spinlock);
......@@ -487,7 +487,7 @@ lsm3_insert(Relation rel, Datum *values, bool *isnull,
if (LockHeldByMe(&tag, RowExclusiveLock))
{
LockRelease(&tag, RowExclusiveLock, false);
Lsm3ReleasedLocks = lappend_oid(Lsm3ReleasedLocks, entry->top[1-active_index]);
lsmReleasedLocks = lappend_oid(lsmReleasedLocks, entry->top[1-active_index]);
}
/* If all inserts in previous active index are completed then we can start merge */
......@@ -496,7 +496,7 @@ lsm3_insert(Relation rel, Datum *values, bool *isnull,
entry->start_merge = true;
if (entry->merger == NULL) /* lazy start of bgworker */
{
lsm3_launch_bgworker(entry);
lsm_launch_bgworker(entry);
}
SetLatch(&entry->merger->procLatch);
}
......@@ -507,10 +507,10 @@ lsm3_insert(Relation rel, Datum *values, bool *isnull,
}
static IndexScanDesc
lsm3_beginscan(Relation rel, int nkeys, int norderbys)
lsm_beginscan(Relation rel, int nkeys, int norderbys)
{
IndexScanDesc scan;
Lsm3ScanOpaque* so;
lsmScanOpaque* so;
int i;
/* no order by operators allowed */
......@@ -519,9 +519,9 @@ lsm3_beginscan(Relation rel, int nkeys, int norderbys)
/* get the scan */
scan = RelationGetIndexScan(rel, nkeys, norderbys);
scan->xs_itupdesc = RelationGetDescr(rel);
so = (Lsm3ScanOpaque*)palloc(sizeof(Lsm3ScanOpaque));
so->entry = lsm3_get_entry(rel);
so->sortKeys = lsm3_build_sortkeys(rel);
so = (lsmScanOpaque*)palloc(sizeof(lsmScanOpaque));
so->entry = lsm_get_entry(rel);
so->sortKeys = lsm_build_sortkeys(rel);
for (i = 0; i < 2; i++)
{
so->top_index[i] = index_open(so->entry->top[i], AccessShareLock);
......@@ -534,7 +534,7 @@ lsm3_beginscan(Relation rel, int nkeys, int norderbys)
so->scan[i]->xs_want_itup = true;
so->scan[i]->parallel_scan = NULL;
}
so->unique = rel->rd_options ? ((Lsm3Options*)rel->rd_options)->unique : false;
so->unique = rel->rd_options ? ((lsmOptions*)rel->rd_options)->unique : false;
so->curr_index = -1;
scan->opaque = so;
......@@ -542,10 +542,10 @@ lsm3_beginscan(Relation rel, int nkeys, int norderbys)
}
static void
lsm3_rescan(IndexScanDesc scan, ScanKey scankey, int nscankeys,
lsm_rescan(IndexScanDesc scan, ScanKey scankey, int nscankeys,
ScanKey orderbys, int norderbys)
{
Lsm3ScanOpaque* so = (Lsm3ScanOpaque*) scan->opaque;
lsmScanOpaque* so = (lsmScanOpaque*) scan->opaque;
so->curr_index = -1;
for (int i = 0; i < 3; i++)
......@@ -556,9 +556,9 @@ lsm3_rescan(IndexScanDesc scan, ScanKey scankey, int nscankeys,
}
static void
lsm3_endscan(IndexScanDesc scan)
lsm_endscan(IndexScanDesc scan)
{
Lsm3ScanOpaque* so = (Lsm3ScanOpaque*) scan->opaque;
lsmScanOpaque* so = (lsmScanOpaque*) scan->opaque;
for (int i = 0; i < 3; i++)
{
......@@ -573,9 +573,9 @@ lsm3_endscan(IndexScanDesc scan)
static bool
lsm3_gettuple(IndexScanDesc scan, ScanDirection dir)
lsm_gettuple(IndexScanDesc scan, ScanDirection dir)
{
Lsm3ScanOpaque* so = (Lsm3ScanOpaque*) scan->opaque;
lsmScanOpaque* so = (lsmScanOpaque*) scan->opaque;
int min = -1;
int curr = so->curr_index;
/* We start with active top index, then merging index and last of all: largest base index */
......@@ -603,7 +603,7 @@ lsm3_gettuple(IndexScanDesc scan, ScanDirection dir)
* then we can stop after locating first occurrence.
* If make it possible to avoid lookups of all three indexes.
*/
elog(DEBUG1, "Lsm3: lookup %d indexes", j+1);
elog(DEBUG1, "lsm: lookup %d indexes", j+1);
while (++j < 3) /* prevent search of all remanining indexes */
{
so->eof[try_index_order[j]] = true;
......@@ -620,7 +620,7 @@ lsm3_gettuple(IndexScanDesc scan, ScanDirection dir)
}
else
{
int result = lsm3_compare_index_tuples(so->scan[i], so->scan[min], so->sortKeys);
int result = lsm_compare_index_tuples(so->scan[i], so->scan[min], so->sortKeys);
if (result == 0)
{
/* Duplicate: it can happen during merge when same tid is both in top and base index */
......@@ -649,9 +649,9 @@ lsm3_gettuple(IndexScanDesc scan, ScanDirection dir)
}
static int64
lsm3_getbitmap(IndexScanDesc scan, TIDBitmap *tbm)
lsm_getbitmap(IndexScanDesc scan, TIDBitmap *tbm)
{
Lsm3ScanOpaque* so = (Lsm3ScanOpaque*)scan->opaque;
lsmScanOpaque* so = (lsmScanOpaque*)scan->opaque;
int64 ntids = 0;
for (int i = 0; i < 3; i++)
{
......@@ -662,7 +662,7 @@ lsm3_getbitmap(IndexScanDesc scan, TIDBitmap *tbm)
}
Datum
lsm3_handler(PG_FUNCTION_ARGS)
lsm_handler(PG_FUNCTION_ARGS)
{
IndexAmRoutine *amroutine = makeNode(IndexAmRoutine);
......@@ -686,22 +686,22 @@ lsm3_handler(PG_FUNCTION_ARGS)
amroutine->amparallelvacuumoptions = 0;
amroutine->amkeytype = InvalidOid;
amroutine->ambuild = lsm3_build;
amroutine->ambuild = lsm_build;
amroutine->ambuildempty = btbuildempty;
amroutine->aminsert = lsm3_insert;
amroutine->aminsert = lsm_insert;
amroutine->ambulkdelete = btbulkdelete;
amroutine->amvacuumcleanup = btvacuumcleanup;
amroutine->amcanreturn = btcanreturn;
amroutine->amcostestimate = btcostestimate;
amroutine->amoptions = lsm3_options;
amroutine->amoptions = lsm_options;
amroutine->amproperty = btproperty;
amroutine->ambuildphasename = btbuildphasename;
amroutine->amvalidate = btvalidate;
amroutine->ambeginscan = lsm3_beginscan;
amroutine->amrescan = lsm3_rescan;
amroutine->amgettuple = lsm3_gettuple;
amroutine->amgetbitmap = lsm3_getbitmap;
amroutine->amendscan = lsm3_endscan;
amroutine->ambeginscan = lsm_beginscan;
amroutine->amrescan = lsm_rescan;
amroutine->amgettuple = lsm_gettuple;
amroutine->amgetbitmap = lsm_getbitmap;
amroutine->amendscan = lsm_endscan;
amroutine->ammarkpos = NULL; /* When do we need index_markpos? Can we live without it? */
amroutine->amrestrpos = NULL;
amroutine->amestimateparallelscan = NULL;
......@@ -717,7 +717,7 @@ lsm3_handler(PG_FUNCTION_ARGS)
/* We do not need to load data in top top index: just initialize index metadata */
static IndexBuildResult *
lsm3_build_empty(Relation heap, Relation index, IndexInfo *indexInfo)
lsm_build_empty(Relation heap, Relation index, IndexInfo *indexInfo)
{
Page metapage;
......@@ -752,7 +752,7 @@ lsm3_build_empty(Relation heap, Relation index, IndexInfo *indexInfo)
}
static bool
lsm3_dummy_insert(Relation rel, Datum *values, bool *isnull,
lsm_dummy_insert(Relation rel, Datum *values, bool *isnull,
ItemPointer ht_ctid, Relation heapRel,
IndexUniqueCheck checkUnique,
IndexInfo *indexInfo)
......@@ -761,7 +761,7 @@ lsm3_dummy_insert(Relation rel, Datum *values, bool *isnull,
}
Datum
lsm3_btree_wrapper(PG_FUNCTION_ARGS)
lsm_btree_wrapper(PG_FUNCTION_ARGS)
{
IndexAmRoutine *amroutine = makeNode(IndexAmRoutine);
......@@ -785,14 +785,14 @@ lsm3_btree_wrapper(PG_FUNCTION_ARGS)
amroutine->amparallelvacuumoptions = 0;
amroutine->amkeytype = InvalidOid;
amroutine->ambuild = lsm3_build_empty;
amroutine->ambuild = lsm_build_empty;
amroutine->ambuildempty = btbuildempty;
amroutine->aminsert = lsm3_dummy_insert;
amroutine->aminsert = lsm_dummy_insert;
amroutine->ambulkdelete = btbulkdelete;
amroutine->amvacuumcleanup = btvacuumcleanup;
amroutine->amcanreturn = btcanreturn;
amroutine->amcostestimate = btcostestimate;
amroutine->amoptions = lsm3_options;
amroutine->amoptions = lsm_options;
amroutine->amproperty = btproperty;
amroutine->ambuildphasename = btbuildphasename;
amroutine->amvalidate = btvalidate;
......@@ -811,10 +811,10 @@ lsm3_btree_wrapper(PG_FUNCTION_ARGS)
}
/*
* Utulity hook handling creation of Lsm3 indexes
* Utulity hook handling creation of lsm indexes
*/
static void
lsm3_process_utility(PlannedStmt *plannedStmt,
lsm_process_utility(PlannedStmt *plannedStmt,
const char *queryString,
ProcessUtilityContext context,
ParamListInfo paramListInfo,
......@@ -833,7 +833,7 @@ lsm3_process_utility(PlannedStmt *plannedStmt,
List* drop_oids = NULL;
ListCell* cell;
Lsm3Entry = NULL; /* Reset entry to check it after utility statement execution */
lsmEntry = NULL; /* Reset entry to check it after utility statement execution */
if (IsA(parseTree, DropStmt))
{
drop = (DropStmt*)parseTree;
......@@ -843,9 +843,9 @@ lsm3_process_utility(PlannedStmt *plannedStmt,
{
RangeVar* rv = makeRangeVarFromNameList((List *) lfirst(cell));
Relation index = relation_openrv(rv, ExclusiveLock);
if (index->rd_indam->ambuild == lsm3_build)
if (index->rd_indam->ambuild == lsm_build)
{
Lsm3DictEntry* entry = lsm3_get_entry(index);
lsmDictEntry* entry = lsm_get_entry(index);
if (drop_objects == NULL)
{
drop_objects = new_object_addresses();
......@@ -874,9 +874,9 @@ lsm3_process_utility(PlannedStmt *plannedStmt,
destReceiver,
completionTag);
if (Lsm3Entry)
if (lsmEntry)
{
if (IsA(parseTree, IndexStmt)) /* This is Lsm3 creation statement */
if (IsA(parseTree, IndexStmt)) /* This is lsm creation statement */
{
IndexStmt* stmt = (IndexStmt*)parseTree;
char* originIndexName = stmt->idxname;
......@@ -888,9 +888,9 @@ lsm3_process_utility(PlannedStmt *plannedStmt,
{
PushActiveSnapshot(GetTransactionSnapshot());
}
stmt->accessMethod = "lsm3_btree_wrapper";
stmt->idxname = psprintf("%s_top%d", get_rel_name(Lsm3Entry->base), i);
Lsm3Entry->top[i] = DefineIndex(Lsm3Entry->heap,
stmt->accessMethod = "lsm_btree_wrapper";
stmt->idxname = psprintf("%s_top%d", get_rel_name(lsmEntry->base), i);
lsmEntry->top[i] = DefineIndex(lsmEntry->heap,
stmt,
InvalidOid,
InvalidOid,
......@@ -908,13 +908,13 @@ lsm3_process_utility(PlannedStmt *plannedStmt,
{
for (int i = 0; i < 2; i++)
{
if (Lsm3Entry->top[i] == InvalidOid)
if (lsmEntry->top[i] == InvalidOid)
{
char* topidxname = psprintf("%s_top%d", get_rel_name(Lsm3Entry->base), i);
Lsm3Entry->top[i] = get_relname_relid(topidxname, get_rel_namespace(Lsm3Entry->base));
if (Lsm3Entry->top[i] == InvalidOid)
char* topidxname = psprintf("%s_top%d", get_rel_name(lsmEntry->base), i);
lsmEntry->top[i] = get_relname_relid(topidxname, get_rel_namespace(lsmEntry->base));
if (lsmEntry->top[i] == InvalidOid)
{
elog(ERROR, "Lsm3: failed to lookup %s index", topidxname);
elog(ERROR, "lsm: failed to lookup %s index", topidxname);
}
}
}
......@@ -928,19 +928,19 @@ lsm3_process_utility(PlannedStmt *plannedStmt,
/* Mark top index as invalid to prevent planner from using it in queries */
for (int i = 0; i < 2; i++)
{
index_set_state_flags(Lsm3Entry->top[i], INDEX_DROP_CLEAR_VALID);
index_set_state_flags(lsmEntry->top[i], INDEX_DROP_CLEAR_VALID);
}
LWLockRelease(Lsm3DictLock); /* Release lock set by lsm3_build */
LWLockRelease(lsmDictLock); /* Release lock set by lsm_build */
}
else if (drop_objects)
{
performMultipleDeletions(drop_objects, drop->behavior, 0);
LWLockAcquire(Lsm3DictLock, LW_EXCLUSIVE);
LWLockAcquire(lsmDictLock, LW_EXCLUSIVE);
foreach (cell, drop_oids)
{
hash_search(Lsm3Dict, &lfirst_oid(cell), HASH_REMOVE, NULL);
hash_search(lsmDict, &lfirst_oid(cell), HASH_REMOVE, NULL);