【读书笔记】Expert Oracle Architecture (by Tom) (1)
2009-10-25 10:25
549 查看
Abstract: 这个读书笔记系列是关于Tom的大作《Expert Oracle Database Architecture》
Chapter 1: Developing Successful Oracle Application
1. Bitmap index In the first session:Note: Don’t commit or rollback for now. Session Id is
In the second session:
This session is hanging! Session Id is
The Lock view (v$lock) shows..
Description on Lock view
ADDR | RAW(4 | 8) | Address of lock state object |
KADDR | RAW(4 | 8) | Address of lock |
SID | NUMBER | Identifier for session holding or acquiring the lock |
TYPE | VARCHAR2(2) | Type of user or system lock The locks on the user types are obtained by user applications. Any process that is blocking others is likely to be holding one of these locks. The user type locks are: TM - DML enqueue TX - Transaction enqueue UL - User supplied The locks on the system types are held for extremely short periods of time. |
ID1 | NUMBER | Lock identifier #1 (depends on type) |
ID2 | NUMBER | Lock identifier #2 (depends on type) |
LMODE | NUMBER | Lock mode in which the session holds the lock: 0 - none 1 - null (NULL) 2 - row-S (SS) 3 - row-X (SX) 4 - share (S) 5 - S/Row-X (SSX) 6 - exclusive (X) |
REQUEST | NUMBER | Lock mode in which the process requests the lock: 0 - none 1 - null (NULL) 2 - row-S (SS) 3 - row-X (SX) 4 - share (S) 5 - S/Row-X (SSX) 6 - exclusive (X) |
CTIME | NUMBER | Time since current mode was granted |
BLOCK | NUMBER | The lock is blocking another lock |
In the first session:
Notice “Select … for update” (where id = 1, only lock the rows with id = 1) In another session:
Update the rows with id = 2 won’t be blocked. While updating the rows with id = 1 will be blocked,
The sqlplus hangs now! 5. Multi-Versioning Bear in mind that Oracle does not “answer” the query. It does not copy the data anywhere when you open a cursor—imagine how long it would take to open a cursor on a 1-billion-row table if it did. The cursor opens instantly and it answers the query as it goes along. In other words, it just reads data from the table as you fetch from it. 6. Multi-Versioning and Flashback SCN is Oracle’s internal clock: every time a commit occurs, this clock ticks upward (increments).
If you receive the error “ORA-08189: cannot flashback the table because row movement is not enabled using the FLASHBACK command,” you must issue ALTER TABLE EMP ENABLE ROW MOVEMENT. This, in effect, gives Oracle the permission to change the rowid assigned to a row. In Oracle, when you insert a row, a rowid is assigned to it and that row will forever have that rowid. The flashback table process will perform a DELETE against EMP and reinsert the rows, hence assigning them a new rowid. You must allow Oracle to do this operation in order to flash back.
7. Read Consistency and Non-Blocking Reads Oracle uses multi-versioning to get the answer, as it existed at the point in time the query began, and the query will take place without locking a single thing. Oracle does NOT have a “shared read” lock because it doesn’t need it. Whenever you modify data, Oracle creates undo entries. These entries are written to undo segments. If your transaction fails and needs to be undone, Oracle will read the “before” image from the rollback segment and restore the data. In addition to using this rollback segment data to undo transactions, Oracle uses it to undo changes to blocks as it is reading them to restore the block to the point in time your query began. This gives you the ability to read right through a lock and to get consistent, correct answers without locking any data yourself. 8. In Oracle… If you created the tables in a stored procedure in Oracle, you would find that • Doing DDL is a scalability inhibitor. • Doing DDL constantly is not fast. • Doing DDL commits your transaction. • You would have to use dynamic SQL in all of your stored procedures to access this table—no static SQL. • Dynamic SQL in PL/SQL is not as fast or as optimized as static SQL. 9. Autonomous transaction http://www.oracle-base.com/articles/misc/AutonomousTransactions.php Autonomous transactions allow you to leave the context of the calling transaction, perform an independent transaction, and return to the calling transaction without affecting its state. The autonomous transaction has no link to the calling transaction, so only commited data can be shared by both transactions.
The following types of PL/SQL blocks can be defined as autonomous transactions: · Stored procedures and functions. · Local procedures and functions defined in a PL/SQL declaration block. · Packaged procedures and functions. · Type methods. · Top-level anonymous blocks.
Notice that I issued the “commit” in the anonymous block.
The 2 rows inserted by our current session (transaction) have been rolled back, while the rows inserted by the autonomous transactions remain. The presence of the PRAGMA AUTONOMOUS_TRANSACTION compiler directive made the anonymous block run in its own transaction, so the internal commit statement did not affect the calling session. As a result rollback was still able to affect the DML issued by the current statement. Autonomous transactions are commonly used by error logging routines, where the error messages must be preserved, regardless of the commit/rollback status of the transaction. Be careful how you use autonomous transactions. If they are used indiscriminately they can lead to deadlocks, and cause confusion when analyzing session trace. To hammer this point home, here's a quote from Tom Kyte posted on my blog (here): ... in 999 times out of 1000, if you find yourself "forced" to use an autonomous transaction - it likely means you have a serious data integrity issue you haven't thought about.
Where do people try to use them? · in that trigger that calls a procedure that commits (not an error logging routine). Ouch, that has to hurt when you rollback. · in that trigger that is getting the mutating table constraint. Ouch, that hurts *even more* Error logging - OK.
Almost everything else - not OK. 10. Profile
-- To Be Continued --
相关文章推荐
- 【读书笔记】Expert Oracle Architecture (by Tom) (2)
- 读书笔记 Expert Oracle Database Architecture
- Expert Oracle Database Architecture, 2nd Edition
- Expert Oracle Database Architecture: 9i and 10g Programming Techniques and Solutions by Thomas Kyte
- Expert Oracle Database Architecture学习笔记之:Setting Up Your Environment
- Expert Oracle Database Architecture: 9i and 10g Programming Techniques and Solutions
- Expert oracle database architecture 2nd学习
- expert-oracle-database-architecture-oracle-database-programming-9i-10g-and-11g-techniques-and-soluti.pdf
- 读书笔记 Expert one by one 第一章 开发成功的oracle应用
- 17.读书笔记收获不止Oracle之 索引存储列值
- 25.读书笔记收获不止Oracle之 位图索引
- 29.读书笔记收获不止Oracle之表的循环嵌套连接
- 37.读书笔记收获不止Oracle之常用诊断命令汇总
- 《基于ORACLE SQL优化》读书笔记-表的连接方式
- oracle官方文档之Memory Architecture之Shared SQL Areas and Private SQL Areas
- Expert One-on-One Oracle Chapter 14 分区表 读书笔记(1)-分区表的可用性
- Oracle OFA(Optimal Flexible Architecture) 说明
- 2011年12月11日星期日(oracle读书笔记)
- 2011年12月24日 星期六(oracle读书笔记)
- 《Expert Cube Development with Microsoft SQL Server 2008 Analysis Services》读书笔记第九章:保护Cube(一)