optimizing sql pertemuan 13 matakuliah: t0413/current popular it ii tahun: 2007

12
Optimizing SQL Pertemuan 13 Matakuliah : T0413/Current Popular IT II Tahun : 2007

Post on 21-Dec-2015

219 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Optimizing SQL Pertemuan 13 Matakuliah: T0413/Current Popular IT II Tahun: 2007

Optimizing SQLPertemuan 13

Matakuliah : T0413/Current Popular IT IITahun : 2007

Page 2: Optimizing SQL Pertemuan 13 Matakuliah: T0413/Current Popular IT II Tahun: 2007

Bina Nusantara

Learning Outcomes

Pada akhir pertemuan ini, diharapkan mahasiswa akan mampu mendemonstrasikan proses optimasi di dalam SQL

Page 3: Optimizing SQL Pertemuan 13 Matakuliah: T0413/Current Popular IT II Tahun: 2007

Bina Nusantara

Outline Materi

• Using indexes• Types of indexes• Reprashing queries

Page 4: Optimizing SQL Pertemuan 13 Matakuliah: T0413/Current Popular IT II Tahun: 2007

Bina Nusantara

USING INDEX

One of important ways to improve systemPerformance

Page 5: Optimizing SQL Pertemuan 13 Matakuliah: T0413/Current Popular IT II Tahun: 2007

Bina Nusantara

SEVERAL WAYS TO CATEGORIZE INDEXES

• UNIQUE• NON UNIQUE

Page 6: Optimizing SQL Pertemuan 13 Matakuliah: T0413/Current Popular IT II Tahun: 2007

Bina Nusantara

CREATE INDEX• SINTAX :

CREATE [UNIQUE] INDEX index-Name ON table-Name ( Simple-column-Name [ ASC | DESC ] [ , Simple-column-Name [ ASC | DESC ]] * )

Page 7: Optimizing SQL Pertemuan 13 Matakuliah: T0413/Current Popular IT II Tahun: 2007

Bina Nusantara

TYPE OF INDEXS • B+ trees• Join indexes & clusters• Bitmap indexes• R-trees

Page 8: Optimizing SQL Pertemuan 13 Matakuliah: T0413/Current Popular IT II Tahun: 2007

Bina Nusantara

REPHRASING QUERIES• Optimizer in the DBMS is supposed to convert

queries to the most efficient formulation and execution

• Two general flavors of optimizer– Rule based– Cost based

Page 9: Optimizing SQL Pertemuan 13 Matakuliah: T0413/Current Popular IT II Tahun: 2007

Bina Nusantara

REPHRASING QUERIES• Here are some rules of thumb to make queries

run faster :1. Be careful about using value expressions or datatype

conversions on indexed values used in predicates2. The same applies to <> (does not equal)

Page 10: Optimizing SQL Pertemuan 13 Matakuliah: T0413/Current Popular IT II Tahun: 2007

Bina Nusantara

REPHRASING QUERIES (Cont.)3. ANY and EXISTS

4. Place the predicates that are likely to eliminate the most rows from the output first in where clause

Page 11: Optimizing SQL Pertemuan 13 Matakuliah: T0413/Current Popular IT II Tahun: 2007

Bina Nusantara

REPHRASING QUERIES (Cont.)5. LEFT and RIGHT OUTER joins are interconvertible.

LEFT joins may be faster6. In a join, place the table with fewer rows first in the

FROM clause.7. With an indexes column referenced in a predicate,

you may do a bit better by combining equalities and inequalities

(x>=8 lebih cepat daripada x>7)8. NULLs value

Page 12: Optimizing SQL Pertemuan 13 Matakuliah: T0413/Current Popular IT II Tahun: 2007

Bina Nusantara

REPHRASING QUERIES (Cont.)9. If we want more than 20 percent rows of table

better off without using an index10. If we refferencing a multi column index, you

need not reference the query every column11. Avoid using like12. Often a UNION of two queries will do better than

a single query (using OR)