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.





2015-06-23 18:57 GMT+02:00 Sergi Vladykin <[email protected]>:

> Pablo,
>
> Indexes are supported in custom tables - see org.h2.table.Table.getIndexes
> Here you can return any Index implementations you want and optimizer will
> try to choose the best one.
>
> Sergi
>
>
> 2015-06-23 17:30 GMT+03:00 Pablo Beltran <[email protected]>:
>
>> Hi Sergi, I think this thread is related to other thread I started some
>> days ago:
>>
>> https://groups.google.com/forum/#!topic/h2-database/7O4chpOQ8vo
>>
>> I plugged some tables without indexes and I think this brings some
>> confusion to the H2 execution query optimizer because the engine is not
>> aware about the optimized columns (indexed) in order to choose the better
>> sequence to invoke the tables. In my opinion, supporting indexes on the
>> plugged tables would be the right way because it would also prevent no
>> expert users from write heavy queries furthermore it is the standard way
>> for databases in general and the expected way by the H2 engine, of course
>>
>> Anyway thanks!!
>> Pablo.
>>
>> 2015-06-23 13:06 GMT+02:00 Sergi Vladykin <[email protected]>:
>>
>>> Hi!
>>>
>>> Just use left join on foreign key, your conditions in where clause
>>> already will make sure that there will be no extra entries in result set.
>>>
>>> Sergi
>>>
>>> 2015-06-23 13:23 GMT+03:00 Pablo Beltran <[email protected]>:
>>>
>>>> I forgot to mention that *there are not indexes* on any column because
>>>> they are plugged tables....
>>>>
>>>> On Tuesday, June 23, 2015 at 4:06:18 AM UTC+2, Pablo Beltran wrote:
>>>>
>>>>> Hi,
>>>>>
>>>>> Sometimes the execution order of tables can vary a lot by add-in a
>>>>> simple condition.
>>>>>
>>>>> select * from
>>>>> tableA a
>>>>> INNER JOIN
>>>>> tableB  b on b.id=a.id
>>>>> WHERE
>>>>> ..
>>>>>
>>>>> depending on the where conditions tableA is invoked first or not.
>>>>>
>>>>> How to force H2 to use tableA prior tableB always?
>>>>>
>>>>> Thanks!
>>>>> Pablo.
>>>>>
>>>>>
>>>>>  --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "H2 Database" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to [email protected].
>>>> To post to this group, send email to [email protected].
>>>> Visit this group at http://groups.google.com/group/h2-database.
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>
>>>  --
>>> You received this message because you are subscribed to a topic in the
>>> Google Groups "H2 Database" group.
>>> To unsubscribe from this topic, visit
>>> https://groups.google.com/d/topic/h2-database/7O4chpOQ8vo/unsubscribe.
>>> To unsubscribe from this group and all its topics, send an email to
>>> [email protected].
>>> To post to this group, send email to [email protected].
>>> Visit this group at http://groups.google.com/group/h2-database.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "H2 Database" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To post to this group, send email to [email protected].
>> Visit this group at http://groups.google.com/group/h2-database.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>  --
> You received this message because you are subscribed to a topic in the
> Google Groups "H2 Database" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/h2-database/7O4chpOQ8vo/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/h2-database.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/d/optout.

Reply via email to