is it possible to use honeysql to generate query with use index (mysql index hints)? like
select * from tbl use index (my_index) where ...Currently, only MS SQL hints are available -- see https://github.com/seancorfield/honeysql/issues/522
Feel free to create a new issue for MySQL referencing that old issue and I'll think about it.
In general, USE INDEX can be very problematic since the query optimizer is often better than you 🙂
At work, we had a few USE INDEX hints in MySQL code -- and when we upgraded MySQL, we got worse performance until we removed those hints.
Thank you! recently we performed some optimization (de-fragmentation) on a large table and noticed that the query on it became slower. We found that the root cause was a change in the index chosen by query optimizer. As a workaround, we explicitly specified the index in the query.
@social820 I went ahead and implemented this: {:select :* :from [^{:use-index [:my-index]} :tbl] :where ...} -- try it out with the latest 2.7.9999-SNAPSHOT or git deps with SHA 3701da16325c7c09da282898e82f5121b27c73fb
Sure, thank you for the quick support @seancorfield!
java.lang.IllegalArgumentException: Metadata can only be applied to IMetasOh, sorry, I missed a bracket. The documentation has a correct example -- Clause Reference for FROM
{:select :* :from [^{:use-index [:my-index]} [:tbl]] :where ...} -- the docs even explain why you have to have those extra [ .. ] there 🙂
sorry i did't read the doc carefully, it's working now. do you have a plan to update helpers/form accordingly?
Not sure what you mean?
user=> (-> (h/select :*) (h/from ^{:use-index [:my-index]} [:tbl]) (h/where := :name "steve") (sql/format))
["SELECT * FROM tbl USE INDEX (my_index) WHERE name = ?" "steve"]that's exactly what i mean, i'm not familiar with the implementation, i though you need to update the helpers as well. Thank you for your help 🙂
In general, the helpers are just thin wrappers around assoc or update / into so as long as core functions "work", nothing special needs to be done with helpers when the core DSL is updated.