Skip to content

Commit 8fe33a7

Browse files
committed
add costestimate 0 -> always uses; creating new btrees when curr is full
1 parent 16558aa commit 8fe33a7

File tree

3 files changed

+40
-5
lines changed

3 files changed

+40
-5
lines changed

src/backend/access/smerge/smbtree.c

+24-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ create_btree_index_stmt(Relation heap, int attsnum, AttrNumber *attrs, char *ind
2727
List* indexParams;
2828
IndexElem* indexElem;
2929

30-
ListCell* head;
3130
ListCell* prevCell;
3231
ListCell* currCell;
3332

@@ -97,3 +96,27 @@ create_btree_index_stmt(Relation heap, int attsnum, AttrNumber *attrs, char *ind
9796
btreeIndStmt->if_not_exists = false;
9897
return btreeIndStmt;
9998
}
99+
100+
ObjectAddress
101+
_sm_create_curr_btree (Relation heap, SmMetadata* metadata) {
102+
IndexStmt* btreeIndStmt;
103+
ObjectAddress addr;
104+
105+
btreeIndStmt = create_btree_index_stmt(heap, metadata->attnum, metadata->attrs, NULL);
106+
addr = DefineIndex(RelationGetRelid(heap),
107+
btreeIndStmt,
108+
InvalidOid,
109+
false,
110+
true,
111+
false,
112+
true);
113+
114+
if ( addr.objectId == InvalidOid ) {
115+
printf("Error creating sub btree index\n");
116+
}
117+
else {
118+
printf("OID: %d \n", addr.objectId);
119+
}
120+
121+
return addr;
122+
}

src/backend/access/smerge/smerge.c

+13-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
#include "utils/memutils.h"
3434

3535
#include "access/nbtree.h"
36-
#include "commands/defrem.h"
3736

3837

3938
#include <string.h>
@@ -197,7 +196,15 @@ smergeinsert(Relation rel, Datum *values, bool *isnull,
197196

198197
if (sm_metadata->currTuples >= MAX_INMEM_TUPLES) {
199198
printf("Exceeded! (:3)\n");
200-
199+
sm_metadata->tree[0][sm_metadata->levels[0]++] = sm_metadata->curr;
200+
ObjectAddress addr = _sm_create_curr_btree(heapRel, sm_metadata);
201+
sm_metadata->currTuples = 0;
202+
if (addr.objectId != InvalidOid)
203+
sm_metadata->curr = addr.objectId;
204+
else
205+
printf("Error in creating a sub-btree\n");
206+
207+
// call merge func here
201208
}
202209

203210
_sm_write_metadata(rel, sm_metadata);
@@ -370,5 +377,8 @@ smergecostestimate(PlannerInfo *root,
370377
Selectivity *indexSelectivity,
371378
double *indexCorrelation)
372379
{
373-
380+
*indexStartupCost = 0.0;
381+
*indexTotalCost = 0.01;
382+
*indexSelectivity = 0.0;
383+
*indexCorrelation = 0.9;
374384
}

src/include/access/smerge.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "access/xlogreader.h"
2323
#include "access/attnum.h"
2424

25+
#include "catalog/objectaddress.h"
2526
#include "catalog/pg_index.h"
2627
#include "lib/stringinfo.h"
2728
#include "storage/bufmgr.h"
@@ -37,7 +38,7 @@
3738
#include "utils/rel.h"
3839

3940
#include "storage/smgr.h"
40-
41+
#include "commands/defrem.h"
4142
/*
4243
* Define constants here
4344
*/
@@ -106,6 +107,7 @@ typedef SmScanOpaqueData* SmScanOpaque;
106107
// btree create functions
107108
extern Node* create_false_node(void);
108109
extern IndexStmt* create_btree_index_stmt(Relation heap, int attsnum, AttrNumber *attrs, char *indname);
110+
extern ObjectAddress _sm_create_curr_btree (Relation heap, SmMetadata* metadata);
109111

110112
/*
111113
* start smerge specific

0 commit comments

Comments
 (0)