A different approach: You seem not to be concerned about memory usage.. so.. . I might try to:
- create a heap table (in memory table in MySql terms)
- query just the red range into that table
- run a query against the heap table to delete records with green values outside the range of what you want
- then do the same type of query to delete the records which are outside the range of blue values you want
The initial heap table will probably be huge, but I am guessing you have plenty of memory.
This is of course a brute force method, and you may have to limit your initial query a bit more. However, once the initial query is done:
- the subsequent delete queries will be very fast
- you will recover unused memory
Once you are down to the initially required set, further queries will be very, very fast.
Not elegant, but I have done this with large data sets when I don't have the time to mess with re-designing the schema, or coding fancy algorithms (which I am not good at anyway), and it worked great!..
Just a thought....
- ...the majority is always wrong, and always the last to know about it...
- The Spice must flow...
- ..by my will, and by will alone.. I set my mind in motion