// ----------------------------------------------
// 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);
} else {
tablesToEstimate = current_previousTables;
}
if (trace.val)
LOG.trace(String.format("Calculating memory size of current solution [%s]:\n%s", current_col.fullName(), StringUtil.join("\n", current_previousTables)));
try {
memory = this.memory_estimator.estimate(info.catalogContext.database, info.getNumPartitions(), tablesToEstimate);
} catch (Throwable ex) {
throw new RuntimeException("Failed to estimate memory using new attribute " + current_col.fullName(), ex);
}
memory_exceeded = (memory > this.hints.max_memory_per_partition);
if (trace.val)
LOG.trace(String.format("%s Memory: %s [ratio=%.2f, exceeded=%s]", current_col.fullName(), StringUtil.formatSize(memory), memory / (double) hints.max_memory_per_partition,
memory_exceeded));
current_attribute = current_col;
// ----------------------------------------------
// PROCEDURE PARTITIONING PARAMETER