有什么方法可以在 REFERENCETYPE 列上使用索引。下面是表结构和执行计划。
SQL> desc messaginginbox
Name Null? Type
----------------------------------------- -------- ---------------------------
MESSAGINGINBOXID NOT NULL VARCHAR2(28)
REFERENCEID NOT NULL VARCHAR2(28)
REFERENCETYPE VARCHAR2(1)
LISTINGID NOT NULL VARCHAR2(28)
CREATEDATE DATE
LASTUPDATED NOT NULL DATE
UPDATEDBY NOT NULL VARCHAR2(28)
RENTERLISTINGMANAGERID VARCHAR2(28)
OWNERLISTINGMANAGERID VARCHAR2(28)
OCA NOT NULL NUMBER(38)
SQL> create index idx_MESSAGINGIN_REFERENCE on MESSAGINGINBOX( REFERENCETYPE);
Index created.
SQL> analyze table MESSAGINGINBOX compute statistics;
Table analyzed.
SQL> select * from MESSAGINGINBOX where referencetype='B';
55 rows selected.
Execution Plan
-------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
-------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 71354 | 9M| 873 (1)|
|* 1 | TABLE ACCESS FULL| MESSAGINGINBOX | 71354 | 9M| 873 (1)|
-------------------------------------------------------------------------
SQL> create bitmap index idx_MESSAGINGIN_REFERENCE
on MESSAGINGINBOX( REFERENCETYPE);
Index created.
SQL> analyze table MESSAGINGINBOX compute statistics;
Table analyzed.
SQL> select * from MESSAGINGINBOX where referencetype='B';
55 rows selected.
Execution Plan
-------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
-------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 71354 | 9M| 873 (1)|
|* 1 | TABLE ACCESS FULL| MESSAGINGINBOX | 71354 | 9M| 873 (1)|
-------------------------------------------------------------------------
SQL> select count(*) from MESSAGINGINBOX;
COUNT(*)
----------
142707
SQL> select distinct referencetype from MESSAGINGINBOX;
REFERENCETYPE
-------------
I
B
SQL> select count(distinct referencetype) from MESSAGINGINBOX;
COUNT(DISTINCTREFERENCETYPE)
----------------------------
2