3 \begin{enumerate}[label=(\alph*)]
8 SELECT distinct(displayname) FROM posts p
9 JOIN users u ON p.owneruserid = u.id
10 WHERE p.viewcount > u.views;
14 Just converted the selection to a JOIN.
15 This improves the $n_{users} + n_{users} * n_{posts}$ Seq Scans
16 to one JOIN and two Seq Scans.
20 Planning time: 0.978 ms
21 Execution time: 86179.847 ms
26 Planning time: 0.960 ms
27 Execution time: 37.354 ms
34 SELECT score FROM comments WHERE text ILIKE 'yes%';
42 Planning time: 0.540 ms
43 Execution time: 60.946 ms
48 TODO, current query is slower..
55 SELECT DISTINCT postid FROM votes WHERE postid NOT IN (
56 SELECT postid FROM votes WHERE votetypeid != 2
61 Instead of doing about twelve million Seq Scans this is now reduced to
62 two Seq Scans by inverting the condition.
67 On a different machine with SSD and no time limit it took 16 minutes.
72 Planning time: 1.093 ms
73 Execution time: 81.776 ms
80 SELECT p.*, c.*, u.* FROM posts p
81 JOIN comments c ON p.id = c.postid
82 JOIN users u ON p.owneruserid = u.id
83 JOIN badges b on u.id = b.userid
84 WHERE u.upvotes+3 >= (
85 SELECT AVG(upvotes) FROM users
86 WHERE u.creationdate > c.creationdate
88 SELECT 1 FROM postlinks l
89 WHERE l.relatedpostid > p.id
90 ) AND b.name IN ('Autobiographer','Supporter');
94 Converted the joins via WHERE clause to proper JOINs
98 Planning time: 4.084 ms
99 Execution time: 4006.044 ms
104 Planning time: 2.954 ms
105 Execution time: 3081.461 ms