[20180408]那些函数索引适合字段的查询.txt

--//一般不主张建立函数索引,往往是开发的无知,使用trunc等函数,实际上一些函数也可以用于字段的查询.
--//以前零碎的写过一些,放假看了https://blog.pythian.com/tackling-time-troubles-use-dates-correctly-oracle/.
--//自己也做一些总结:

1.环境:
SCOTT@test01p> @ ver1
PORT_STRING                    VERSION        BANNER                                                                               CON_ID
------------------------------ -------------- -------------------------------------------------------------------------------- ----------
IBMPC/WIN_NT64-9.1.0           12.1.0.1.0     Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production              0

2.trunc函数:
--//trunc函数是开发最常使用的函数,实际上还是一句话无知,开发根本不知道这样建立查询条件导致普通索引无效,必须建立函数索引.
--//但是建立trunc函数索引却可以使用在普通日期字段的查询.

SCOTT@test01p> create index if_emp_hiredate on emp(trunc(hiredate));
Index created.

SCOTT@test01p> select * from emp where hiredate=to_date('1980/12/17','yyyy-mm-dd');

EMPNO ENAME      JOB              MGR HIREDATE                   SAL       COMM     DEPTNO
---------- ---------- --------- ---------- ------------------- ---------- ---------- ----------
      7369 SMITH      CLERK           7902 1980-12-17 00:00:00        800                    20

SCOTT@test01p> @ dpc '' ''
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID  1ct8dum3uyy7u, child number 0
-------------------------------------
select * from emp where hiredate=to_date('1980/12/17','yyyy-mm-dd')
Plan hash value: 4059437819
--------------------------------------------------------------------------------------------------------
| Id  | Operation                           | Name            | E-Rows |E-Bytes| Cost (%CPU)| E-Time   |
--------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                    |                 |        |       |     2 (100)|          |
|*  1 |  TABLE ACCESS BY INDEX ROWID BATCHED| EMP             |      1 |    38 |     2   (0)| 00:00:01 |
|*  2 |   INDEX RANGE SCAN                  | IF_EMP_HIREDATE |      1 |       |     1   (0)| 00:00:01 |
--------------------------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
   1 - SEL$1 / EMP@SEL$1
   2 - SEL$1 / EMP@SEL$1
Predicate Information (identified by operation id):
---------------------------------------------------
   1 - filter("HIREDATE"=TO_DATE(' 1980-12-17 00:00:00', 'syyyy-mm-dd hh24:mi:ss'))
   2 - access("EMP"."SYS_NC00010$"=TRUNC(TO_DATE(' 1980-12-17 00:00:00', 'syyyy-mm-dd hh24:mi:ss')))

--//顺便看看范围查询是否有效:
SCOTT@test01p> select * from emp where hiredate between to_date('1980/12/17','yyyy-mm-dd') and to_date('1980/12/18','yyyy-mm-dd');
     EMPNO ENAME      JOB              MGR HIREDATE                   SAL       COMM     DEPTNO
---------- ---------- --------- ---------- ------------------- ---------- ---------- ----------
      7369 SMITH      CLERK           7902 1980-12-17 00:00:00        800                    20

SCOTT@test01p> @ dpc '' ''
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID  a00watu79k28f, child number 0
-------------------------------------
select * from emp where hiredate between
to_date('1980/12/17','yyyy-mm-dd') and
to_date('1980/12/18','yyyy-mm-dd')
Plan hash value: 4059437819
--------------------------------------------------------------------------------------------------------
| Id  | Operation                           | Name            | E-Rows |E-Bytes| Cost (%CPU)| E-Time   |
--------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                    |                 |        |       |     2 (100)|          |
|*  1 |  TABLE ACCESS BY INDEX ROWID BATCHED| EMP             |      1 |    38 |     2   (0)| 00:00:01 |
|*  2 |   INDEX RANGE SCAN                  | IF_EMP_HIREDATE |      1 |       |     2   (0)| 00:00:01 |
--------------------------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
   1 - SEL$1 / EMP@SEL$1
   2 - SEL$1 / EMP@SEL$1
