PostgreSQL'de Sorgu Performansını İyileştirme
Amy McCarty
Instructor
| Sıra | İfade | Amaç |
|---|---|---|
| 1 | FROM | tablo(lar)ı belirtir |
| 2 | WHERE | kayıtları filtreler/sınırlar |
EXPLAIN
SELECT * FROM phones
Seq Scan on phones (cost = 0.00..22.7
,rows=1270
,width=36)
Sorgu planlayıcı

EXPLAIN
SELECT * FROM phones
WHERE phone_code = 235
Seq Scan on phones (cost = 0.00..25.8
,rows=6,width=636)
Filter: (phone_code=235)
Sorgu planlayıcı

| ülke | phone_code | güvenilirlik |
|---|---|---|
| Çad | 235 | orta |
| Çin | 86 | yüksek |
| Kosta Rika | 506 | yüksek |
| Hindistan | 91 | orta |
| Endonezya | 62 | orta |
| Irak | 964 | düşük |
EXPLAIN
SELECT * FROM phones
WHERE country LIKE 'Ch%'
OR country LIKE 'In%'
Seq Scan on phones (cost = 0.00..29.05
,rows=13,width=36)
Filter: ((country~~'Ch%'::text)
OR(country~~'In%'::text))
| ülke | phone_code | güvenilirlik |
|---|---|---|
| Çad | 235 | orta |
| Çin | 86 | yüksek |
| Kosta Rika | 506 | yüksek |
| Hindistan | 91 | orta |
| Endonezya | 62 | orta |
| Irak | 964 | düşük |
EXPLAIN
SELECT * FROM phones
WHERE country
LIKE ANY(ARRAY['Ch%','In%'])
Seq Scan on phones (cost = 0.00..25.88
,rows=13,width=36)
Filter: ((country~~ANY('{Ch%,In%}'
::text[]))
| ülke | phone_code | güvenilirlik |
|---|---|---|
| Çad | 235 | orta |
| Çin | 86 | yüksek |
| Kosta Rika | 506 | yüksek |
| Hindistan | 91 | orta |
| Endonezya | 62 | orta |
| Irak | 964 | düşük |
EXPLAIN
SELECT * FROM phones
WHERE country = 'Chad'
OR country = 'China'
Seq Scan on phones (cost = 0.00..29.05
,rows=13,width=36)
Filter: ((country='Chad'::text)
OR(country='China'::text))
| ülke | phone_code | güvenilirlik |
|---|---|---|
| Çad | 235 | orta |
| Çin | 86 | yüksek |
| Kosta Rika | 506 | yüksek |
| Hindistan | 91 | orta |
| Endonezya | 62 | orta |
| Irak | 964 | düşük |
EXPLAIN
SELECT * FROM phones
WHERE country IN ('Chad','China')
Seq Scan on phones (cost = 0.00..25.88
,rows=13,width=36)
Filter: ((country=ANY('{Chad,China}'
::text[]))
| ülke | phone_code | güvenilirlik |
|---|---|---|
| Çad | 235 | orta |
| Çin | 86 | yüksek |
| Kosta Rika | 506 | yüksek |
| Hindistan | 91 | orta |
| Endonezya | 62 | orta |
| Irak | 964 | düşük |
EXPLAIN
SELECT *
FROM phones
WHERE phone_code IN (235,86)
Seq Scan on phones (cost = 0.00..25.88
,rows=13,width=36)
Filter: (phone_code=ANY('{235,86}'
::integer[]))
Sayısal avantajlar
Sayısal avantajlar
| İyi | Daha iyi |
|---|---|
| Metin | Sayısal |
| OR | IN, ARRAY |
PostgreSQL'de Sorgu Performansını İyileştirme