Are views in PostgreSQL completely recalculated every time one of underneath tables are changed?
More precisely, if I have aggregate view over table votes, will complete recalculation of a view be needed, when any changes are made in votes table?
If I expect often changes of votes table, what are alternatives to aggregate view? I need polylogarithmic time complexity of simple querys.
Normal VIEWS in Postgres (and other RDBMS’s that I’m aware of) are really nothing more than a stored SELECT statement. Its not storing the actual information in a static table – thats a materialized VIEW (which Postgres doesn’t currently have, and you’ll have to roll your own). It will in a sense “recalculate every time”, in that it doesn’t store the calculated data.
Check the previous link for how to do a materialized view if you want to store the complex calculations.
EDIT: If like OMG Ponies says, you’re talking about ALTER TABLE on the underlying table – then its easy…Postgres won’t let you change the definition of a column that used in a VIEW without dropping the VIEW first.