maxmind / getting-started-with-mmdb

A quick guide to writing and reading from your own MMDB databases.
37 stars 11 forks source link

Query : Understanding Node Count in mmdb #18

Closed zanpakuto closed 1 year ago

zanpakuto commented 1 year ago

I created an mmdb with just one subnet using go writer. Since it is binary search tree in the background, I expected the number of nodes in the search tree to be equal to the prefix length (41 in current example). However when I examined the mmdb file using mmdbctl tool, the number of nodes are way higher than prefix length (370 in current example).

What is the reason behind creating 370 nodes rather than 41?

Wouldn't creating a Search tree with just the bits in the prefix, be more optimal?

Ouput of mmdbctl commands:

% mmdbctl metadata 1rec.mmdb

% mmdbctl export 1rec.mmdb range,city,country,postal,subdivisions 2001:420:5400::/41,"{""names"":{""en"":""Delhi""}}","{""iso_code"":""IN"",""names"":{""en"":""India""}}","{""code"":""110001""}","[{""names"":{""en"":""Delhi""}}]"

oschwald commented 1 year ago

I am guessing you are building your database with remove_reserved_networks enabled. Although I haven't looked at the Perl writer recently, I am guessing there are nodes for all the reserved networks.