Could you provide more data (the tables, the indexes, did you run
analyze, how many rows per table, sample data, what does ANALYZE
EXPLAIN SELECT return)?
Regards,
Thomas
I don't understand yet what the problem could be... Did you run
ANALYZE before running the query?
What is the selectivity of the columns? To get this data, you need to
run ANALYZE and then SCRIPT NODATA. This will get you the CREATE TABLE
statements with the column selectivity. Could you then post those
CREATE TABLE statements?
Regards,
Thomas
> Thomas if you wish I can email you a link to the .db file file
> itself, or the INSERT statements, in 7z or zip form. Please let me
> know which you prefer.
Whatever is the smallest. The database file would be a bit simpler I guess.
Regards,
Thomas
For me, the query took less than 2 seconds. Does it really take 36
seconds for you? I don't really understand the query, could you try to
explain what it does and why do you think it should be fast? I don't
know exactly how PostgreSQL manages to be faster for this query, maybe
it uses a merge join which is not implemented yet in H2. But I don't
see any obvious bug in H2. The indexes have a very bad selectivity.
Some indexes are not needed, for example om_objid_idx (because
om_objid_omattribid contains the same data) and om_omschemaid_idx
(because om_attrval_id contains the same data).
Regards,
Thomas
You are right, I think it's a bug. There is a workaround, instead of:
SELECT count(*)
FROM om AS a INNER JOIN om AS b ON a.objId=b.objId AND a.omattribid=28
LEFT JOIN om AS own ON a.objId=own.objId AND own.omattribid=83
WHERE b.omattribid=25
AND b.objValue BETWEEN '8000012b6f634c01' AND '8000012b7489a7ff';
use:
SELECT count(*)
FROM om AS b INNER JOIN om AS a ON a.objId=b.objId AND a.omattribid=28
LEFT JOIN om AS own ON a.objId=own.objId AND own.omattribid=83
WHERE b.omattribid=25
AND b.objValue BETWEEN '8000012b6f634c01' AND '8000012b7489a7ff';
So, basically swap the joins manually. Of course it should be done
automatically, and I will try to fix it.
Regards,
Thomas
I am not the OP, but in the long discussion you showed the will to
examine and really understand - to finally identify a bug which you
also admited. From the developers I know, you are one of those who do
not primarily assume a user fault. - To show my respect, 20 Euros have
been donated.
> SELECT count(*)
> FROM om AS a INNER JOIN om AS b ON a.objId=b.objId AND a.omattribid=28
> LEFT JOIN om AS own ON a.objId=own.objId AND own.omattribid=83
> WHERE b.omattribid=25
> AND b.objValue BETWEEN '8000012b6f634c01' AND '8000012b7489a7ff';
>
> use:
>
> SELECT count(*)
> FROM om AS b INNER JOIN om AS a ON a.objId=b.objId AND a.omattribid=28
> LEFT JOIN om AS own ON a.objId=own.objId AND own.omattribid=83
> WHERE b.omattribid=25
> AND b.objValue BETWEEN '8000012b6f634c01' AND '8000012b7489a7ff';
I don't really understand why this makes a difference, it's all the same table.
> So, basically swap the joins manually. Of course it should be done
> automatically, and I will try to fix it.
As a workaround, when is it recommended to do it the other way round?
I ask because I assume that such an issue is noticed often only in
live systems when tables get large enough.
So I would like to know the circumstances I need to be aware of to be
careful with.
Best regards,
Martin.
--
Martin Wildam
> --
> You received this message because you are subscribed to the Google Groups "H2 Database" group.
> To post to this group, send email to h2-da...@googlegroups.com.
> To unsubscribe from this group, send email to h2-database...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/h2-database?hl=en.
>
>
> Do you have an estimate of when this might ready for testing?
Sorry, I don't have an estimate right now. It looks like it's a bigger
change, sorry.
Regards,
Thomas
> I thought I would ask since it's been a while; would you be able to give a
> timeframe for this fix?
I'm sorry, I can't tell you right now. It's a relatively big change I
believe, and currently it's not a very high priority for me. I suggest
to re-write the query, and if you are using a tool such as Hibernate
then run the problematic query manually (that is, not using
Hibernate). I know it's not a nice solution. Maybe there is a way to
specify the join order within the tool?
> getting the author to reverse the tables in a join (for h2's sake) might be
> met with resistance.
I know, but I'm afraid that's the only solution I have.
> Also it seems likely that other users are encountering
> this and (silently) concluding h2 is not a viable alternative to their other
> database.. I hope it deserve a top spot on the todo list(?)
Well, other things that are important as well. There are a lot of
possible optimizations in H2, but I also believe tools should have an
option to override the generated statement in some way, specially for
complex statements.
Regards,
Thomas