日期:2014-05-16  浏览次数:20919 次

temptable类型的视图问题
merge类型的视图会将查询视图时使用的where条件与定义视图时的where条件相结合,然后从基表中取数据;
temptable类型的是将视图中的数据保存到一个临时表中。
我做了一个测试,就是向基表中插入数据,对于merge类型的视图,查询出新插入的数据很正常,因为本来就是对基表进行查询,可是对于temptable类型的视图,也能查询出新插入的数据!这块没太理解,临时表应该不会有新插入的数据吧?

------解决方案--------------------
请给出基表和temptable的结构
------解决方案--------------------
引用For UNDEFINED, MySQL chooses which algorithm to use. It prefers MERGE over TEMPTABLE if possible, because MERGE is usually more efficient and because a view cannot be updatable if a temporary table is used.

A reason to choose TEMPTABLE explicitly is that locks can be released on underlying tables after the temporary table has been created and before it is used to finish processing the statement. This might result in quicker lock release than the MERGE algorithm so that other clients that use the view are not blocked as long.