Skip to content

Commit 410898d

Browse files
committed
create btree params changed for attributes list, metadata: add attrslist
1 parent 8183044 commit 410898d

File tree

4 files changed

+46
-26
lines changed

4 files changed

+46
-26
lines changed

src/backend/access/smerge/smbtree.c

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@ create_false_node(void) {
2121

2222

2323
IndexStmt*
24-
create_btree_index_stmt(Relation heap, IndexInfo *indexInfo, char *indname) {
24+
create_btree_index_stmt(Relation heap, int attsnum, AttrNumber *attrs, char *indname) {
2525
IndexStmt* btreeIndStmt;
2626
RangeVar* relation;
2727
List* indexParams;
2828
IndexElem* indexElem;
2929

3030
ListCell* head;
3131
ListCell* tail;
32+
ListCell* currCell;
3233

3334
relation = (RangeVar*) palloc(sizeof(RangeVar));
3435
relation->type =T_RangeVar;
@@ -49,28 +50,32 @@ create_btree_index_stmt(Relation heap, IndexInfo *indexInfo, char *indname) {
4950

5051
indexParams = (List*) palloc(sizeof(List));
5152
indexParams->type = T_List;
52-
indexParams->length = 1;
53+
indexParams->length = attsnum;
5354

55+
// currCell = NULL;
56+
// for (int i = 0; i != attsnum; i++) {
5457
// {type = T_IndexElem, name = 0x555555e80688 "uid", expr = 0x0, indexcolname = 0x0, collation = 0x0, opclass = 0x0, ordering = SORTBY_DEFAULT, nulls_ordering = SORTBY_NULLS_DEFAULT}
55-
indexElem = (IndexElem*) palloc(sizeof(IndexElem));
56-
indexElem->type = T_IndexElem;
57-
indexElem->name = heap->rd_att->attrs[indexInfo->ii_KeyAttrNumbers[0] - 1]->attname.data;
58-
indexElem->expr = NULL;
59-
indexElem->indexcolname = NULL;
60-
indexElem->collation = NULL;
61-
indexElem->opclass = NULL;
62-
indexElem->ordering = SORTBY_DEFAULT;
63-
indexElem->nulls_ordering = SORTBY_NULLS_DEFAULT;
58+
indexElem = (IndexElem*) palloc(sizeof(IndexElem));
59+
indexElem->type = T_IndexElem;
60+
indexElem->name = heap->rd_att->attrs[attrs[0] - 1]->attname.data;
61+
indexElem->expr = NULL;
62+
indexElem->indexcolname = NULL;
63+
indexElem->collation = NULL;
64+
indexElem->opclass = NULL;
65+
indexElem->ordering = SORTBY_DEFAULT;
66+
indexElem->nulls_ordering = SORTBY_NULLS_DEFAULT;
6467

65-
head = (ListCell*) palloc(sizeof(ListCell));
66-
indexParams->head = head;
67-
head->data.ptr_value = (void *) indexElem;
68-
head->next = NULL;
68+
// if (currCell != NULL)
6969

70-
tail = (ListCell*) palloc(sizeof(ListCell));
71-
indexParams->tail = tail;
72-
tail->data.ptr_value = (void *) indexElem;
73-
tail->next = NULL;
70+
currCell = (ListCell*) palloc(sizeof(ListCell));
71+
currCell->data.ptr_value = (void *) indexElem;
72+
currCell->next = NULL;
73+
74+
// if (i == 0)
75+
indexParams->head = currCell;
76+
indexParams->tail = currCell;
77+
// if (i == attsnum - 1)
78+
// }
7479

7580
btreeIndStmt->indexParams = indexParams;
7681
btreeIndStmt->options = NULL;

src/backend/access/smerge/smerge.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ smergehandler(PG_FUNCTION_ARGS)
5454
amroutine->amcanorderbyop = false;
5555
amroutine->amcanbackward = false;
5656
amroutine->amcanunique = true;
57-
amroutine->amcanmulticol = false;
57+
amroutine->amcanmulticol = true;
5858
amroutine->amoptionalkey = true;
5959
amroutine->amsearcharray = false;
6060
amroutine->amsearchnulls = false;
@@ -99,7 +99,7 @@ smergebuild(Relation heap, Relation index, IndexInfo *indexInfo)
9999
Oid bt_index;
100100
Page metapage;
101101

102-
btreeIndStmt = create_btree_index_stmt(heap, indexInfo, NULL);
102+
btreeIndStmt = create_btree_index_stmt(heap, indexInfo->ii_NumIndexAttrs, indexInfo->ii_KeyAttrNumbers, NULL);
103103
addr = DefineIndex(RelationGetRelid(heap),
104104
btreeIndStmt,
105105
InvalidOid,
@@ -121,7 +121,7 @@ smergebuild(Relation heap, Relation index, IndexInfo *indexInfo)
121121
/* Construct metapage. */
122122
metapage = (Page) palloc(BLCKSZ);
123123

124-
_sm_init_metadata(metapage, bt_index);
124+
_sm_init_metadata(metapage, bt_index, indexInfo);
125125
_sm_writepage(index, metapage, SMERGE_METAPAGE);
126126

127127

src/backend/access/smerge/smmeta.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,22 @@
33

44

55
void
6-
_sm_init_metadata(Page metapage, Oid bt_index) {
6+
_sm_init_metadata(Page metapage, Oid bt_index, IndexInfo *indexInfo) {
77
SmMetadata* sm_metadata;
88

99
PageInit(metapage, BLCKSZ, 0);
1010

1111
sm_metadata = (SmMetadata*) PageGetContents(metapage);
1212
sm_metadata->K = 132;
1313
sm_metadata->N = 35;
14+
15+
sm_metadata->attnum = indexInfo->ii_NumIndexAttrs;
16+
for (int i = 0; i < sm_metadata->attnum; i++)
17+
sm_metadata->attrs[i] = indexInfo->ii_KeyAttrNumbers[i];
18+
1419
sm_metadata->numList = 1;
1520
sm_metadata->list[0] = bt_index;
21+
memcpy(sm_metadata, PageGetContents(metapage), sizeof(SmMetadata));
1622

1723
((PageHeader) metapage)->pd_lower =
1824
((char *) sm_metadata + sizeof(SmMetadata)) - (char *) metapage;

src/include/access/smerge.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@
1414
#ifndef SMERGE_H
1515
#define SMERGE_H
1616

17+
#include "pg_config_manual.h"
18+
1719
#include "access/amapi.h"
1820
#include "access/itup.h"
1921
#include "access/sdir.h"
2022
#include "access/xlogreader.h"
23+
#include "access/attnum.h"
24+
2125
#include "catalog/pg_index.h"
2226
#include "lib/stringinfo.h"
2327
#include "storage/bufmgr.h"
@@ -38,7 +42,8 @@
3842
* Define constants here
3943
*/
4044
#define SMERGE_METAPAGE 0
41-
45+
#define MAX_K 16
46+
#define MAX_N 8
4247

4348
/*
4449
* prototypes for functions in smerge.c (external entry points for smerge)
@@ -71,6 +76,10 @@ extern void smergecostestimate(PlannerInfo *root, IndexPath *path, double loop_c
7176
typedef struct SmMetadata {
7277
int K;
7378
int N;
79+
80+
int attnum;
81+
AttrNumber attrs[INDEX_MAX_KEYS];
82+
7483
int numList;
7584
Oid list[64];
7685
} SmMetadata;
@@ -88,12 +97,12 @@ typedef SmScanOpaqueData* SmScanOpaque;
8897

8998
// btree create functions
9099
extern Node* create_false_node(void);
91-
extern IndexStmt* create_btree_index_stmt(Relation heap, IndexInfo *indexInfo, char *indname);
100+
extern IndexStmt* create_btree_index_stmt(Relation heap, int attsnum, AttrNumber *attrs, char *indname);
92101

93102
/*
94103
* start smerge specific
95104
*/
96-
extern void _sm_init_metadata(Page metapage, Oid bt_index);
105+
extern void _sm_init_metadata(Page metapage, Oid bt_index, IndexInfo *indexInfo);
97106
extern void _sm_writepage(Relation index, Page page, BlockNumber blkno);
98107
extern SmMetadata* _sm_getmetadata(Relation rel);
99108

0 commit comments

Comments
 (0)