【问题标题】:Create index on foreign table PostgreSQL在外部表 PostgreSQL 上创建索引
【发布时间】:2016-05-11 13:11:48
【问题描述】:

我正在使用 postgres_fdw 在两个数据库之间创建链接。然后我设置外部表并从外部表插入到我的实时表中。我注意到这需要相当长的时间,因为它们没有索引。

你能在外表上创建索引吗,是标准的吗

CREATE INDEX ON foreign_table_name (column)?  

【问题讨论】:

    标签: postgresql indexing postgres-fdw


    【解决方案1】:

    不,你会得到一个错误:

    ERROR:  cannot create index on foreign table "tablename"
    ********** Error **********
    
    ERROR: cannot create index on foreign table "tablename"
    SQL state: 42809
    

    这是有道理的,因为每次查询表时,查询都会“穿越”网络并从原始数据库中检索数据(不会将数据存储到索引中)。

    您可以做的是使用详细解释来获取正在另一端执行的查询,并相应地为远程表建立索引。

    explain verbose select * from schema.foreign_table
    
    "Foreign Scan on schema.foreign_table  (cost=25.00..1025.00 rows=1000 width=84)"
    "  Output: field1, field2, field3
    "  Remote server startup cost: 25"
    "  Remote query: SELECT field1, field2, field3 FROM schema.original_table
    

    希望对您有所帮助。 祝你好运!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-18
      • 1970-01-01
      • 2017-04-27
      • 1970-01-01
      • 1970-01-01
      • 2016-05-27
      • 2013-10-24
      • 2013-11-27
      相关资源
      最近更新 更多