学习oracle技术,每天学一点,每天进步一点

oracle sql tunning all hints

上一篇 / 下一篇  2007-12-24 18:25:02

The following is a list of all hints available in Oracle9i. Many of the hints are also available in earlier releases of Oracle. The purpose of this list is not to exhaustively describe the syntax of each hint, but to show the way each hint is most commonly used.ITPUB个人空间!SD l9w7H.r
ALL_ROWSITPUB个人空间TV Mak[s
Optimizes for least resource usageto return all rows required by the query. This hint will sometimes override a NESTED LOOP with a SORT MERGE or a HASH JOIN if applied to a SELECT, UPDATE, or DELETE statement when OPTIMIZER_MODE=CHOOSE.
3s ^h;D3];[0SELECT /*+ ALL_ROWS */ ...
GV J*GN%g0ITPUB个人空间,nTX)h N bx
AND_EQUAL (table index1 index2[... index5])
pmI|vX)I0Explicitly merges single-column indexes. A minimum of two indexes must be specified, and no more than five are allowed. Single-column index merges can be incredibly inefficient if the first index in the WHERE returns a lot of rows.
OuN:aM0SELECT /*+ AND_EQUAL(horse_owners ho_ndx1
^ Ny;z2W}m0ho_ndx2 ho_ndx3) */ITPUB个人空间l6C Tyt*?Kf8tQ
count(*)ITPUB个人空间0b!r| B tMY8u
FROM horse_owners
6Q0vO.mZ0WHERE horse_name = 'WILD CHARM'
,O;k(D:Y_}E0AND wner = 'Mr M A Gurry'ITPUB个人空间D6Z.O.KmVb
AND identifier = 14;ITPUB个人空间"N*wAG9n9G2E6x

9J"gsr;f0S0APPENDITPUB个人空间{2p/r0T:m8MMw3P9m;}
Allows a direct path insert to a table. Data to be inserted bypasses the buffer cache, and is appended to the end of the table. Integrity constraints are ignored during the load, although I have observed that after the load has taken place, the integrity checks are made and your statement can still fail with an integrity constraint error.ITPUB个人空间!}gT sO(}
INSERT /*+ APPEND */ * INTO y
2k,w(rZ/N0SELECT FROM winners;
)S'L&w]A Sa0
g@O J nXN%V ~W0CACHE (table)ITPUB个人空间%}6J RDC~/|
Instructs the optimizer to position all blocks retrieved via a full table scan at the most recently used end of the LRU (Least Recently Used) list in the buffer cache. You wouldITPUB个人空间,B3D-RBpKR2WF

