Sample Header Ad - 728x90

Why does postgres/citus use the index when querying the table, but not trough the view?

0 votes
0 answers
105 views
I have a Citus 9.5 database (postgres 11) on Azure and executing a complicated query with CTEs. The schema has a simple view from another schema as:
create view my_schema.table1
as
select * from other_schema.table1
When my query joins to my_schema.table1 it does a Seq Scan on the table which leads to poor performance. However when my query joins directly to other_schema.table1 it uses the primary key index which is fast. I have run ANALYZE [table] on both the table and the view. Why does Postgres not use the index when I query via the view, but it does when I query via the table?
Asked by Brendan Hill (301 rep)
Dec 13, 2021, 10:55 PM
Last activity: Dec 14, 2021, 12:16 AM