I have two sizable (~1M rows each) Oracle tables that I need to join on a range of integers. For example,
Range_Descriptors
-----------------
range_id
from_value number(38)
to_value number(38)
descriptor
Values
------
value_id
value number(38)
...
And so in this case I need to get the Range_Descriptors.descriptor
for each record in Values where value
falls between from_value
and to_value
.
The most obvious query does return the expected results; however, it runs extremely slowly (~20 minutes):
select v.value_id, r.descriptor
from Values v join Range_Descriptors r on v.value between r.from_value and r.to_value;
I’ve played around with different indexing options, but I haven’t found anything that significantly improves performance. Currently there are indexes on Range_Descriptors(from_value, to_value) and on Values(value). Suggestions?
verbalclay is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.