f-t1A2fm0usually use this hint on small tables, but I have seen sites with a very large amount of memory cache very large tables that are infrequently changed.
k8D0b'Ij!Y"u5z:c0SELECT /*+ FULL(winners) CACHE(winners)
\8I4k)lH0*/ count(*)
9b)G@(rModi"b%PZ'k0FROM winners
C }h#OL'i0ITPUB个人空间 v4F(kw;bA {$L
CHOOSE
+o:doz0E2b{m0Uses the cost-based optimizer if statistics are available for at least one table; otherwise, uses the rule-based optimizer.ITPUB个人空间0A4d2k8NT9o
SELECT /*+ CHOOSE */
I*t*|$t/^0z _"Z6F0
n0p/fF&{2iN1Y3u6JO0CLUSTER(table)ITPUB个人空间pB?#S"g(GS
Forces the use of a cluster scan for the specified table. This hint can only be used for objects that are clustered. A cluster is two or more related tables with the parents and the related child records stored physically next to each other. For example, account1 will have its transactions stored in the same physical block as the account record.ITPUB个人空间cq-WRuL
SELECT /*+ CLUSTER(a) */ acct_name
H7`,VnU@;R0FROM acct aITPUB个人空间\)QW^fJ7I4F

\X*H l*?)VH^0CURSOR_SHARING_EXACT
cO!f!FOM0Prevents Oracle from translating literals into bind variables even when the CURSOR_SHARING parameter is set to FORCE or SIMILAR. For example:ITPUB个人空间@;`#N;p.W#K3NC e
SELECT /*+ CURSOR_SHARING_EXACT */ name, suburbITPUB个人空间)I}3d*S.z1^&G W"}ES
FROM empITPUB个人空间!?*v1b u c rmS,N2gJ
WHERE surname = 'GURRY';
pJ5WVfMkc0If the hint was not used on this SQL statement, and CURSOR_SHARING was set to SIMILAR or FORCE, the `GURRY' value in this example would be translated into a bind variable.
'b r0JcG U M Um]0ITPUB个人空间+um-Q\l/_,W D
FACT(table)ITPUB个人空间H \&Tz7v4[.j
Tells the cost-based optimizer that the table listed is a fact table and should be treated as such. This hint is used with the STAR_TRANSFORMATION operation.
5w P+[2a2PpVaT0SELECT /*+ FACT(results) */
0V+Tb'WF I-wxW-g0ITPUB个人空间Ll2a6{ n.H8b"Xcp
FIRST_ROWS or FIRST_ROWS(n)
U:MPQ GSo0Optimizes for best response time to return the first n rows required by a query. Statistics do not have to be available for any table involved in the SQL statement; their statistics can be estimated by the optimizer. Other "access path hints" can be included with the FIRST_ ROWS hint, and may override FIRST_ROWS. If you use the (n) option to specify the exact number of rows to be returned, Oracle can make a more precise execution plan decision. The (n) option is only available with Oracle9i and later.ITPUB个人空间?c6}gy!Nd/M8R
ITPUB个人空间/}B`Ge1o#gv
For example:ITPUB个人空间k#g.S8N u'TH
SELECT /*+ FIRST_ROWS(100) */
5W9{9Q kp0This hint:ITPUB个人空间 B0Z4z u d9hVnIF
• Will always choose an index over a full table scan.
A J+j*v/^W0|b\p0• Uses nested loop joins over sort/merge joins, where possible.ITPUB个人空间.i[ GcF+u }3p
• Uses an index to satisfy an ORDER BY clause, where possible.ITPUB个人空间 R,~jUmW%hP

2^*?o$q9K7x7U0The optimizer ignores the hints for DELETE and UPDATE statement blocks, and for any SELECT statement block that contains a "grouping" operation (UNION, INTERSECT, MINUS, GROUP BY, DISTINCT, MAX, MIN, SUM, etc.) or a FOR UPDATE clause. Such statements cannot be optimized for best response time, because all rows must be accessed before the first row can be returned.
6]W_*IN/]k8`0
4?&s-v }6n0FULL(table)ITPUB个人空间1I_!Rx-D(Xi
Forces the use of a full table scan on the specified table.
Fj8vbgW\0SELECT /*+ FULL(emp) */ ename
oA#S(x#D,q0FROM emp
@-a._4x"Rs!da!~!_ U0WHERE commencement_date > sysdate - 7
hv.kc D9V"g0If a table has an alias, you must specify the alias name in the hint:
&u#E{FJ([*p2D0SELECT /*+ FULL(a) */ ename
C_#G}(V6Y K4]O0FROM emp a
(rQ Z)J!_IHb0WHERE a.commencement_date > sysdate - 7
?Ea S8zR0t(M0
x9K:e!M}zI0HASH(table)
?8x |f pIy:R0Forces the use of a hash table scan for the specified table. This hint applies only to tables stored in a cluster.
/Aj:N;eBM0SELECT /*+ HASH(a) */ acct_name
I4xTZ`"zp3n0FROM acct a
jDo1t(i0A lot of people get this hint mixed up with USE_HASH, which forces a hash join. This is not the same hint!ITPUB个人空间*L/Ec~kN
ITPUB个人空间e_3a&xa ^9B:Mkfp
HASH_AJITPUB个人空间Qa lV0i R
Provides substantial performance improvements by turning a nested loop operation for a NOT IN into a hash join operation. This hint needs to be placed against the SELECT statement in the subquery, not in the main select clause.ITPUB个人空间l f#W+?^*e*H:e
SELECT count(*)ITPUB个人空间Cf(}0UW/N:? J?
FROM horses
&_+E1O"V+}3Ld(?0WHERE horse_name LIKE 'M%'
V+s3OG[ pWG1Yh*rQ0AND horse_name NOT IN
'I2Al+l {2f0
9\s p#m'UN&c^ Rl0( SELECT /*+ HASH_AJ */ horse_nameITPUB个人空间*h@2l:r(`!q R!xr
FROM horse_owners
o ])[MmAO0WHERE owner LIKE '%Lombardo%');
kq-Pll1q&w,}0ITPUB个人空间9} F5Qmz
HASH_SJ
grI]#_ Yu0Often speeds response times in an EXISTS subquery by returning the rows in the subquery only once.
-{f&U|PUk*j0SELECT count(*)
},PNur C:q.p#O J0FROM horses
T9o-l/o(Ki0WHERE horse_name LIKE 'M%'
8o`c4l6fm!f u0AND EXISTSITPUB个人空间+p B8{!w6F#Y&B
( SELECT /*+ HASH_SJ */ horse_name
(v1lv,i*~ Ow0FROM horse_owners
&t] BG G3fM/QLn2G lN0WHERE owner LIKE '%Lombardo%'
s'[2Xa*J0AND horses.horse_name= horse_owners.horse_name)ITPUB个人空间9L$d.@f'M8K8Qg0u x
There are some restrictions on this hint:
M\|"tzaU)Cb01. There must be only one table listed in the subquery.
z0w*a9q p8Y/jq0t-_02. The hint can't be used in a subquery within a subquery.ITPUB个人空间)bS3aaHRraS&v
3. The subquery must be correlated with an equality predicate, which is a requirement for all hash joins.ITPUB个人空间5UHTs;?wsh
4. The subquery must have no GROUP BY clause, CONNECT BY clause, or ROWNUM reference.
/S/l-@ N"J:iw l+j0ITPUB个人空间WE%j4H{TR&| z8f ["Ej
INDEX(table [index [index...]])ITPUB个人空间'@pz!x;@b]3n
Forces the use of an indexed table scan for the specified table. You can optionally specify one or more indexes in the hint. If no indexes are included, the optimizer calculates the cost of all indexes for the table, and uses the most efficient (several indexes may be used in tandem). If several indexes are listed, the optimizer calculates the cost of only those indexes that are specified, and uses the most efficient (several indexes from the list may be used in tandem if they are single-column indexes). If a single index is specified, the optimizer performs a scan using that index.ITPUB个人空间%X2BqnK,Tk
SELECT /*+ INDEX(EMP EMP_NDX1) */ITPUB个人空间)x1p.D;P9j sP
SELECT /*+ INDEX(EMP) */
M^y7\KH1r4Q0
.}i'O+N T|8?5n#q0INDEX_ASC(table [index])
t `k M&v`E(I0Forces the use of an ascending indexed table scan for the specified table. Oracle will scan indexes in ascending order by default anyway. So why use this hint? Good question! I suppose this hint guarantees that the index will be traversed in ascending order, even if
q&a(O1]i }|0
Gf.MDI7zN0Oracle decides to behave differently. The exception to the rule is if the index has been created as a reverse key index, e.g., CREATE INDEX POST ON OWNERS (ZIPCODE) REVERSE.
-\y2_3FQh0SELECT /*+ INDEX_ASC(EMP EMP_NDX1) */...ITPUB个人空间X4NB(JW-_(i6SW'B
ITPUB个人空间 D6o&R A:K+|0B
INDEX_COMBINE(table [index [index...]])
;E sduw(z0Explicitly chooses bitmap indexes to access the table information.
.X x%v1YjA/?\e"as0SELECT /*+ INDEX_COMBINE(ACCT_TRAN AT_STATE_BMI AT_TYPE_BMI) */
/p{[ s)nOV@0
*]%ru2f-HNU}0INDEX_DESC(table [index])
c5X.fk c9[bB"w0Forces the use of a descending indexed table scan for the specified table. By default, Oracle scans indexes in ascending sequence. This hint guarantees that the index will be traversed in descending order. A typical usage of this hint would be to retrieve the latest transactions on your bank account in descending order by date. This hint can be of great value in distributed queries.
|(p7dD p^q0SELECT /*+ INDEX_DESC(ACCT_TRANS ACCT_TRANS_DATE_NDX) */...
0v#sDT/Av0ITPUB个人空间(mqz3]VN8u"R
INDEX_FFS(table [index])ITPUB个人空间"{DQ IIl&f
Instructs the optimizer to do a full scan of an index rather than a full scan of a table. The index scan can sometimes run faster, but if and only if every column in the WHERE clause for the specified table exists in the index.
7YOdxo CZ0SELECT /*+ INDEX_FFS(ACCT_TRAN AT_STATE_NDX1) */ITPUB个人空间b\EeE?
ITPUB个人空间7v;kj*L:KV
INDEX_JOIN(table [index] table [index2)]
@#C1{1Y%I1l }+A:p4I0This hint tells the optimizer to join two indexes as the access path. Typically the execution plan will include a hash join of the two indexes, which can return some performance improvements. In the following example, two of the table's three primary key columns have been used in the WHERE clause (HORSE_NAME and OWNER), as has the leading column (IDENTIFIER) of a non-primary key index.
QZ ~5K;@ C9n8F0SELECT /*+ INDEX_JOIN(HORSE_OWNERS HO_NDX2 HO_PK) */
r;J3U1X)A0Horse_name, ownerITPUB个人空间Ke#QR;rD
FROM HORSE_OWNERS
3nW+gYy0WHERE horse_name = 'WILD CHARM'ITPUB个人空间7Z`JO3\ yf
AND wner = 'Mr M A Gurry'ITPUB个人空间 Ol*K7qny Pi
AND identifier = 10;
.\F\^ZU?6K0As a matter of interest, without the INDEX_JOIN hint, the optimizers will usually only join the single-column indexes.ITPUB个人空间$Y'~9^6Vp/Z`:GW

)ZO"v'f]!VP0MERGE(table)ITPUB个人空间*yehh:Hrg

