› MySQL 5.5 Community Server
› MySQL 5.6 Community Server
› Percona Configuration Wizard
› XtraBackup 搭建主从复制
Great Sites on MySQL
› Percona
› MySQL Performance Blog
› Severalnines
推荐管理工具
› Sequel Pro
› phpMyAdmin
推荐书目
› MySQL Cookbook
MySQL 相关项目
› MariaDB
› Drizzle
参考文档
› http://mysql-python.sourceforge.net/MySQLdb.html
id4alex
V2EX  ›  MySQL

PG 如何创建包含地理位置信息和其他字段的复合索引?

  •  
  •   id4alex · Aug 31, 2016 · 3034 views
    This topic created in 3680 days ago, the information mentioned may be changed or developed.
    sorry 不好意思暂时不知道把这个挪到什么节点下面去。暂时挂在 mysql 下面把。


    最近有个场景有地理位置的需求,所以试用了下 PG, 关于这块不太熟悉.


    表 DDL:
    CREATE TABLE test
    (
    longid bigint NOT NULL DEFAULT nextval('test_longid_seq'::regclass),
    longitude double precision,
    latitude double precision,
    create_ts_long bigint,
    CONSTRAINT test_pkey PRIMARY KEY (longid)
    )

    如果仅仅是创建关于地理位置信息的索引,如下操作可以解决。
    CREATE INDEX ll_idx
    ON test USING gist
    (ll_to_earth(latitude ::double precision, longitude ::double precision))
    TABLESPACE pg_default;

    但是有这样一个场景,筛选出在具体时间段内距离最近的记录, 这种情况下应该如何创建复合索引?


    先拜谢了!
    2 replies  •  2016-08-31 14:00:59 +08:00
    lazyCoder
        1
    lazyCoder  
       Aug 31, 2016
    pg 是 postgresql 么?

    创建复合索引不就是这样么
    create index index_name on table_name on (c1,c2);
    id4alex
        2
    id4alex  
    OP
       Aug 31, 2016
    @lazyCoder 复合索引包含 ll_to_earth(latitude ::double precision, longitude ::double precision),再加上 timestamp 作为索引。 看起来似乎有点麻烦。

    我现在想切换成 geohash 来做吧, 似乎成本更低。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   4141 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 21ms · UTC 00:07 · PVG 08:07 · LAX 17:07 · JFK 20:07
    ♥ Do have faith in what you're doing.