【问题标题】:Which Index is best for PostgreSQL inet datatype?哪个索引最适合 PostgreSQL inet 数据类型?
【发布时间】:2018-08-06 15:54:43
【问题描述】:

我正在使用 PostgreSQL 从表中获取“IP 到城市”数据,但响应时间过长。我还在 network 列上使用 btree 索引。

我的查询是:

SELECT city_name, subdivision, country_name,continent_name FROM ip4_to_city_tbl WHERE '104.225.250.92' LIMIT强> 1;

表 'ip4_to_city_tbl' 有 9685491 条记录。

如果我们在 1 秒内有超过 400 个请求,那么响应需要 200 到 900 毫秒。

我希望在 10 毫秒内得到查询的响应。

EXPLAIN 命令在 ip4_to_city_tbl 查询中显示 Seq Scan 而不是 Index Scan

那么请告诉我,应该如何提高响应时间以及哪个索引最适合 PostgreSQL inet 数据类型?

【问题讨论】:

    标签: database postgresql ip


    【解决方案1】:

    一般来说,inet_ops 索引类型是 inet 和 cidr 数据类型的首选。

     create index on ip4_to_city_tbl using gist (network inet_ops);
    

    【讨论】:

    • 显示ERROR: operator class "inet_ops" does not exist for access method "gist"
    • 现在它在将 PostgreSQL 版本更新到 10.4 后可以完美运行 感谢@Joe Love
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-02-14
    • 2010-12-29
    • 2016-11-19
    • 1970-01-01
    • 2019-07-23
    • 2010-11-02
    • 2011-07-26
    相关资源
    最近更新 更多