Predicate Information (identified by operation id):
---------------------------------------------------
   1 - filter(("HIREDATE"<=TO_DATE(' 1980-12-18 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND
              "HIREDATE">=TO_DATE(' 1980-12-17 00:00:00', 'syyyy-mm-dd hh24:mi:ss')))
   2 - access("EMP"."SYS_NC00010$">=TRUNC(TO_DATE(' 1980-12-17 00:00:00', 'syyyy-mm-dd
              hh24:mi:ss')) AND "EMP"."SYS_NC00010$"<=TRUNC(TO_DATE(' 1980-12-18 00:00:00', 'syyyy-mm-dd
              hh24:mi:ss')))
--//一样有效.补充11g下执行计划:
SCOTT@book> @ &r/ver1
PORT_STRING                    VERSION        BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx            11.2.0.4.0     Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

SCOTT@book> select * from emp where hiredate between to_date('1980/12/16 09:00:00','yyyy-mm-dd hh24:mi:ss') and to_date('1980/12/18 10:00:00','yyyy-mm-dd hh24:mi:ss');
     EMPNO ENAME      JOB              MGR HIREDATE                   SAL       COMM     DEPTNO
---------- ---------- --------- ---------- ------------------- ---------- ---------- ----------
      7369 SMITH      CLERK           7902 1980-12-17 00:00:00        800                    20

--//执行计划:

SQL_ID  f532a3utw8dfh, child number 0
-------------------------------------
select * from emp where hiredate between to_date('1980/12/16
09:00:00','yyyy-mm-dd hh24:mi:ss') and to_date('1980/12/18
10:00:00','yyyy-mm-dd hh24:mi:ss')

Plan hash value: 3187737602

------------------------------------------------------------------------------------------------
| Id  | Operation                   | Name            | E-Rows |E-Bytes| Cost (%CPU)| E-Time   |
------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT            |                 |        |       |     2 (100)|          |
|*  1 |  TABLE ACCESS BY INDEX ROWID| EMP             |      1 |    46 |     2   (0)| 00:00:01 |
|*  2 |   INDEX RANGE SCAN          | IF_EMP_HIREDATE |      1 |       |     1   (0)| 00:00:01 |
------------------------------------------------------------------------------------------------

Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------

1 - SEL$1 / EMP@SEL$1
   2 - SEL$1 / EMP@SEL$1

Predicate Information (identified by operation id):
---------------------------------------------------

1 - filter(("HIREDATE"<=TO_DATE(' 1980-12-18 10:00:00', 'syyyy-mm-dd hh24:mi:ss')
              AND "HIREDATE">=TO_DATE(' 1980-12-16 09:00:00', 'syyyy-mm-dd hh24:mi:ss')))
   2 - access("EMP"."SYS_NC00009$">=TRUNC(TO_DATE(' 1980-12-16 09:00:00', 'syyyy-mm-dd
              hh24:mi:ss')) AND "EMP"."SYS_NC00009$"<=TRUNC(TO_DATE(' 1980-12-18 10:00:00',
              'syyyy-mm-dd hh24:mi:ss')))

3.substr函数:
--//这个函数非常特殊,你建立的索引必须是substr(col,1,N)的格式,必须是从1开始截取,否则普通字段查询不会使用.这个很好理解.
--//看standard_hash函数后面的例子.

4.standard_hash函数:

--//缺点这个函数12c下才有.以前的测试,重复贴出,不想写了.
--//链接:http://blog.itpub.net/267265/viewspace-772856/
--//到目前为之,我仅仅知道这3个函数可以在普通字段查询时使用.
--//trunc,substr(Col,1,N)还合适范围查询.standard_hash(12c才有的函数)仅仅适合等值查询.

[20130916]12c Indexing Extended Data Types and index.txt

http://richardfoote.wordpress.com/2013/09/12/12c-indexing-extended-data-types-part-i-a-big-hurt/

--//参考以上链接,做一些测试:

1.测试环境:
SCOTT@test01p> @ver
BANNER                                                                               CON_ID
-------------------------------------------------------------------------------- ----------
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production              0

SCOTT@test01p> create table bowie (id number, text varchar2(32000));
Table created.

SCOTT@test01p> create index bowie_text_i on bowie(text);
create index bowie_text_i on bowie(text)
                             *
ERROR at line 1:
ORA-01450: maximum key length (6398) exceeded

--//超长字段无法在上建议索引。
--//12c提供standard_hash函数,可以实现其上建立函数索引。

2.插入一些数据,便于测试:
SCOTT@test01p> insert into bowie (id, text) values (1, lpad('a',1110,'a'));
1 row created.

SCOTT@test01p> commit ;
Commit complete.

SCOTT@test01p> select length(text) from bowie;
LENGTH(TEXT)
------------
        1110

SCOTT@test01p> insert into bowie (id, text) select 2, text||text||text||text||text||text||text||text||text||text from bowie;
1 row created.

SCOTT@test01p> commit ;
Commit complete.

SCOTT@test01p> select length(text) from bowie;
LENGTH(TEXT)
------------
        1110
       11100

SCOTT@test01p> insert into bowie (id, text) select rownum+2, to_char(rownum)||'BOWIE' from dual connect by level<=99998;
99998 rows created.

SCOTT@test01p> commit ;
Commit complete.

SCOTT@test01p> exec dbms_stats.gather_table_stats(ownname=>user, tabname=>'BOWIE', method_opt=>'FOR ALL COLUMNS SIZE 1');
PL/SQL procedure successfully completed.

3.建立函数索引:
SCOTT@test01p> create index bowie_hash_text_i on bowie(standard_hash(text));
Index created.

SCOTT@test01p> select index_name, num_rows, leaf_blocks from dba_indexes where index_name = 'BOWIE_HASH_TEXT_I';
INDEX_NAME           NUM_ROWS LEAF_BLOCKS
------------------ ---------- -----------
BOWIE_HASH_TEXT_I      100000         447

4.查询看看情况:
SCOTT@test01p> column text format a100
SCOTT@test01p> select * from bowie where text = '42BOWIE';
        ID TEXT
---------- ---------------------------------------------------
        44 42BOWIE

SCOTT@test01p> @dpc '' ''
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID  3uz6tby2rv7bh, child number 1
-------------------------------------
select * from bowie where text = '42BOWIE'

Plan hash value: 1900956348

---------------------------------------------------------------------------------------
| Id  | Operation                           | Name              | E-Rows | Cost (%CPU)|
---------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                    |                   |        |     3 (100)|
|*  1 |  TABLE ACCESS BY INDEX ROWID BATCHED| BOWIE             |      1 |     3   (0)|
|*  2 |   INDEX RANGE SCAN                  | BOWIE_HASH_TEXT_I |      1 |     2   (0)|
---------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

1 - filter((INTERNAL_FUNCTION("TEXT") AND
              INTERNAL_FUNCTION("TEXT")='42BOWIE'))
   2 - access("BOWIE"."SYS_NC00003$"=HEXTORAW('A2C98939EDB479BC3EB0CDC560DDCD15
              75D47F62'))
--可以发现可以使用这个函数索引。

5.但是这种情况存在一些限制,做like 或者between时,不能使用该函数索引:

SCOTT@test01p> select * from bowie where text like 'aaaaaaaaaaaaaaaaaaaaaa%';
...

SCOTT@test01p> @dpc '' ''
PLAN_TABLE_OUTPUT
-------------------------------------------------------------------------
SQL_ID  01fn3bq946un9, child number 0
-------------------------------------
select * from bowie where text like 'aaaaaaaaaaaaaaaaaaaaaa%'

Plan hash value: 1845943507

---------------------------------------------------------
| Id  | Operation         | Name  | E-Rows | Cost (%CPU)|
---------------------------------------------------------
|   0 | SELECT STATEMENT  |       |        |   208 (100)|
|*  1 |  TABLE ACCESS FULL| BOWIE |      1 |   208   (2)|
---------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

1 - filter((INTERNAL_FUNCTION("TEXT") AND INTERNAL_FUNCTION("TEXT")
              LIKE 'aaaaaaaaaaaaaaaaaaaaaa%'))

SCOTT@test01p> select * from bowie where text between '4299BOWIE' and '42BOWIE';
        ID TEXT
---------- ---------------------------------------------------------------------
        44 42BOWIE
       431 429BOWIE
      4301 4299BOWIE

SCOTT@test01p> @dpc '' ''
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
SQL_ID  1uk9ud7fq8fdx, child number 0
-------------------------------------
select * from bowie where text between '4299BOWIE' and '42BOWIE'

Plan hash value: 1845943507

---------------------------------------------------------
| Id  | Operation         | Name  | E-Rows | Cost (%CPU)|
---------------------------------------------------------
|   0 | SELECT STATEMENT  |       |        |   208 (100)|
|*  1 |  TABLE ACCESS FULL| BOWIE |      2 |   208   (2)|
---------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

1 - filter((INTERNAL_FUNCTION("TEXT") AND
              INTERNAL_FUNCTION("TEXT")<='42BOWIE' AND
              INTERNAL_FUNCTION("TEXT")>='4299BOWIE'))

SCOTT@test01p> select * from bowie where text > 'zzz';
no rows selected

SCOTT@test01p> @dpc '' ''
PLAN_TABLE_OUTPUT
---------------------------------------------------------------
SQL_ID  39wfprrkz66td, child number 0
-------------------------------------
select * from bowie where text > 'zzz'

Plan hash value: 1845943507

---------------------------------------------------------
| Id  | Operation         | Name  | E-Rows | Cost (%CPU)|
---------------------------------------------------------
|   0 | SELECT STATEMENT  |       |        |   208 (100)|
|*  1 |  TABLE ACCESS FULL| BOWIE |      1 |   208   (2)|
---------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------
   1 - filter((INTERNAL_FUNCTION("TEXT") AND
              INTERNAL_FUNCTION("TEXT")>'zzz'))

6.很明显,无法在该列上建议唯一约束。
SCOTT@test01p> alter table bowie add constraint bowie_text_unq unique (text);
alter table bowie add constraint bowie_text_unq unique (text)
*
ERROR at line 1:
ORA-01450: maximum key length (6398) exceeded

--//建立以上约束,需要在该列上建立索引,超长无法建立。同样可以变通的方法建立:

SCOTT@test01p> drop index bowie_hash_text_i;
Index dropped.

SCOTT@test01p> alter table bowie add (text_hash as (standard_hash(text)));
Table altered.

SCOTT@test01p> alter table bowie add constraint bowie_text_unq unique (text_hash);
Table altered.

SCOTT@test01p> insert into bowie (id, text) values (1000001, '42BOWIE');
insert into bowie (id, text) values (1000001, '42BOWIE')
*
ERROR at line 1:
ORA-00001: unique constraint (SCOTT.BOWIE_TEXT_UNQ) violated

--再重复以上查询:
SCOTT@test01p> select * from bowie where text = '42BOWIE';
        ID TEXT     TEXT_HASH
---------- -------- ----------------------------------------
        44 42BOWIE  A2C98939EDB479BC3EB0CDC560DDCD1575D47F62

SCOTT@test01p> @dpc '' ''
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID  3uz6tby2rv7bh, child number 1
-------------------------------------
select * from bowie where text = '42BOWIE'

Plan hash value: 2691947611

----------------------------------------------------------------------------
| Id  | Operation                   | Name           | E-Rows | Cost (%CPU)|
----------------------------------------------------------------------------
|   0 | SELECT STATEMENT            |                |        |     2 (100)|
|*  1 |  TABLE ACCESS BY INDEX ROWID| BOWIE          |      1 |     2   (0)|
|*  2 |   INDEX UNIQUE SCAN         | BOWIE_TEXT_UNQ |      1 |     1   (0)|
----------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

1 - filter((INTERNAL_FUNCTION("TEXT") AND
              INTERNAL_FUNCTION("TEXT")='42BOWIE'))
   2 - access("BOWIE"."TEXT_HASH"=HEXTORAW('A2C98939EDB479BC3EB0CDC560DD
              CD1575D47F62'))

--但是如果做范围查询,结果如何应该同上是选择全表扫描。
SCOTT@test01p> select * from bowie where text between '429BOWIE' and '42BOWIE';
        ID TEXT      TEXT_HASH
---------- --------- ----------------------------------------
        44 42BOWIE   A2C98939EDB479BC3EB0CDC560DDCD1575D47F62
       431 429BOWIE  A7E2B59E1429DB4964225E7A98A19998BC3D2AFD

SCOTT@test01p> @dpc '' ''
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID  143xd3cu22ja1, child number 0
-------------------------------------
select * from bowie where text between '429BOWIE' and '42BOWIE'

Plan hash value: 1845943507

---------------------------------------------------------
| Id  | Operation         | Name  | E-Rows | Cost (%CPU)|
---------------------------------------------------------
|   0 | SELECT STATEMENT  |       |        |   208 (100)|
|*  1 |  TABLE ACCESS FULL| BOWIE |      2 |   208   (2)|
---------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

1 - filter((INTERNAL_FUNCTION("TEXT") AND
              INTERNAL_FUNCTION("TEXT")<='42BOWIE' AND
              INTERNAL_FUNCTION("TEXT")>='429BOWIE'))

7.如果做范围查询如何显示呢?期待作者的第2部分new extended columns in Part II.
自己也想一下,实际上作者的例子,text组成前面数字+BOWIE。前面5位具有很好的选择性。通过函数substr建立函数应该也可以,
自己测试看看。

SCOTT@test01p> create index i_bowie_text_substr_1_5 on bowie (substr(text,1,5));
Index created.

SCOTT@test01p> @dpc '' ''
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID  143xd3cu22ja1, child number 0
-------------------------------------
select * from bowie where text between '429BOWIE' and '42BOWIE'

Plan hash value: 1199225668

---------------------------------------------------------------------------------------------
| Id  | Operation                           | Name                    | E-Rows | Cost (%CPU)|
---------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                    |                         |        |    92 (100)|
|*  1 |  TABLE ACCESS BY INDEX ROWID BATCHED| BOWIE                   |      2 |    92   (0)|
|*  2 |   INDEX RANGE SCAN                  | I_BOWIE_TEXT_SUBSTR_1_5 |    450 |     3   (0)|
---------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

1 - filter((INTERNAL_FUNCTION("TEXT") AND INTERNAL_FUNCTION("TEXT")<='42BOWIE'
              AND INTERNAL_FUNCTION("TEXT")>='429BOWIE'))
   2 - access("BOWIE"."SYS_NC00004$">='429BO' AND "BOWIE"."SYS_NC00004$"<='42BOW')

--可以发现使用我建立的索引,看看使用大于的情况呢?
SCOTT@test01p> select * from bowie where text > 'zzz';
no rows selected

SCOTT@test01p> @dpc '' ''
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID  39wfprrkz66td, child number 0
-------------------------------------
select * from bowie where text > 'zzz'
Plan hash value: 1199225668
---------------------------------------------------------------------------------------------
| Id  | Operation                           | Name                    | E-Rows | Cost (%CPU)|
---------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                    |                         |        |   181 (100)|
|*  1 |  TABLE ACCESS BY INDEX ROWID BATCHED| BOWIE                   |      1 |   181   (0)|
|*  2 |   INDEX RANGE SCAN                  | I_BOWIE_TEXT_SUBSTR_1_5 |    900 |     4   (0)|
---------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
   1 - filter((INTERNAL_FUNCTION("TEXT") AND INTERNAL_FUNCTION("TEXT")>'zzz'))
   2 - access("BOWIE"."SYS_NC00004$">='zzz')

--//依旧可以使用我建立的函数索引,但是使用like情况如何呢?

SCOTT@test01p> @dpc '' ''
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID  1mq1xczjrz3uw, child number 0
-------------------------------------
select * from bowie where text like 'aaaaaaaaaaaaaaaaaaaaaa%'

Plan hash value: 1845943507

---------------------------------------------------------
| Id  | Operation         | Name  | E-Rows | Cost (%CPU)|
---------------------------------------------------------
|   0 | SELECT STATEMENT  |       |        |   208 (100)|
|*  1 |  TABLE ACCESS FULL| BOWIE |      1 |   208   (2)|
---------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

1 - filter((INTERNAL_FUNCTION("TEXT") AND INTERNAL_FUNCTION("TEXT")
              LIKE 'aaaaaaaaaaaaaaaaaaaaaa%'))

--//like 无效,不知道作者还有什么好方法,期待作者的第2部分,也许有更好的例子。
--//改写为范围查询也许是一个替换like的方法,但是不适合'%aaaa%'的情况。

SCOTT@test01p>  select * from bowie where text between 'aaaaaaaaaaaaaaaaaaaaaa' and 'aaaaaaaaaaaaaaaaaaaaaa'||chr(255);
SCOTT@test01p> @dpc '' ''
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID  bkunhv8x64k0a, child number 1
-------------------------------------
 select * from bowie where text between 'aaaaaaaaaaaaaaaaaaaaaa' and
'aaaaaaaaaaaaaaaaaaaaaa'||chr(255)

Plan hash value: 1199225668

---------------------------------------------------------------------------------------------
| Id  | Operation                           | Name                    | E-Rows | Cost (%CPU)|
---------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                    |                         |        |     2 (100)|
|*  1 |  TABLE ACCESS BY INDEX ROWID BATCHED| BOWIE                   |      1 |     2   (0)|
|*  2 |   INDEX RANGE SCAN                  | I_BOWIE_TEXT_SUBSTR_1_5 |      2 |     1   (0)|
---------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

1 - filter((INTERNAL_FUNCTION("TEXT") AND
              INTERNAL_FUNCTION("TEXT")>='aaaaaaaaaaaaaaaaaaaaaa' AND
              INTERNAL_FUNCTION("TEXT")<='aaaaaaaaaaaaaaaaaaaaaa'))
   2 - access("BOWIE"."SYS_NC00004$"='aaaaa')

--//总结:
--//BTW:如果字符字段很长,使用substr函数取前面选择性很强的几位,建立函数索引,有时候不失为一个方法,这样可以减少索引大小,
--//这种方法在10G,11G使用同样有效。
--//12C extended columns中提供的standard_hash函数,作为等值查询,不失为一个很好的选择。

[20180408]那些函数索引适合字段的查询.txt的更多相关文章

  1. 使用Oracle的instr函数与索引配合提高模糊查询的效率

    使用Oracle的instr函数与索引配合提高模糊查询的效率 一般来说,在Oracle数据库中,我们对tb表的name字段进行模糊查询会采用下面两种方式:1.select * from tb wher ...

  2. MYSQ创建联合索引,字段的先后顺序,对查询的影响分析

    MYSQ创建联合索引,字段的先后顺序,对查询的影响分析 前言 最左匹配原则 为什么会有最左前缀呢? 联合索引的存储结构 联合索引字段的先后顺序 b+树可以存储的数据条数 总结 参考 MYSQ创建联合索 ...

  3. MySQL 查询 存储过程 视图 触发器 函数 索引 建表语句 数据库版本 当前登录用户 当前数据库名称

    MySQL 查询 存储过程 视图 触发器 函数 索引 建表语句 数据库版本 当前登录用户 当前数据库名称   INFORMATION_SCHEMA.TABLES INFORMATION_SCHEMA. ...

  4. [慢查优化]建索引时注意字段选择性 & 范围查询注意组合索引的字段顺序

    文章转自:http://www.cnblogs.com/zhengyun_ustc/p/slowquery2.html 写在前面的话: 之前曾说过"不要求每个人一定理解 联表查询(join/ ...

  5. 注意使用 BTREE 复合索引各字段的 ASC/DESC 以优化 order by 查询效率

    tbl_direct_pos_201506 表有 190 万数据.DDL: CREATE TABLE `tbl_direct_pos_201506` ( `acq_ins_code` char(13) ...

  6. Mybatis-Plus中使用max、sum聚合函数、只查询指定字段、查询语句多个OR处理

    聚合函数查询 可以使用以下方法 QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.select(" I ...

  7. oracle的位图索引和函数索引

    1.位图索引 位图索引适用于性别.婚姻状态.行政区等只有几列固定值的类型列,身份证号等就不适合位图索引,位图索引适用于静态数据,频繁更新的字段不适用建立位图索引,因为更新会导致索引块区的变更,还会引起 ...

  8. Mysql 索引原理《一》索引原理与慢查询2

    一 索引未命中 并不是说我们创建了索引就一定会加快查询速度,若想利用索引达到预想的提高查询速度的效果,我们在添加索引时,必须遵循以下问题 1 范围问题,或者说条件不明确,条件中出现这些符号或关键字:& ...

  9. MySQL索引原理与慢查询

    =========索引原理与慢查询======= 阅读目录 -     一.介绍 -     二.索引的原理 -     三.索引的数据结构 -     四.聚集索引与辅助索引 -     五.MyS ...

随机推荐

  1. 【xsy1303】生成树 乱搞

    题目大意:给你n个点,问这n个点构成的最小标准差生成树的值 这题题解里面写的都是什么代码?? 你用O(n^4)的复杂度,枚举出两条边,然后求平均数. 对于剩下的边,我们求出这些边与平均数的差,然后求最 ...

  2. curl: (7) Failed connect to 172.16.100.199:9200; 没有到主机的路由

    没有到主机的路由这种问题很常见,多数是由机器的防火墙没有关闭. Ubuntu 查看防火墙状态 ufw status 关闭防火墙 ufw disable centos6 查看防火墙状态 service ...

  3. UFLDL 教程学习笔记(四)主成分分析

    UFLDL(Unsupervised Feature Learning and Deep Learning)Tutorial 是由 Stanford 大学的 Andrew Ng 教授及其团队编写的一套 ...

  4. android UI:Fragment碎片

    碎片(Fragment) 嵌入与活动中的UI片段,为了合理的分配布局而存在,这是我的简单理解.多用于兼顾手机与平板的UI,也适用于灵活高级的UI制作. Demo 简单的按键切换两片不同的Demo 新建 ...

  5. Unity3D鼠标坐标转世界坐标和局部坐标

    鼠标坐标转世界坐标和局部坐标: Vector3 MousePosition2Local () { mousePosition = Input.mousePosition; //获取屏幕坐标 mouse ...

  6. js------保留指定位数小数

    // tofix.js文件// params// val: 要处理的数据,Number | String// len: 保留小数位数,位数不足时,以0填充// side: 1|-1 对应 入|舍exp ...

  7. Apollo 2 如何支持 @Value 注解自动更新

    前言 Apollo 在 v0.10.0 版本后,支持自动更新.v0.10.0之前的版本在配置变化后不会重新注入,需要重启才会更新. 也就是说,如果一个属性加入了 @Value 注解,并且这个配置在配置 ...

  8. spring cloud config服务器

    Spring Cloud Config提供了一种在分布式系统中外部化配置服务器和客户端的支持.配置服务器有一个中心位置,管理所有环境下的应用的外部属性.客户端和服务器映射到相同Spring Event ...

  9. GridView控件的属性、事件

    GridView控件的属性 属性 描述 AllowPaging 指示该控件是否支持分页. AllowSorting 指示该控件是否支持排序. AutoGenerateColumns 指示是否自动地为数 ...

  10. Hybris IMPEX.

    1.Impex是基于java Model的一种面向对象的数据操作手段,因此写impex代码前需要理清java Model之间的依赖关系.   2.基本语法:mode type[modifier=val ...