-> Index Scan using film_titre on film f2 (cost=0.28..8.29 rows=1 width=4) (actual time=0.020..0.021 rows=1 loops=1)
Index Cond: ((titre)::text = 'Star Wars'::text)
-> Index Scan using index_votes on film f1 (cost=0.28..31.04 rows=615 width=20) (actual time=0.007..0.007 rows=0 loops=1)
Index Cond: (votes > f2.votes)
Planning time: 0.239 ms
Execution time: 0.068 ms
```
**La jointure coûte très chère dans le premier cas. Dans deuxième cas, l'index permet de d'augmenter la vitesse de la jointure**
## Question 4
1. Sans index
* SELECT titre FROM film WHERE titre LIKE ’I%’;
```
Seq Scan on film (cost=0.00..38.05 rows=18 width=16) (actual time=0.020..0.317 rows=25 loops=1)
Filter: ((titre)::text ~~ 'I%'::text)
Rows Removed by Filter: 1819
Planning time: 0.131 ms
Execution time: 0.378 ms
(5 rows)
```
* SELECT titre FROM film WHERE substr(titre,1,1) = ’I’;
```
Seq Scan on film (cost=0.00..42.66 rows=9 width=16) (actual time=0.024..0.547 rows=25 loops=1)
Filter: (substr((titre)::text, 1, 1) = 'I'::text)
Rows Removed by Filter: 1819
Planning time: 0.072 ms
Execution time: 0.580 ms
```
* SELECT titre FROM film WHERE titre LIKE ’%A’;
```
Seq Scan on film (cost=0.00..38.05 rows=18 width=16) (actual time=0.020..0.351 rows=30 loops=1)
Filter: ((titre)::text ~~ '%A'::text)
Rows Removed by Filter: 1814
Planning time: 0.079 ms
Execution time: 0.384 ms
```
2. Avec index
* SELECT titre FROM film WHERE titre LIKE ’I%’;
* SELECT titre FROM film WHERE substr(titre,1,1) = ’I’;
* SELECT titre FROM film WHERE titre LIKE ’%A’;
**Dans les 3 cas, Pas de changements**
3.
* SELECT titre FROM film WHERE titre LIKE ’I%’;
* SELECT titre FROM film WHERE substr(titre,1,1) = ’I’;
* SELECT titre FROM film WHERE titre LIKE ’%A’;
**Seul la première est plus performante car elle est capable d'exploiter varchar_pattern_ops (fonction LIKE), et la dernière ne change rien car on part de la fin du mot**