o*k p3e,C d.A0Used to force the merging of a nested (inline) view with the main driving query. In the example given, the GROUP BY inline view is merged with the selection from the OWNERS table.
\`+e:Tbb0The hint can also be used for subqueries if the IN statement is uncorrelated; that is, it does not reference join columns in the main query.
)I1|pUf/N$X4N+Q|0SELECT /*+ MERGE(w) */ o.owner,
7}f,A4IsMc%v0W0w.num_wins, o.suburb
qImq/T5a0V,^*z0FROM owners o,ITPUB个人空间4Xg@2N]PIC
(SELECT owner, count(*) num_wins
Nu8W2L [@0FROM winnersITPUB个人空间 V/aIG3veO
WHERE position = 1
nv-Xs%bsi8n7l3v0GROUP BY owner) w
y\3o*F7W7s!b0WHERE o.owner = w.ownerITPUB个人空间FY']4h2u8F5C
AND w.num_wins > 15
#Cc9FE(t9x0\~Q3H0ORDER BY w.num_wins descITPUB个人空间!sLwc5O/M;b

'lv;V'vm| X!~+T0MERGE_AJITPUB个人空间[.y+bbE+HL X!as
Provides substantial performance improvements by turning a nested loop operation for a NOT IN into a merge join operation (similar to HASH_AJ). This hint needs to be placed against the SELECT statement in the subquery, not in the main select clause.ITPUB个人空间\0lpKEy3ik @@&p
SELECT count(*)ITPUB个人空间]+e ?,`)hP!Qi
FROM horsesITPUB个人空间-X~.lyA*G!m
WHERE horse_name LIKE 'M%'
J _ug L{*N0AND horse_name NOT IN
`,u"u.uxE@J+]0( SELECT /*+ MERGE_AJ */ horse_nameITPUB个人空间M/@9p3CTr&r
FROM horse_ownersITPUB个人空间 A:? ^.vZJF
WHERE owner LIKE '%Lombardo%');ITPUB个人空间/eQd e M
ITPUB个人空间k T$x"j3Y WT&S
MERGE_SJITPUB个人空间 }Y pD$H0HGXSWz h
This hint will often speed response times in an EXISTS subquery by returning the rows in the subquery only once.ITPUB个人空间&w-RvaH%k ?e5B5R
SELECT count(*)
D+L3}d+c!UR0FROM horses
AqA|'aX0WHERE horse_name LIKE 'M%'
:] K9z7eb2ra0AND EXISTSITPUB个人空间Tqw&o_M^6N
( SELECT /*+ MERGE_SJ */ horse_name
's\E!fo(B5R0FROM horse_ownersITPUB个人空间?*n&aQ2GMpN
WHERE owner LIKE '%Lombardo%'ITPUB个人空间9v0lyZ/uY

fa.?*?7g4P uk0AND horses.horse_name= horse_owners.horse_name)
d }N\2[2Jt g9V0There are some restrictions on this hint:ITPUB个人空间z:X YDo.|2Aj VA
1. There must be only one table in the subquery.ITPUB个人空间rxYe4a O[ g
2. The subquery can't be a subquery within a subquery.ITPUB个人空间|;b%t i;|z1u&zcA8Z
3. The subquery must be correlated with an equality predicate.
"R ED9^7r04. The subquery must have no GROUP BY clause, CONNECT BY clause, or ROWNUM reference.
#UXosNV0ITPUB个人空间2GNOHjP#bA[ C
NL_AJ
A"U_%LUww@0Occasionally provides some performance improvements by forcing a nested loop operation for a NOT IN. However, nested loop performance is often inferior to that of the hash join and the sort merge join. The hint needs to be placed against the SELECT statement in the subquery, not in the main select clause.
l`!gh/x O q0SELECT count(*)
m{5m:G9JI0FROM horsesITPUB个人空间1^lNE4C ?$a9V2D v
WHERE horse_name LIKE 'M%'ITPUB个人空间1~QX*^?/g\Q
AND horse_name NOT INITPUB个人空间 ~ fR6wm [4w@
( SELECT /*+ NL_AJ */ horse_name
'Jb`*B:Xv0FROM horse_ownersITPUB个人空间H4D,Q8]6P*dX1b
WHERE owner LIKE '%Lombardo%');ITPUB个人空间'G)S `J Rx m+@

c4|1@S-a.L(x0NL_SJ
N.rm)D+{ rT6t0This hint is similar to the HASH_SJ and MERGE_SJ hints, but uses the nested loop operation for the semi join.ITPUB个人空间OI$dq p*Sj
SELECT count(*)ITPUB个人空间&p F;ncsp0wm
FROM horses
R][4Lz yw~e[0WHERE horse_name LIKE 'M%'ITPUB个人空间%]dw }| z
AND EXISTS
} I"v/y5j.O0( SELECT /*+ NL_SJ */ horse_name
AE9vi%e6_,f0r0FROM horse_ownersITPUB个人空间"z"am"~j'|"omz
WHERE owner LIKE '%Lombardo%'ITPUB个人空间9TM _H7q \
AND horses.horse_name=
w'W:W:i#gGB[ @+G0horse_owners.horse_name)ITPUB个人空间7_RY8g7L.L-Z5JE.`
There are some restrictions on this hint:
QVM ~%M3i01. There must be only one table in the subquery.ITPUB个人空间2b aM~_W
2. It can't be a subquery within a subquery.ITPUB个人空间D8v}Jx

k S y rh#CW*H+{B/w0ITPUB个人空间@'jg2e"mv+icX
3. The subquery must be correlated with an equality predicate.
M T4@@7\!b/k)t04. The subquery must have no GROUP BY, CONNECT BY, or ROWNUM reference.ITPUB个人空间}c4_*iD X b

