Package edu.brown.designer

Examples of edu.brown.designer.AccessGraph


        } // FOR
        return (agraph);
    }

    public static AccessGraph convertToSingleColumnEdges(Database catalog_db, AccessGraph orig_agraph) {
        AccessGraph agraph = new AccessGraph(catalog_db);
        Map<CatalogPair, DesignerEdge> entry_edges = new HashMap<CatalogPair, DesignerEdge>();

        for (DesignerVertex v : orig_agraph.getVertices()) {
            agraph.addVertex(v);
        } // FOR

        for (DesignerEdge e : orig_agraph.getEdges()) {
            // Split up the ColumnSet into separate edges, one per entry
            PredicatePairs cset = e.getAttribute(EdgeAttributes.COLUMNSET);
            assert (cset != null);
            Collection<DesignerVertex> vertices = orig_agraph.getIncidentVertices(e);
            DesignerVertex v0 = CollectionUtil.first(vertices);
            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));

            for (CatalogPair entry : cset) {
                DesignerEdge new_e = entry_edges.get(entry);
                if (new_e == null) {
                    PredicatePairs new_cset = new PredicatePairs(cset.getStatements());
                    new_cset.add(entry);
                    new_e = new DesignerEdge(agraph, e);
                    new_e.setAttribute(EdgeAttributes.COLUMNSET, new_cset);
                    entry_edges.put(entry, new_e);

                    CatalogType parent0 = entry.getFirst().getParent();
                    CatalogType parent1 = entry.getSecond().getParent();

                    if (parent0 == null && parent1 == null) {
                        if (d)
                            LOG.debug(String.format("Skipping %s ===> %s, %s", entry, v0, v1));
                        continue;

                        // Check whether this is a self-referencing edge
                    } else if ((parent0 == null && parent1.equals(catalog_tbl0)) || (parent1 == null && parent0.equals(catalog_tbl0))) {
                        if (d)
                            LOG.debug(String.format("Self-referencing edge %s ===> %s, %s", entry, v0, v0));
                        agraph.addEdge(new_e, v0, v0);

                    } else if ((parent0 == null && parent1.equals(catalog_tbl1)) || (parent1 == null && parent0.equals(catalog_tbl1))) {
                        if (d)
                            LOG.debug(String.format("Self-referencing edge %s ===> %s, %s", entry, v1, v1));
                        agraph.addEdge(new_e, v1, v1);

                    } else if ((parent0.equals(catalog_tbl0) && parent1.equals(catalog_tbl1) == false) || (parent1.equals(catalog_tbl0) && parent0.equals(catalog_tbl1) == false)
                            || (parent0.equals(catalog_tbl0) && parent1.equals(catalog_tbl0))) {
                        if (d)
                            LOG.debug(String.format("Self-referencing edge %s ===> %s, %s", entry, v0, v0));
                        agraph.addEdge(new_e, v0, v0);

                    } else if ((parent0.equals(catalog_tbl1) && parent1.equals(catalog_tbl0) == false) || (parent1.equals(catalog_tbl1) && parent0.equals(catalog_tbl0) == false)
                            || (parent0.equals(catalog_tbl0) && parent1.equals(catalog_tbl0))) {
                        if (d)
                            LOG.debug(String.format("Self-referencing edge %s ===> %s, %s", entry, v1, v1));
                        agraph.addEdge(new_e, v1, v1);

                    } else {
                        if (d)
                            LOG.debug(String.format("New edge %s ===> %s, %s", entry, v0, v1));
                        agraph.addEdge(new_e, v0, v1);

                    }
                }
                // Add weights from original edge to this new edge
                new_e.addToWeight(e);
View Full Code Here


        DesignerInfo info = new DesignerInfo(args);
        boolean global = true;
        boolean single = false;

        if (global) {
            AccessGraph agraph = AccessGraphGenerator.generateGlobal(info);
            assert (agraph != null);
            if (single)
                agraph = AccessGraphGenerator.convertToSingleColumnEdges(args.catalog_db, agraph);
            agraph.setVerbose(true);
            GraphvizExport<DesignerVertex, DesignerEdge> gv = new GraphvizExport<DesignerVertex, DesignerEdge>(agraph);
            gv.setEdgeLabels(true);
            String path = "/tmp/" + args.catalog_type.toString().toLowerCase() + ".dot";
            FileUtil.writeStringToFile(path, gv.export(args.catalog_type.toString()));
            LOG.info("Wrote Graphviz file to " + path);

        } else {
            for (Procedure catalog_proc : args.catalog_db.getProcedures()) {
                if (catalog_proc.getSystemproc())
                    continue;
                if (catalog_proc.getName().equals("neworder") == false)
                    continue;
                AccessGraphGenerator gen = new AccessGraphGenerator(info, catalog_proc);
                final AccessGraph agraph = new AccessGraph(args.catalog_db);
                gen.generate(agraph);
                agraph.setVerbose(true);

                GraphvizExport<DesignerVertex, DesignerEdge> gv = new GraphvizExport<DesignerVertex, DesignerEdge>(agraph);
                gv.setEdgeLabels(true);
                String path = "/tmp/" + catalog_proc.getName() + ".dot";
                FileUtil.writeStringToFile(path, gv.export(catalog_proc.getName()));
View Full Code Here

        boolean calculate_memory = (hints.force_replication_size_limit != null && hints.max_memory_per_partition != 0);

        // Generate the list of which columns we will randomly select from for
        // each table
        Map<Table, List<Column>> table_columns = new HashMap<Table, List<Column>>();
        AccessGraph agraph = (this.limit_columns ? this.generateAccessGraph() : null);
        for (Table catalog_tbl : info.catalogContext.database.getTables()) {
            List<Column> columns = new ArrayList<Column>();
            if (this.limit_columns) {
                List<Column> column_keys = PartitionerUtil.generateColumnOrder(info, agraph, catalog_tbl, hints, true, false);
                assert (!column_keys.isEmpty()) : "No potential partitioning columns selected for " + catalog_tbl;
View Full Code Here

    protected AccessGraph generateAccessGraph() throws Exception {
        if (debug.val)
            LOG.debug("Generating AccessGraph for entire catalog");
        assert (info.workload != null);

        AccessGraph agraph = new AccessGraph(info.catalogContext.database);
        for (Procedure catalog_proc : info.catalogContext.database.getProcedures()) {
            // Skip if there are no transactions in the workload for this
            // procedure
            if (info.workload.getTraces(catalog_proc).isEmpty()) {
                if (debug.val)
View Full Code Here

    private static final String HOST_INNER = "\u251c";
    private static final String HOST_LAST = "\u2514";

    public static double complexity(ArgumentsParser args, Database catalog_db, Workload workload) throws Exception {
        AccessGraph agraph = new AccessGraph(catalog_db);
        DesignerInfo info = new DesignerInfo(args);
        for (Procedure catalog_proc : catalog_db.getProcedures()) {
            // Skip if there are no transactions in the workload for this
            // procedure
            if (workload.getTraces(catalog_proc).isEmpty() || catalog_proc.getSystemproc())
                continue;
            new AccessGraphGenerator(info, catalog_proc).generate(agraph);
        } // FOR

        double ret = 1;
        for (Table catalog_tbl : catalog_db.getTables()) {
            DesignerVertex v = agraph.getVertex(catalog_tbl);
            if (v == null)
                continue;

            Set<Column> used_cols = new HashSet<Column>();
            Collection<DesignerEdge> edges = agraph.getIncidentEdges(v);
            if (edges == null)
                continue;
            for (DesignerEdge e : edges) {
                PredicatePairs cset = e.getAttribute(agraph, AccessGraph.EdgeAttributes.COLUMNSET);
                assert (cset != null) : e.debug();
View Full Code Here

        // Go through and count up all the attribute sets that aren't used for
        // partitioning
        //
        PartitionTree ptree = null; // FIXME designer.getPartitionTree();
        for (Procedure catalog_proc : info.catalogContext.database.getProcedures()) {
            AccessGraph agraph = designer.getAccessGraph(catalog_proc);
            if (agraph == null)
                continue;

            for (DesignerEdge edge : agraph.getEdges()) {
                ArrayList<DesignerVertex> vertices = new ArrayList<DesignerVertex>();
                vertices.addAll(agraph.getIncidentVertices(edge));
                // FIXME
                if (true || !(ptree.getPath(vertices.get(0), vertices.get(1)).isEmpty() && ptree.getPath(vertices.get(1), vertices.get(0)).isEmpty())) {
                    PredicatePairs cset = (PredicatePairs) (edge.getAttribute(AccessGraph.EdgeAttributes.COLUMNSET.name()));
                    for (DesignerVertex vertex : vertices) {
                        Table catalog_tbl = vertex.getCatalogItem();
View Full Code Here

    public PartitionPlan generate(DesignerHints hints) throws Exception {
        final PartitionPlan pplan = new PartitionPlan();

        // Generate an AccessGraph and select the column with the greatest
        // weight for each table
        final AccessGraph agraph = this.generateAccessGraph();
        final boolean calculate_memory = (hints.force_replication_size_limit != null && hints.max_memory_per_partition != 0);

        double total_partitionRatio = 0.0;
        long total_partitionSize = 0l;

        for (DesignerVertex v : agraph.getVertices()) {
            Table catalog_tbl = v.getCatalogItem();
            String table_key = CatalogKey.createKey(catalog_tbl);

            Collection<Column> forced_columns = hints.getForcedTablePartitionCandidates(catalog_tbl);
            TableStatistics ts = info.stats.getTableStatistics(catalog_tbl);
            assert (ts != null) : "Null TableStatistics for " + catalog_tbl;
            double partition_size = (calculate_memory ? (ts.tuple_size_total / (double) info.getNumPartitions()) : 0);
            double partition_ratio = (calculate_memory ? (ts.tuple_size_total / (double) hints.max_memory_per_partition) : 0);
            TableEntry pentry = null;

            if (debug.val) {
                Map<String, Object> m = new ListOrderedMap<String, Object>();
                m.put("Read Only", ts.readonly);
                m.put("Table Size", StringUtil.formatSize(ts.tuple_size_total));
                m.put("Table Partition Size", StringUtil.formatSize((long)partition_size));
                m.put("Table Partition Ratio", String.format("%.02f", partition_ratio));
                m.put("Total Partition Size", String.format("%s / %s", StringUtil.formatSize(total_partitionSize), StringUtil.formatSize(hints.max_memory_per_partition)));
                m.put("Total Partition Ratio", String.format("%.02f", total_partitionRatio));
                LOG.debug(String.format("%s\n%s", catalog_tbl.getName(), StringUtil.formatMaps(m)));
            }

            // -------------------------------
            // Replication
            // -------------------------------
            if (hints.force_replication.contains(table_key) || (calculate_memory && ts.readonly && hints.enable_replication_readonly && partition_ratio <= hints.force_replication_size_limit)) {
                total_partitionRatio += partition_ratio;
                total_partitionSize += ts.tuple_size_total;
                Column catalog_col = ReplicatedColumn.get(catalog_tbl);
                pentry = new TableEntry(PartitionMethodType.REPLICATION, catalog_col);
                if (debug.val)
                    LOG.debug(String.format("Replicating %s at all partitions [%s]", catalog_tbl.getName(), catalog_col.fullName()));

                // -------------------------------
                // Forced Selection
                // -------------------------------
            } else if (forced_columns.isEmpty() == false) {
                // Assume there is only one candidate
                assert (forced_columns.size() == 1) : "Unexpected number of forced columns: " + forced_columns;
                Column catalog_col = CollectionUtil.first(forced_columns);
                pentry = new TableEntry(PartitionMethodType.HASH, catalog_col);
                total_partitionRatio += partition_size / (double) hints.max_memory_per_partition;
                total_partitionSize += partition_size;
                if (debug.val)
                    LOG.debug(String.format("Forcing %s to be partitioned by specific column [%s]", catalog_tbl.getName(), catalog_col.fullName()));

                // -------------------------------
                // Select Most Popular
                // -------------------------------
            } else {
                // If there are no edges, then we'll just randomly pick a column
                // since it doesn't matter
                final Collection<DesignerEdge> edges = agraph.getIncidentEdges(v);
                if (edges.isEmpty())
                    continue;
                if (trace.val)
                    LOG.trace(catalog_tbl + " has " + edges.size() + " edges in AccessGraph");

                ObjectHistogram<Column> column_histogram = null;
                ObjectHistogram<Column> join_column_histogram = new ObjectHistogram<Column>();
                ObjectHistogram<Column> self_column_histogram = new ObjectHistogram<Column>();
                // Map<Column, Double> unsorted = new HashMap<Column, Double>();
                for (DesignerEdge e : edges) {
                    Collection<DesignerVertex> vertices = agraph.getIncidentVertices(e);
                    DesignerVertex v0 = CollectionUtil.get(vertices, 0);
                    DesignerVertex v1 = CollectionUtil.get(vertices, 1);
                    boolean self = (v0.equals(v) && v1.equals(v));
                    column_histogram = (self ? self_column_histogram : join_column_histogram);

                    double edge_weight = e.getTotalWeight();
                    PredicatePairs cset = e.getAttribute(AccessGraph.EdgeAttributes.COLUMNSET);
                    if (trace.val)
                        LOG.trace("Examining ColumnSet for " + e.toString(true));

                    Histogram<Column> cset_histogram = cset.buildHistogramForType(Column.class);
                    Collection<Column> columns = cset_histogram.values();
                    if (trace.val)
                        LOG.trace("Constructed Histogram for " + catalog_tbl + " from ColumnSet:\n"
                                + cset_histogram.setDebugLabels(CatalogUtil.getHistogramLabels(cset_histogram.values())).toString(100, 50));
                    for (Column catalog_col : columns) {
                        if (!catalog_col.getParent().equals(catalog_tbl))
                            continue;
                        if (catalog_col.getNullable())
                            continue;
                        long cnt = cset_histogram.get(catalog_col);
                        if (trace.val)
                            LOG.trace("Found Match: " + catalog_col.fullName() + " [cnt=" + cnt + "]");
                        column_histogram.put(catalog_col, Math.round(cnt * edge_weight));
                    } // FOR
                    // System.err.println(cset.debug());
                    // LOG.info("[" + e.getTotalWeight() + "]: " + cset);
                } // FOR

                // If there were no join columns, then use the self-reference
                // histogram
                column_histogram = (join_column_histogram.isEmpty() ? self_column_histogram : join_column_histogram);
                if (column_histogram.isEmpty()) {
                    EventObserver<DesignerVertex> observer = new EventObserver<DesignerVertex>() {
                        @Override
                        public void update(EventObservable<DesignerVertex> o, DesignerVertex v) {
                            for (DesignerEdge e : agraph.getIncidentEdges(v)) {
                                LOG.info(e.getAttribute(AccessGraph.EdgeAttributes.COLUMNSET));
                            }
                            LOG.info(StringUtil.repeat("-", 100));
                        }
                    };
View Full Code Here

TOP

Related Classes of edu.brown.designer.AccessGraph

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.