Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Efficient v6 subnet queries #57

Closed
leoluk opened this issue Jul 22, 2020 · 2 comments
Closed

Efficient v6 subnet queries #57

leoluk opened this issue Jul 22, 2020 · 2 comments
Milestone

Comments

@leoluk
Copy link
Member

leoluk commented Jul 22, 2020

Trivial with an IPv4, surprisingly non-trivial with IPv6 because it's a FixedString(16) and we can't do bitwise ops on it.

ClickHouse/ClickHouse#6808

ClickHouse/ClickHouse#11245

This is the only way to do a bitwise query:

select count(Date) from flows_raw where EType = 0x0800 and IPv6CIDRToRange(DstAddr, 104).1 = toIPv6('::44.0.0.0');

Calculate the bitmask by adding 96 to the CIDR mask (i.e. /24 == 24 + 96 == 120).

If you want to filter for the 44.0.0.0/8 network, the query for the "Custom SQL" field would be IPv6CIDRToRange(DstAddr, 104).1 = toIPv6('::44.0.0.0').

For known query patterns, it would be advisable to materialize computed columns.

@leoluk leoluk added this to the v1.0.0 milestone Jul 22, 2020
@fionera
Copy link
Collaborator

fionera commented Oct 21, 2022

In the current version of clickhouse there is a function for this:
https://clickhouse.com/docs/en/sql-reference/functions/ip-address-functions#isipaddressinrange

 select SrcAddr from flows_raw where isIPAddressInRange(toString(SrcAddr), '::44.0.0.0/104') == 1  limit 10;

@fionera
Copy link
Collaborator

fionera commented Dec 7, 2022

Implemented with 3052806

@fionera fionera closed this as completed Dec 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants