复合索引和INDEXSKIPSCAN
今天是2014-01-21,在此学习一下复合索引和INDEX SKIP SCAN; 复合索引很简单无非就是在创建索引的时候指定接字段,但是要注意字段的选择是有一定的可参考性的,在字段选择的时候我们一般将where条件之后经常使用的字段创建为复合索引,也就是说where条件自居
今天是2014-01-21,在此学习一下复合索引和INDEX SKIP SCAN;
复合索引很简单无非就是在创建索引的时候指定接字段,但是要注意字段的选择是有一定的可参考性的,在字段选择的时候我们一般将where条件之后经常使用的字段创建为复合索引,也就是说where条件自居中不同的键一起频繁出现,且使用“与”操作这些列时复合索引是不错的选择。
eg:
SQL> select index_type,index_name,table_name from user_indexes where table_name=upper('dept'); INDEX_TYPE INDEX_NAME TABLE_NAME --------------------------- ------------------------------ ------------------------------ NORMAL DEPT_PK DEPT SQL> drop index dept_pk; drop index dept_pk * ERROR at line 1: ORA-02429: cannot drop index used for enforcement of unique/primary key SQL> alter table dept drop constraint dept_pk; alter table dept drop constraint dept_pk * ERROR at line 1: ORA-02273: this unique/primary key is referenced by some foreign keys SQL> select constraint_name,constraint_type,table_name,status from user_constraints where table_name in ('DEPT','EMP'); CONSTRAINT_NAME C TABLE_NAME STATUS ------------------------------ - ------------------------------ -------- DEPT_PK P DEPT ENABLED EMP_FK R EMP ENABLED SQL> ALTER TABLE EMP DROP CONSTRAINT EMP_FK; Table altered. SQL> ALTER TABLE DEPT DROP CONSTRAINT DEPT_PK; Table altered. SQL>
创建复合索引:
SQL> create index dept_idx1 on dept(deptno,dname); Index created. SQL> set autotrace trace exp SQL> select * from dept where deptno=20; Execution Plan ---------------------------------------------------------- Plan hash value: 2855125856 ----------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ----------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | 18 | 2 (0)| 00:00:01 | | 1 | TABLE ACCESS BY INDEX ROWID| DEPT | 1 | 18 | 2 (0)| 00:00:01 | |* 2 | INDEX RANGE SCAN | DEPT_IDX1 | 1 | | 1 (0)| 00:00:01 | ----------------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 2 - access("DEPTNO"=20) SQL>
可以看到在只查询前导列deptno的时候,出现了索引范围扫描,但是由于loc字段没有在复合索引列中,那么还需要增加对表的扫描,无疑增加了额外的I/0,。
重新选择复合索引列值:
eg:
SQL> set autotrace off SQL> drop index dept_idx1; Index dropped. SQL> create index dept_idx1 on dept(deptno,dname,loc); Index created. SQL> set autotrace trace exp SQL> select * from dept where deptno=20; Execution Plan ---------------------------------------------------------- Plan hash value: 2571496166 ------------------------------------------------------------------------------ | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ------------------------------------------------------------------------------ | 0 | SELECT STATEMENT | | 1 | 18 | 1 (0)| 00:00:01 | |* 1 | INDEX RANGE SCAN| DEPT_IDX1 | 1 | 18 | 1 (0)| 00:00:01 | ------------------------------------------------------------------------------ Predicate Information (identified by operation id): --------------------------------------------------- 1 - access("DEPTNO"=20) SQL>
可以看到在选择复合索引的列值是应该注意的地方。在此只是一个非常简单的例子,但是却反应了一个很大问题所在。
对于 index skip scan是从oracle 9I引入的,当没引入该技术时,在复合索引中,如果where条件没有使用到前导列,那么就走全表扫描而不使用索引,在9I之后该技术的引入才打破了这一局限。
官方介绍:
Index skip scans improve index scans by non-prefix columns since it is often faster to scan index blocks than scanning table data blocks. A non-prefix index is an index which does not contain a key column as its first column.
This concept is easier to understand if one imagines a prefix index to be similar to a partitioned table. In a partitioned object the partition key (in this case the leading column) defines which partition data is stored within. In the index case every row underneath each key (the prefix column) would be ordered under that key. Thus in a skip scan of a prefixed index, the prefixed value is skipped and the non-prefix columns are accessed as logical sub-indexes. The trailing columns are ordered within the prefix column and so a 'normal' index access can be done ignoring the prefix.
In this case a composite index is split logically into smaller subindexes. The number of logical subindexes depends on the cardinality of the initial column. Hence it is now possible to use the index even if the leading column is not used in a where clause.
也就是说,索引跳跃式扫描及时通过逻辑子索引消除或跳过一个复合索引,这个时候复合索引可以认为化成了几个逻辑子索引。如果在where条件中没有使用前导列就会采用索引跳跃式扫描。
在看如下例子:
SQL> select dbms_metadata.get_ddl('INDEX','EMP_IDX1','AMY') FROM DUAL; DBMS_METADATA.GET_DDL('INDEX','EMP_IDX1','AMY') -------------------------------------------------------------------------------- CREATE INDEX "AMY"."EMP_IDX1" ON "AMY"."EMP" ("EMPNO", "ENAME", "SAL") PCT SQL> SQL> set autotrace trace exp SQL> SQL> select * from emp where sal=1250; Execution Plan ---------------------------------------------------------- Plan hash value: 954130750 ---------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ---------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | 32 | 2 (0)| 00:00:01 | | 1 | TABLE ACCESS BY INDEX ROWID| EMP | 1 | 32 | 2 (0)| 00:00:01 | |* 2 | INDEX SKIP SCAN | EMP_IDX1 | 1 | | 1 (0)| 00:00:01 | ---------------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 2 - access("SAL"=1250) filter("SAL"=1250) SQL> [oracle@oracle-one ~]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.4.0 Production on Tue Jan 21 15:24:25 2014 Copyright (c) 1982, 2013, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, Automatic Storage Management, OLAP, Data Mining and Real Application Testing options SQL> conn amy/rhys Connected. SQL> alter session set events '10046 trace name context forever,level 12'; Session altered. SQL> select * from emp where sal=1250; EMPNO ENAME JOB MGR HIREDATE SAL COMM ---------- ---------- --------- ---------- --------- ---------- ---------- DEPTNO ---------- 7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30 7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30 SQL> alter session set events '10046 trace name context off'; Session altered. SQL> SQL> select * from v$diag_info; INST_ID NAME VALUE ---------- ------------------------------------------------------------ ------------------------------------------------------------ 1 Diag Enabled TRUE 1 ADR Base /opt/app/oracle 1 ADR Home /opt/app/oracle/diag/rdbms/rhys/RHYS 1 Diag Trace /opt/app/oracle/diag/rdbms/rhys/RHYS/trace 1 Diag Alert /opt/app/oracle/diag/rdbms/rhys/RHYS/alert 1 Diag Incident /opt/app/oracle/diag/rdbms/rhys/RHYS/incident 1 Diag Cdump /opt/app/oracle/diag/rdbms/rhys/RHYS/cdump 1 Health Monitor /opt/app/oracle/diag/rdbms/rhys/RHYS/hm 1 Default Trace File /opt/app/oracle/diag/rdbms/rhys/RHYS/trace/RHYS_ora_4694.trc 1 Active Problem Count 1 1 Active Incident Count 1 11 rows selected. SQL> 看一下执行计划: [oracle@oracle-one script]$ tkprof RHYS_ora_4694.trc tkprof_4694.txt sys=no aggregate=yes explain=amy/rhys record=record_sql.sql waits=yes TKPROF: Release 11.2.0.4.0 - Development on Tue Jan 21 15:31:42 2014 Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. [oracle@oracle-one script]$ [oracle@oracle-one script]$ vi tkprof_4694.txt TKPROF: Release 11.2.0.4.0 - Development on Tue Jan 21 15:31:42 2014 Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. Trace file: RHYS_ora_4694.trc Sort options: default ******************************************************************************** count = number of times OCI procedure was executed cpu = cpu time in seconds executing elapsed = elapsed time in seconds executing disk = number of physical reads of buffers from disk query = number of buffers gotten for consistent read current = number of buffers gotten in current mode (usually for update) rows = number of rows processed by the fetch or execute call ******************************************************************************** SQL ID: ajqsk3f0nk06d Plan Hash: 954130750 select * from emp where sal=1250 call count cpu elapsed disk query current rows ------- ------ -------- ---------- ---------- ---------- ---------- ---------- Parse 1 0.00 0.03 0 0 0 0 Execute 1 0.00 0.00 0 0 0 0 Fetch 2 0.00 0.00 0 4 0 2 ------- ------ -------- ---------- ---------- ---------- ---------- ---------- total 4 0.00 0.03 0 4 0 2 Misses in library cache during parse: 1 Optimizer mode: ALL_ROWS Parsing user id: 90 (AMY) Number of plan statistics captured: 1 Rows (1st) Rows (avg) Rows (max) Row Source Operation ---------- ---------- ---------- --------------------------------------------------- 2 2 2 TABLE ACCESS BY INDEX ROWID EMP (cr=4 pr=0 pw=0 time=41 us cost=2 size=32 card=1) 2 2 2 INDEX SKIP SCAN EMP_IDX1 (cr=2 pr=0 pw=0 time=42 us cost=1 size=0 card=1)(object id 88000) Rows Execution Plan ------- --------------------------------------------------- 0 SELECT STATEMENT MODE: ALL_ROWS 2 TABLE ACCESS MODE: ANALYZED (BY INDEX ROWID) OF 'EMP' (TABLE) 2 INDEX MODE: ANALYZED (SKIP SCAN) OF 'EMP_IDX1' (INDEX) Elapsed times include waiting on following events: Event waited on Times Max. Wait Total Waited ---------------------------------------- Waited ---------- ------------ SQL*Net message to client 2 0.00 0.00 SQL*Net message from client 2 14.93 14.93 ******************************************************************************** SQL>

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제











Windows 11에서 100% 디스크 사용량을 수정하는 방법 100% 디스크 사용량을 유발하는 문제가 있는 응용 프로그램이나 서비스를 찾는 간단한 방법은 작업 관리자를 사용하는 것입니다. 작업 관리자를 열려면 시작 메뉴를 마우스 오른쪽 버튼으로 클릭하고 작업 관리자를 선택합니다. 가장 많은 리소스를 사용하는 항목을 보려면 디스크 열 헤더를 클릭하세요. 거기에서 어디서부터 시작해야 할지에 대한 좋은 아이디어를 갖게 될 것입니다. 그러나 문제는 단순히 애플리케이션을 닫거나 서비스를 비활성화하는 것보다 더 심각할 수 있습니다. 문제의 잠재적인 원인과 해결 방법을 알아보려면 계속 읽어보세요. SuperfetchSuperfetch 기능(Windows 11에서는 SysMain이라고도 함)을 비활성화하면 프리페치 파일에 액세스하여 시작 시간을 줄이는 데 도움이 됩니다.

<h2>Windows 11 검색에서 파일 및 폴더를 숨기는 방법</h2><p>가장 먼저 살펴봐야 할 것은 Windows 검색 파일의 위치를 사용자 지정하는 것입니다. 이러한 특정 위치를 건너뛰면 보호하려는 파일을 숨기는 동시에 결과를 더 빨리 볼 수 있습니다. </p><p>Windows 11 검색에서 파일과 폴더를 제외하려면 다음 단계를 따르세요. </p><ol&

Windows 11에서 검색 창이 작동하지 않는 경우 즉시 검색 창을 활성화하고 실행할 수 있는 몇 가지 빠른 방법이 있습니다! 모든 Microsoft 운영 체제에서는 때때로 결함이 발생할 수 있으며 최신 운영 체제도 이 규칙에서 면제되지 않습니다. 또한 Reddit의 u/zebra_head1 사용자가 지적한 대로 22H2Build22621.1413이 포함된 Windows 11에서도 동일한 오류가 나타납니다. 사용자들은 작업 표시줄 검색 상자를 무작위로 전환하는 옵션이 사라졌다고 불평했습니다. 그러므로 어떤 상황에도 대비해야 합니다. 내 컴퓨터의 검색창에 입력할 수 없는 이유는 무엇입니까? 컴퓨터에 입력할 수 없는 현상은 다양한 요인과 프로세스로 인해 발생할 수 있습니다. 주의해야 할 사항은 다음과 같습니다. Ctfmon.

Oracle 인덱스 유형은 다음과 같습니다. 1. B-트리 인덱스, 3. 함수 인덱스, 5. 역방향 키 인덱스, 7. 도메인 인덱스, 비트맵 연결 인덱스 10. 복합 인덱스. 세부 소개: 1. B-트리 인덱스는 동시 작업을 효율적으로 지원할 수 있는 자체 균형 트리 데이터 구조입니다. Oracle 데이터베이스에서 B-트리 인덱스는 가장 일반적으로 사용되는 인덱스 유형입니다. 2. 비트 그래프 인덱스는 인덱스 유형 기반입니다. 비트맵 알고리즘 등에 관한 것입니다.

Outlook에서 검색 및 인덱싱 문제 해결사 실행 시작할 수 있는 보다 간단한 해결 방법 중 하나는 검색 및 인덱싱 문제 해결사를 실행하는 것입니다. Windows 11에서 문제 해결사를 실행하려면: 시작 버튼을 클릭하거나 Windows 키를 누르고 메뉴에서 설정을 선택합니다. 설정이 열리면 시스템 > 문제 해결 > 추가 문제 해결을 선택합니다. 오른쪽에서 아래로 스크롤하여 SearchandIndexing을 찾아 실행 버튼을 클릭하세요. 결과를 반환하지 않으려면 Outlook 검색을 선택하고 화면 지침을 계속 진행합니다. 실행하면 문제 해결사가 자동으로 문제를 식별하고 해결합니다. 문제 해결사를 실행한 후 Outlook을 열고 검색이 제대로 작동하는지 확인하세요. 좋다

해결 방법은 다음과 같습니다. 1. 인덱스 값이 올바른지 확인합니다. 먼저 인덱스 값이 배열의 길이 범위를 초과하는지 확인합니다. 배열의 인덱스는 0부터 시작하므로 최대 인덱스 값은 배열 길이에서 1을 뺀 값이어야 합니다. 2. 루프 경계 조건을 확인하세요. 루프에서 배열 액세스에 인덱스를 사용하는 경우 루프 경계 조건이 올바른지 확인하세요. 3. 배열 초기화: 배열을 사용하기 전에 배열이 올바르게 초기화되었는지 확인하십시오. 4. 예외 처리 사용: 프로그램의 예외 처리 메커니즘을 사용하여 인덱스가 배열 범위를 초과하는 오류를 잡을 수 있습니다. 그에 따라 처리하십시오.

이 글은 PHP가 다른 문자열에서 문자열의 시작 위치부터 끝 위치까지 문자열을 반환하는 방법을 자세히 설명합니다. 편집자는 이것이 꽤 실용적이라고 생각하므로 참고용으로 공유하겠습니다. 이 기사에서 뭔가를 얻을 수 있습니다. PHP에서 substr() 함수를 사용하여 문자열에서 부분 문자열을 추출합니다. substr() 함수는 문자열에서 지정된 범위 내의 문자를 추출할 수 있습니다. 구문은 다음과 같습니다. substr(string,start,length) 여기서: string: 하위 문자열을 추출할 원래 문자열입니다. start: 하위 문자열의 시작 위치에 대한 인덱스입니다(0부터 시작). 길이(선택 사항): 하위 문자열의 길이입니다. 지정하지 않은 경우

인덱스를 통해 PHP 및 MySQL에서 데이터 그룹화 및 데이터 집계의 효율성을 향상시키는 방법은 무엇입니까? 소개: PHP와 MySQL은 현재 가장 널리 사용되는 프로그래밍 언어이자 데이터베이스 관리 시스템으로, 웹 애플리케이션을 구축하고 대용량 데이터를 처리하는 데 자주 사용됩니다. 데이터 그룹화 및 데이터 집계는 대용량 데이터를 처리할 때 흔히 수행되는 작업이지만, 인덱스를 적절하게 설계하고 사용하지 않으면 이러한 작업은 매우 비효율적일 수 있습니다. 이 기사에서는 인덱스를 사용하여 PHP 및 MySQL에서 데이터 그룹화 및 데이터 집계의 효율성을 향상시키는 방법을 소개하고,
