Package org.voltdb.catalog

Examples of org.voltdb.catalog.Index


            if (skip_constraints.contains(catalog_const)) continue;
            ConstraintType const_type = ConstraintType.get(catalog_const.getType());

            // Primary Keys / Unique Constraints
            if (const_type == ConstraintType.PRIMARY_KEY || const_type == ConstraintType.UNIQUE) {
                Index catalog_idx = catalog_const.getIndex();
                if (!tableIsView) {
                    // Get the ConstraintType.

                    sb.append(add + spacer);
                    if (!catalog_const.getTypeName().startsWith(HSQLInterface.AUTO_GEN_PREFIX)) {
                        sb.append("CONSTRAINT " + catalog_const.getTypeName() + " ");
                    }
                    if (const_type == ConstraintType.PRIMARY_KEY || const_type == ConstraintType.UNIQUE) {
                        if (const_type == ConstraintType.PRIMARY_KEY) {
                            sb.append("PRIMARY KEY (");
                        }
                        else {
                            if (catalog_idx.getAssumeunique()) {
                                sb.append("ASSUMEUNIQUE (");
                            }
                            else {
                                sb.append("UNIQUE (");
                            }
                        }
                        String col_add = "";
                        String exprStrings = new String();
                        if (catalog_idx.getExpressionsjson() != null && !catalog_idx.getExpressionsjson().equals("")) {
                            StmtTargetTableScan tableScan = new StmtTargetTableScan(catalog_tbl, catalog_tbl.getTypeName());
                            try {
                                List<AbstractExpression> expressions = AbstractExpression.fromJSONArrayString(catalog_idx.getExpressionsjson(), tableScan);
                                String sep = "";
                                for (AbstractExpression expr : expressions) {
                                    exprStrings += sep + expr.explain(catalog_tbl.getTypeName());
                                    sep = ",";
                                }
                            }
                            catch (JSONException e) {
                            }
                            sb.append(col_add + exprStrings);
                        }
                        else {
                            for (ColumnRef catalog_colref : CatalogUtil.getSortedCatalogItems(catalog_idx.getColumns(), "index")) {
                                sb.append(col_add + catalog_colref.getColumn().getTypeName() );
                                col_add = ", ";
                            } // FOR
                        }
                        sb.append(")");
                    }
                    else
                    if (const_type == ConstraintType.LIMIT) {
                        sb.append("LIMIT PARTITION ROWS " + String.valueOf(catalog_tbl.getTuplelimit()) );
                    }

                }
                if (catalog_idx.getTypeName().startsWith(HSQLInterface.AUTO_GEN_PREFIX) ||
                        catalog_idx.getTypeName().startsWith(HSQLInterface.AUTO_GEN_MATVIEW) ) {
                    skip_indexes.add(catalog_idx);
                }

            // Foreign Key
            } else if (const_type == ConstraintType.FOREIGN_KEY) {
                Table catalog_fkey_tbl = catalog_const.getForeignkeytable();
                String col_add = "";
                String our_columns = "";
                String fkey_columns = "";
                for (ColumnRef catalog_colref : catalog_const.getForeignkeycols()) {
                    // The name of the ColumnRef is the column in our base table
                    Column our_column = catalog_tbl.getColumns().getIgnoreCase(catalog_colref.getTypeName());
                    assert(our_column != null);
                    our_columns += col_add + our_column.getTypeName();

                    Column fkey_column = catalog_colref.getColumn();
                    assert(fkey_column != null);
                    fkey_columns += col_add + fkey_column.getTypeName();

                    col_add = ", ";
                }
                sb.append(add + spacer + "CONSTRAINT " + catalog_const.getTypeName() + " " +
                                         "FOREIGN KEY (" + our_columns + ") " +
                                         "REFERENCES " + catalog_fkey_tbl.getTypeName() + " (" + fkey_columns + ")" );
            }
            skip_constraints.add(catalog_const);
        }

        if (catalog_tbl.getTuplelimit() != Integer.MAX_VALUE) {
            sb.append(add + spacer + "LIMIT PARTITION ROWS " + String.valueOf(catalog_tbl.getTuplelimit()) );
        }

        if (viewQuery != null) {
            sb.append("\n) AS \n");
            sb.append(spacer + viewQuery + ";\n");
        }
        else {
            sb.append("\n);\n");
        }

        // Partition Table
        if (catalog_tbl.getPartitioncolumn() != null && viewQuery == null) {
            sb.append("PARTITION TABLE " + catalog_tbl.getTypeName() + " ON COLUMN " +
                    catalog_tbl.getPartitioncolumn().getTypeName() + ";\n" );
        }

        // All other Indexes
        for (Index catalog_idx : catalog_tbl.getIndexes()) {
            if (skip_indexes.contains(catalog_idx)) continue;

            if (catalog_idx.getUnique()) {
                if (catalog_idx.getAssumeunique()) {
                    sb.append("CREATE ASSUMEUNIQUE INDEX ");
                }
                else {
                    sb.append("CREATE UNIQUE INDEX ");
                }
            }
            else {
                sb.append("CREATE INDEX ");
            }


            sb.append(catalog_idx.getTypeName() +
                   " ON " + catalog_tbl.getTypeName() + " (");
            add = "";

            String jsonstring = catalog_idx.getExpressionsjson();

            if (jsonstring.isEmpty()) {
                for (ColumnRef catalog_colref : CatalogUtil.getSortedCatalogItems(catalog_idx.getColumns(), "index")) {
                    sb.append(add + catalog_colref.getColumn().getTypeName() );
                    add = ", ";
                }
            } else {
                List<AbstractExpression> indexedExprs = null;
View Full Code Here


     * @param catalogTable
     * @return An ordered list of the primary key columns
     */
    public static Collection<Column> getPrimaryKeyColumns(Table catalogTable) {
        Collection<Column> columns = new ArrayList<Column>();
        Index catalog_idx = null;
        try {
            catalog_idx = CatalogUtil.getPrimaryKeyIndex(catalogTable);
        } catch (Exception ex) {
            // IGNORE
            return (columns);
        }
        assert(catalog_idx != null);

        for (ColumnRef catalog_col_ref : getSortedCatalogItems(catalog_idx.getColumns(), "index")) {
            columns.add(catalog_col_ref.getColumn());
        }
        return (columns);
    }
View Full Code Here

        for (Table table : db.getTables()) {
            if (readTableNames.contains(table.getTypeName())) {
                readTableNames.remove(table.getTypeName());
                for (String indexName : indexes) {
                    Index index = table.getIndexes().get(indexName);
                    if (index != null) {
                        updateIndexUsageAnnotation(index, stmt);
                    }
                }
                if (updated != null && updated.equals(table.getTypeName())) {
View Full Code Here

                return plan;
            }

            // create an empty bindingExprs list, used for store (possible) bindings for adHoc query
            ArrayList<AbstractExpression> bindings = new ArrayList<AbstractExpression>();
            Index ret = findQualifiedIndex(((SeqScanPlanNode)child), aggExpr, bindings);

            if (ret == null) {
                return plan;
            } else {
                // 1. create one INDEXSCAN plan node with inlined LIMIT
View Full Code Here

            // meets a naive planner that doesn't just cull the no-op ORDER BY. Who, us?
            return new TableCountPlanNode(isp, aggplan);
        }

        // check for the index's support for counting
        Index idx = isp.getCatalogIndex();
        if ( ! idx.getCountable()) {
            return plan;
        }

        // The core idea is that counting index needs to know the start key and end key to
        // jump to to get counts instead of actually doing any scanning.
View Full Code Here

        // got here? we're got ourselves a sequential scan over a real table
        assert (scanNode.getChildCount() == 0);
        StmtTableScan tableScan = scanNode.getTableScan();
        assert(tableScan != null);

        Index indexToScan = null;

        // Pick the narrowest index from all of the unique tree indexes.
        // note: This is not the same as picking the narrowest key in c++,
        // which is probably what you want if it turns out this optimization
        // does anything for performance at all.
View Full Code Here

               in one edge case, an NLIJ of a MaterializedScan and an index scan plan node.
     */
    protected static AbstractPlanNode getIndexAccessPlanForTable(StmtTableScan tableScan, AccessPath path)
    {
        // now assume this will be an index scan and get the relevant index
        Index index = path.index;
        IndexScanPlanNode scanNode = new IndexScanPlanNode(tableScan, index);
        AbstractPlanNode resultNode = scanNode;
        // set sortDirection here becase it might be used for IN list
        scanNode.setSortDirection(path.sortDirection);
        // Build the list of search-keys for the index in question
View Full Code Here

TOP

Related Classes of org.voltdb.catalog.Index

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.