Due to a configuration problem at my host, I'd like to execute the query "SET optimizer_search_depth=0;" in the same DB session as a specific Views query. I looked into hook_views_query_alter() and hook_views_pre_execute(), but in both cases the query is only available as a Query object.

I think I need some way to modify the raw query string before it's executed, but (presumably) after it's built. Is this possible?

1 Answer 1


Why do you think you need to alter the query itself? You literally said you needed to set a …session value.

You can issue any query prior to the views query on that page load to achieve the desired affect. Eg db_query('set mysql_max_group_concat=5;');

If you want to so it in the views lifecycle you could use any hook_views_* api call which states it runs prior to query execution. Look at the views api docs.

Or you could likely use hook_page_build for all its worth. Or hook_init ... whatever suits your needs.

  • For some reason I thought that each query was atomic in its own separate session. This is basically exactly what I ended up doing; thanks!
    – joshf
    Commented Aug 26, 2014 at 20:57
  • In php most frameworks/CMSs define a single database connection per page request (eg, every thing the page has to do (and for drupal this is easily 50+ queries) happens with a single database connection handler).
    – tenken
    Commented Aug 26, 2014 at 21:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.