You are on page 1of 14

Khoa HTTT - i hc

CNTT 1
Bi 8: Ti u ha cu hi
Khoa HTTT - i hc CNTT 2
Ni dung
1. Gii thiu
2. Cc nguyn tc tng qut ti u ha cu hi
2.1 Biu thc tng ng
2.1.1 nh ngha
2.1.2 Tnh cht ca php kt v php tch
2.2 Nguyn tc tng qut
2.3 Cc php bin i tng ng
3. Mt s k thut ti u ha cu hi bng SQH
3.1 K thut (dy php chn, php chiu, hon v )
3.2 Thut gii ti u ho cu hi trong
Khoa HTTT - i hc CNTT 3
1. Gii thiu (1)
Mc ch:
Gim thi gian x l cu hi, gim khi lng
d liu trung gian.
Kt hp gia cc php tch, php kt vi php
chn vi php chiu.
V d:

] )[ ) : ((
] )[ : ) ((
2 0 1
0 2 1
C Q a A Q
C a A Q Q

= +
= +
Khoa HTTT - i hc CNTT 4
1. Gii thiu (2)
K hiu:
X
R
Q
D
R
Q
AuB
R S
Q
Q=R[S]
Q=R:D
Q=R S
B Au

Khoa HTTT - i hc CNTT 5


1. Gii thiu (3)
V d
Q
1
Q
2
A
A=a
0
C
A
Q
1
C
Q
2
A=a
0
] )[ : ) ((
0 2 1
C a A Q Q = ] )[ ) : ((
2 0 1
C Q a A Q =
Khoa HTTT - i hc CNTT 6
2.1 Tnh tng ng (1)
2.1.1 nh ngha: hai biu thc A, B l tng
ng nu c cng mt tnh trng CSDL th u
cho mt kt qu.
2.1.2 Tnh cht ca php kt v php tch
Php kt
Giao hon
Kt hp
Php tch
Giao hon:
Kt hp:
1 2 2 1
Q Q Q Q
dk dk
=
3
2
2
1
1 3
2
2
1
1
) ( ) ( Q Q Q Q Q Q
dk dk dk dk
=
1 2 2 1
Q Q Q Q =
3 2 1 3 2 1
) ( ) ( Q Q Q Q Q Q =
Khoa HTTT - i hc CNTT 7
2.1 Tnh tng ng (2)
2.1.3 Cc php bin i tng ng
] ))[ , ( ] [ ] [ (( ] [ ) , ( ) , ( . 5
) ,..., ( ]) [ ... ] [ ] [ ( ) ,..., ( . 4
)) ( ) (( . 3
) : ( ) , ( ) , ( . 2
]) [ ] [ : ( ) , ( ) , ( . 1
1 2 1 1 2 1
1 2 1 1
2 1 2 1
2 1 2 1
2 1 2 1 2 1
B B A Q A Q B Q B Q B A Q B A Q
X X Q X Q X Q X Q X X Q
Q Q Q Q
D B Q Q D C Q B A Q
B Q B Q Q Q C B Q B A Q
n n n
D B
B




=
u
u

Khoa HTTT - i hc CNTT 8


2.2 Nguyn tc tng qut
1. Thc hin php chiu, php chn cng sm cng tt
2. Gom cc php chn v chiu cng quan h thc
hin cng lc
3. Bin php tch thnh php kt t nhin hay theta kt
4. Tm cc biu thc con chung trong mt biu thc
5. Tin x l cc quan h: lp ch mc
6. nh gi trc khi thc hin tnh ton
Khoa HTTT - i hc CNTT 9
3.1 Cc k thut ti u (1)
1. Dy cc php chn
2. Dy cc php chiu
3. Hon v gia php chiu v php chn
4. Hon v gia php chn v php tch
5. Hon v gia php hp v php chn
6. Hon v gia php chn v php tr
7. Hon v gia php chiu v php hi
8. Hon v gia php chiu v php tch
Khoa HTTT - i hc CNTT 10
3.1 Cc k thut ti u (2)
1. Dy cc php chn


2. Dy php chiu

V d:
dkn dk dk Q dkn dk dk Q ... 2 1 : ) : )... 2 : ) 1 : ((( . .
Y Z Z Q Z Y Q _ , ] [ ] ])[ [ (
] [ ] ])[ , , [ (
) , , , (
AD Q AD D C A Q
D C B A Q Cho

Khoa HTTT - i hc CNTT 11


3.1 Cc k thut ti u (3)
3. Hon v gia php chiu v php chn
Nu


Nu Y X .
Y X _
) ( : ]) [ ( ] ))[ ( : ( X dk Y X Q Y X dk Q
) ( : ]) [ ( ] ))[ ( : ( X dk Y Q Y X dk Q
Khoa HTTT - i hc CNTT 12
3.1 Cc k thut ti u (4)
4. Hon v gia php chn v php tch:
iu kin dk xc lp trn cc thuc tnh ca X

Nu , dk1 xc lp trn cc thuc
tnh ca X, dk2 xc lp trn cc thuc tnh ca Y.

Nu dk1 xc lp trn cc thuc tnh ca X v dk2
xc lp trn cc thuc tnh ca XY
dk Y Q X Q Y Q X dk X Q : )) ( ) ( ( ) ( ) ( : )) ( (
2 1 2 1

2 1 dk dk dk . =
) 2 : ) ( ( ) 1 : ) ( (( ) ( 2 ) ( 1 : )) ( ) ( ((
2 1 2 1
dk Y Q dk X Q Y dk X dk Y Q X Q .
)) ( 2 : )) ( ( ) 1 : ) ( ((
) ( 2 ) ( 1 : )) ( ) ( ((
2 1
2 1
Y X dk Y Q dk X Q
Y X dk X dk Y Q X Q

.
Khoa HTTT - i hc CNTT 13
3.1 Cc k thut ti u (5)
5. Hon v gia php hi v php chn

6. Hon v gia php chn v php tr

7. Hon v gia php chiu v php hi

8. Hon v gia php chiu v php tch
) : ( ) : ( : ) (
2 1 2 1
dk Q dk Q dk Q Q
) : ( ) : ( : ) (
2 1 2 1
dk Q dk Q dk Q Q
]) [ ( ]) [ ( ] )[ (
2 1 2 1
Z Q Z Q Z Q Q
Y X Z Z Y Q Z Y Q Z Y Q X Q e , ]) [ ( ]) [ ( ] ))[ ( ) ( (
2 1 2 1
Khoa HTTT - i hc CNTT 14
3.2 Thut ton
Bc 1: p dng cc php bin i tng ng
Bc 2: p dng (1)
Bc 3: i vi cc php chn p dng (3), (4), (5), (6)
nhm a php chn cng su cng tt
Bc 4: i vi cc php chiu p dng (2), (3), (7), (8)
nhm a php chiu cng su cng tt
Bc 5:
Tp trung cc php chn p dng (1)
Kt hp php tch v php chn chuyn thnh php kt