DyO1C v2FN&Y,N0NO_EXPAND
,L!A(?itoX!uC0Prevents a query from being broken up into separate pieces, which is almost the reverse of the USE_CONCAT hint.
7p ]UD,Vz7sF0SELECT /*+ NO_EXPAND */ COUNT(*)ITPUB个人空间3opM7i,UF?;|
FROM horse_ownersITPUB个人空间9M"D*D3[H
WHERE identifier < 10 OR identifier > 20ITPUB个人空间8n9]%z+s-M?

(P.^)w8]6@[0NO_FACT(table)ITPUB个人空间(|pq%GUmv e
Tells the cost-based optimizer that the table listed is not a fact table and should not be treated as such. This hint is used with STAR_TRANSFORMATION processing.
{6k C E|vpa#]0SELECT /*+ NO_FACT(results) */
2KR Zx h/`7f0
.g]$R7D*\{4Az)jx0NO_MERGE(table)
_X-k+R9M5ir0Prevents the merging of a nested (inline) view.
@;~ @1]z.{6n0SELECT /*+ NO_MERGE(w) */ o.owner,
g*Y,e5mR0w.num_wins, o.suburb
C+sN/GV-u9P(CT.c#B0FROM owners o,
? F6q4E^7sdz IPU3r0(SELECT owner, count(*) num_winsITPUB个人空间$GP'ogqr
FROM winnersITPUB个人空间M3c+HdX5K1e8d2U%k
WHERE position = 1ITPUB个人空间;n6\ m?+f1xQ { JyMD
GROUP BY owner) w
sD9_&Ku(D0WHERE o.owner = w.owner
1b5J9D/Vv0|c/O&a0AND w.num_wins > 15ITPUB个人空间o2YN`w,w['\
ORDER BY w.num_wins desc
,t Z!b3z @J{0
5{7b\'Y/^ J"T[3^0NO_PUSH_PRED(table)ITPUB个人空间%e3U Z'_ G:~r
Prevents the join predicate from being pushed into an inline view.
+b aWR)Md0SELECT /*+ NO_PUSH_PRED(v) */ count(*)ITPUB个人空间 r;Z,tq/p4tE5^!HUfeL
FROM horses h,ITPUB个人空间*r*s6JkX$L/o
(SELECT w.horse_name, o.owner,ITPUB个人空间NQ2uthev9k
w.positionITPUB个人空间:Egtt(VLlT k8|!D
FROM winners w, owners o
w i+op)D&hH_-Fm3T0WHERE w.owner = o.owner) v
5w1M"z@f4\`Kf0WHERE h.horse_name = v.horse_nameITPUB个人空间Odk X7a['rG
AND v.position = 1
TP?(N QqD"b0NO_UNNEST
Jp?AT!M"P} ?'{"~0ITPUB个人空间$rd7D*~ hAv*@uB
Prevents the merging of a subquery into the main statement body. Can only be used when UNNEST_SUBQUERY=TRUE.
5O l)W kBB#@0SELECT /*+ NO_UNNEST */ count(*)ITPUB个人空间 yz6JRUQ\G+o
FROM horses
Mb c-G? q'A0WHERE horse_name LIKE 'M%'ITPUB个人空间u2]+D"m8P4@fh"C;H
AND horse_name NOT IN
v/u `x%Ru0( SELECT horse_name
7i\E;p.|kl0FROM horse_owners
)NM:AN2A5o9]-Vm0WHERE owner LIKE '%Lombardo%');ITPUB个人空间k;Dd+`B#}j Q4p%M8^7`
ITPUB个人空间]he r)i)D
NOAPPEND
:U/\$J$qY{0The opposite of APPEND; results in a conventional insert into a table. There is no guarantee that the data will be appended at the end of the table. The rows to be inserted do not bypass the buffer cache, and integrity constraints are respected.
s2R"pV4Ba0INSERT /*+ NOAPPEND */ * INTO y
}lNtrJ2Z0SELECT FROM winners;ITPUB个人空间0]gb.F:|$Na
SELECT /*+ FULL(winners) NOCACHE(winners)ITPUB个人空间^ `2Z$ThO]
*/ count(*)ITPUB个人空间5e6p_2e(k'fQ#W]1kc
FROM winnersITPUB个人空间Z:s)Nx,DS7~ U"L$w3C
ITPUB个人空间`\v)cX9?*y.Z
NOCACHE(table)ITPUB个人空间/C-s;Mv9q
Instructs the optimizer to position all blocks fetched for the specified table at the leastrecently used end of the LRU list in the buffer cache when performing a full table scan. This is the normal behavior. for a full table scan.ITPUB个人空间!K jV+p$f6DEMe i

DD2L \"K%u2y-{2A0NOINDEX(table [index [index...]])ITPUB个人空间!~K0B/H~P
Eliminates the indexes listed from usage in the execution plan for a query.
1Vi'i*^ i2b0SELECT /*+ NOINDEX(EMP EMP_NDX1) */
Zb&gNe6^0If a table is specified without an index, no indexes on the table can be used.ITPUB个人空间;X4x"d"?S KA5gIo
SELECT /*+ NOINDEX(EMP) */
` @9Vz(A }7P0
,q;F,icE S%\0NOPARALLEL(table)
7as~SX&J Dt0Prevents Oracle from using parallelism (multiple processes) to scan the specified table. For example, assume you enable parallelism as follows:
*oB t a l|0ALTER TABLE x PARALLEL 2;
!o0b1ox7G"fN0Oracle now attempts to use two processes in parallel whenever the table needs to be scanned. The following statement uses the NOPARALLEL hint to prevent that parallelism from occurring:ITPUB个人空间$J]%V4[.r7N+_Uyv
SELECT /*+ NOPARALLEL(x) */ COUNT(*)ITPUB个人空间?/O0X ?4yuzgk6h
FROM x;
KhX k-E-}f$Sw0ITPUB个人空间(UQ hkr5j:I
NOPARALLEL_INDEX(table, index)
3K [$N j \7k#I0Ensures that parallel index processing does not occur for a partitioned index.
%h_'tLz k0SELECT /*+ NOPARALLEL_INDEX(emp, emp_ndx) */ITPUB个人空间u C`'Po7SI8[y cF
ITPUB个人空间;Q!vOx\{D6Z[?~,E
NOREWRITE
/XJ@ { G;D/y @ I]0N0Prevents Oracle from utilizing materialized views based on a selected table. It is the exact reverse of the REWRITE hint.ITPUB个人空间-Da GW9p7Ll
SELECT /*+ NOREWRITE */ horse_name, owner, position, COUNT(*)ITPUB个人空间y @&H/|'rD
FROM resultsITPUB个人空间i O7DCqH U
GROUP BY horse_name, owner, position
IMj g-P0hjEb0
/d^,Z"aX1\3c0ORDEREDITPUB个人空间eL1F4a"j?k `$F
Forces the optimizer to join tables in the same order as that in which they are specified in the FROM clause (left to right). This hint can give enormous performance gains in a reporting environment. It is also usually the case that the larger the number of tables in the FROM clause, the larger the benefits from this hint. Following is an example of its use:
cc2qOfY`0SELECT /*+ ORDERED */ITPUB个人空间L U&?Mr3s i$[
acct_name, trans_date, amount,
v3\w;pN*}'b2pM.}.T0dept, addressITPUB个人空间;a0tV"D8U`%I
FROM trans t, account a, category c ,ITPUB个人空间6wQ1W^pG
branch b, zip z
{#WY3k0{K0WHERE t.trans_date > sysdate - 30
w2U)a.a/A.@*hu9c0AND a.zip = z.zipITPUB个人空间KOs`$|~b)O
AND z.state = 'WA'ITPUB个人空间+d$C&S4}_Y
AND t.account between 700000 andITPUB个人空间)?LGb0tN/]
799999ITPUB个人空间8}B^#jfz
AND t.account = a.accountITPUB个人空间,\{f6JL
AND a.account = 'ACTIVE'ITPUB个人空间.lEt Q3K uC
AND a.category = c.category
N7i)C~ pP&l7Ys0AND c.catgory = 'RETAIL'ITPUB个人空间m {!bs7j-v
AND t.branch_id = b.branch_id
rT!El_;a0q V YM0AND b.branch = 'BELLEVUE'ITPUB个人空间3}(J7y-\U Q
Usually the driving index, and thus the driving table, for a query are determined by the type of index, how many columns are in the index, the number of rows in the index, and so on. For example, a table that has a UNIQUE index column equality check in the WHERE clause will become a driving table over a table that has a NON-UNIQUE column specified in the WHERE clause.
z3EDgI`j`0ITPUB个人空间t_EV*C
Interestingly, if all things are equal, the cost-based optimizer will use the left to right order in the FROM clause, which is the exact reverse of the rule-based optimizer. However, in a complex query, it is rare to find all things equal in the WHERE clause. Use this hint to guarantee the join order.ITPUB个人空间g hZmb,M_blv

lE0u%w1b l4a0ORDERED_PREDICATESITPUB个人空间 |Z#u4~ M
Causes WHERE clause predicates to be evaluated in the order in which they are listed in the WHERE clause. If you do not specify ORDERED_PREDICATES, Oracle will evaluate subqueries and user functions first.ITPUB个人空间'hf(@2w L#uS
SELECT ...
h fe^'C?0...ITPUB个人空间(M5iU5s0B@
WHERE /*+ ORDERED_PREDICATES */
#B1W o0T~Jp0This is the only hint that goes in the WHERE clause rather than after the keyword that begins the statement.
m{;V9V%J0
-Uy uH6q |0PARALLEL(table [,integer] [,integer])
y!zH8?2Z}M0Explicitly specifies the actual number of concurrent query servers that will be used to service the query. The first optional value specifies the degree of parallelism (number of query servers) for the table. This is the number of processes assigned to perform. the scan of the specified table in parallel on a single instance. The second optional value specifies the number of Oracle parallel server instances to split the query across. If you specify PARALLEL(EMP, 4 2), there will be four parallel query processes running on two separate parallel server instances. If no parameters are specified, the default (calculated) degree of parallelism and number of parallel servers is sourced from the parameters specified in the INIT.ORA file.
`%@4S%A rXN0The hint can be used for selects, updates, deletes, and inserts. To get performance improvements using the parallel hint, your datafiles must be striped across multiple disks. Don't set the degree of parallelism higher than the number of disks that the table is striped over. Having multiple processors will make the operation run even faster, but only if the table is striped.
y$n)tb\c0SELECT /*+ PARALLEL (x 4) */ COUNT(*)ITPUB个人空间QY$T!C~OY
FROM x;ITPUB个人空间}.okQ.A8d2e
SELECT /*+ PARALLEL (x 4 2) */ COUNT(*)ITPUB个人空间/U,{7kNW K
FROM x;ITPUB个人空间B%Cu%{!h~4f3VD ik
UPDATE /*+ PARALLEL (x 4) */ xITPUB个人空间f;E:AjuP d5p8H;\-XB
SET position = position+1;
*l!_Q7JAQkq#@0
Bq:} LCN4u0DELETE /*+ parallel(x 4) */ from x;
[p4b{ u\4W0INSERT INTO x
-@G!]1M8|n1d4Zr0SELECT /*+ PARALLEL(winners 4) */ *ITPUB个人空间2P_o4e'cM\E Y)cc
FROM winners;
dyy7zR3_'_0
4^rN/pp0PARALLEL_INDEX(table, index, degree of parallelism, cluster split)ITPUB个人空间)hr8aT%D8b;w&K D
Allows you to parallelize index range scans for partitioned indexes. Also allows the work to be done across multiple instances of a parallel server architecture. The following example tells the optimizer to utilize parallel index processing on the EMP table, which is partitioned, to use the EMP_NDX index, and to run at a parallel degree of four over two Oracle parallel server instances.
a,b['qa0SELECT /*+ PARALLEL_INDEX(emp, emp_ndx, 4, 2) */ITPUB个人空间2G.^.^&foq
...
.H-q SGy8h0
Soh3qe0PQ_DISTRIBUTE(table [Outer Distribution] [Inner Distribution])
Kif`x8v!n0Used to improve parallel join performance. There are six possibilities for distribution hints, as listed in Table 1-6.ITPUB个人空间My3U\N c-\,dD(Y
SELECT /*+ USE_HASH(o)ITPUB个人空间?B.hA]
PQ_DISTRIBUTE(o HASH, HASH) */ COUNT(*)ITPUB个人空间#K^+v0D5^'r1y
FROM winners w, owners oITPUB个人空间"N$w:j py fUb)u?
WHERE w.owner = o.owner;
'C Bj+PvA/@0Table 1-6. PQ_DISTRIBUTE combinationsITPUB个人空间:|7t`B5P6Gai
Distribution combination Meaning
f:nc)e$\)Y n7U0HASH, HASH Uses a hash function on the join keys for each query server process. Can be used for a hash join or sort merge join. Works best when tables are approximately the same size.ITPUB个人空间?$T:K7e+U9CX$~`
BROADCAST, NONE Broadcasts all rows of the outer table to each of the parallel query servers. Use this when the outer table is considerably smaller than the inner table.ITPUB个人空间 QA_ B4RN;vI
NONE, BROADCAST Broadcasts all rows of the inner table to each of the parallel query servers. Use this option when the size of the inner table is much smaller than the outer table.ITPUB个人空间z,d\ |:` X
PARTITION, NONE Maps the rows of the outer table using the partitioning of the inner table. The inner table must be partitioned and equi-joined on the join keys. This option works most effectively if the number of partitions in the outer table is equal to the number of parallel query processes utilized.
*iOsBY%yMK`4vN0w%c0
8@;p#T7t;tR&r:\0
4`{C7i1T s0NONE, PARTITION Maps the rows of the inner table using the partitioning of the outer table. The outer table must be partitioned on the join keys. Use this option when the number of partitions on the outer table is equal to the number of parallel query servers.
KWf1ko Jr3y V g?0NONE, NONE Causes each query server to perform. a join operation between a pair of matching partitions, one from each table. Both tables must be equi-partitioned for this option to be used effectively.ITPUB个人空间Y"X T](g6g*Oc
ITPUB个人空间nv?e#z"]
PUSH_PRED(table)
b#Z1lAi$FY\,Z0Pushes the join predicate for a table into an inline view. Doing so can sometimes help the cost-based optimizer make better decisions.ITPUB个人空间`${;{0u;bDC/P,{%}-M
SELECT /*+ PUSH_PRED(v) */ count(*)ITPUB个人空间 r\ @1gF_"P
FROM horses h,ITPUB个人空间W#L0d.P j"vr)q W*P4\
(SELECT w.horse_name, o.owner,ITPUB个人空间&dq+J,IWk
w.positionITPUB个人空间{ ccRX
FROM winners w, owners o
(P h j3J ?0WHERE w.owner = o.owner) vITPUB个人空间JSw(zv8[!I'N``
WHERE h.horse_name = v.horse_name
9n@Nm!|$Y Bz4K!gt0AND v.position = 1
%T0wwC`:x0The difference in the execution plan for the example is that the HORSE_NAME in the WHERE clause is joined to the inline view as part of the inline view selection.ITPUB个人空间)V](K k[@a u1D O

k7G)U]u.N}0PUSH_SUBQITPUB个人空间"id1Y cDX
Forces nonmerged subqueries to be evaluated as early as possible in the execution plan. Nonmerged subqueries are normally executed as the last step of an execution plan. This hint has no effect on a subquery if the subquery is over a remote table (as in a distributed SQL statement), or if the subquery uses a merge join.ITPUB个人空间5A+{R!p\/E*he
SELECT count(*)
&pq{LFKy2@0FROM horses
M9P zk?{:o+O0WHERE EXISTS
3i%@E1O8|:R4p R0( SELECT /*+ PUSH_SUBQ */ 'x'ITPUB个人空间:n$SE$}W j,G
FROM horse_ownersITPUB个人空间t}XD,g5y"Z
WHERE owner LIKE '%Lombardo%'
4F&qx.?k3{0AND horses.horse_name=ITPUB个人空间\G z$u4M4r
horse_owners.horse_name)ITPUB个人空间^7JdN(@$UGi
ITPUB个人空间k.j6p {:R&qX
REWRITEITPUB个人空间ur4G3} PJ!X$\S1|[
Allows Oracle to utilize materialized views based on a selected table. In the example that follows, we have a table that contains horse race results. We have created a materialized
/ta,R&Y){)mH0
S.g(@'n!VI.~U_v0view that stores the OWNER, HORSE_NAME, POSITION, and the COUNT(*) for each of those combinations.
z"| ^ ];Xr0CREATE MATERIALIZE VIEW LOG ON RESULTS
X(sn"c t0WITH ROWID,ITPUB个人空间K%tDu,M^hv0nD
PRIMARY KEY (HORSE_NAME, OWNER,ITPUB个人空间D E~'o*O$Sjhh
RACE_DATE)ITPUB个人空间g^"y/| w rc
INCLUDING NEW VALUES;ITPUB个人空间%a2GRhS"mZ
CREATE MATERIALIZED VIEW winning_horse_owners_vwITPUB个人空间W6L2k(j+y?\5X2YH
USING INDEX
(kn#X{C;],}{8p0REFRESH ON COMMITITPUB个人空间2]_ uL.P%A
ENABLE QUERY REWRITE
L1K} rQc0AS SELECT horse_name, owner, position, COUNT(*)ITPUB个人空间r-VVK}m
FROM resultsITPUB个人空间/{.jRE?6z(b4_R
GROUP BY horse_name, owner, position;
0} x.Z hh*KjTq0In order for this materialized view to be useful, you must have the INIT.ORA parameter QUERY_REWRITE_ENABLED=TRUE, and the schema MUST HAVE the privilege QUERY REWRITE assigned. For example:
E&s,G j%Mdx0GRANT QUERY REWRITE TO HROA;
.d4x[ Lr{(r1[k%i0The SQL query shown next is able to obtain all of the data it requires from the view, and therefore the optimizer will use the view in preference to the table, despite the SELECT being made against the table.
T sP0iH c IW0SELECT /*+ REWRITE */ horse_name, owner, position, COUNT(*)
B@J;jj0FROM resultsITPUB个人空间0eM:F'ysP+p
GROUP BY horse_name, owner, position;ITPUB个人空间/v|Jr7S

:m X;z {8GY:vD0ROWID(table)ITPUB个人空间-|1d t[cGD ~|,C%u
Forces a table scan by ROWID for the specified table. The rowid is the physical disk address of the row.ITPUB个人空间Kvs,??7u
SELECT /*+ ROWID(a) */ enameITPUB个人空间l/p Xi:|
FROM emp aITPUB个人空间8v;R~8^0N } C_
WHERE rowid > 'AAAGJ2AAIAAABn4AAA'
y(y!~!U;v0AND surname like 'GURR%'ITPUB个人空间g f'} K A!u|M
ITPUB个人空间W;K-b,G7z J9V Q
RULE
mn%e D4vm-m(n0Uses the rule-based optimizer for the current statement block. You can achieve the same effect by having the CHOOSE option specified for the INIT.ORA parameter
~I)AE^;N D-Y0ITPUB个人空间 l^]D!x5Rp
OPTIMIZER_MODE, and not analyzing the tables and indexes used in the SELECT statement.
+_i\"`4[KG0ITPUB个人空间'q k Y_[5N
STAR
4FQAh+s0Forces the largest table to be last in the join order. Typically the other tables should be lookup or reference tables. This hint is used extensively in data warehouse applications. STAR is only effective when you are joining at least three tables.
}0k'k cS0] |;Y_v0SELECT /*+ STAR */ h.horse_name, o.owner,
sW%p?S+O(j0r.position, r.location, r.race_date
P'i`#I Z0FROM results r, horses h, owners oITPUB个人空间klwA FUk;@
WHERE h.horse_name like 'WI%'ITPUB个人空间8JC!C5o4JBe
AND h.horse_name = r.horse_nameITPUB个人空间_&|#sg }d[o h&x
AND r.owner = o.owner;ITPUB个人空间f"Bw%T6HD)v
ITPUB个人空间X:q,og~&O{
STAR_TRANSFORMATION
I%apC?L)l0Works on fact and dimension tables, and is similar to the STAR hint. The major difference is that it allows the cost-based optimizer to decide if it is worth transforming the statement into a new statement before determining the execution plan. By "transforming," I mean that the statement is broken into a number of subqueries that are able to take advantage of bitmap indexes.ITPUB个人空间B8VR9s0M_#Np
To use this hint, it is essential that you have STAR_TRANSFORMATION_ENABLED=TRUE in your INIT.ORA file.ITPUB个人空间9Lb/nE @&z
The most pronounced difference between this hint and the STAR hint is that the STAR_TRANSFORMATION will often combine bitmap indexes on the various fact table columns rather than using a Cartesian join. This is achieved by breaking the statement into subquery pieces.ITPUB个人空间 j'~:g_-xuF
SELECT /*+ STAR_TRANSFORMATION */
'F/j&NdcC`i)\0...
:ZbZ8M!g6Ds0ITPUB个人空间 K*A%sFo6i4T({$p$q
UNNEST
;Z!MW+{%i7V0Merges the body of a subquery into the body of the main statement, which can often improve optimizer decision making. UNNEST can only be used when the session parameter UNNEST_SUBQUERY=TRUE.ITPUB个人空间!P;s\(h`wCu/v
SELECT /*+ UNNEST */ count(*)
1@ S'dW_Kf6e"c0FROM horsesITPUB个人空间!D'td V6]
WHERE horse_name LIKE 'M%'ITPUB个人空间7e9Qf/Jt2[8p
AND horse_name NOT INITPUB个人空间&T0N'q#N(})r
( SELECT horse_nameITPUB个人空间(wx|7m2O)z\h
FROM horse_owners
Rn0dw`^|&A p0ITPUB个人空间bm*dPsEYXSk6Y
WHERE owner LIKE '%Lombardo%');ITPUB个人空间dX-aZ(yo|#o!~
ITPUB个人空间"|k `%av8` Y
USE_CONCATITPUB个人空间Zcu0`:fD!@T
Forces the optimizer to take OR conditions in the WHERE clause and convert them to a UNION ALL query operation. In an example such as the one that follows, the index is scanned twice, once for each condition on the two sides of the OR. The data is then joined into one result set via a concatenation operation.
9[X @7d,s(p5]GA]0SELECT /*+ USE_CONCAT */ COUNT(*)
)f)Wi-hyKb3B0FROM horse_ownersITPUB个人空间3X*_l7C[f3e)m6DM
WHERE identifier < 10 OR identifier > 20ITPUB个人空间VKT:\` Y e b
ITPUB个人空间.^ C-W[0v.u(wG
USE_HASH (table)ITPUB个人空间 lP5V5d,j |+U]q
A hash join is an alternative to a nested loop. A hash table is created in memory of the smallest table, and then the other table(s) is scanned, with its rows being compared to the hash. A hash join will run faster than a merge join (sort merge) if memory is adequate to hold the entire table that is being hashed. The entire join operation must be performed before a single row is returned to the user. Therefore, hash joins are usually used for reporting and batch processing.
K zhO:FYY1I/a:_0SELECT /*+ USE_HASH(w o) */ count(*)
rN}D"knd,Bv0FROM winners w, owners oITPUB个人空间Pj0slCxO
WHERE w.owner like 'Mr M A Gurry'
7Y6VQ$n9s` ^0AND w.owner= o.ownerITPUB个人空间a4D'gTy}2u4v
AND o.suburb = 'RICHMOND'
v h.x6VB5|0A hash join can only be used for equality-based joins (=), and not for range-based joins (<, <=, >, >=). A merge join is often appropriate when a hash join cannot be used.ITPUB个人空间Cd2f/q8Z*T
ITPUB个人空间,ns h5P V Z_s
Don't confuse the HASH hint with USE_HASH.ITPUB个人空间`Y}5n|n4p
ITPUB个人空间4M!qNNt%A[z9d
ITPUB个人空间!{ca/C}p
USE_MERGE(table)ITPUB个人空间Q so Oa;s2a
A merge join is an alternative to nested loop and hash joins. All tables are sorted, unless all of the columns in the WHERE clause are contained within an index. This sort can be expensive and it explains why a hash join will often run faster then a merge join.ITPUB个人空间T2[1zs4\*uh
SELECT /*+ USE_MERGE(w o) */ count(*)
RQ2q] F7|?(n0FROM winners w, owners o
"h7E8Kpq&|;XY0WHERE w.owner like 'Mr M A Gurry'
$^,yMQ`2Da.G0AND w.owner < o.ownerITPUB个人空间1X.s&dk|Fd1KY
AND o.suburb = 'RICHMOND'ITPUB个人空间h@cR~Q(lx9T [ y
ITPUB个人空间3Z.sE,D^?
The entire set of data must be returned before a single row is returned to the user. Therefore hash joins are usually used for reporting and batch processing.ITPUB个人空间/E;l l!P$yq v0o
ITPUB个人空间2\0K bLAk`sy,rt
Don't confuse the MERGE hint and USE_MERGE.ITPUB个人空间N z5@,Q9bV}c
ITPUB个人空间U _k2z(JR1X

T{&wHl!D.Iui Q0Merge joins work effectively for equality-based joins as well as for range-based joins. Merge joins also often run much faster than a hash join when all of the columns in the WHERE clause are pre-sorted in an index.
F#Y h8[3vCn-]0
ls @_wK|b*K1e+Q-^0USE_NL(table)
-L.Bd$Ku.D/Ew0Forces the optimizer to join the specified table to another table (or subquery) using a nested loop join. The specified table is joined as the inner table of the nested loops. Nested loop joins are faster than sort/merge or hash joins at retrieving the first row of a query statement.ITPUB个人空间 \ l8EcV9O}c
Online screens should definitely use nested loops, because data will be returned immediately. As a rule of thumb, if less than 10% of the rows are returned from the tables, consider using nested loops. Use hash joins or sort merges if 10% or more of the rows are being returned.
2g6Q&FT:J/Z2r0SELECT /*+ USE_NL(w o) */ count(*)
|y](MU0FROM winners w, owners o
}4k2Ju\%jsn a,S0WHERE w.owner like 'Mr M A Gurry'
cr ?s | @l0AND w.owner= o.ownerITPUB个人空间3FPd8frc
AND o.suburb = 'RICHMOND'
/z'mF4j tb0

TAG:

 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

日历

« 2008-10-13  
   1234
567891011
12131415161718
19202122232425
262728293031 

数据统计

  • 访问量: 20359
  • 日志数: 291
  • 图片数: 2
  • 建立时间: 2007-12-11
  • 更新时间: 2008-10-04

RSS订阅

Open Toolbar