Hi, Community.
I’m currently working on storing a table with IP ranges as the partition key (ip_from
and ip_to
declared as inet type). Since IP ranges may overlap, I’ve added an additional unique clustering key row_num
, to ensure that I can always select the same row from a set of ranges. The create table statement looks like this:
create table my_table ( ip_from inet, ip_to inet, row_num bigint, …, primary key ((ip_from, ip_to), row_num) )
I’m executing queries to find a row with an IP range that includes a provided IP address:
select * from my_table where ip_from <= ? and ip_to >= ? limit 1 allow filtering
In some cases, I manage to find the row I’m looking for (for example, any IP in the range 2607:fb90:e200:8000::
to 2607:fb90:e200:80ff:ffff:ffff:ffff:ffff
), but in other cases, nothing is found (for example, any IP in the range 2603:2000::
to 2603:203f:ffff:ffff:ffff:ffff:ffff:ffff
).
Could anyone explain this behavior?
(I understand that this might not be the most appropriate task to solve using Scylla, but perhaps there’s a way to tackle it somehow)
UPD: I found workaround hack but I don’t think that it is best solution. I converted all ip ranges to CIDR format and used 2 parts of it as 2 primary keys. For example, ip range 2607:fb90:e200:8000::
- 2607:fb90:e200:80ff:ffff:ffff:ffff:ffff
can be presented as 2607:fb90:e200:8000::/56
- 2607:fb90:e200:8000::
as first key and 56
as second key. It is good, if all ranges has the same ip prefix in CIDR, but in my case this is not the true. I have to iterate with passed ip to find needed ip_prefix from 128 to 1 for IPv6 and from 32 to 1 for IPv4.
It looks like the best solution is to use vector search mechanism like Cassandra supports now, but as I know Scylla don’t support it yet.