@Override public void add(Session session, Row row) { if (trace.isDebugEnabled()) { trace.debug("{0} add {1}", getName(), row); } // safe memory SearchRow newRow = getSearchRow(row); try { addRow(newRow); } finally { store.incrementChangeCount(); } }
public PageBtreeIndex(RegularTable table, int id, String indexName, IndexColumn[] columns, IndexType indexType, boolean create, Session session) { initBaseIndex(table, id, indexName, columns, indexType); if (!database.isStarting() && create) { checkIndexColumnTypes(columns); } else { rootPageId = store.getRootPageId(id); PageBtree root = getPage(rootPageId); rowCount = root.getRowCount(); trace.debug("opened {0} rows: {1}", getName() , rowCount);
int i = (l + r) >>> 1; SearchRow row = getRow(i); comp = index.compareRows(row, compare); if (comp == 0) { if (add && index.indexType.isUnique()) { if (!index.mayHaveNullDuplicates(compare)) { throw index.getDuplicateKeyException(compare.toString()); comp = index.compareKeys(row, compare); if (comp == 0) { return i;
@Override int getRowCount() { if (rowCount == UNKNOWN_ROWCOUNT) { int count = 0; for (int i = 0; i < entryCount + 1; i++) { int child = childPageIds[i]; PageBtree page = index.getPage(child); count += page.getRowCount(); index.getDatabase().setProgress( DatabaseEventListener.STATE_SCAN_FILE, index.getName(), count, Integer.MAX_VALUE); } rowCount = count; } return rowCount; }
@Override SearchRow remove(SearchRow row) { int at = find(row, false, false, true); SearchRow delete = getRow(at); if (index.compareRows(row, delete) != 0 || delete.getKey() != row.getKey()) { throw DbException.get(ErrorCode.ROW_NOT_FOUND_WHEN_DELETING_1, index.getSQL() + ": " + row); } index.getPageStore().logUndo(this, data); if (entryCount == 1) { // the page is now empty return row; } removeRow(at); memoryChange(); index.getPageStore().update(this); if (at == entryCount) { // the last row changed return getRow(at - 1); } // the last row didn't change return null; }
int i = (l + r) >>> 1; SearchRow row = getRow(i); comp = index.compareRows(row, compare); if (comp == 0) { if (add && index.indexType.isUnique()) { if (!index.containsNullAndAllowMultipleNull(compare)) { throw index.getDuplicateKeyException(compare.toString()); comp = index.compareKeys(row, compare); if (comp == 0) { return i;
@Override public String toString() { return "page[" + getPos() + "] b-tree leaf table:" + index.getId() + " entries:" + entryCount; }
private PageBtreeNode(PageBtreeIndex index, int pageId, Data data) { super(index, pageId, data); this.pageStoreInternalCount = index.getDatabase(). getSettings().pageStoreInternalCount; }
@Override public Cursor findNext(Session session, SearchRow first, SearchRow last) { return find(session, first, true, last); }
@Override public double getCost(Session session, int[] masks, TableFilter[] filters, int filter, SortOrder sortOrder, HashSet<Column> allColumnsSet) { return 10 * getCostRangeIndex(masks, tableData.getRowCount(session), filters, filter, sortOrder, false, allColumnsSet); }
@Override public boolean next() { if (current == null) { return false; } if (i >= current.getEntryCount()) { current.nextPage(this); if (current == null) { return false; } } currentSearchRow = current.getRow(i); currentRow = null; if (last != null && index.compareRows(currentSearchRow, last) > 0) { currentSearchRow = null; return false; } i++; return true; }
indexType, true, create, session); } else { index = new PageBtreeIndex(this, indexId, indexName, cols, indexType, create, session);
@Override int getRowCount() { if (rowCount == UNKNOWN_ROWCOUNT) { int count = 0; for (int i = 0; i < entryCount + 1; i++) { int child = childPageIds[i]; PageBtree page = index.getPage(child); count += page.getRowCount(); index.getDatabase().setProgress( DatabaseEventListener.STATE_SCAN_FILE, index.getName(), count, Integer.MAX_VALUE); } rowCount = count; } return rowCount; }
@Override SearchRow remove(SearchRow row) { int at = find(row, false, false, true); SearchRow delete = getRow(at); if (index.compareRows(row, delete) != 0 || delete.getKey() != row.getKey()) { throw DbException.get(ErrorCode.ROW_NOT_FOUND_WHEN_DELETING_1, index.getSQL() + ": " + row); } index.getPageStore().logUndo(this, data); if (entryCount == 1) { // the page is now empty return row; } removeRow(at); memoryChange(); index.getPageStore().update(this); if (at == entryCount) { // the last row changed return getRow(at - 1); } // the last row didn't change return null; }
int i = (l + r) >>> 1; SearchRow row = getRow(i); comp = index.compareRows(row, compare); if (comp == 0) { if (add && index.indexType.isUnique()) { if (!index.containsNullAndAllowMultipleNull(compare)) { throw index.getDuplicateKeyException(compare.toString()); comp = index.compareKeys(row, compare); if (comp == 0) { return i;
@Override public String toString() { return "page[" + getPos() + "] b-tree node table:" + index.getId() + " entries:" + entryCount; }
private PageBtreeLeaf(PageBtreeIndex index, int pageId, Data data) { super(index, pageId, data); this.optimizeUpdate = index.getDatabase().getSettings().optimizeUpdate; }
@Override public Cursor find(Session session, SearchRow first, SearchRow last) { return find(session, first, false, last); }