作者:Mr_维力_811 | 来源:互联网 | 2023-09-06 16:01
Ihaveatableof1.6MIPrangeswithorganizationnames.TheIPaddressesareconvertedtointegers
I have a table of 1.6M IP ranges with organization names. The IP addresses are converted to integers. The table is in the form of:
我有一个包含1.6M个IP范围和组织名称的表。IP地址被转换成整数。该表的形式为:
![enter image description here](https://www.#.com/go/aHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS9iaTVkYi5wbmc=)
I have a list of 2000 unique ip addresses (e.g. 321223, 531223, ....) that need to be translated to an organization name.
我有2000个不同的ip地址列表(如321223年,321223年,....)需要翻译一个组织的名字。
I loaded the translation table as a mysql table with an index on IP_from and IP_to. I looped through the 2000 IP addresses, running one query per ip address, and after 15 minutes the report was still running. The query I'm using is
我将翻译表作为mysql表加载,其中包含IP_from和IP_to的索引。我浏览了2000个IP地址,每个IP地址运行一个查询,15分钟后报告仍在运行。我使用的查询是
select organization from iptable where ip_addr BETWEEN ip_start AND ip_end
Is there a more efficient way to do this batch look-up? I'll use my fingers if it's a good solution. And in case someone has a Ruby-specific solution, I want to mention that I'm using Ruby.
是否有更有效的方法来进行批查找?如果这是个好办法,我就用我的手指。如果有人有特定于Ruby的解决方案,我想说我正在使用Ruby。
2 个解决方案