Clone SelectQuery doesn't seem to work I want to change the sorting of a view with something very specific which needs 2 subqueries.

So far, I tried to do something like this:

$sorted = false;

function mymodule_query_alter(&amp;$query) {
  global $sorted;

  $view = $query-&gt;getMetaData('view');
  if( !$sorted &amp;&amp; $view-&gt;name == 'my_view' ) {
    $sorted = true;

    $subquery_1 = clone $query;
    $subquery_2 = clone $query;

    // Apply sorting stuff...

    $query = $subquery_1-&gt;union($subquery_2);
}


Then I just realized that this desn't even work (while my view is working):

$subquery = clone $query;
$query = $subquery;
dpm($query-&gt;__toString());
dpm($query-&gt;arguments());


It doesn't return any result, but everything seems ok in the dpm dump.

Have I done something wrong? Or maybe should I handle this problem in another way?

EDIT: 

I need to get a list of nodes sorted this way:


Sticky nodes | order by date.
Nodes in one of the taxonomy-term selected in user profile | order by date.
Other nodes | order by date.


I've already a working SQL request (actually 3 with UNION), but I need to make it work with Drupal.
So, I was working on a test for @Mołot to reproduce the clone bug, and I couldn't with a fresh view.

I tracked down the difference :


With the filter Published or admin: the cloned query didn't return anything.
No problem with the simple Published filter.


Don't ask me why.

As @autopoietic said, working with core query_alter_hook wasn't a good idea. I switched to views hook, and got the SelectQuery object :

function mymodule_views_pre_execute(&amp;$view) {
  $query = &amp;$view-&gt;build_info['query'];
}


Then I was able to do my sorting.