简体   繁体   English

索引跨越PostgreSQL中的多个表

[英]Index spanning multiple tables in PostgreSQL

Is it possible in PostgreSQL to place an index on an expression containing fields of multiple tables. 在PostgreSQL中是否可以在包含多个表的字段的表达式上放置索引。 So for example an index to speed up an query of the following form: 例如,加速查询以下形式的索引:

SELECT *, (table1.x + table2.x) AS z
FROM table1
INNER JOIN table2
ON table1.id = table2.id
ORDER BY z ASC

No it's not possible to have an index on many tables, also it really wouldn't guarantee speeding up anything since you won't always get an Index Only Scan. 不,它不可能在许多表上都有索引,它也不能保证加速任何东西,因为你不会总是得到一个Index Only Scan。 What you really want is a materialized view but pg doesn't have those either. 你真正想要的是物化视图,但pg也没有。 You can try implementing it yourself using triggers like this or this . 您可以尝试使用此类 或此类的触发器自行实现它。


Update 更新

As noted by @petter. 如@petter所述。 The materialized views were introduced in 9.3 . 物化观点在9.3中介绍

No, that's not possible in any currently shipping SQL dbms. 不,这不可能在任何目前出货的SQL数据库管理系统。 Oracle supports bitmap join indexes , but that might not be relevant. Oracle支持位图连接索引 ,但这可能不相关。 It's not clear to me whether you want an index on only the join columns of multiple tables, or whether you want an index on arbitrary columns of joined tables. 我不清楚您是否只想在多个表的连接列上建立索引,或者是否要在连接表的任意列上建立索引。

To determine the real source of performance problems, learn to read the output of PostgreSQL's EXPLAIN ANALYZE . 要确定性能问题的真正来源,请学习阅读PostgreSQL的EXPLAIN ANALYZE的输出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM