Question

Is MySQL VIEW created and stored with data on file system, so when we do query to view, it will come from VIEW table instead of doing query to actual table.

Or it hold only definition of VIEW and always fetch from actual table when ever we do query on view.

If MySQL don't support VIEW data caching is there any other database that support this?

Was it helpful?

Solution

In general, the view definition is stored in the database and substituted into queries as the query (not as the results). This is standard in all databases.

What you are talking about are "materialized views".

MySQL does not support materialized views. SQL Server and Oracle do support them. Other databases may as well.

OTHER TIPS

MySQL

No, MySQL does not store the data for a view.

You can get something like materialized views using an open-source tool called FlexViews, which scans the binary log to make incremental updates to a table holding the materialized view.

See https://github.com/greenlion/swanhart-tools

PostgreSQL

PostgreSQL 9.3 supports materialized views as a new feature, although refreshing a view is not incremental or automatic.

See https://wiki.postgresql.org/wiki/What%27s_new_in_PostgreSQL_9.3#Materialized_Views

Others

I don't know of any other open-source RDBMS that supports materialized views.


The following are non-open-source databases:

Oracle

Oracle has supported materialized views since at least release 9i.

See Materialized View Concepts and Architecture.

Microsoft SQL Server

Microsoft has indexed views since 2005. While these are not exactly the same as materialized views, they may be similar enough they do what you want.

See http://aboutsqlserver.com/2011/03/24/indexed-materialized-views-in-microsoft-sql-server/

IBM DB2

In DB2, a materialized query table (MQT) is a table whose definition is based on the result of a query. As such, the MQT typically contains precomputed results based on the data existing in the table or tables that its definition is based on. If the query compiler determines that a query will run more efficiently against an MQT than the base table or tables, the query executes against the MQT and you obtain the result faster than you otherwise would. This concept is identical to the materialized view concept in Oracle.

See Comparing DB2 materialized query tables and Oracle materialized views

Sybase

Sybase SQL Anywhere 12 supports materialized views.

A materialized view is a view whose result set has been computed and stored on disk, similar to a base table. Conceptually, a materialized view is both a view (it has a query specification stored in the catalog) and a table (it has persistent materialized rows). So, many operations that you perform on tables can be performed on materialized views as well. For example, you can build indexes on, and unload from, materialized views.

See Working with materialized views.

Informix

Informix does not support materialized views as most people think of the term. Informix uses the term "materialized view" differently than most people:

However, a query against a view might execute more slowly than expected when the complexity of the view definition causes a temporary table to be created to process the query. This temporary table is referred to as a materialized view. For example, you can create a view with a union to combine results from several SELECT statements.

See View Costs in the Informix 11.50 Performance Guide.

Teradata

Teradata has implemented materialized views since at least 2002.

See Introduction to Materialized Views in Teradata (PDF).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top