![]() |
MySQL:Views vs Tables |
|
|
Motivation: MySQL 5.x supports views - what database developers gain MySQL version 5.0 adds views, triggers and stored procedures to the MySQL DML-Data Manipulation Language features and functions. Given that users can already : LOAD DATA ... INTO TABLE - import data into tables from external files So what does a VIEW get users over and above the Tables created dynamically using any of the above commands with a powerful SELECT with same possibilities of Joins and Subqueries as used in a CRETE VIEW statement ? Do VIEWS bring anything to the table ? The Tradeoffs CREATE VIEW creates a new view from the underlying tables each time a query of the View is made In contrast when we do a query on the Snapshot table, test1. The old value Saito remains in the There is another difference - see what approach the MySQL developers have taken: Summary Think of Views as dynamic queries into the underlying table(s) that make up the View. In contrast all the other snapshot views are static - that was a onetime query that was done when the table was created. Each is valuable for developers depending on the circumstances. In addition, MySQL is committed to making the underlying tables updatable directly through the View. One can imagine the complexities involved - MySQL has to figure what table(s) to lock to maintain data integrity through the update operation using a view. Finally there is another trade-off involved in using Views - space saved versus the extra time required to do the underlying query that creates the View. Now if a View is queried several times in a row, MySQL is smart enough to cache the underlying View data so that only has to be done once. So there are advantages to doing all queries on a View together to reduce the query time. The space saved can be quite substantial if many views are employed in a system. (C)JBSurveyer Home SQL Overview |
|