How do you use hook_query_alter to get inside a query's creation? I'm getting no love from hook_query_alter.  I have a simple query to which I want to add a tag, while also adding a node_access tag.  Thus the whole query looks like this:

$the_nodes = db_select('node', 'n')
     -&gt;condition('n.type', 'some_node_type')
     -&gt;fields('n', array('nid', 'title'))
     -&gt;addTag('node_access')
     -&gt;addTag('my_custom_tag')
     -&gt;execute()-&gt;fetchAll();


I then define a handler in one of my modules and litter it with debugging statements, hoping something will happen:

function mymodule_query_alter(QueryAlterableInterface $the_query) {
    dsm("inside mymodule_query_alter");
    dsm($the_query);
    if ($the_query-&gt;hasTag('my_custom_tag')) {
        dsm('Found it!');
        // do real work here
    }
}


I then clear the system cache.  Once I've done this, the following things happen:


My handler is running, and reports a number of invocations from
various system calls.
The objects being dumped by the dsm calls are all very much alike --
they contain only an alterTags array, which typically has entries
for either node_load_multiple or file_load_multiple, but nothing else -- certainly nothing like a full Query object.
None of the alterTags arrays have an entry for my_custom_tag.
The inner "Found it!" message never fires.


Arggh.  This is my first encounter with hook_query_alter(), and I'm probably just missing something basic about its use.  Can anybody clue me in?  (BTW, based on some browsing around, I've also tried defining handlers for my_module_query_my_custom_tag_alter and my_module_query_node_access_alter, but never see anything from them.)
Just to close this item out: It appears that my definition of hook_query_alter was, in fact, working correctly.  My problem was in assuming that I would be able to do things like  dsm($the_query) and see the components of the query object in preparation for doing stuff with them.  This doesn't seem to be the case -- dsm() wasn't returning anything of real use other than alterTags, but the orderby() (and other similar actions) did in fact alter the query.  So, I'd argue that it's a bit confusing, but works-as-designed, I guess...