@Override public Expression optimize(ExpressionColumn expressionColumn, Column column) { return expressions[column.getColumnId()]; }
@Override public double getCost(Session session, int[] masks, TableFilter[] filters, int filter, SortOrder sortOrder, HashSet<Column> allColumnsSet) { for (Column column : columns) { int index = column.getColumnId(); int mask = masks[index]; if ((mask & IndexCondition.EQUALITY) != IndexCondition.EQUALITY) { return Long.MAX_VALUE; } } return 2; }
@Override public double getCost(Session session, int[] masks, TableFilter[] filters, int filter, SortOrder sortOrder, HashSet<Column> allColumnsSet) { for (Column column : columns) { int index = column.getColumnId(); int mask = masks[index]; if ((mask & IndexCondition.EQUALITY) != IndexCondition.EQUALITY) { return Long.MAX_VALUE; } } return 2; }
/** * @param c1 First column. * @param c2 Second column. * @return {@code true} If they are the same. */ public static boolean equals(IndexColumn c1, IndexColumn c2) { return c1.column.getColumnId() == c2.column.getColumnId(); }
/** {@inheritDoc} */ @Override public Index addIndex(Session session, String indexName, int indexId, IndexColumn[] cols, IndexType indexType, boolean create, String indexComment) { assert cols.length == 1 : "len: " + cols.length; int colId = cols[0].column.getColumnId(); assert colId == ID : "colId: " + colId; return index; }
/** * Re-assign column ids after removal of column(s). */ public void refreshColumnIds() { assert columnIds.length == columns.length; for (int pos = 0; pos < columnIds.length; ++pos) columnIds[pos] = columns[pos].getColumnId(); } }
/** * Internal logic to check whether column qualifies for partition extraction or not. * * @param col Column. * @param strict Strict flag. * @return {@code True} if column could be used for partition. */ private boolean isColumnForPartitionPruning0(Column col, boolean strict) { if (affKeyCol == null) return false; int colId = col.getColumnId(); if (colId == affKeyCol.column.getColumnId()) return true; return (affKeyColIsKey || !strict) && desc.isKeyColumn(colId); }
@Override public int getColumnIndex(Column col) { if (col.getColumnId() == mainIndex.getMainIndexColumn()) { return 0; } return -1; }
/** * Check whether the given row contains data. * * @param row the row * @return true if it contains data */ boolean hasData(SearchRow row) { return row.getValue(columns[0].getColumnId()) != null; }
@Override public int getColumnIndex(Column col) { if (col.getColumnId() == mainIndex.getMainIndexColumn()) { return 0; } return -1; }
/** * Check whether columns list contains key or key alias column. * * @param desc Row descriptor. * @param cols Columns list. * @return Result. */ public static boolean containsKeyColumn(GridH2RowDescriptor desc, List<IndexColumn> cols) { for (int i = cols.size() - 1; i >= 0; i--) { if (desc.isKeyColumn(cols.get(i).column.getColumnId())) return true; } return false; }
public HashIndex(RegularTable table, int id, String indexName, IndexColumn[] columns, IndexType indexType) { initBaseIndex(table, id, indexName, columns, indexType); this.indexColumn = columns[0].column.getColumnId(); this.tableData = table; reset(); }
/** * @param data Data. */ public GridH2MetaTable(CreateTableData data) { super(data); ArrayList<Column> cols = data.columns; assert cols.size() == 4 : cols; Column id = cols.get(ID); assert "ID".equals(id.getName()) && id.getType() == Value.INT : cols; assert id.getColumnId() == ID; index = new MetaIndex(); }
public NonUniqueHashIndex(RegularTable table, int id, String indexName, IndexColumn[] columns, IndexType indexType) { initBaseIndex(table, id, indexName, columns, indexType); this.indexColumn = columns[0].column.getColumnId(); this.tableData = table; reset(); }
private void setWhere(Prepared command, int pos, Row row) { for (int i = 0, len = refColumns.length; i < len; i++) { int idx = refColumns[i].column.getColumnId(); Value v = row.getValue(idx); ArrayList<Parameter> params = command.getParameters(); Parameter param = params.get(pos + i); param.setValue(v); } }
private void find(Value v) { v = inColumn.convert(v); int id = inColumn.getColumnId(); start.setValue(id, v); cursor = index.find(tableFilter, start, start); }
/** * Create a search row for this row. * * @param row the row * @return the search row */ private SearchRow getSearchRow(Row row) { SearchRow r = table.getTemplateSimpleRow(columns.length == 1); r.setKeyAndVersion(row); for (Column c : columns) { int idx = c.getColumnId(); r.setValue(idx, row.getValue(idx)); } return r; }
/** * Get the size of a row (only the part that is stored in the index). * * @param dummy a dummy data page to calculate the size * @param row the row * @param onlyPosition whether only the position of the row is stored * @return the number of bytes */ int getRowSize(Data dummy, SearchRow row, boolean onlyPosition) { int rowsize = Data.getVarLongLen(row.getKey()); if (!onlyPosition) { for (Column col : columns) { Value v = row.getValue(col.getColumnId()); rowsize += dummy.getValueLen(v); } } return rowsize; }
/** * Write a row to the data page at the given offset. * * @param data the data * @param offset the offset * @param onlyPosition whether only the position of the row is stored * @param row the row to write */ void writeRow(Data data, int offset, SearchRow row, boolean onlyPosition) { data.setPos(offset); data.writeVarLong(row.getKey()); if (!onlyPosition) { for (Column col : columns) { int idx = col.getColumnId(); data.writeValue(row.getValue(idx)); } } }
private ValueArray convertToKey(SearchRow r) { if (r == null) { return null; } Value[] array = new Value[keyColumns]; for (int i = 0; i < columns.length; i++) { Column c = columns[i]; int idx = c.getColumnId(); Value v = r.getValue(idx); if (v != null) { array[i] = v.convertTo(c.getType()); } } array[keyColumns - 1] = ValueLong.get(r.getKey()); return ValueArray.get(array); }