zoukankan      html  css  js  c++  java
  • where is the data come from after we drop the table

    When I was reading a oracle document, it said that the select action will not put any locks on the table you are reading. That is different from what I thought before. I understand that if a table were selecting, the session will not put any locks to stop othere sesssion from writing the table. Or I should say I understand that read will not block write in Oracle.  But I was also thinging that there should be a table lock protecting the structure of the table. This lock is not to protect the data of the table only the table structure. If there is not this kind of lock that means we can drop a table when we reading it. And I think that will make the reading session be aborted because the drop action will not generate UNDO information. So I did a test.

    1. first i create a table below. Then I run a sqlstatement which is very time consuming

     1 SQL> create table scott.emp1 as select * from scott.emp;
     2 
     3 Table created.
     4 
     5 Elapsed: 00:00:00.09
     6 SQL>
     7 SQL> select * from scott.emp1 where (select count(*) from dba_objects,dba_tables) = (select count(*) from dba_objects,dba_tables);
     8 
     9 
    10      EMPNO ENAME                          JOB                                MGR HIREDATE                   SAL       COMM     DEPTNO
    11 ---------- ------------------------------ --------------------------- ---------- ------------------- ---------- ---------- ----------
    12       7369 SMITH                          CLERK                             7902 1980-12-17 00:00:00        800                    20
    13       7499 ALLEN                          SALESMAN                          7698 1981-02-20 00:00:00       1600        300         30
    14       7521 WARD                           SALESMAN                          7698 1981-02-22 00:00:00       1250        500         30
    15       7566 JONES                          MANAGER                           7839 1981-04-02 00:00:00          1                    20
    16       7654 MARTIN                         SALESMAN                          7698 1981-09-28 00:00:00       1250       1400         30
    17       7698 BLAKE                          MANAGER                           7839 1981-05-01 00:00:00       2850                    30
    18       7782 CLARK                          MANAGER                           7839 1981-06-09 00:00:00       2450                    10
    19       7788 SCOTT                          ANALYST                           7566 1987-04-19 00:00:00       3000                    20
    20       7839 KING                           PRESIDENT                              1981-11-17 00:00:00       5000                    10
    21       7844 TURNER                         SALESMAN                          7698 1981-09-08 00:00:00       1500          0         30
    22       7876 ADAMS                          CLERK                             7788 1987-05-23 00:00:00       1100                    20
    23 
    24      EMPNO ENAME                          JOB                                MGR HIREDATE                   SAL       COMM     DEPTNO
    25 ---------- ------------------------------ --------------------------- ---------- ------------------- ---------- ---------- ----------
    26       7900 JAMES                          CLERK                             7698 1981-12-03 00:00:00        950                    30
    27       7902 FORD                           ANALYST                           7566 1981-12-03 00:00:00      99999                    20
    28       7934 MILLER                         CLERK                             7782 1982-01-23 00:00:00       9999                    10
    29 
    30 14 rows selected.

    2. Before that select finish, I drop the table in another session.

    SQL> drop table scott.emp1 purge;
    
    Table dropped.

    3. But the select still can run successfully

     1 SQL> select * from scott.emp1 where (select count(*) from dba_objects,dba_tables) = (select count(*) from dba_objects,dba_tables);
     2 
     3 
     4      EMPNO ENAME                          JOB                                MGR HIREDATE                   SAL       COMM     DEPTNO
     5 ---------- ------------------------------ --------------------------- ---------- ------------------- ---------- ---------- ----------
     6       7369 SMITH                          CLERK                             7902 1980-12-17 00:00:00        800                    20
     7       7499 ALLEN                          SALESMAN                          7698 1981-02-20 00:00:00       1600        300         30
     8       7521 WARD                           SALESMAN                          7698 1981-02-22 00:00:00       1250        500         30
     9       7566 JONES                          MANAGER                           7839 1981-04-02 00:00:00          1                    20
    10       7654 MARTIN                         SALESMAN                          7698 1981-09-28 00:00:00       1250       1400         30
    11       7698 BLAKE                          MANAGER                           7839 1981-05-01 00:00:00       2850                    30
    12       7782 CLARK                          MANAGER                           7839 1981-06-09 00:00:00       2450                    10
    13       7788 SCOTT                          ANALYST                           7566 1987-04-19 00:00:00       3000                    20
    14       7839 KING                           PRESIDENT                              1981-11-17 00:00:00       5000                    10
    15       7844 TURNER                         SALESMAN                          7698 1981-09-08 00:00:00       1500          0         30
    16       7876 ADAMS                          CLERK                             7788 1987-05-23 00:00:00       1100                    20
    17 
    18      EMPNO ENAME                          JOB                                MGR HIREDATE                   SAL       COMM     DEPTNO
    19 ---------- ------------------------------ --------------------------- ---------- ------------------- ---------- ---------- ----------
    20       7900 JAMES                          CLERK                             7698 1981-12-03 00:00:00        950                    30
    21       7902 FORD                           ANALYST                           7566 1981-12-03 00:00:00      99999                    20
    22       7934 MILLER                         CLERK                             7782 1982-01-23 00:00:00       9999                    10
    23 
    24 14 rows selected.
    25 
    26 Elapsed: 00:01:04.59

    There were two theorie

    https://forums.oracle.com/forums/thread.jspa?messageID=10689825

    http://www.itpub.net/forum.php?mod=viewthread&tid=1776743&page=1#pid21235290

    This should be figure out some other time 

  • 相关阅读:
    How Default Heap Of Process Grows
    希腊字母表
    Ubuntu第一次亲密接触
    Ubuntu中的挂载点(mount point)
    要一专多能
    First touch with JIT debugging
    小学一下环境变量
    安装VMware Tools
    [转]ReiserFS与ext3的比较
    [bbk4485]第二章Flashback Database 05
  • 原文地址:https://www.cnblogs.com/kramer/p/2993767.html
Copyright © 2011-2022 走看看