Is DUAL a real table?

Source: Internet
Author: User

Is DUAL a real table or is the optimizer specially processing DUAL references?

Conclusion: It is a real table. See the following analysis.

At the same time, according to the database creation script $ ORACLE_HOME/RDBMS/ADMIN/dcore. bsq, the optimizer has special processing for this table. There is no detailed description on how to deal with this table.

1. Execution Plan

 
 
  1. select * from dual;  
  2.  
  3. Plan hash value: 272002086  
  4.    
  5. --------------------------------------------------------------------------  
  6. | Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |  
  7. --------------------------------------------------------------------------  
  8. |   0 | SELECT STATEMENT  |      |     1 |     2 |     2   (0)| 00:00:01 |  
  9. |   1 |  TABLE ACCESS FULL| DUAL |     1 |     2 |     2   (0)| 00:00:01 | 

2 rowid

 
 
  1. select dbms_rowid.rowid_object(rowid) obj,  
  2.        dbms_rowid.rowid_relative_fno(rowid) rfno,  
  3.        dbms_rowid.rowid_block_number(rowid) bno,  
  4.        dbms_rowid.rowid_row_number(rowid) rno from dual;  
  5.         
  6. OBJ RFNO BNO RNO  
  7. 258 1 2082 0        
  8.  
  9. select owner,object_name,object_id from dba_objects where object_id=258;  
  10. OWNER OBJECT_NAME OBJECT_ID  
  11. SYS DUAL 258 

3. dump block

 
 
  1. alter system dump datafile 1 block 2082;  
  2. --------------------------------------------------  
  3. /u01/app/oracle/product/10.2.0/db_1/admin/bocnet/udump/bocnet_ora_557.trc  
  4. Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production  
  5. With the Partitioning, OLAP and Data Mining options  
  6. ORACLE_HOME = /u01/app/oracle/product/10.2.0/db_1  
  7. System name: Linux  
  8. Node name: bocnet95  
  9. Release: 2.6.18-164.el5xen  
  10. Version: #1 SMP Thu Sep 3 04:47:32 EDT 2009  
  11. Machine: i686  
  12. Instance name: bocnet  
  13. Redo thread mounted by this instance: 1  
  14. Oracle process number: 50  
  15. Unix process pid: 557, image:oracle@bocnet95(TNS V1-V3)  
  16.  
  17. *** SERVICE NAME:(SYS$USERS) 2011-05-29 04:54:44.485  
  18. *** SESSION ID:(135.9121) 2011-05-29 04:54:44.485  
  19. Start dump data blocks tsn: 0 file#: 1 minblk 2082 maxblk 2082  
  20. buffer tsn: 0 rdba: 0x00400822 (1/2082)  
  21. scn: 0x0006.c428013f seq: 0x01 flg: 0x04 tail: 0x013f0601  
  22. frmt: 0x02 chkval: 0x89a3 type: 0x06=trans data  
  23. Hex dump of block: st=0, typ_found=1  
  24. Dump of memory from 0x0D6D0400 to 0x0D6D2400  
  25. D6D0400 0000A206 00400822 C428013F 04010006  [....".@.?.(.....]  
  26. D6D0410 000089A3 00000001 00000102 A514474A  [............JG..]  
  27. D6D0420 00000001 00030002 00000000 00200009  [.............. .]  
  28. D6D0430 00003DF2 00820CFC 00070E84 00018000  [.=..............]  
  29. D6D0440 A41874A9 00230001 00004CA9 00800C2F  [.t....#..L../...]  
  30. D6D0450 002A1137 0001A000 A513B6E3 00010100  [7.*.............]  
  31. D6D0460 0014FFFF 1F831F9B 00001F83 1F9B0001  [................]  
  32. D6D0470 00000000 00000000 00000000 00000000  [................]  
  33.         Repeat 503 times  
  34. D6D23F0 00000000 2C000000 58010100 013F0601  [.......,...X..?.]  
  35. Block header dump:  0x00400822  
  36.  Object id on Block? Y  
  37.  seg/obj: 0x102  csc: 0x01.a514474a  itc: 2  flg: O  typ: 1 - DATA  
  38.      fsl: 0  fnx: 0x0 ver: 0x01  
  39.    
  40.  Itl           Xid                  Uba         Flag  Lck        Scn/Fsc  
  41. 0x01   0x0009.020.00003df2  0x00820cfc.0e84.07  C---    0  scn 0x0001.a41874a9  
  42. 0x02   0x0001.023.00004ca9  0x00800c2f.1137.2a  C-U-    0  scn 0x0001.a513b6e3  
  43.    
  44. data_block_dump,data header at 0xd6d045c  
  45. ===============  
  46. tsiz: 0x1fa0  
  47. hsiz: 0x14  
  48. pbl: 0x0d6d045c  
  49. bdba: 0x00400822  
  50.      76543210  
  51. flag=--------  
  52. ntab=1  
  53. nrow=1  
  54. frre=-1  
  55. fsbo=0x14  
  56. fseo=0x1f9b  
  57. avsp=0x1f83  
  58. tosp=0x1f83  
  59. 0xe:pti[0] nrow=1 offs=0  
  60. 0x12:pri[0] offs=0x1f9b  
  61. block_row_dump:  
  62. tab 0, row 0, @0x1f9b  
  63. tl: 5 fb: --H-FL-- lb: 0x0  cc: 1  
  64. col  0: [ 1]  58  
  65. end_of_block_dump  
  66. End dump data blocks tsn: 0 file#: 1 minblk 2082 maxblk 2082  
  67. --------------------------------------------------- 

4. manual database creation script

 
 
  1. $ORACLE_HOME/RDBMS/ADMIN/dcore.bsq  
  2. --dual  
  3. create table dual                   /* pl/sql's standard pckg requires dual. */  
  4.   (dummy varchar2(1))    /* note, the optimizer knows sys.dual is single row */  
  5.   storage (initial 1)  
  6. /  
  7. insert into dual values('X')  
  8. /  
  9. create public synonym dual for dual  
  10. /  

Extended Extension: What is DUAL?

DUAL: Diffusing Update Algorithm, one of the dispersion Update Algorithm. Dual is a virtual table automatically created by Oracle and the data dictionary. It has only one column: DUMMY, whose data type is VARCHAR2 (1 ). There is only one row of data in dual: 'X '. Dual belongs to the sys mode, but all users can access it using the dual name. This table is often used to calculate the constant expression and pseudo column equivalence using the SELECT statement, because it only returns one row of data and uses other multiple data rows may be returned. It is used to query the content that does not belong to the actual table, and sometimes it is used to check the existence of records of a certain condition in a table.

 
 
  1. For example, select sysdate from dual;
  2. Select 3 + 3 from dual;
  3. Equivalent to SQL Server's
  4. Set @ Date = getdate ()


 
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.