<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>AnySQL.net &#187; Fast</title>
	<atom:link href="http://www.anysql.net/tag/fast/feed" rel="self" type="application/rss+xml" />
	<link>http://www.anysql.net</link>
	<description>SQLULDR2, DataCopy, DataSync, WebChart, OraMon, AUL/MyDUL, 性能优化及容量分析</description>
	<lastBuildDate>Sun, 29 Aug 2010 00:14:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Oracle的实体化视图(MVIEW)的深入研究之四</title>
		<link>http://www.anysql.net/oracle/mvlog_with_rowid_primarykey.html</link>
		<comments>http://www.anysql.net/oracle/mvlog_with_rowid_primarykey.html#comments</comments>
		<pubDate>Fri, 09 Mar 2007 18:27:58 +0000</pubDate>
		<dc:creator>anysql</dc:creator>
				<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Fast]]></category>
		<category><![CDATA[Log]]></category>
		<category><![CDATA[MVIEW]]></category>
		<category><![CDATA[Refresh]]></category>

		<guid isPermaLink="false">http://www.anysql.net/wordpress/uncategorized/oracle%e7%9a%84%e5%ae%9e%e4%bd%93%e5%8c%96%e8%a7%86%e5%9b%bemview%e7%9a%84%e6%b7%b1%e5%85%a5%e7%a0%94%e7%a9%b6%e4%b9%8b%e5%9b%9b.html</guid>
		<description><![CDATA[&#160; &#160; 现在对第一篇中基表进行移动(Move)操作, 会发现不能进行快速刷新, 必须进行全部(Complete)刷新才行. 如下所示: SQL&#62; ALTER TABLE T_MVLOG MOVE; Table altered. SQL&#62; EXEC DBMS_MVIEW.REFRESH(&#8216;MV_T_MVLOG&#8217;,'FAST&#8217;); BEGIN DBMS_MVIEW.REFRESH(&#8216;MV_T_MVLOG&#8217;,'FAST&#8217;); END; * ERROR at line 1: ORA-12034: materialized view log on &#8220;ANYSQL&#8221;.&#8221;T_MVLOG&#8221; younger than last refresh ORA-06512: at &#8220;SYS.DBMS_SNAPSHOT&#8221;, line 803 ORA-06512: at &#8220;SYS.DBMS_SNAPSHOT&#8221;, line 860 ORA-06512: at &#8220;SYS.DBMS_SNAPSHOT&#8221;, line 841 ORA-06512: at line 1 &#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>&nbsp; &nbsp; 现在对<a href="http://www.anysql.net/oracle/improve_mv_refresh.html">第一篇</a>中基表进行移动(Move)操作, 会发现不能进行快速刷新, 必须进行全部(Complete)刷新才行. 如下所示: </p>
<blockquote class="prefont"><p>
SQL&gt; ALTER TABLE T_MVLOG MOVE;</p>
<p>Table altered.</p>
<p>SQL&gt; EXEC DBMS_MVIEW.REFRESH(&#8216;MV_T_MVLOG&#8217;,'FAST&#8217;);<br />
BEGIN DBMS_MVIEW.REFRESH(&#8216;MV_T_MVLOG&#8217;,'FAST&#8217;); END;</p>
<p>*<br />
ERROR at line 1:<br />
ORA-12034: materialized view log on &#8220;ANYSQL&#8221;.&#8221;T_MVLOG&#8221; younger than last refresh<br />
ORA-06512: at &#8220;SYS.DBMS_SNAPSHOT&#8221;, line 803<br />
ORA-06512: at &#8220;SYS.DBMS_SNAPSHOT&#8221;, line 860<br />
ORA-06512: at &#8220;SYS.DBMS_SNAPSHOT&#8221;, line 841<br />
ORA-06512: at line 1
</p></blockquote>
<p>&nbsp; &nbsp; 为什么失败, 可以仔细分析一下基于ROWID的MVIEW LOG被刷新的过程, 当基表移动后, ROWID的值变了, 因此不能再继续支持主表的UPDATE/DELETE这样的操作了. 下面将这个实体化视图重新定义成基于主键(Primary Key)的, 首先删除现有的实体化视图及日志, 再为表加一个主键, 重新创建实体化视图 : </p>
<blockquote class="prefont"><p>
SQL&gt;&nbsp;&nbsp;alter table t_mvlog modify col1 not null;</p>
<p>Table altered.</p>
<p>SQL&gt; alter table t_mvlog add primary key (col1);</p>
<p>Table altered.</p>
<p>SQL&gt; create materialized view log on t_mvlog with primary key, sequence;</p>
<p>Materialized view log created.</p>
<p>SQL&gt; CREATE MATERIALIZED VIEW MV_T_MVLOG <br />
&nbsp;&nbsp;2&nbsp;&nbsp;&nbsp;&nbsp;REFRESH FAST WITH PRIMARY KEY<br />
&nbsp;&nbsp;3&nbsp;&nbsp;AS SELECT ROWID R_ID, A.* FROM T_MVLOG A; </p>
<p>Materialized view created.
</p></blockquote>
<p>&nbsp; &nbsp; 再对基表作移动(Move)操作后, 就可以进行增量刷新了. </p>
<blockquote class="prefont"><p>
SQL&gt; alter table t_mvlog move;</p>
<p>Table altered.</p>
<p>SQL&gt; exec dbms_mview.refresh(&#8216;MV_T_MVLOG&#8217;,'FAST&#8217;);</p>
<p>PL/SQL procedure successfully completed.
</p></blockquote>
<p>&nbsp; &nbsp; 选择基于ROWID还是基于主键(Primary Key)的实体化视图日志, 还是很重要的. </p>
<h3  class="related_post_title">Relative Posts:</h3><ul class="related_post"><li>2007/03/09 -- <a href="http://www.anysql.net/oracle/star_in_mview.html" title="Oracle的实体化视图(MVIEW)的深入研究之三">Oracle的实体化视图(MVIEW)的深入研究之三</a> (0)</li><li>2007/03/08 -- <a href="http://www.anysql.net/oracle/improve_mv_refresh.html" title="Oracle的实体化视图(MVIEW)的深入研究之一">Oracle的实体化视图(MVIEW)的深入研究之一</a> (0)</li><li>2007/12/18 -- <a href="http://www.anysql.net/oracle/mview_ora_04031.html" title="MVIEW引起ORA-04031">MVIEW引起ORA-04031</a> (0)</li><li>2007/07/17 -- <a href="http://www.anysql.net/dba/capture_table_row_change.html" title="问题解答 &#8212; 如何得知一张表的纪录有变化?">问题解答 &#8212; 如何得知一张表的纪录有变化?</a> (2)</li><li>2007/03/29 -- <a href="http://www.anysql.net/tools/refresh_mysql_delete_where.html" title="使refresh_mysql适用于数据归档的一点改进">使refresh_mysql适用于数据归档的一点改进</a> (0)</li><li>2007/03/29 -- <a href="http://www.anysql.net/dba/data_lost_by_mview_refresh.html" title="由物化视图Complete刷新引起的数据丢失">由物化视图Complete刷新引起的数据丢失</a> (11)</li><li>2007/03/14 -- <a href="http://www.anysql.net/tools/oracle_mysql_replication_demo.html" title="refresh_mysql.pl角本的一个配置例子">refresh_mysql.pl角本的一个配置例子</a> (0)</li><li>2007/03/08 -- <a href="http://www.anysql.net/oracle/reorg_master_table.html" title="Oracle的实体化视图(MVIEW)的深入研究之二">Oracle的实体化视图(MVIEW)的深入研究之二</a> (0)</li><li>2008/07/24 -- <a href="http://www.anysql.net/oracle/linux_move_files.html" title="事务数高了会如何?">事务数高了会如何?</a> (3)</li><li>2008/03/06 -- <a href="http://www.anysql.net/dba/shareplex_from_europe.html" title="HVR, 欧州的Shareplex?">HVR, 欧州的Shareplex?</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.anysql.net/oracle/mvlog_with_rowid_primarykey.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Oracle的实体化视图(MVIEW)的深入研究之一</title>
		<link>http://www.anysql.net/oracle/improve_mv_refresh.html</link>
		<comments>http://www.anysql.net/oracle/improve_mv_refresh.html#comments</comments>
		<pubDate>Thu, 08 Mar 2007 18:36:25 +0000</pubDate>
		<dc:creator>anysql</dc:creator>
				<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Fast]]></category>
		<category><![CDATA[MVIEW]]></category>
		<category><![CDATA[Query Rewrite]]></category>
		<category><![CDATA[Refresh]]></category>

		<guid isPermaLink="false">http://www.anysql.net/wordpress/uncategorized/oracle%e7%9a%84%e5%ae%9e%e4%bd%93%e5%8c%96%e8%a7%86%e5%9b%bemview%e7%9a%84%e6%b7%b1%e5%85%a5%e7%a0%94%e7%a9%b6%e4%b9%8b%e4%b8%80.html</guid>
		<description><![CDATA[&#160; &#160; 从Oracle 8i开始提供了实体化视图, 能过预先计算好的中间表来提高应用的访问速度, 在特定的情况下是很有用的一项技术. 另外实体化视图还可用于数据复制, 在这个上面的应用越来越多. MVIEW中经常跗以遇到刷新很慢的情况, 如何提高呢? 首先来研究一下刷新的过程. 下面是用来创建演示表的角本: CREATE TABLE T_MVLOG (COL1 VARCHAR2(20)); CREATE MATERIALIZED VIEW LOG ON T_MVLOG &#160;&#160;&#160;&#160;WITH ROWID, sequence; CREATE MATERIALIZED VIEW MV_T_MVLOG &#160;&#160; REFRESH FAST &#160;&#160; WITH ROWID AS &#160;&#160; SELECT ROWID R_ID, A.* FROM T_MVLOG A; &#160; &#160; 我们对DBMS_MVIEW.REFRESH作一个SQL_TRACE, 在这个例子中, 我在基表中插入了一打记录, 然后作跟踪的. 可以看到第一步为: update &#8220;ANYSQL&#8221;.&#8221;MLOG$_T_MVLOG&#8221; set [...]]]></description>
			<content:encoded><![CDATA[<p>&nbsp; &nbsp; 从Oracle 8i开始提供了实体化视图, 能过预先计算好的中间表来提高应用的访问速度, 在特定的情况下是很有用的一项技术. 另外实体化视图还可用于数据复制, 在这个上面的应用越来越多. MVIEW中经常跗以遇到刷新很慢的情况, 如何提高呢? 首先来研究一下刷新的过程. 下面是用来创建演示表的角本: </p>
<blockquote class="prefont"><p>
CREATE TABLE T_MVLOG (COL1 VARCHAR2(20));<br />
CREATE MATERIALIZED VIEW LOG ON T_MVLOG <br />
&nbsp;&nbsp;&nbsp;&nbsp;WITH ROWID, sequence;<br />
CREATE MATERIALIZED VIEW MV_T_MVLOG <br />
&nbsp;&nbsp; REFRESH FAST <br />
&nbsp;&nbsp; WITH ROWID <br />
AS <br />
&nbsp;&nbsp; SELECT ROWID R_ID, A.* FROM T_MVLOG A;
</p></blockquote>
<p>&nbsp; &nbsp; 我们对DBMS_MVIEW.REFRESH作一个SQL_TRACE, 在这个例子中, 我在基表中插入了一打记录, 然后作跟踪的. 可以看到第一步为: </p>
<blockquote class="prefont"><p>
update &#8220;ANYSQL&#8221;.&#8221;MLOG$_T_MVLOG&#8221; set snaptime$$ = :1&nbsp;&nbsp;<br />
&nbsp;&nbsp; where snaptime$$ &gt; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;to_date(&#8217;2100-01-01:00:00:00&#8242;,&#8217;YYYY-MM-DD:HH24:MI:SS&#8217;)
</p></blockquote>
<p>&nbsp; &nbsp; 第二步, 取得在这段时间内发生修改的每一行的ROWID</p>
<blockquote class="prefont"><p>
SELECT DISTINCT M_ROW$$ FROM <br />
(<br />
&nbsp;&nbsp; SELECT M_ROW$$ <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FROM &#8220;ANYSQL&#8221;.&#8221;MLOG$_T_MVLOG&#8221; MLOG$ <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;WHERE &#8220;SNAPTIME$$&#8221; &gt; :1 AND (&#8220;DMLTYPE$$&#8221; != &#8216;I&#8217;)<br />
) LOG$ <br />
WHERE (M_ROW$$) NOT IN <br />
&nbsp;&nbsp;&nbsp;&nbsp; (<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SELECT ROWID FROM &#8220;T_MVLOG&#8221; &#8220;MAS_TAB$&#8221; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WHERE MAS_TAB$.ROWID = LOG$.M_ROW$$<br />
&nbsp;&nbsp;&nbsp;&nbsp; )
</p></blockquote>
<p>&nbsp; &nbsp; 第三步, 取得刷新后的值</p>
<blockquote class="prefont"><p>
SELECT CURRENT$.&#8221;R_ID&#8221;,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CURRENT$.&#8221;COL1&#8243;,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ROWIDTOCHAR(CURRENT$.ROWID) M_ROW$$ <br />
FROM <br />
(<br />
&nbsp;&nbsp;SELECT &#8220;A&#8221;.ROWID &#8220;R_ID&#8221;,&#8221;A&#8221;.&#8221;COL1&#8243; &#8220;COL1&#8243; FROM &#8220;T_MVLOG&#8221; &#8220;A&#8221;<br />
) CURRENT$, <br />
(<br />
&nbsp;&nbsp;SELECT DISTINCT M_ROW$$ FROM &#8220;ANYSQL&#8221;.&#8221;MLOG$_T_MVLOG&#8221; MLOG$ <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;WHERE &#8220;SNAPTIME$$&#8221; &gt; :1 AND (&#8220;DMLTYPE$$&#8221; != &#8216;D&#8217;)<br />
) LOG$ <br />
WHERE CURRENT$.ROWID = LOG$.M_ROW$$
</p></blockquote>
<p>&nbsp; &nbsp; 第四步, 对MVIEW进行插入</p>
<blockquote class="prefont"><p>
INSERT INTO &#8220;ANYSQL&#8221;.&#8221;MV_T_MVLOG&#8221;&nbsp;&nbsp;(&#8220;R_ID&#8221;,&#8221;COL1&#8243;,&#8221;M_ROW$$&#8221;)<br />
&nbsp;&nbsp; VALUES (:1,:2,:3)
</p></blockquote>
<p>&nbsp; &nbsp; 最后一步, 删除MVLOG中的值</p>
<blockquote class="prefont"><p>
delete from &#8220;ANYSQL&#8221;.&#8221;MLOG$_T_MVLOG&#8221; where snaptime$$ &lt;= :1
</p></blockquote>
<p>&nbsp; &nbsp; 从这外过程来看,  可以调的方法有四个, 首先<strong>尽量使用快速刷新, 提高刷新频率</strong>, 其次可以<strong>在MLOG$_T_MVLOG这个表的snaptime$$字段上建索引</strong>, 第三<strong>为刷新的过程设定会话级的DB_FILE_MULTIBLOCK_READ_COUNT以及SORT_AREA_SIZE等参数</strong>, 第四选择时间<strong>对MLOG$_T_MVLOG这个表进行重组以减少表的大小</strong>. 这些方法仅供参考.</p>
<h3  class="related_post_title">Relative Posts:</h3><ul class="related_post"><li>2007/03/09 -- <a href="http://www.anysql.net/oracle/mvlog_with_rowid_primarykey.html" title="Oracle的实体化视图(MVIEW)的深入研究之四">Oracle的实体化视图(MVIEW)的深入研究之四</a> (2)</li><li>2007/03/09 -- <a href="http://www.anysql.net/oracle/star_in_mview.html" title="Oracle的实体化视图(MVIEW)的深入研究之三">Oracle的实体化视图(MVIEW)的深入研究之三</a> (0)</li><li>2007/12/18 -- <a href="http://www.anysql.net/oracle/mview_ora_04031.html" title="MVIEW引起ORA-04031">MVIEW引起ORA-04031</a> (0)</li><li>2007/03/29 -- <a href="http://www.anysql.net/tools/refresh_mysql_delete_where.html" title="使refresh_mysql适用于数据归档的一点改进">使refresh_mysql适用于数据归档的一点改进</a> (0)</li><li>2007/03/29 -- <a href="http://www.anysql.net/dba/data_lost_by_mview_refresh.html" title="由物化视图Complete刷新引起的数据丢失">由物化视图Complete刷新引起的数据丢失</a> (11)</li><li>2007/03/14 -- <a href="http://www.anysql.net/tools/oracle_mysql_replication_demo.html" title="refresh_mysql.pl角本的一个配置例子">refresh_mysql.pl角本的一个配置例子</a> (0)</li><li>2008/01/17 -- <a href="http://www.anysql.net/oracle/drop_busy_materialized_view.html" title="不能删除物化视图?">不能删除物化视图?</a> (1)</li><li>2007/09/04 -- <a href="http://www.anysql.net/developer/tuning_with_array_dml.html" title="在Perl中用Array DML来进行性能调优">在Perl中用Array DML来进行性能调优</a> (0)</li><li>2007/07/17 -- <a href="http://www.anysql.net/dba/capture_table_row_change.html" title="问题解答 &#8212; 如何得知一张表的纪录有变化?">问题解答 &#8212; 如何得知一张表的纪录有变化?</a> (2)</li><li>2007/03/24 -- <a href="http://www.anysql.net/developer/mysql_mview_log.html" title="在MySQL中建立实体化视图日志">在MySQL中建立实体化视图日志</a> (2)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.anysql.net/oracle/improve_mv_refresh.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
