Undo Quiz – Bringing the Right Tools for the Job

17092012

September 17, 2012

Sometimes humor is a good recipe for undo. A mid-50s man was driving down the road, riding a purple mule, when he saw a house with a new window. Uninvited, the man decided to take a closer look using an obvious tool of choice, a tire iron (YPDNTI). Elapsed time, roughly 60 seconds. The man is obviously familiar with Oracle Database’s concept of transactions and issuing a ROLLBACK, but did not account for video recording in several autonomous transactions. Even through a COMMIT was not issued, that does not imply that nothing happened in those 60 seconds.

Riding a purple mule… strange.

—

On to the quiz. Assume that there are three and only three users connected to an Oracle database (preferrably a test database of sorts). The first session is connected as the SYS user, and the other two sessions are connected as a normal database user (the same user ID, but with access permissions for DBA_SOURCE). Assume that session 1 creates a new undo tablespace that cannot grow beyond 1MB in size:

In my case, I used the Oracle sample schema in Oracle Database 11.2.0.3 (tablespace for T10 is ASSM AUTOALLOCATE). Let’s check the amount of space consumed (not necessarily all used for data strorage yet) for the T10 table:

The first quiz question is simple: How it is possible for Oracle Database to provide a read consistent view of a table that requires approximately 88MB of storage space when the file supporting the undo tablespace cannot exceed 1MB? Maybe someone will be kind enough to share the answer with the OP in this message thread:
dbaforums.org/oracle/index.php?s=439a689327b6fbd09ba0018b320041d8&showtopic=21972

The second quiz question is also simple: Why did the first select of the table require 81 more consistent gets than the second select from that table?

—–

Continuing with the test case, this time working in session 3. Let’s delete some rows from the table created in session 2:

The third question is slightly more challenging: Why is Oracle attempting to extend a segment when the session is deleting rows; also, what does the number 8 signify?

Let’s try again with a smaller number of rows:

DELETE FROM
T10
WHERE
ROWNUM<=30;
30 rows deleted.

That worked. Interestingly, the first time I tried the test case, I named the tablespace SMALL_UNDO and specified “RETENTION GUARANTEE” when creating the undo tablespace, and the following message appeared when executing the above command:

The fourth question is again slightly more challenging: why was the 30 row delete from table T10 successful when the SMALL_UNDO2 undo tablespace was the default undo tablespace, yet that delete failed when the SMALL_UNDO tablespace was set as the default tablespace – until 3 rows were first deleted from the table?

Going back to the forum thread, another interesting question arises. The fifth question is again challenging: What type of compression is used in undo logs?

I was curious about the last question. In session 1 I executed the following:

I just tried replying to the thread and received the message “Sorry, you do not have permission to reply to that topic.”, so it does appear that replying to that thread is restricted.

The one reply that the OP received in the thread is incomplete. That reply seems to suggest that it is the SELECT that receives the “ORA-30036: unable to extend segment by n in undo tablespace” in the undo tablespaces’ files are unable to expand to the size of the tables that are queried. The OP in the thread might have been thinking about “ORA-01555: snapshot too old”, however, that error would not apply in the OP’s test case.

—

Off subject humor (unrelated to David’s comment) 1- what was the guy on the purple mule attempting to accomplish?:
* He is a Windows 1.0 beta tester, still reporting bugs found in the field, his report: 1 moth dead due to heat exhaustion, 3 lady bugs, and a frog.
* He is a Windows 8.0 beta tester trying to get the hang of the touch screen interface.
* He found that Windows 8.0 requires new hardware, and found that a tire iron is the perfect accessory for disabling the Windows Metro interface.
* He decided to re-tire, but forget where he parked the car.
* He is a trademark infringement lawyer for Microsoft, researching a lawsuit against the hole in the wall companies that sell unrelated products under the Windows label.
* He is looking for the cliff-jumping little red riding horse.
* He was checking to see if the Window violated any of Sun’s patents, such as those covering OpenWindows (http://en.wikipedia.org/wiki/OpenWindows).
* He was interested in checking out the scene at the police bars that he had heard so much about.

And he appears to understand as much about UNDO as the OP. It is a downside to the internet that bad information is as freely available as good information and sadly sometimes the bad information is more popular and returns search results in the top entries.

Charles, are you wanting answers to the questions posed? My small understanding of UNDO is that a select does not create undo unless a transaction is outstanding that has not commited changes to the data you are looking at. So,

Question 1) Undo isn’t used here to get a read consistent view of the data. The data is already in a consistent state.

Question 2) I’m sure the difference in consistent gets is the hard parse of the select statement indicated by the 11 recursive calls dropping to zero the second time.

Question 3)The delete’s will create undo records so that this transaction can roll back. That’s where the extend has originated. Deleting 300,000 records will result in an attempt to create 300,000 undo records one for each row deleted. This requirement broke the 1M limit. The transaction rolled back, so 1M of undo was now available. Deleting 30 rows required less than 1M so this was successful. I’m not sure as to the value of 8, but I would hazard a guess it is the smallest automatic extent size in blocks?

