prepareStatement("select * from " + TAB + " where id1 = 10")
.executeQuery());
// We expect three stats objects for the single index; one per
// leading columns combination (c1, c1-c2, and c1-c2-c3).
IdxStats statsObj[] = stats.getStatsTable(TAB, 3);
assertEquals(3, statsObj.length);
Timestamp now = new Timestamp(new Date().getTime());
for (int i=0; i < statsObj.length; i++) {
IdxStats s = statsObj[i];
assertEquals(rows, s.rows);
// DERBY-6144
// Stats cannot have been created after the current time (future).
assertFalse(
"expected stat created in past:now = " + now +
";s.created = " + s.created,
s.created.compareTo(now) > 0);
switch (s.lcols) {
case 1:
assertEquals(100, s.card);
break;
case 2:
assertEquals(5000, s.card);
break;
case 3:
assertEquals(50000, s.card);
break;
default:
fail("unexpected number of leading columns: " + s.lcols);
}
}
// Now create a second index in the opposite order, check stats.
stmt.executeUpdate("create index IDXREV on " + TAB + "(id3, id2, id1)");
statsObj = stats.getStatsIndex("IDXREV", 3);
assertEquals(3, statsObj.length);
Timestamp earlier = now;
now = new Timestamp(new Date().getTime());
for (int i=0; i < statsObj.length; i++) {
IdxStats s = statsObj[i];
assertEquals(rows, s.rows);
assertTrue("current stats created " + s.created +
", previous stats created " + earlier,
s.created.after(earlier));
// Stats cannot have been created after the current time (future).