Using OR in where clause does not use index

90 views
Skip to first unread message

BrianR

unread,
Oct 2, 2012, 11:57:30 AM10/2/12
to h2-da...@googlegroups.com
If column a is index and running a query of 

SELECT * FROM tableFoo WHERE a = 'value' OR a LIKE 'value2'

does not use the index on a.

I also noticed the following query does not use an index

SELECT * FROM tableFoo WHERE a = 'value' OR 1=1

This may be by design but probably should be documented somewhere.


vrota...@gmail.com

unread,
Oct 3, 2012, 6:12:47 AM10/3/12
to h2-da...@googlegroups.com

This was already discussed some time ago. A working workaround is to use

    (SELECT ..) UNION (SELECT ...)

instead of OR.



--
You received this message because you are subscribed to the Google Groups "H2 Database" group.
To view this discussion on the web visit https://groups.google.com/d/msg/h2-database/-/GjKh5-2c-H4J.
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.

--
   Vasile Rotaru

BrianR

unread,
Oct 4, 2012, 12:02:23 PM10/4/12
to h2-da...@googlegroups.com
I understand the workaround. 

Shouldn't this information be on the h2 site somewhere (and not only in the forums)?

The same with the fact that REGEXP does not use indicies. I'm worried that there are other commands that do not use indicies and I dont know about them because they are in some posting and not in the documentation.

Thomas Mueller

unread,
Oct 23, 2012, 3:33:10 PM10/23/12
to h2-da...@googlegroups.com
Hi,

Most optimizations are documented at http://h2database.com/html/performance.html#explain_plan - but I agree the documentation could be improved, patches are welcome. 

Regards,
Thomas


To view this discussion on the web visit https://groups.google.com/d/msg/h2-database/-/Fy_NTkf0qGUJ.
Reply all
Reply to author
Forward
0 new messages