Package org.voltdb.catalog

Examples of org.voltdb.catalog.Table


            return (this.tables.size());
        }
        public Object getValueAt(int row, int col) {
            String ret = null;
           
            Table catalog_tbl = this.tables.get(row);
            switch (col) {
                case 0:
                    ret = catalog_tbl.getName();
                    break;
                case 1:
                    ret = (catalog_tbl.getPartitioncolumn() != null ? catalog_tbl.getPartitioncolumn().getName() : "-");
                    break;
                case 2:
                    ret = Boolean.toString(catalog_tbl.getIsreplicated());
                    break;
            } // SWITCH
            return (ret);
        }
View Full Code Here


            DesignerVertex v1 = v0;
            if (vertices.size() > 1)
                v1 = CollectionUtil.get(vertices, 1);
            assert (v1 != null);

            Table catalog_tbl0 = v0.getCatalogItem();
            assert (catalog_tbl0 != null);
            Table catalog_tbl1 = v1.getCatalogItem();
            assert (catalog_tbl1 != null);

            if (d)
                LOG.debug(String.format("%s <-> %s\n%s", v0, v1, cset));
View Full Code Here

        if (t)
            LOG.trace("SQL: " + catalog_stmt.getSqltext());
        List<Table> tables = new ArrayList<Table>();
        tables.addAll(CatalogUtil.getReferencedTables(catalog_stmt));
        for (int ctr = 0, cnt = tables.size(); ctr < cnt; ctr++) {
            Table table0 = tables.get(ctr);
            boolean debug_table = (debug_tables.contains(table0) && t);

            // --------------------------------------------------------------
            // (1) Add an edge from table0 to all other tables in the query
            // --------------------------------------------------------------
            for (int ctr2 = ctr + 1; ctr2 < cnt; ctr2++) {
                Table table1 = tables.get(ctr2);
                PredicatePairs cset = CatalogUtil.extractStatementPredicates(catalog_stmt, true, table0, table1);
                if (debug_table)
                    LOG.trace("Creating join edge between " + table0 + "<->" + table1 + " for " + catalog_stmt);
                this.addEdge(agraph, AccessType.SQL_JOIN, cset, agraph.getVertex(table0), agraph.getVertex(table1), catalog_stmt);
            } // FOR
View Full Code Here

            // so that we can have specific edges between vertices
            Map<Table, Set<Column>> table_column_xref0 = new HashMap<Table, Set<Column>>();
            Map<Table, Set<Column>> table_column_xref1 = new HashMap<Table, Set<Column>>();
            for (CatalogType ctype : columns0) {
                Column col = (Column) ctype;
                Table tbl = (Table) col.getParent();
                if (!table_column_xref0.containsKey(tbl)) {
                    table_column_xref0.put(tbl, new HashSet<Column>());
                }
                table_column_xref0.get(tbl).add(col);
            } // FOR
            for (CatalogType ctype : columns1) {
                Column col = (Column) ctype;
                Table tbl = (Table) col.getParent();
                if (!table_column_xref1.containsKey(tbl)) {
                    table_column_xref1.put(tbl, new HashSet<Column>());
                }
                table_column_xref1.get(tbl).add(col);
            } // FOR
View Full Code Here

                Collection<Constraint> catalog_consts = CatalogUtil.getConstraints(catalog_col.getConstraints());
                catalog_consts = CatalogUtil.findAll(catalog_consts, "type", ConstraintType.FOREIGN_KEY.getValue());
                if (!catalog_consts.isEmpty()) {
                    assert (catalog_consts.size() == 1) : CatalogUtil.getDisplayName(catalog_col) + " has " + catalog_consts.size() + " foreign key constraints: " + catalog_consts;
                    Constraint catalog_const = CollectionUtil.first(catalog_consts);
                    Table catalog_fkey_tbl = catalog_const.getForeignkeytable();
                    assert (catalog_fkey_tbl != null);

                    // Important! We only want to include tables that are
                    // actually referenced in this procedure
                    if (proc_tables.contains(catalog_fkey_tbl)) {
View Full Code Here

            // Ancestors
            final Vector<Table> ancestors = new Vector<Table>();
            new AbstractTreeWalker<Table>() {
                protected void populate_children(AbstractTreeWalker.Children<Table> children, Table element) {
                    TableEntry current_entry = table_entries.get(element);
                    Table parent = current_entry.getParent();
                    if (parent != null) {
                        TableEntry parent_entry = PartitionPlan.this.table_entries.get(parent);
                        if (parent_entry == null) {
                            LOG.warn(String.format("Missing parent entry %s for child %s: %s", parent, element, table_entries.keySet()));
                        } else {
                            // assert(parent_entry != null) :
                            // "Missing parent entry " + parent + " for " +
                            // element;
                            if (!this.hasVisited(parent))
                                children.addAfter(parent);
                        }
                    }
                };

                @Override
                protected void callback(Table element) {
                    if (element != this.getFirst()) {
                        ancestors.add(element);
                    }
                }
            }.traverse(catalog_tbl);
            this.table_ancestors.put(catalog_tbl, ancestors);
        } // FOR

        // Descendants & Roots
        // Table last_tbl = null;
        for (Table catalog_tbl : this.table_ancestors.keySet()) {
            for (Table ancestor_tbl : this.table_ancestors.get(catalog_tbl)) {
                if (!this.table_descendants.containsKey(ancestor_tbl)) {
                    this.table_descendants.put(ancestor_tbl, new HashSet<Table>());
                }
                this.table_descendants.get(ancestor_tbl).add(catalog_tbl);
            } // FOR

            Table root = (this.table_ancestors.get(catalog_tbl).isEmpty() ? catalog_tbl : CollectionUtil.last(this.table_ancestors.get(catalog_tbl)));
            this.table_roots.put(catalog_tbl, root);

            // last_tbl = catalog_tbl;
        } // FOR
    }
View Full Code Here

            if (e.getValue() != null)
                assert (e.getKey().equals(e.getValue().getParent())) : e;

            // Table Partitioning
            if (e.getKey() instanceof Table) {
                Table catalog_tbl = (Table) e.getKey();
                Column catalog_col = (Column) e.getValue();
                Column attribute = null;
                if (catalog_col instanceof ReplicatedColumn) {
                    method = PartitionMethodType.REPLICATION;
                } else {
                    method = PartitionMethodType.HASH;
                    attribute = catalog_col;
                    assert (catalog_col != null) : "Unexcept Null Partitioning Column: " + catalog_tbl.getName();
                    assert (catalog_col.getParent().equals(e.getKey())) : "Parent mismatch: " + catalog_col.getParent() + " != " + e.getKey();
                }
                TableEntry pentry = new TableEntry(method, attribute, null, null);
                try {
                    pplan.addTablePartitionEntry(catalog_tbl, pentry);
View Full Code Here

                // ----------------------------------------------
                // TABLE PARTITIONING KEY
                // ----------------------------------------------
                if (is_table) {
                    Table current_tbl = (Table) current;
                    Column search_col = (Column) attribute;
                    Column current_col = null;

                    // Check whether this is our replication marker column
                    if (search_col instanceof ReplicatedColumn) {
                        current_tbl.setIsreplicated(true);
                        current_col = ReplicatedColumn.get(current_tbl);
                    }
                    // VerticalPartitionColumn
                    else if (search_col instanceof VerticalPartitionColumn) {
                        // We need to update the statements that can use them
                        // using the pre-compiled query plans
                        current_tbl.setIsreplicated(false);
                        current_col = search_col;
                        vp_col = (VerticalPartitionColumn) search_col;
                        assert (CatalogUtil.getDatabase(vp_col).equals(info.catalogContext.database)) : String.format("VP_COL[%d] != INFO[%d]", CatalogUtil.getDatabase(vp_col).hashCode(),
                                info.catalogContext.database.hashCode());

                        MaterializedViewInfo catalog_view = vp_col.applyUpdate();
                        assert (catalog_view != null) : "Unexpected null MaterializedViewInfo for " + current_tbl + " vertical partition:\n" + vp_col;
                        if (this.cost_model.isCachingEnabled()) {
                            if (trace.val)
                                LOG.trace("Invalidating VerticalPartition Statements in cost model: " + vp_col.getOptimizedQueries());
                            this.cost_model.invalidateCache(vp_col.getOptimizedQueries());
                        }
                        TableStatistics tstats = VerticalPartitionerUtil.computeTableStatistics(vp_col, info.stats);
                        assert (tstats != null);
                        // Add the vp's sys table to the list of tables that we
                        // need to estimate the memory
                        assert (catalog_view.getDest() != null) : "Missing parent table for " + catalog_view.fullName();
                        assert (this.current_vertical_partitions.contains(catalog_view.getDest()) == false) : vp_col;
                        this.current_vertical_partitions.add(catalog_view.getDest());
                    }
                    // MultiColumn
                    else if (search_col instanceof MultiColumn) {
                        // Nothing special?
                        current_tbl.setIsreplicated(false);
                        current_col = search_col;
                    }
                    // Otherwise partition on this particular column
                    else {
                        current_tbl.setIsreplicated(false);
                        current_col = current_tbl.getColumns().get(search_col.getName());
                    }

                    // We should always have a horizontal partition column
                    assert (current_col != null);
                    current_tbl.setPartitioncolumn(current_col);
                    assert (current_col.getName().equals(current_tbl.getPartitioncolumn().getName())) : "Unexpected " + current_col.fullName() + " != " + current_tbl.getPartitioncolumn().fullName();

                    // Estimate memory size
                    Collection<Table> tablesToEstimate = null;
                    if (hints.enable_vertical_partitioning && this.current_vertical_partitions.isEmpty() == false) {
                        tablesToEstimate = CollectionUtils.union(current_previousTables, this.current_vertical_partitions);
View Full Code Here

     * @param stats
     * @return
     */
    public static TableStatistics computeTableStatistics(VerticalPartitionColumn vp_col, WorkloadStatistics stats) {
        MaterializedViewInfo catalog_view = vp_col.createMaterializedView();
        Table view_tbl = catalog_view.getDest();
        assert (view_tbl != null) : "Destination table for " + catalog_view + " is null?";
        TableStatistics tbl_stats = stats.getTableStatistics(view_tbl);
        if (tbl_stats == null) {
            tbl_stats = new TableStatistics(view_tbl);
            stats.addTableStatistics(view_tbl, tbl_stats);

            Table orig_tbl = catalog_view.getParent();
            TableStatistics orig_tbl_stats = stats.getTableStatistics(orig_tbl);
            assert (orig_tbl_stats != null) : "Missing TableStatistics " + orig_tbl;

            tbl_stats.readonly = true;
            tbl_stats.tuple_count_total = orig_tbl_stats.tuple_count_total;
View Full Code Here

     * @param catalog_tbl
     * @return
     * @throws Exception
     */
    public static Collection<VerticalPartitionColumn> generateCandidates(final Column partition_col, final WorkloadStatistics stats) throws Exception {
        final Table catalog_tbl = partition_col.getParent();
        final Database catalog_db = catalog_tbl.getParent();
        final Set<VerticalPartitionColumn> candidates = new ListOrderedSet<VerticalPartitionColumn>();

        // If the horizontal partition column is null, then there can't be any
        // vertical partition columns
        if (partition_col.getNullable()) {
            if (debug.val)
                LOG.warn("The horizontal partition column " + partition_col.fullName() + " is nullable. Skipping candidate generation");
            return (candidates);
        }

        // Get all the read-only columns for this table
        Collection<Column> readOnlyColumns = CatalogUtil.getReadOnlyColumns(catalog_tbl, true);

        // For the given Column object, figure out what are the potential
        // vertical partitioning candidates
        // if we assume that the Table is partitioned on that Column
        if (debug.val) {
            LOG.debug(String.format("Generating VerticalPartitionColumn candidates based on using %s as the horizontal partitioning attribute", partition_col.fullName()));
            LOG.trace(catalog_tbl + " Read-Only Columns: " + CatalogUtil.debug(readOnlyColumns));
        }
        for (Procedure catalog_proc : CatalogUtil.getReferencingProcedures(catalog_tbl)) {
            // Look for a query on this table that does not use the target
            // column in the predicate
            // But does return it in its output
            for (Statement catalog_stmt : catalog_proc.getStatements()) {
                // We can only look at SELECT statements because we have know
                // way to know the correspondence
                // between the candidate partitioning column and our target
                // column
                if (catalog_stmt.getQuerytype() != QueryType.SELECT.getValue())
                    continue;
                Collection<Column> output_cols = PlanNodeUtil.getOutputColumnsForStatement(catalog_stmt);
                if (partition_col instanceof MultiColumn) {
                    if (output_cols.containsAll((MultiColumn) partition_col) == false)
                        continue;
                } else if (output_cols.contains(partition_col) == false)
                    continue;

                // Skip if this thing is just dumping out all columns
                if (output_cols.size() == catalog_tbl.getColumns().size())
                    continue;

                // We only support single-table queries now
                Collection<Table> stmt_tables = CatalogUtil.getReferencedTables(catalog_stmt);
                if (stmt_tables.size() > 1)
View Full Code Here

TOP

Related Classes of org.voltdb.catalog.Table

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.