I am now at my limit of undo knowledge, so those more knowledgeable than my self can pick up the baton!

‘By enabling the guarantee option, you instruct the database not to overwrite unexpired undo data even if it means risking failure of currently active DML operations.’

So, the delete of 30 records failed due to the first deletes that filled up the tablespace not being reused as they hadn’t expired. When you ran the next set, the undo records had expired and so were re-used.

I’m not sure compression is used, however, encoding will be, so rather than contain an INSERT for every DELETE it will be encoded in the UNDO record.

Yes, I am interested in seeing appropriate answers for the questions – might help people who are searching for answers to similar questions. For the record, some of these questions appeared on the OTN forums in the past, using slightly different wording. There are certainly experienced DBAs reading this blog, and there is a good chance that the answers provided by one or more readers will be better than my answers (a consensus on how things work is usually better than one man’s opinion).

1) As mentioned before the data is already in a consistent state so no undo is generated.

2) I agree that the difference in consistent gets is the hard parse.

3) The 8 is the number of blocks that can’t be allocated for the larger deletes; the smaller deletes have sufficient space for the undo records.

4) The retention guarantee, I believe, creates this issue — it’s the only difference between
the two undo tablespaces. If the undo_retention parameter isn’t changed from its default value (mine is set to 5 in my 11.2.0.3 database) then it’s likely that Oracle considers the current undo (whatever it may be) as unexpired and refuses to overwrite it while the retention guarantee is in place. Once 5 seconds have elapsed (easily the time between the first delete attempt and the second) the undo is available. So, to my knowledge, it’s not the second delete that frees the undo space it’s the elapsed time between the delete attempts that allows the second and subsequent deletes (that aren’t too large) to succeed. As there is no retention guarantee in place for the second undo tablespace Oracle need not preserve unexpired undo should it need the space for further transactions.

Sorry for the delay in responding. WordPress has apparently decided to return the formatting of my blog as a narrow column of text, rather than the full screen width that I configured when I bought the custom CSS option nearly 3 years ago. I am still trying to find a work around for that issue. Between that and fighting with a couple of high-definition security camera that refuse to work correctly, I have not had sufficient free time to check for comments posted to the blog. My review of the high-definition security camera is now live on Amazon’s site:

1) How it is possible for Oracle Database to provide a read consistent view of a table that requires approximately 88MB of storage space when the file supporting the undo tablespace cannot exceed 1MB?That is as well worded as anything I could have written.

2) Why did the first select of the table require 81 more consistent gets than the second select from that table?That is as well worded as anything I could have written.

3) Why is Oracle attempting to extend a segment when the session is deleting rows; also, what does the number 8 signify?Good answer – the Oracle error could have better explained the meaning of 8. Regarding your answer, it would have been slightly more clear to mention that Oracle Database was attempting to allocate another undo extent (64KB in size due to the use of ASSM autoallocate) — I believe that is your implied answer.

4) why was the 30 row delete from table T10 successful when the SMALL_UNDO2 undo tablespace was the default undo tablespace, yet that delete failed when the SMALL_UNDO tablespace was set as the default tablespace – until 3 rows were first deleted from the table?David, I am not sure that your answer is completely correct. The undo from a session cannot be overwritten until that session issues a commit, and the session executing the deletes never executed a commit (sorry if the commit frequency was not very clear). You do make good points regarding how undo retention works. If I recall correctly, when I wrote the question, I noticed that the documentation for 11.2 mentioned that there were certain default behaviors when UNDO tablespaces are created.

5) What type of compression is used in undo logs?I don’t think that anyone has attempted to answer this question yet. Odd, the comment about compression of “undo logs” seems to have been removed from the forum thread. Of course, one might question what is an undo log?

Well, that took a while! I was finally able to fix the formatting of this blog so that the pages are again almost (99%) as wide as the browser window, rather than having the entire page being confined to a width of 780 pixels.

Hints for Posting Code Sections in Comments

********************
When the spacing of text in a comment section is important for readability (execution plans, PL/SQL blocks, SQL, SQL*Plus output, etc.) please use a <pre> tag before the code section and a </pre> tag after the code section:

<pre>

SQL> SELECT
2 SYSDATE TODAY
3 FROM
4 DUAL;
TODAY
---------
01-MAR-12

</pre>
********************
When posting test case samples, it is much easier for people to reproduce the test case when the SQL*Plus line prefixes are not included - if possible, please remove those line prefixes. This:

SELECT
SYSDATE TODAY
FROM
DUAL;

Is easier to execute in a test case script than this:

SQL> SELECT
2 SYSDATE TODAY
3 FROM
4 DUAL;

********************
Greater than and Less than signs in code sections are often interpretted as HTML formatting commands. Please replace these characters in the code sections with the HTML equivalents for these characters: