<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: Running Total</title>
	<atom:link href="http://jonathanlewis.wordpress.com/2012/10/26/running-total/feed/" rel="self" type="application/rss+xml" />
	<link>http://jonathanlewis.wordpress.com/2012/10/26/running-total/</link>
	<description>Just another Oracle weblog</description>
	<lastBuildDate>Fri, 24 May 2013 13:27:07 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Jonathan Lewis</title>
		<link>http://jonathanlewis.wordpress.com/2012/10/26/running-total/#comment-52076</link>
		<dc:creator><![CDATA[Jonathan Lewis]]></dc:creator>
		<pubDate>Thu, 13 Dec 2012 14:21:57 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=9754#comment-52076</guid>
		<description><![CDATA[Sayan,

Very useful points - especially the reminder about write consistency.

In this case, of course, we&#039;re going to be updating every row in the table, so I should have suggested &quot;lock table in exclusive mode&quot; as a starting step - which would be much more efficient than select for update.]]></description>
		<content:encoded><![CDATA[<p>Sayan,</p>
<p>Very useful points &#8211; especially the reminder about write consistency.</p>
<p>In this case, of course, we&#8217;re going to be updating every row in the table, so I should have suggested &#8220;lock table in exclusive mode&#8221; as a starting step &#8211; which would be much more efficient than select for update.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Lewis</title>
		<link>http://jonathanlewis.wordpress.com/2012/10/26/running-total/#comment-52075</link>
		<dc:creator><![CDATA[Jonathan Lewis]]></dc:creator>
		<pubDate>Thu, 13 Dec 2012 14:19:54 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=9754#comment-52075</guid>
		<description><![CDATA[Tony,

I believe your suggestion about why the &quot;next/previous&quot; problem wouldn&#039;t occur to many SQL Server programmers is correct. That doesn&#039;t mean they shouldn&#039;t worry about it, though, it just means they&#039;re slightly less likely to think of it as a problem.]]></description>
		<content:encoded><![CDATA[<p>Tony,</p>
<p>I believe your suggestion about why the &#8220;next/previous&#8221; problem wouldn&#8217;t occur to many SQL Server programmers is correct. That doesn&#8217;t mean they shouldn&#8217;t worry about it, though, it just means they&#8217;re slightly less likely to think of it as a problem.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sayan Malakshinov</title>
		<link>http://jonathanlewis.wordpress.com/2012/10/26/running-total/#comment-51058</link>
		<dc:creator><![CDATA[Sayan Malakshinov]]></dc:creator>
		<pubDate>Tue, 30 Oct 2012 05:34:23 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=9754#comment-51058</guid>
		<description><![CDATA[Lev, your are wrong. If you repeat my example with another simple query:
[sourcecode language=&quot;sql&quot;]
update t1 set running_tot = n1;
[/sourcecode]

or change your query with adding one &quot;dummy&quot; predicate:
[sourcecode language=&quot;sql&quot; highlight=&quot;6&quot;]
update t1
set running_tot = (
                  select sum( t1_1.n1) 
                  from t1 t1_1
                  where t1_1.id &lt;= t1.id
                    and t1_1.n1*0 = t1.n*0
);
[/sourcecode]
 you would see that applied new values.

This behaviour described in articles about &quot;write consistency&quot; and mini-rollbacks(statement restarts).

About posting:
http://jonathanlewis.wordpress.com/comments-on-comment/
http://en.support.wordpress.com/code/posting-source-code/]]></description>
		<content:encoded><![CDATA[<p>Lev, your are wrong. If you repeat my example with another simple query:</p>
<pre class="brush: sql; title: ; notranslate">
update t1 set running_tot = n1;
</pre>
<p>or change your query with adding one &#8220;dummy&#8221; predicate:</p>
<pre class="brush: sql; highlight: [6]; title: ; notranslate">
update t1
set running_tot = (
                  select sum( t1_1.n1) 
                  from t1 t1_1
                  where t1_1.id &lt;= t1.id
                    and t1_1.n1*0 = t1.n*0
);
</pre>
<p> you would see that applied new values.</p>
<p>This behaviour described in articles about &#8220;write consistency&#8221; and mini-rollbacks(statement restarts).</p>
<p>About posting:<br />
<a href="http://jonathanlewis.wordpress.com/comments-on-comment/" rel="nofollow">http://jonathanlewis.wordpress.com/comments-on-comment/</a><br />
<a href="http://en.support.wordpress.com/code/posting-source-code/" rel="nofollow">http://en.support.wordpress.com/code/posting-source-code/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lev Erusalimskiy</title>
		<link>http://jonathanlewis.wordpress.com/2012/10/26/running-total/#comment-51056</link>
		<dc:creator><![CDATA[Lev Erusalimskiy]]></dc:creator>
		<pubDate>Tue, 30 Oct 2012 03:05:24 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=9754#comment-51056</guid>
		<description><![CDATA[I agree that this query is not the fastest, but I don&#039;t think it is more dangerous than any other update statement 
- it sees committed data as of the begging of the query.

Buy the way, how did you add this beautiful formatting to your  post?]]></description>
		<content:encoded><![CDATA[<p>I agree that this query is not the fastest, but I don&#8217;t think it is more dangerous than any other update statement<br />
- it sees committed data as of the begging of the query.</p>
<p>Buy the way, how did you add this beautiful formatting to your  post?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sayan Malakshinov</title>
		<link>http://jonathanlewis.wordpress.com/2012/10/26/running-total/#comment-51044</link>
		<dc:creator><![CDATA[Sayan Malakshinov]]></dc:creator>
		<pubDate>Mon, 29 Oct 2012 18:58:18 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=9754#comment-51044</guid>
		<description><![CDATA[Besides the fact that your query is much heavier (too many current gets), is much more important that it is dangerous because of possible inconsistencies result.
Just simple example with your query:

[sourcecode language=&quot;sql&quot;]
--creating test table with 10 rows, id and n1 = 1..10:
create table t1 as 
select 
   level id
  ,level n1
  ,cast(null as int) running_tot 
from dual 
connect by level&lt;=10;

Table created.

-----------------------
-- in one session we updating n1 to 100 where id=5:
update t1 set n1=100 where id=5;

1 row updated.
-----------------------
            -- in another we updating running_total with your query:
            update t1
            set running_tot = (
                              select sum( t1_1.n1) 
                              from t1 t1_1
                              where t1_1.id &lt;= t1.id
            );
            -- wait for unlocking..
-----------------------
-- now committing in first session:
commit;

Commit complete.
-----------------------
            -- second session unlocked:
            10 rows updated.
            -- let&#039;s see what we got:
            select * from t1;
            
                    ID         N1 RUNNING_TOT
            ---------- ---------- -----------
                     1          1           1
                     2          2           3
                     3          3           6
                     4          4          10
                     5        100          15
                     6          6          21
                     7          7          28
                     8          8          36
                     9          9          45
                    10         10          55

            10 rows selected.
[/sourcecode]]]></description>
		<content:encoded><![CDATA[<p>Besides the fact that your query is much heavier (too many current gets), is much more important that it is dangerous because of possible inconsistencies result.<br />
Just simple example with your query:</p>
<pre class="brush: sql; title: ; notranslate">
--creating test table with 10 rows, id and n1 = 1..10:
create table t1 as 
select 
   level id
  ,level n1
  ,cast(null as int) running_tot 
from dual 
connect by level&lt;=10;

Table created.

-----------------------
-- in one session we updating n1 to 100 where id=5:
update t1 set n1=100 where id=5;

1 row updated.
-----------------------
            -- in another we updating running_total with your query:
            update t1
            set running_tot = (
                              select sum( t1_1.n1) 
                              from t1 t1_1
                              where t1_1.id &lt;= t1.id
            );
            -- wait for unlocking..
-----------------------
-- now committing in first session:
commit;

Commit complete.
-----------------------
            -- second session unlocked:
            10 rows updated.
            -- let's see what we got:
            select * from t1;
            
                    ID         N1 RUNNING_TOT
            ---------- ---------- -----------
                     1          1           1
                     2          2           3
                     3          3           6
                     4          4          10
                     5        100          15
                     6          6          21
                     7          7          28
                     8          8          36
                     9          9          45
                    10         10          55

            10 rows selected.
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lev Erusalimskiy</title>
		<link>http://jonathanlewis.wordpress.com/2012/10/26/running-total/#comment-51032</link>
		<dc:creator><![CDATA[Lev Erusalimskiy]]></dc:creator>
		<pubDate>Mon, 29 Oct 2012 00:03:07 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=9754#comment-51032</guid>
		<description><![CDATA[I think this will work:
[sourcecode]
update t1
 set running_tot = (
                    select sum( t1_1.n1) from t1 t1_1
                     where t1_1.id &lt;= t1.id 
                   );
[/sourcecode]
Not the fastest query in the world, but should work.]]></description>
		<content:encoded><![CDATA[<p>I think this will work:</p>
<pre class="brush: plain; title: ; notranslate">
update t1
 set running_tot = (
                    select sum( t1_1.n1) from t1 t1_1
                     where t1_1.id &amp;lt;= t1.id 
                   );
</pre>
<p>Not the fastest query in the world, but should work.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sayan Malakshinov</title>
		<link>http://jonathanlewis.wordpress.com/2012/10/26/running-total/#comment-51005</link>
		<dc:creator><![CDATA[Sayan Malakshinov]]></dc:creator>
		<pubDate>Fri, 26 Oct 2012 23:45:37 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=9754#comment-51005</guid>
		<description><![CDATA[I think &quot;select for update&quot; is prefer since
  1.&quot;merge&quot; result could be inconsistent(for example with insert and update in another session) 
  2. &quot;select for update&quot; optimized and stabilized with &quot;buffer sort&quot; in 11.2. 
  3. we can optimize case with &quot;for update&quot; cursor with bulk operations(fetch limit+for all)

And would be great if &quot;window sort&quot; executed after locking in next oracle versions like subqueries and functions now, which is not used for sorting into &quot;order by&quot; clause. 
Also i want to ask: has the &quot;for update&quot; mechanism for array locking like &quot;array update&quot;(redo array) ?]]></description>
		<content:encoded><![CDATA[<p>I think &#8220;select for update&#8221; is prefer since<br />
  1.&#8221;merge&#8221; result could be inconsistent(for example with insert and update in another session)<br />
  2. &#8220;select for update&#8221; optimized and stabilized with &#8220;buffer sort&#8221; in 11.2.<br />
  3. we can optimize case with &#8220;for update&#8221; cursor with bulk operations(fetch limit+for all)</p>
<p>And would be great if &#8220;window sort&#8221; executed after locking in next oracle versions like subqueries and functions now, which is not used for sorting into &#8220;order by&#8221; clause.<br />
Also i want to ask: has the &#8220;for update&#8221; mechanism for array locking like &#8220;array update&#8221;(redo array) ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tony</title>
		<link>http://jonathanlewis.wordpress.com/2012/10/26/running-total/#comment-51004</link>
		<dc:creator><![CDATA[Tony]]></dc:creator>
		<pubDate>Fri, 26 Oct 2012 22:29:54 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=9754#comment-51004</guid>
		<description><![CDATA[Your comment about the &quot;shouldn&#039;t&quot; and table order might not apply to SQL Server because the default table structure over there is their version of an IOT.  At least that is what I remember from the All Things Oracle webinar you did.So wouldn&#039;t that enable them to do the previous/next type logic without worrying about the order so much?]]></description>
		<content:encoded><![CDATA[<p>Your comment about the &#8220;shouldn&#8217;t&#8221; and table order might not apply to SQL Server because the default table structure over there is their version of an IOT.  At least that is what I remember from the All Things Oracle webinar you did.So wouldn&#8217;t that enable them to do the previous/next type logic without worrying about the order so much?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
