Why use the IP4R extension and not Postgres’ network address types?
Postgres comes with network address types (doc) like: INET
and CIDR
. Even though they are quite useful in their own merit, they are not as performant at large-scale high-performance IP query operations.
From the rationale section of IP4R extension documentation:
While PostgreSQL already has builtin types ‘inet’ and ‘cidr’, the authors of this module found that they had a number of requirements that were not addressed by the builtin type.
Firstly and most importantly, the builtin types have no good support for index lookups of the form (column >>= parameter), i.e. where you have a table of IP address ranges and wish to find which ones include a given IP address.
Secondly, the builtin inet/cidr are somewhat overloaded with semantics, with inet combining two distinct concepts (a netblock, and a specific IP within that netblock).
Because of the specialized indexing capabilities, operators and data types, IP4R objectively gives high-performance solutions compared to Postgres native network data types.