Yeap, this was my guess. However, it does not work and it's becoming a headache. I would say there is a bug in the Table class method below:
public PlanItem getBestPlanItem(Session session, int[] masks,
TableFilter filter, SortOrder sortOrder) {
PlanItem item = new PlanItem();
item.setIndex(getScanIndex(session));
item.cost = item.getIndex().getCost(session, null, null, null);
ArrayList<Index> indexes = getIndexes();
if (indexes != null && masks != null) {
for (int i = 1, size = indexes.size(); i < size; i++) {
Index index = indexes.get(i);
double cost = index.getCost(session, masks, filter, sortOrder);
if (cost < item.cost) {
item.cost = cost;
item.setIndex(index);
}
}
}
return item;
}
because the first Index defined on a custom Table is totally ignored. The initial value of the for loop should start at 0 rather than 1:
for (int i = 1, size = indexes.size(); i < size; i++) {
for (int i = 0, size = indexes.size(); i < size; i++) {
With the change above, it seems to work a bit better. The Index.getCost() method is then invoked with and without the masks bits in order to compare both costs (fullscan vs index). However there are still some issues which require further investigation because despite this fix the joined tables are not invoked in the expected order yet.