Understanding EXPLAIN
Table des matières
Understanding EXPLAIN....................................................................................................................4
1 Slides license................................................................................................................................5
2 Author..........................................................................................................................................5
3 How can I understand EXPLAIN?..............................................................................................6
4 First, our objects..........................................................................................................................6
5 Let's try to read our table.............................................................................................................7
6 Let's update our table statistics....................................................................................................8
7 What does ANALYZE do?..........................................................................................................8
8 Width............................................................................................................................................9
9 Rows..........................................................................................................................................10
10 Total cost..................................................................................................................................10
11 But what happens really?.........................................................................................................11
12 And at the physical level?........................................................................................................12
13 Let's use the BUFFERS option................................................................................................12
14 And now, with a warm up cache?............................................................................................13
15 Let's try with a bigger cache....................................................................................................14
16 By the way...............................................................................................................................14
17 Now, let's try a WHERE clause...............................................................................................15
18 Cost - more complicated process.............................................................................................16
19 Number of rows - ditto.............................................................................................................17
20 Would an index help here?.......................................................................................................17
21 Why not use the index?............................................................................................................18
22 Let's try to force the use of index.............................................................................................19
23 Let's see with another query....................................................................................................19
24 Let's complicate the filter.........................................................................................................20
25 Let's try to filter on c2 only......................................................................................................20
26 Let's add an index on c2...........................................................................................................21
27 Let's add an index with an opclass...........................................................................................21
28 Let's try a covering index.........................................................................................................22
29 All the major scan nodes..........................................................................................................23
30 Let's try an ORDER BY clause................................................................................................23
31 Are we sure it writes on the disk?............................................................................................24
32 Let's bring more mem to the sort.............................................................................................25
33 An index can also help here.....................................................................................................25
34 Let's get back to c2..................................................................................................................26
35 And now, let's limit the rows....................................................................................................26
36 Let's have another table...........................................................................................................27
37 ... and join them.......................................................................................................................27
38 It helps to have an index..........................................................................................................28
39 Left join anyone?.....................................................................................................................29
40 Let's DROP an index................................................................................................................29
41 We delete some more row........................................................................................................30
42 And with an empty table?........................................................................................................31
43 Always used in a CROSS JOIN...............................................................................................31
44 All the join nodes.....................................................................................................................32
2 / 42