日期:2014-05-17  浏览次数:20754 次

对引索优化问题
1、尽量避免对索引列进行计算 

  根据这句话的意思我开始了自己的测试

SQL code

SQL> desc a05;
Name  Type          Nullable Default Comments                                      
----- ------------- -------- ------- --------------------------------------------- 
A0500 VARCHAR2(2)   Y                门店                                          
A0501 VARCHAR2(6)                    人员编码                                      
A0502 VARCHAR2(10)  Y                人员姓名                                      
A0503 VARCHAR2(10)  Y                简称                                          
A0504 VARCHAR2(32)  Y                密码                                          
A0505 VARCHAR2(255) Y                后台权限                                      
A0506 VARCHAR2(1)   Y                前台权限: 0-超级 1-收款组长 2-普通款员 5-禁用 
A0507 VARCHAR2(4)   Y                所属部门                                      
A0508 VARCHAR2(8)   Y                前台角色                                      
A0509 CHAR(1)       Y                查询权限:0-个人 1-部门 2-分店 3-总店          
A0510 VARCHAR2(8)   Y                后台角色                                      
A0511 DATE          Y                入职日期                                      
A0512 DATE          Y                离职日期    


(1)
  我先不建索引走了一下。
SQL code

SQL> select count(*) from gjh_a05;

  COUNT(*)
----------
      4753

Executed in 0.078 seconds



SQL code

SQL> select * from gjh_a05 where a0506>'5' and rownum<2;

A0500 A0501  A0502      A0503      A0504                A0505                                                                            A0506 A0507 A0508    A0509 A0510    A0511       A0512
----- ------ ---------- ---------- -------------------- -------------------------------------------- ----- ----- -------- ----- -------- ----------- -----------
10    5166   宋宁                  bxtp                 5                                                                                6     0603  13       0     0                    

Executed in 0.078 seconds

SQL> select * from gjh_a05 where a0506>5 and rownum<2;

A0500 A0501  A0502      A0503      A0504                A0505                                                                            A0506 A0507 A0508    A0509 A0510    A0511       A0512
----- ------ ---------- ---------- -------------------- -------------------------------------------- ----- ----- -------- ----- -------- ----------- -----------
10    5166   宋宁                  bxtp                 5                                                                                6     0603  13       0     0                    

Executed in 0.109 seconds

SQL> select * from gjh_a05 where a0506>5 and rownum<2;

A0500 A0501  A0502      A0503      A0504                A0505                                                                            A0506 A0507 A0508    A0509 A0510    A0511       A0512
----- ------ ---------- ---------- -------------------- -------------------------------------------- ----- ----- -------- ----- -------- ----------- -----------
10    5166   宋宁                  bxtp                 5                                                                                6     0603  13       0     0                    

Executed in 0.031 seconds

SQL> select * from gjh_a05 where a0506>'5' and rownum<2;

A0500 A0501  A0502      A0503      A0504                A0505                                                                            A0506 A0507 A0508    A0509 A0510    A0511       A0512