PostgreSQL视图以分组方式返回非常慢的结果

问题描述 投票:1回答:1

我有10个表具有相同的列。像2011,2012 .. 2020一样,我逐年制作了单独的数据。

我制作了一个视图,用于使用union all合并所有表数据。

    create view as a combine
    select * from table_2011
    union all
    select * from table_2012
    ..
    union all 
    select * from table_2020;

现在,当我运行一些查询时,它需要9分钟才能归组。

    select name, count(name) from combine group by name;

有人可以帮助我提高视线速度吗?我已经给所有表和列提供了索引。

analysed select

postgresql postgresql-9.4 postgresql-9.5
1个回答
0
投票

将索引添加到视图的名称列中

© www.soinside.com 2019 - 2024. All rights reserved.