Debian Codegraph @

src/main/org/h2/mvstore/db/MVDelegateIndex.java

raw
1 /*
2 * Copyright 2004-2023 H2 Group. Multiple-Licensed under the MPL 2.0,
3 * and the EPL 1.0 (https://h2database.com/html/license.html).
4 * Initial Developer: H2 Group
5 */
6 package org.h2.mvstore.db;
7
8 import java.util.List;
9
10 import org.h2.command.query.AllColumnsForPlan;
11 import org.h2.engine.SessionLocal;
12 import org.h2.index.Cursor;
13 import org.h2.index.IndexType;
14 import org.h2.message.DbException;
15 import org.h2.mvstore.MVMap;
16 import org.h2.result.Row;
17 import org.h2.result.RowFactory;
18 import org.h2.result.SearchRow;
19 import org.h2.result.SortOrder;
20 import org.h2.table.Column;
21 import org.h2.table.IndexColumn;
22 import org.h2.table.TableFilter;
23 import org.h2.value.VersionedValue;
24
25 /**
26 * An index that delegates indexing to another index.
27 */
28 public class MVDelegateIndex extends MVIndex<Long, SearchRow> {
29
30 private final MVPrimaryIndex mainIndex;
31
32 public MVDelegateIndex(MVTable table, int id, String name, MVPrimaryIndex mainIndex, IndexType indexType) {
33 super(table, id, name, IndexColumn.wrap(new Column[] { table.getColumn(mainIndex.getMainIndexColumn()) }),
34 1, indexType);
35 this.mainIndex = mainIndex;
36 if (id < 0) {
37 throw DbException.getInternalError(name);
38 }
39 }
40
41 @Override
42 public RowFactory getRowFactory() {
43 return mainIndex.getRowFactory();
44 }
45
46 @Override
47 public void addRowsToBuffer(List<Row> rows, String bufferName) {
48 throw DbException.getInternalError();
49 }
50
51 @Override
52 public void addBufferedRows(List<String> bufferNames) {
53 throw DbException.getInternalError();
54 }
55
56 @Override
57 public MVMap<Long,VersionedValue<SearchRow>> getMVMap() {
58 return mainIndex.getMVMap();
59 }
60
61 @Override
62 public void add(SessionLocal session, Row row) {
63 // nothing to do
64 }
65
66 @Override
67 public Row getRow(SessionLocal session, long key) {
68 return mainIndex.getRow(session, key);
69 }
70
71 @Override
72 public boolean isRowIdIndex() {
73 return true;
74 }
75
76 @Override
77 public boolean canGetFirstOrLast() {
78 return true;
79 }
80
81 @Override
82 public void close(SessionLocal session) {
83 // nothing to do
84 }
85
86 @Override
87 public Cursor find(SessionLocal session, SearchRow first, SearchRow last) {
88 return mainIndex.find(session, first, last);
89 }
90
91 @Override
92 public Cursor findFirstOrLast(SessionLocal session, boolean first) {
93 return mainIndex.findFirstOrLast(session, first);
94 }
95
96 @Override
97 public int getColumnIndex(Column col) {
98 if (col.getColumnId() == mainIndex.getMainIndexColumn()) {
99 return 0;
100 }
101 return -1;
102 }
103
104 @Override
105 public boolean isFirstColumn(Column column) {
106 return getColumnIndex(column) == 0;
107 }
108
109 @Override
110 public double getCost(SessionLocal session, int[] masks,
111 TableFilter[] filters, int filter, SortOrder sortOrder,
112 AllColumnsForPlan allColumnsSet) {
113 return 10 * getCostRangeIndex(masks, mainIndex.getRowCountApproximation(session),
114 filters, filter, sortOrder, true, allColumnsSet);
115 }
116
117 @Override
118 public boolean needRebuild() {
119 return false;
120 }
121
122 @Override
123 public void remove(SessionLocal session, Row row) {
124 // nothing to do
125 }
126
127 @Override
128 public void update(SessionLocal session, Row oldRow, Row newRow) {
129 // nothing to do
130 }
131
132 @Override
133 public void remove(SessionLocal session) {
134 mainIndex.setMainIndexColumn(SearchRow.ROWID_INDEX);
135 }
136
137 @Override
138 public void truncate(SessionLocal session) {
139 // nothing to do
140 }
141
142 @Override
143 public long getRowCount(SessionLocal session) {
144 return mainIndex.getRowCount(session);
145 }
146
147 @Override
148 public long getRowCountApproximation(SessionLocal session) {
149 return mainIndex.getRowCountApproximation(session);
150 }
151
152 }