}
if (session.getCancel() != 0) {
// if the connection is closed and there is something to undo
return;
}
Database db = session.getDatabase();
StatementBuilder buff = new StatementBuilder("SELECT ");
Column[] columns = table.getColumns();
for (Column col : columns) {
buff.appendExceptFirst(", ");
int type = col.getType();
if (type == Value.BLOB || type == Value.CLOB) {
// can not index LOB columns, so calculating
// the selectivity is not required
buff.append("100");
} else {
buff.append("SELECTIVITY(").append(col.getSQL()).append(')');
}
}
buff.append(" FROM ").append(table.getSQL());
if (sample > 0) {
buff.append(" LIMIT 1 SAMPLE_SIZE ").append(sample);
}
String sql = buff.toString();
Prepared command = session.prepare(sql);
ResultInterface result = command.query(0);
result.next();
for (int j = 0; j < columns.length; j++) {
int selectivity = result.currentRow()[j].getInt();
columns[j].setSelectivity(selectivity);
}
if (manual) {
db.update(session, table);
} else {
Session s = db.getSystemSession();
if (s != session) {
// if the current session is the system session
// (which is the case if we are within a trigger)
// then we can't update the statistics because
// that would unlock all locked objects
db.update(s, table);
s.commit(true);
}
}
}