Search code examples
postgresqlcachingpostgresql-9.3sql-execution-plan

Does PostgreSQL cache execution plan of a view


Does PostgreSQL cache execution plan of a view, as it does for stored procedures?


Solution

  • No.

    A view is basically a macro - your view definition gets merged with the query against it and then executed.

    So:

    CREATE VIEW v1 AS SELECT * FROM customers WHERE active;
    SELECT * FROM v1 WHERE name LIKE 'A%';
    

    becomes:

    SELECT * FROM customers WHERE active AND name LIKE 'A%';