Advertisement
Guest User

Untitled

a guest
Jun 26th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.35 KB | None | 0 0
  1. EXPLAIN ANALYZE with
  2. matches as
  3. (select forum_id,thread_id,post_id from documents where document @@ to_tsquery('hello'))
  4. select forum_id,thread_id,post_id,bool_or(is_match)
  5. from (select *, true as is_match from matches
  6. union all
  7. select n.*, false
  8. from matches m,
  9. lateral ((select forum_id,thread_id,post_id from documents d1
  10. where (d1.forum_id,d1.thread_id)=(m.forum_id,m.thread_id)
  11. and d1.post_id < m.post_id
  12. order by d1.post_id desc limit 10)
  13. union all
  14. (select forum_id,thread_id,post_id from documents d2
  15. where (d2.forum_id,d2.thread_id)=(m.forum_id,m.thread_id)
  16. and d2.post_id > m.post_id
  17. order by d2.post_id asc limit 10)) n) s1
  18. group by forum_id,thread_id,post_id
  19. order by forum_id, thread_id, post_id;
  20.  
  21. QUERY PLAN
  22. -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  23. Sort (cost=42489.83..42492.35 rows=1008 width=13) (actual time=5.988..6.084 rows=1219 loops=1)
  24. Sort Key: matches.forum_id, matches.thread_id, matches.post_id
  25. Sort Method: quicksort Memory: 106kB
  26. CTE matches
  27. -> Bitmap Heap Scan on documents (cost=19.97..1774.08 rows=480 width=12) (actual time=0.060..0.142 rows=85 loops=1)
  28. Recheck Cond: (document @@ to_tsquery('hello'::text))
  29. Heap Blocks: exact=71
  30. -> Bitmap Index Scan on documents_document_idx (cost=0.00..19.85 rows=480 width=0) (actual time=0.044..0.044 rows=85 loops=1)
  31. Index Cond: (document @@ to_tsquery('hello'::text))
  32. -> HashAggregate (cost=40655.39..40665.47 rows=1008 width=13) (actual time=5.111..5.336 rows=1219 loops=1)
  33. Group Key: matches.forum_id, matches.thread_id, matches.post_id
  34. -> Append (cost=0.00..40554.59 rows=10080 width=13) (actual time=0.063..4.327 rows=1697 loops=1)
  35. -> CTE Scan on matches (cost=0.00..9.60 rows=480 width=13) (actual time=0.063..0.196 rows=85 loops=1)
  36. -> Nested Loop (cost=0.42..40448.99 rows=9600 width=12) (actual time=0.018..3.902 rows=1612 loops=1)
  37. -> CTE Scan on matches m (cost=0.00..9.60 rows=480 width=12) (actual time=0.001..0.023 rows=85 loops=1)
  38. -> Append (cost=0.42..84.05 rows=20 width=12) (actual time=0.015..0.042 rows=19 loops=85)
  39. -> Limit (cost=0.42..41.92 rows=10 width=12) (actual time=0.015..0.020 rows=9 loops=85)
  40. -> Index Only Scan Backward using documents_forum_id_thread_id_post_id_idx on documents d1 (cost=0.42..58.53 rows=14 width=12) (actual time=0.014..0.018 rows=9 loops=85)
  41. Index Cond: ((forum_id = m.forum_id) AND (thread_id = m.thread_id) AND (post_id < m.post_id))
  42. Heap Fetches: 802
  43. -> Limit (cost=0.42..41.92 rows=10 width=12) (actual time=0.012..0.019 rows=10 loops=85)
  44. -> Index Only Scan using documents_forum_id_thread_id_post_id_idx on documents d2 (cost=0.42..58.53 rows=14 width=12) (actual time=0.012..0.017 rows=10 loops=85)
  45. Index Cond: ((forum_id = m.forum_id) AND (thread_id = m.thread_id) AND (post_id > m.post_id))
  46. Heap Fetches: 810
  47. Planning time: 0.490 ms
  48. Execution time: 6.248 ms
  49. (26 rows)
  50.  
  51.  
  52.  
  53.  
  54.  
  55. =# EXPLAIN ANALYZE with
  56. matches as
  57. (select * from documents where document @@ to_tsquery('hello'))
  58. select *, true as is_match from matches
  59. union
  60. select n.*, false
  61. from matches m,
  62. lateral ((select * from documents d1
  63. where (d1.forum_id,d1.thread_id)=(m.forum_id,m.thread_id)
  64. and d1.post_id < m.post_id
  65. order by d1.post_id desc limit 10)
  66. union all
  67. (select * from documents d2
  68. where (d2.forum_id,d2.thread_id)=(m.forum_id,m.thread_id)
  69. and d2.post_id > m.post_id
  70. order by d2.post_id asc limit 10)) n
  71. order by forum_id, thread_id, post_id;
  72.  
  73.  
  74. QUERY PLAN
  75. ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  76. Unique (cost=43003.75..43154.95 rows=10080 width=541) (actual time=6.200..7.650 rows=1265 loops=1)
  77. CTE matches
  78. -> Bitmap Heap Scan on documents (cost=19.97..1774.08 rows=480 width=566) (actual time=0.059..0.129 rows=85 loops=1)
  79. Recheck Cond: (document @@ to_tsquery('hello'::text))
  80. Heap Blocks: exact=71
  81. -> Bitmap Index Scan on documents_document_idx (cost=0.00..19.85 rows=480 width=0) (actual time=0.044..0.044 rows=85 loops=1)
  82. Index Cond: (document @@ to_tsquery('hello'::text))
  83. -> Sort (cost=41229.67..41254.87 rows=10080 width=541) (actual time=6.199..6.303 rows=1697 loops=1)
  84. Sort Key: matches.forum_id, matches.thread_id, matches.post_id, matches.document, (true)
  85. Sort Method: quicksort Memory: 1502kB
  86. -> Append (cost=0.00..40559.39 rows=10080 width=541) (actual time=0.063..4.025 rows=1697 loops=1)
  87. -> CTE Scan on matches (cost=0.00..9.60 rows=480 width=44) (actual time=0.063..0.175 rows=85 loops=1)
  88. -> Nested Loop (cost=0.42..40448.99 rows=9600 width=566) (actual time=0.019..3.629 rows=1612 loops=1)
  89. -> CTE Scan on matches m (cost=0.00..9.60 rows=480 width=12) (actual time=0.000..0.027 rows=85 loops=1)
  90. -> Append (cost=0.42..84.05 rows=20 width=566) (actual time=0.014..0.037 rows=19 loops=85)
  91. -> Limit (cost=0.42..41.92 rows=10 width=566) (actual time=0.013..0.018 rows=9 loops=85)
  92. -> Index Scan Backward using documents_forum_id_thread_id_post_id_idx on documents d1 (cost=0.42..58.53 rows=14 width=566) (actual time=0.013..0.016 rows=9 loops=85)
  93. Index Cond: ((forum_id = m.forum_id) AND (thread_id = m.thread_id) AND (post_id < m.post_id))
  94. -> Limit (cost=0.42..41.92 rows=10 width=566) (actual time=0.011..0.017 rows=10 loops=85)
  95. -> Index Scan using documents_forum_id_thread_id_post_id_idx on documents d2 (cost=0.42..58.53 rows=14 width=566) (actual time=0.011..0.015 rows=10 loops=85)
  96. Index Cond: ((forum_id = m.forum_id) AND (thread_id = m.thread_id) AND (post_id > m.post_id))
  97. Planning time: 0.435 ms
  98. Execution time: 7.792 ms
  99. (23 rows)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement