timingTracer.traceTime("end validation");
SqlDialect sqlDialect =
SqlDialect.create(stmt.getSession().getDatabaseMetaData());
final SqlString sql = validatedSqlNode.toSqlString(sqlDialect);
if (analyzedSql != null) {
if (validatedSqlNode instanceof SqlSelect) {
// assume we're validating a view
SqlSelect select = (SqlSelect) validatedSqlNode;
if (select.getOrderList() != null) {
analyzedSql.hasTopLevelOrderBy = true;
}
}
// Need to force preparation so we can dig out required info, so
// don't use cache. Also, don't need to go all the way with
// stmt implementation either; can stop after validation, which
// provides needed metadata. (In fact, we CAN'T go much further,
// because if a view is being created as part of a CREATE SCHEMA
// statement, some of the tables it depends on may not have
// storage defined yet.)
analyzedSql.canonicalString = sql;
stmt.analyzeSql(validatedSqlNode, analyzedSql);
timingTracer.traceTime("end analyzeSql");
return null;
}
String key = sql + ";label=";
FarragoDbSession session = (FarragoDbSession) stmt.getSession();
Long labelCsn = session.getSessionLabelCsn();
if (labelCsn != null) {
key += labelCsn;
}
final String stmtKey = key;
FarragoObjectCache.Entry cacheEntry;
FarragoObjectCache.CachedObjectFactory stmtFactory =
new FarragoObjectCache.CachedObjectFactory() {
public void initializeEntry(
Object key,
FarragoObjectCache.UninitializedEntry entry)
{
timingTracer.traceTime("code cache miss");
assert (key.equals(stmtKey));
FarragoSessionExecutableStmt executableStmt =
stmt.prepare(validatedSqlNode, sqlNode);
long memUsage =
FarragoUtil.getStringMemoryUsage(sql.getSql())
+ executableStmt.getMemoryUsage();
entry.initialize(
executableStmt,
memUsage,
stmt.mayCacheImplementation());