* @throws Exception
*/
protected void init(DesignerHints hints) throws Exception {
assert (hints != null);
this.init_called = true;
AccessGraph first = this.generateAccessGraph();
this.agraph = AccessGraphGenerator.convertToSingleColumnEdges(info.catalogContext.database, first);
// Set the limits initially from the hints file
if (hints.limit_back_tracks != null)
this.last_backtrack_limit = new Double(hints.limit_back_tracks);
if (hints.limit_local_time != null)
this.last_localtime_limit = new Double(hints.limit_local_time);
if (this.last_entropy_weight == null)
this.last_entropy_weight = hints.weight_costmodel_skew;
// HACK: Reload the correlations file so that we can get the proper
// catalog objects
this.mappings.load(info.getMappingsFile(), info.catalogContext.database);
// this.agraph.setVertexVerbose(true);
// GraphvizExport<DesignerVertex, DesignerEdge> gv = new
// GraphvizExport<DesignerVertex, DesignerEdge>(this.agraph);
// gv.setCollapseEdges(true);
// System.err.println("ORIG GRAPH:" + gv.writeToTempFile());
//
// gv = new GraphvizExport<DesignerVertex,
// DesignerEdge>(this.single_agraph);
// gv.setCollapseEdges(true);
// System.err.println("SINGLE GRAPH:" + gv.writeToTempFile());
// Gather all the information we need about each table
for (Table catalog_tbl : PartitionerUtil.generateTableOrder(info, this.agraph, hints)) {
// Ignore this table if it's not used in the AcessGraph
DesignerVertex v = null;
try {
v = this.agraph.getVertex(catalog_tbl);
} catch (IllegalArgumentException ex) {
// IGNORE
}
if (v == null) {
LOG.warn(String.format("Ignoring %s - No references in workload AccessGraph", catalog_tbl));
this.ignore_tables.add(catalog_tbl);
continue;
}
// Potential Partitioning Attributes
Collection<Column> columns = PartitionerUtil.generateColumnOrder(info, this.agraph, catalog_tbl, hints, false, true);
assert (!columns.isEmpty()) : "No potential partitioning columns selected for " + catalog_tbl;
this.orig_table_attributes.put(catalog_tbl, (ListOrderedSet<Column>) CollectionUtil.addAll(new ListOrderedSet<Column>(), columns));
// Table Size (when the table is and is not replicated)
TableStatistics ts = info.stats.getTableStatistics(catalog_tbl);
this.table_nonreplicated_size.put(catalog_tbl, Math.round(ts.tuple_size_total / (double) this.num_partitions));
this.table_replicated_size.put(catalog_tbl, ts.tuple_size_total);
if (trace.val)
LOG.trace(catalog_tbl.getName() + ": " + columns);
} // FOR
// We also need to know some things about the Procedures and their
// ProcParameters
Histogram<String> workloadHistogram = info.workload.getProcedureHistogram();
for (Procedure catalog_proc : info.catalogContext.database.getProcedures()) {
// Skip if we're explicitly force to ignore this guy
if (PartitionerUtil.shouldIgnoreProcedure(hints, catalog_proc)) {
if (debug.val) LOG.warn(String.format("Ignoring %s - Set to be ignored by the DesignerHints.", catalog_proc));
this.ignore_procs.add(catalog_proc);
continue;
}
// Or if there are not transactions in the sample workload
else if (workloadHistogram.get(CatalogKey.createKey(catalog_proc), 0) == 0) {
if (debug.val) LOG.warn(String.format("Ignoring %s - No transaction records in sample workload.", catalog_proc));
this.ignore_procs.add(catalog_proc);
continue;
}
Collection<Column> columns = CatalogUtil.getReferencedColumns(catalog_proc);
if (columns.isEmpty()) {
if (debug.val) LOG.warn(String.format("Ignoring %s - Does not reference any columns in its queries.", catalog_proc));
this.ignore_procs.add(catalog_proc);
continue;
}
this.proc_columns.put(catalog_proc, columns);
// Aha! Use the Procedure-specific AccessGraph to build our
// Histogram! Where's your god now??
AccessGraph proc_agraph = this.designer.getAccessGraph(catalog_proc);
assert (proc_agraph != null);
// if (catalog_proc.getName().equals("GetAccessData")) {
// GraphVisualizationPanel.createFrame(proc_agraph).setVisible(true);
// }
this.proc_column_histogram.put(catalog_proc, PartitionerUtil.generateProcedureColumnAccessHistogram(info, hints, proc_agraph, catalog_proc));