INDEX
DBMS 요약
- 조회 속도를 향상시키기 위한 데이터베이스 검색 기술
- 색인이라는 뜻으로 해당 테이블의 조회 결과를 빠르게 하기 위해 사용.
- 인덱스가 필요한 이유는 인덱스를 생성해 줌으로써
조회 속도를 빠르게 할 수 있기 때문이다.
- index를 테이블의 특정 컬럼에 한 개 이상 주게 되면 index table이
따로 만들어지고, 인덱스 컬럼의 로우값과 rowid값이 저장되며,
로우값은 정렬된 트리 구조로 저장시켜 두었다가 검색 시 좀 더 빠르게
해당 데이터를 찾는데 도움을 준다.
참고) rowid
-> 테이블에 데이터를 입력하면 하나의 row가 생성된다.
oracle에서는 각각의 데이터 마다 rowid를 가지게 된다.
- 하지만 DML명령을 사용할 때는 원본 테이블은 물론, index 테이블에도
데이터를 같이 갱신해줘야 하기 때문에, update, insert, delete 명령을
쓸 때 속도가 느려진다.
- index 생성이 불필요한 경우
-> 데이터가 적은(수 천건 미만) 경우에는 인덱스를 설정하지 않는게
오히려 성능이 좋다.
-> 조회 보다 삽입, 수정, 삭제 처리가 많은 테이블
- unique index
: 인덱스를 사용한 컬럼의 중복값들을 포함하지 않고 사용할 수 있는 장점
create unique index 인덱스명 on 테이블명(컬럼) ;
-- index
-- 오류
CREATE TABLE EMPLOYEES3 AS SELECT * FROM EMPLOYEES e ;
SELECT * FROM EMPLOYEES3 ;
SELECT rowid, EMPLOYEE_ID
FROM EMPLOYEES3 e
WHERE EMPLOYEE_ID = 200
;
SELECT *
FROM EMPLOYEES3 e
WHERE EMPLOYEE_ID = 100
;
INSERT INTO EMPLOYEES3 (EMPLOYEE_ID, FIRST_NAME, LAST_NAME)
VALUES (100, 'User', 'Name') ;
-- unique index 생성
CREATE UNIQUE INDEX idx_employees3_id
ON employees3(employee_id)
;
- non-unique index
: 인덱스를 사용한 컬럼에 중복 데이터 값을 가질 수 있다.
create index 인덱스명 on 테이블명(컬럼) ;
SELECT * FROM EMPLOYEES3 e WHERE FIRST_NAME = 'Michael';
INSERT INTO EMPLOYEES3 (employee_id, FIRST_NAME, LAST_NAME)
VALUES (500, 'Michael', 'Hartstein');
INSERT INTO EMPLOYEES3 (employee_id, FIRST_NAME, LAST_NAME)
VALUES (501, 'Michael', 'Hartstein');
-- index 생성
CREATE INDEX idx_emp3_first_name
ON employees3(first_name);
DBMS
Oracle, Tibero, MySql, MariaDB, sqlite, h2, Postgresql
SQL
DDL ( create, alter, drop, truncate )
DML ( select, update, insert, delete )
DCL ( grant, revoke )
select
where / and or
as
distinct
not( !=, <> )
between A and B
in ( )
like
is null / is not null
order by (ASC)
order by DESC
sum( )
count( )
avg( )
max( )
min( )
dual 더미 테이블
abs( )
round( )
trunc( )
concat( ) / ||
initcap( )
upper( )
lower( )
LPAD( ) / RPAD( )
LTRIM( )
RTRIM( )
substr( )
translate
sysdate
to_char( )
nvl( )
decode( )
case when then else end
group by
having
join
inner join
left outer join
subQuery
oracle data type
char / varchar2
Number( P, S )
DATE
LOB
create table / create table as select ~
alter table add
alter table modify
alter table 테이블명 drop column
drop table 테이블명
truncate 테이블
insert
update
delete
drop vs truncate vs delete
transaction
commit
rollback
auto commit
제약조건
not null
unique
check
primary key
foreign key
on delete cascade
on delete set null
view
create view 뷰이름 ( 뷰 컬럼 ) as select ( 테이블명 )
drop
read only
sequence
nextvalue
currval
index