能不能兩張表共用一個INDEX
能不能兩張表共用一個INDEX?
答案:兩張表的ROWID都不一樣,怎麼可能共用索引。多麼強有力的論據。
但是從9i開始引入了Bitmap join indexes可以索引來自其他表的列:
SQL> conn scott/tiger@afc
Connected.
SQL> desc dept
Name Null?
---------------------------------------------------------------------------------------------------
DEPTNO NOT NULL
DNAME
LOC
SQL> desc emp
Name Null?
---------------------------------------------------------------------------------------------------
EMPNO NOT NULL
ENAME
JOB
MGR
HIREDATE
SAL
COMM
DEPTNO
SQL> create bitmap index emp_bm_idx
2 on emp( d.dname )
3 from emp e, dept d
4 where e.deptno = d.deptno;
Index created.
SQL> exec dbms_stats.gather_schema_stats('scott',cascade=>true);
PL/SQL procedure successfully completed.
SQL> set autotrace traceonly explain;
SQL> select count(*)
2 from emp, dept
3 where emp.deptno = dept.deptno
4 and dept.dname = 'SALES';
Execution Plan
----------------------------------------------------------
Plan hash value: 2538954156
------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 3 | 1 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 3 | | |
| 2 | BITMAP CONVERSION COUNT | | 5 | 15 | 1 (0)| 00:00:01 |
|* 3 | BITMAP INDEX SINGLE VALUE| EMP_BM_IDX | | | | |
------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
3 - access("EMP"."SYS_NC00009$"='SALES')
SQL> conn scott/tiger@afc
Connected.
SQL> desc dept
Name Null?
---------------------------------------------------------------------------------------------------
DEPTNO NOT NULL
DNAME
LOC
SQL> desc emp
Name Null?
---------------------------------------------------------------------------------------------------
EMPNO NOT NULL
ENAME
JOB
MGR
HIREDATE
SAL
COMM
DEPTNO
SQL> create bitmap index emp_bm_idx
2 on emp( d.dname )
3 from emp e, dept d
4 where e.deptno = d.deptno;
Index created.
SQL> exec dbms_stats.gather_schema_stats('scott',cascade=>true);
PL/SQL procedure successfully completed.
SQL> set autotrace traceonly explain;
SQL> select count(*)
2 from emp, dept
3 where emp.deptno = dept.deptno
4 and dept.dname = 'SALES';
Execution Plan
----------------------------------------------------------
Plan hash value: 2538954156
------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 3 | 1 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 3 | | |
| 2 | BITMAP CONVERSION COUNT | | 5 | 15 | 1 (0)| 00:00:01 |
|* 3 | BITMAP INDEX SINGLE VALUE| EMP_BM_IDX | | | | |
------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
3 - access("EMP"."SYS_NC00009$"='SALES')
但是有個前提:
Bitmap join indexes do have a prerequisite. The join condition must join to a primary or
unique key in the other table. In the preceding example, DEPT.DEPTNO is the primary key of the
DEPT table, and the primary key must be in place, otherwise an error will occur:
ops$tkyte@ORA10G> create bitmap index emp_bm_idx
2 on emp( d.dname )
3 from emp e, dept d
4 where e.deptno = d.deptno
5 /
from emp e, dept d
*
ERROR at line 3:
ORA-25954: missing primary key or unique constraint on dimension
參考地址:http://www.itpub.net/viewthread.php?tid=719902&extra=&page=1
Bitmap join indexes do have a prerequisite. The join condition must join to a primary or
unique key in the other table. In the preceding example, DEPT.DEPTNO is the primary key of the
DEPT table, and the primary key must be in place, otherwise an error will occur:
ops$tkyte@ORA10G> create bitmap index emp_bm_idx
2 on emp( d.dname )
3 from emp e, dept d
4 where e.deptno = d.deptno
5 /
from emp e, dept d
*
ERROR at line 3:
ORA-25954: missing primary key or unique constraint on dimension
參考地址:http://www.itpub.net/viewthread.php?tid=719902&extra=&page=1
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9252210/viewspace-586508/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 同一張表的兩個欄位比較查詢
- 點陣圖索引(Bitmap Index)——索引共用索引Index
- 使用SQL語句將資料庫中的兩個表合併成一張表SQL資料庫
- 多個model共用一個service可以嗎
- ORACLE能不能給一個表中的列授權Oracle
- 【SQL】根據兩列資訊,整合兩張表資料SQL
- 高人請幫助我java同一個包裡兩個能能不能互相引用?Java
- 同一Server上兩個資料庫例項共用listener.ora ,監聽多個埠Server資料庫
- db2 sql批量插入一張表插入另一張表DB2SQL
- mysql怎麼複製一張表的資料到另一張表MySql
- mysql從一張表中取出資料插入到另一張表MySql
- django(django學習) 兩張表建立 插入資料Django
- Python操作excel(將多張excel表融合到一張表)PythonExcel
- mybatis中一對多對映,但兩張表id相同怎麼辦?MyBatis
- 兩個顯示器怎樣共用一臺主機 win10一拖二互不干擾Win10
- mysql單表體積和一個庫設計多少張表為妥MySql
- Oracle中把一個查詢結果插入到一張表中Oracle
- mysql同步一張表設定MySql
- mysql 兩個表結果合拼到一個表,用常量區別不同的表MySql
- 如何將Excel中多個不同的工作表彙總成一張總表Excel
- 通過SQL查詢兩張表中不匹配的行SQL
- 【SQL 資料庫】將一張資料表資訊複製到另一張資料表SQL資料庫
- Appfuse:第一張表維護APP
- ORACLE EBS中掛一張報表Oracle
- 如果通過語句Check兩個資料庫中Index是一樣的 ?資料庫Index
- optimizer_index_caching和optimizer_index_cost_adj兩個引數說明Index
- Sender 的應用:所有Edit共用一個過濾格式 (轉)
- 多張表的新增與更新用一個佇列合適嗎佇列
- 查詢訪問同一表的兩個以上索引(一)索引
- 更新一張與另一張表關聯的連線欄位記錄
- 用slot和component實現表單共用
- django 兩個表或多個表聯合查詢Django
- mysql 對比兩個表的一致性MySql
- 【PostgresSQL】同時更新兩個表SQL
- 使用 jOOQ 連線兩個表
- 記錄多專案共用一個公眾號邏輯修改
- oracle中檢視一張表是否有主鍵,主鍵在哪個欄位上Oracle
- 解放雙手!這個外掛只要一張表就能生成CRUD程式碼