Can you create an index on a foreign table?(外部表可以创建索引吗?)

简介: 来自google搜索的一段回答No, you will get an error:ERROR: cannot create index on foreign table "tablename"********** Error **********ERROR: cannot create...

来自google搜索的一段回答

No, you will get an error:

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

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

And it makes sense as the query will "travel" througth the net and retrieve the data from the original database each time you query the table (will not store data to index).

What you can do is to use explain verbose to get the query that is being execute on the other side , and index the remote table accordingly .

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

Hope that helps. Good luck!

相关文章
|
4月前
|
前端开发
`<table>`
【10月更文挑战第17天】
63 1
|
7月前
|
SQL Oracle 关系型数据库
CREATE TABLE 时的 SQL FOREIGN KEY 约束
【7月更文挑战第24天】CREATE TABLE 时的 SQL FOREIGN KEY 约束。
65 5
|
9月前
|
存储 SQL 关系型数据库
CREATE TABLE语句
在MySQL中,使用CREATE TABLE语句来创建表。你需要指定表名和列的定义,包括列名、数据类型以及约束等,结合实际存储和上一课学习的数据类型选取合适的。创建一个book_types表
247 0
|
SQL 存储 关系型数据库
PostgreSQL 动态表复制(CREATE TABLE AS & CREATE TABLE LIKE)
PostgreSQL 动态表复制(CREATE TABLE AS & CREATE TABLE LIKE)
956 0
|
JavaScript 前端开发 数据可视化
vxe-table
vxe-table
786 0
vxe-table
|
SQL 数据库
CREATE TABLE 语句
CREATE TABLE 语句
139 1
|
SQL Oracle 关系型数据库
SQL FOREIGN KEY Constraint on CREATE TABLE
SQL FOREIGN KEY Constraint on CREATE TABLE
98 1
|
SQL HIVE
HIVE: create table 与 create external table 区别
HIVE: create table 与 create external table 区别
|
SQL 数据库
CREATE TABLE
CREATE TABLE
170 0
|
Java 索引
Table(表)
Table(表)
95 0