So I recommend you to find out another method, for instance, putting your data in a custom work table, etc.
I thinked that the problem was resolved when I checked it with an expected result of 30.000 registries and it worked, but now, I have tried with more than 50.000 registries and, in this case, the result of the query is an empty resultset.
The queryDef is as you can see bellow:
Anyone knows what is the problem? Maybe a memory limitations?