/** * Create an array of index columns from a list of columns. The default sort * type is used. * * @param columns the column list * @return the index column array */ public static IndexColumn[] wrap(Column[] columns) { IndexColumn[] list = new IndexColumn[columns.length]; for (int i = 0; i < list.length; i++) { list[i] = new IndexColumn(); list[i].column = columns[i]; } return list; }
/** * * @param tbl Table. * @param name Name of the proxy index. * @param colsList Column list for the proxy index. * @param idx Target index. */ public GridH2ProxyIndex(GridH2Table tbl, String name, List<IndexColumn> colsList, Index idx) { IndexColumn[] cols = colsList.toArray(new IndexColumn[colsList.size()]); IndexColumn.mapColumns(cols, tbl); initBaseIndex(tbl, 0, name, cols, IndexType.createNonUnique(false, false, idx instanceof SpatialIndex)); this.idx = idx; }
@Override public String toString() { return "IndexColumn " + getSQL(); } }
@Override public Index getScanIndex(Session session) { return new FunctionIndex(this, IndexColumn.wrap(columns)); }
@Override public Index getScanIndex(Session session) { return new MetaIndex(this, IndexColumn.wrap(columns), true); }
/** * Creates index column for table. * * @param col Column index. * @param sorting Sorting order {@link SortOrder} * @return Created index column. */ public IndexColumn indexColumn(int col, int sorting) { IndexColumn res = new IndexColumn(); res.column = getColumn(col); res.columnName = res.column.getName(); res.sortType = sorting; return res; }
/** * @param ctx Context. * @param tbl Table. * @param name Index name. */ public GridMergeIndexUnsorted(GridKernalContext ctx, GridMergeTable tbl, String name) { super(ctx, tbl, name, TYPE, IndexColumn.wrap(tbl.getColumns())); }
public DbException getNewDuplicateKeyException() { String sql = "PRIMARY KEY ON " + table.getSQL(); if (mainIndexColumn >= 0 && mainIndexColumn < indexColumns.length) { sql += "(" + indexColumns[mainIndexColumn].getSQL() + ")"; } DbException e = DbException.get(ErrorCode.DUPLICATE_KEY_1, sql); e.setSource(this); return e; }
/** * @param cctx Cache context. * @param tbl Table. * @param name Index name. * @param colsList Index columns. * @param segments Segments. */ public H2PkHashIndex( GridCacheContext<?, ?> cctx, GridH2Table tbl, String name, List<IndexColumn> colsList, int segments ) { assert segments > 0: segments; this.segments = segments; IndexColumn[] cols = colsList.toArray(new IndexColumn[colsList.size()]); IndexColumn.mapColumns(cols, tbl); initBaseIndex(tbl, 0, name, cols, IndexType.createPrimaryKey(false, true)); this.tbl = tbl; this.cctx = cctx; }
/** * @param tbl Table. * @param sortCols Sort columns. * @return Index columns. */ public static IndexColumn[] toIndexColumns(Table tbl, List<GridSqlSortColumn> sortCols) { assert !F.isEmpty(sortCols); IndexColumn[] res = new IndexColumn[sortCols.size()]; for (int i = 0; i < res.length; i++) { GridSqlSortColumn sc = sortCols.get(i); Column col = tbl.getColumn(sc.column()); IndexColumn c = new IndexColumn(); c.column = col; c.columnName = col.getName(); c.sortType = sc.asc ? SortOrder.ASCENDING : SortOrder.DESCENDING; if (sc.nullsFirst) c.sortType |= SortOrder.NULLS_FIRST; if (sc.nullsLast) c.sortType |= SortOrder.NULLS_LAST; res[i] = c; } return res; }
@Override public ArrayList<Index> getIndexes() { ArrayList<Index> list = New.arrayList(); if (metaIndex == null) { return list; } list.add(new MetaIndex(this, IndexColumn.wrap(columns), true)); // TODO re-use the index list.add(metaIndex); return list; }
/** * Get the list of columns as a string. * * @return the list of columns */ private String getColumnListSQL() { StatementBuilder buff = new StatementBuilder(); for (IndexColumn c : indexColumns) { buff.appendExceptFirst(", "); buff.append(c.getSQL()); } return buff.toString(); }
/** * @param tbl Table. * @param name Index name. * @param pk Primary key. * @param colsList Index columns. */ public H2TreeClientIndex( GridH2Table tbl, String name, boolean pk, List<IndexColumn> colsList ) { IndexColumn[] cols = colsList.toArray(new IndexColumn[colsList.size()]); IndexColumn.mapColumns(cols, tbl); initBaseIndex(tbl, 0, name, cols, pk ? IndexType.createPrimaryKey(false, false) : IndexType.createNonUnique(false, false, false)); }
private IndexColumn[] parseIndexColumnList() { ArrayList<IndexColumn> columns = New.arrayList(); do { IndexColumn column = new IndexColumn(); column.columnName = readColumnIdentifier(); columns.add(column); if (readIf("ASC")) { // ignore } else if (readIf("DESC")) { column.sortType = SortOrder.DESCENDING; } if (readIf("NULLS")) { if (readIf("FIRST")) { column.sortType |= SortOrder.NULLS_FIRST; } else { read("LAST"); column.sortType |= SortOrder.NULLS_LAST; } } } while (readIfMore(true)); return columns.toArray(new IndexColumn[0]); }
private void addIndex(List<Column> list, IndexType indexType) { // bind the index to the leading recognized columns in the index // (null columns might come from a function-based index) int firstNull = list.indexOf(null); if (firstNull == 0) { trace.info("Omitting linked index - no recognized columns."); return; } else if (firstNull > 0) { trace.info("Unrecognized columns in linked index. " + "Registering the index against the leading {0} " + "recognized columns of {1} total columns.", firstNull, list.size()); list = list.subList(0, firstNull); } Column[] cols = list.toArray(new Column[0]); Index index = new LinkedIndex(this, 0, IndexColumn.wrap(cols), indexType); indexes.add(index); }
for (IndexColumn c : columns) { buff.appendExceptFirst(", "); buff.append(c.getSQL()); for (IndexColumn c : columns) { buff.appendExceptFirst(" AND "); buff.append(c.getSQL()).append(" IS NOT NULL "); for (IndexColumn c : columns) { buff.appendExceptFirst(", "); buff.append(c.getSQL()); for (IndexColumn c : columns) { buff.appendExceptFirst(" AND "); buff.append("C.").append(c.getSQL()).append('='). append("P.").append(refColumns[i++].getSQL());
IndexColumn.mapColumns(cols, tbl);
private void createIndex() { IndexColumn[] indexCols = null; // If we need to do distinct, the distinct columns may not match the // sort columns. So we need to disregard the sort. Not ideal. if (sort != null && !distinct) { int[] colIndex = sort.getQueryColumnIndexes(); indexCols = new IndexColumn[colIndex.length]; for (int i = 0; i < colIndex.length; i++) { IndexColumn indexColumn = new IndexColumn(); indexColumn.column = table.getColumn(colIndex[i]); indexColumn.sortType = sort.getSortTypes()[i]; indexColumn.columnName = COLUMN_NAME + i; indexCols[i] = indexColumn; } } else { indexCols = new IndexColumn[columnCount]; for (int i = 0; i < columnCount; i++) { IndexColumn indexColumn = new IndexColumn(); indexColumn.column = table.getColumn(i); indexColumn.columnName = COLUMN_NAME + i; indexCols[i] = indexColumn; } } String indexName = table.getSchema().getUniqueIndexName(session, table, Constants.PREFIX_INDEX); int indexId = session.getDatabase().allocateObjectId(); IndexType indexType = IndexType.createNonUnique(true); index = table.addIndex(session, indexName, indexId, indexCols, indexType, true, null); }
/** * @param tbl Table. * @param col Column. */ SqlSystemIndex(SqlSystemTable tbl, Column... col) { IndexColumn[] idxCols; if (col != null && col.length > 0) idxCols = IndexColumn.wrap(col); else idxCols = new IndexColumn[0]; initBaseIndex(tbl, 0, null, idxCols, IndexType.createNonUnique(false)); }