Hello,
I shall try to provide some answers on the remarks of Simon and Jeff.
Compatibility mode for sure was not on, although I set it during the tests, in that particular run was off (I checked sp_show_options)
There was not any plan clause and also the sysqueryplans is empty, so I don't think that some existing plan was loaded.
It is really interesting to check what Jeff proposed, I hope to do it later today, for the moment I have not access on the system.
I mean the use of parenthesis in this
(query 1
union
query 2)
union all
(query 3
union
query 4)
Concerning the use of the large pool, is something I also noticed and it keeps happening in many queries in this installation. The average query in this system contains complex joins and many tables like the ones I have posted here. The biggest table in terms of number of rows is around 1 million and usually these joins involve 2-3 tables of 400000-500000 rows and some very small tables (less than 1000). I am not sure if this is an explanation.
alternative_greedy_search was on, I tested the query with this setting offand I think it run slightly slower.
I appreciate a lot Simon's remarks on reformatting, this case is something like an advanced workshop for me.
Thank you a lot for your help