How do I mark a database query with a tag?
In case you're struggling to find the documentation, the class is called SelectQuery, and you're looking for the addTag function.

$query = db_select('table', 't')-&gt;fields('t')-&gt;addTag('my_tag');


Then in your query alter:

function MYMODULE_query_alter(QueryAlterableInterface $query) {
  if ($query-&gt;hasTag('my_tag')) {
    // Do something...
  }
}