Столкнулся с проблемой. Слишком много времени, полсекунды, постгрес тратит на планирование запроса. План выбирает правильный, к этому претензий нет. Исполняется запрос тоже быстро, за сотые доли секунды. На сервере Postgres 9.5.
запрос 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24.
EXPLAIN
(ANALYZE)
SELECT
*
FROM
"usage"
INNER JOIN "time" ON ("usage"."time_id" = "time"."id")
INNER JOIN "geo" ON ("usage"."geo_id" = "geo"."id")
INNER JOIN "clienturi" ON ("usage"."clienturi_id" = "clienturi"."id")
INNER JOIN "useragent" ON ("usage"."useragent_id" = "useragent"."id")
INNER JOIN "backend" ON ("usage"."backend_id" = "backend"."id")
INNER JOIN "proto" ON ("usage"."proto_id" = "proto"."id")
INNER JOIN "referrer" ON ("usage"."referrer_id" = "referrer"."id")
INNER JOIN "clienturi" T9 ON ("usage"."clienturi_parent_id" = T9."id")
WHERE
"time"."year" IS NOT NULL AND "time"."month" IS NULL AND "time"."day" IS NULL AND "time"."hour" IS NULL AND "time"."minute" IS NULL
AND "usage"."geo_id" IN (1, 753)
AND "usage"."clienturi_id" IN (288119418, 559795958)
AND "usage"."useragent_id" IN (1, 4176)
AND "usage"."backend_id" IN (86, 210)
AND "usage"."proto_id" IN (1, 68)
AND "usage"."referrer_id" IN (1, 11713775)
ORDER BY
"time"."year" ASC;
план 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. 63. 64. 65. 66. 67. 68. 69. 70. 71. 72. 73. 74. 75. 76. 77. 78. 79. 80. 81. 82. 83. 84. 85. 86. 87. 88. 89. 90. 91. 92. 93. 94. 95. 96. 97. 98. 99. 100. 101. 102. 103. 104. 105. 106. 107. 108. 109. 110. 111. 112. 113. 114. 115. 116. 117. 118. 119. 120. 121. 122. 123. 124. 125. 126. 127. 128. 129. 130. 131. 132. 133. 134. 135. 136. 137. 138. 139. 140. 141. 142. 143. 144.
QUERY PLAN
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Nested Loop (cost=0.85..25312874517804736.00 rows=4220849214413699809280 width=399) (actual time=7.131..22.270 rows=4 loops=1)
-> Nested Loop (cost=0.85..8895890141.26 rows=1482451866583578 width=310) (actual time=7.122..22.233 rows=4 loops=1)
-> Nested Loop (cost=0.85..150152.76 rows=520980380 width=221) (actual time=7.109..22.194 rows=4 loops=1)
-> Nested Loop (cost=0.85..28358.34 rows=7194 width=195) (actual time=7.101..22.157 rows=4 loops=1)
-> Nested Loop (cost=0.85..23782.28 rows=313 width=164) (actual time=7.094..22.129 rows=4 loops=1)
-> Nested Loop (cost=0.85..23438.48 rows=46 width=130) (actual time=7.083..22.088 rows=4 loops=1)
-> Nested Loop (cost=0.85..23372.31 rows=5 width=121) (actual time=7.076..22.061 rows=4 loops=1)
-> Nested Loop (cost=0.85..23358.88 rows=3 width=115) (actual time=7.070..22.037 rows=4 loops=1)
-> Merge Append (cost=0.85..15693.00 rows=3 width=28) (actual time=1.269..15.570 rows=5 loops=1)
Sort Key: "time".year
-> Index Scan using time_year_month_day_hour_minute_second_idx on "time" (cost=0.12..8.15 rows=1 width=28) (actual time=0.008..0.008 rows=0 loops=1)
Index Cond: ((year IS NOT NULL) AND (month IS NULL) AND (day IS NULL) AND (hour IS NULL) AND (minute IS NULL))
-> Index Scan using time_2016_year_month_day_hour_minute_second_idx on time_2016 (cost=0.42..15549.80 rows=1 width=28) (actual time=1.128..15.427 rows=4 loops=1)
Index Cond: ((year IS NOT NULL) AND (month IS NULL) AND (day IS NULL) AND (hour IS NULL) AND (minute IS NULL))
-> Index Scan using time_2017_year_month_day_hour_minute_second_idx on time_2017 (cost=0.28..134.97 rows=1 width=28) (actual time=0.131..0.132 rows=1 loops=1)
Index Cond: ((year IS NOT NULL) AND (month IS NULL) AND (day IS NULL) AND (hour IS NULL) AND (minute IS NULL))
-> Append (cost=0.00..2555.10 rows=20 width=87) (actual time=0.491..1.291 rows=1 loops=5)
-> Seq Scan on usage (cost=0.00..0.00 rows=1 width=87) (actual time=0.001..0.001 rows=0 loops=5)
Filter: ((geo_id = ANY ('{1,753}'::integer[])) AND (clienturi_id = ANY ('{288119418,559795958}'::bigint[])) AND (useragent_id = ANY ('{1,4176}'::integer[])) AND (backend_id = ANY ('{86,210}'::integer[])) AND (proto_id = ANY ('{1,68}'::integer[])) AND (referrer_id = ANY ('{1,11713775}'::integer[])) AND ("time".id = time_id))
-> Index Scan using usage_2016_time_id_clienturi_id_geo_id_useragent_id_backen_idx on usage_2016 (cost=0.70..306.57 rows=1 width=87) (actual time=0.071..0.183 rows=1 loops=5)
Index Cond: ((time_id = "time".id) AND (clienturi_id = ANY ('{288119418,559795958}'::bigint[])) AND (geo_id = ANY ('{1,753}'::integer[])) AND (useragent_id = ANY ('{1,4176}'::integer[])) AND (backend_id = ANY ('{86,210}'::integer[])) AND (proto_id = ANY ('{1,68}'::integer[])) AND (referrer_id = ANY ('{1,11713775}'::integer[])))
-> Index Scan using usage_2016_08_time_id_clienturi_id_geo_id_useragent_id_back_idx on usage_2016_08 (cost=0.71..306.73 rows=1 width=87) (actual time=0.154..0.154 rows=0 loops=5)
Index Cond: ((time_id = "time".id) AND (clienturi_id = ANY ('{288119418,559795958}'::bigint[])) AND (geo_id = ANY ('{1,753}'::integer[])) AND (useragent_id = ANY ('{1,4176}'::integer[])) AND (backend_id = ANY ('{86,210}'::integer[])) AND (proto_id = ANY ('{1,68}'::integer[])) AND (referrer_id = ANY ('{1,11713775}'::integer[])))
-> Index Scan using usage_2016_09_time_id_clienturi_id_geo_id_useragent_id_back_idx on usage_2016_09 (cost=0.71..306.73 rows=1 width=87) (actual time=0.155..0.155 rows=0 loops=5)
Index Cond: ((time_id = "time".id) AND (clienturi_id = ANY ('{288119418,559795958}'::bigint[])) AND (geo_id = ANY ('{1,753}'::integer[])) AND (useragent_id = ANY ('{1,4176}'::integer[])) AND (backend_id = ANY ('{86,210}'::integer[])) AND (proto_id = ANY ('{1,68}'::integer[])) AND (referrer_id = ANY ('{1,11713775}'::integer[])))
-> Index Scan using usage_2016_10_time_id_clienturi_id_geo_id_useragent_id_back_idx on usage_2016_10 (cost=0.71..306.89 rows=1 width=87) (actual time=0.153..0.153 rows=0 loops=5)
Index Cond: ((time_id = "time".id) AND (clienturi_id = ANY ('{288119418,559795958}'::bigint[])) AND (geo_id = ANY ('{1,753}'::integer[])) AND (useragent_id = ANY ('{1,4176}'::integer[])) AND (backend_id = ANY ('{86,210}'::integer[])) AND (proto_id = ANY ('{1,68}'::integer[])) AND (referrer_id = ANY ('{1,11713775}'::integer[])))
-> Index Scan using usage_2016_11_time_id_clienturi_id_geo_id_useragent_id_back_idx on usage_2016_11 (cost=0.71..306.89 rows=1 width=87) (actual time=0.154..0.154 rows=0 loops=5)
Index Cond: ((time_id = "time".id) AND (clienturi_id = ANY ('{288119418,559795958}'::bigint[])) AND (geo_id = ANY ('{1,753}'::integer[])) AND (useragent_id = ANY ('{1,4176}'::integer[])) AND (backend_id = ANY ('{86,210}'::integer[])) AND (proto_id = ANY ('{1,68}'::integer[])) AND (referrer_id = ANY ('{1,11713775}'::integer[])))
-> Index Scan using usage_2016_12_time_id_clienturi_id_geo_id_useragent_id_back_idx on usage_2016_12 (cost=0.71..306.89 rows=1 width=87) (actual time=0.153..0.153 rows=0 loops=5)
Index Cond: ((time_id = "time".id) AND (clienturi_id = ANY ('{288119418,559795958}'::bigint[])) AND (geo_id = ANY ('{1,753}'::integer[])) AND (useragent_id = ANY ('{1,4176}'::integer[])) AND (backend_id = ANY ('{86,210}'::integer[])) AND (proto_id = ANY ('{1,68}'::integer[])) AND (referrer_id = ANY ('{1,11713775}'::integer[])))
-> Index Scan using usage_2017_time_id_clienturi_id_geo_id_useragent_id_backend_idx on usage_2017 (cost=0.56..297.45 rows=1 width=87) (actual time=0.142..0.142 rows=0 loops=5)
Index Cond: ((time_id = "time".id) AND (clienturi_id = ANY ('{288119418,559795958}'::bigint[])) AND (geo_id = ANY ('{1,753}'::integer[])) AND (useragent_id = ANY ('{1,4176}'::integer[])) AND (backend_id = ANY ('{86,210}'::integer[])) AND (proto_id = ANY ('{1,68}'::integer[])) AND (referrer_id = ANY ('{1,11713775}'::integer[])))
-> Index Scan using usage_2017_01_time_id_clienturi_id_geo_id_useragent_id_back_idx on usage_2017_01 (cost=0.70..306.57 rows=1 width=87) (actual time=0.154..0.154 rows=0 loops=5)
Index Cond: ((time_id = "time".id) AND (clienturi_id = ANY ('{288119418,559795958}'::bigint[])) AND (geo_id = ANY ('{1,753}'::integer[])) AND (useragent_id = ANY ('{1,4176}'::integer[])) AND (backend_id = ANY ('{86,210}'::integer[])) AND (proto_id = ANY ('{1,68}'::integer[])) AND (referrer_id = ANY ('{1,11713775}'::integer[])))
-> Bitmap Heap Scan on usage_2017_02 (cost=1.51..10.03 rows=1 width=87) (actual time=0.002..0.002 rows=0 loops=5)
Recheck Cond: (time_id = "time".id)
Filter: ((geo_id = ANY ('{1,753}'::integer[])) AND (clienturi_id = ANY ('{288119418,559795958}'::bigint[])) AND (useragent_id = ANY ('{1,4176}'::in
teger[])) AND (backend_id = ANY ('{86,210}'::integer[])) AND (proto_id = ANY ('{1,68}'::integer[])) AND (referrer_id = ANY ('{1,11713775}'::integer[])))
-> Bitmap Index Scan on usage_2017_02_time_id_clienturi_parent_id_geo_id_useragent__idx (cost=0.00..1.51 rows=4 width=0) (actual time=0.001..0.001 rows=0 loops=5)
Index Cond: (time_id = "time".id)
-> Bitmap Heap Scan on usage_2017_03 (cost=1.51..10.03 rows=1 width=87) (actual time=0.001..0.001 rows=0 loops=5)
Recheck Cond: (time_id = "time".id)
Filter: ((geo_id = ANY ('{1,753}'::integer[])) AND (clienturi_id = ANY ('{288119418,559795958}'::bigint[])) AND (useragent_id = ANY ('{1,4176}'::integer[])) AND (backend_id = ANY ('{86,210}'::integer[])) AND (proto_id = ANY ('{1,68}'::integer[])) AND (referrer_id = ANY ('{1,11713775}'::integer[])))
-> Bitmap Index Scan on usage_2017_03_time_id_clienturi_parent_id_geo_id_useragent__idx (cost=0.00..1.51 rows=4 width=0) (actual time=0.001..0.001 rows=0 loops=5)
Index Cond: (time_id = "time".id)
-> Bitmap Heap Scan on usage_2017_04 (cost=1.51..10.03 rows=1 width=87) (actual time=0.001..0.001 rows=0 loops=5)
Recheck Cond: (time_id = "time".id)
Filter: ((geo_id = ANY ('{1,753}'::integer[])) AND (clienturi_id = ANY ('{288119418,559795958}'::bigint[])) AND (useragent_id = ANY ('{1,4176}'::integer[])) AND (backend_id = ANY ('{86,210}'::integer[])) AND (proto_id = ANY ('{1,68}'::integer[])) AND (referrer_id = ANY ('{1,11713775}'::integer[])))
-> Bitmap Index Scan on usage_2017_04_time_id_clienturi_parent_id_geo_id_useragent__idx (cost=0.00..1.51 rows=4 width=0) (actual time=0.001..0.001 rows=0 loops=5)
Index Cond: (time_id = "time".id)
-> Bitmap Heap Scan on usage_2017_05 (cost=1.51..10.03 rows=1 width=87) (actual time=0.001..0.001 rows=0 loops=5)
Recheck Cond: (time_id = "time".id)
Filter: ((geo_id = ANY ('{1,753}'::integer[])) AND (clienturi_id = ANY ('{288119418,559795958}'::bigint[])) AND (useragent_id = ANY ('{1,4176}'::integer[])) AND (backend_id = ANY ('{86,210}'::integer[])) AND (proto_id = ANY ('{1,68}'::integer[])) AND (referrer_id = ANY ('{1,11713775}'::integer[])))
-> Bitmap Index Scan on usage_2017_05_time_id_clienturi_parent_id_geo_id_useragent__idx (cost=0.00..1.51 rows=4 width=0) (actual time=0.001..0.001 rows=0 loops=5)
Index Cond: (time_id = "time".id)
-> Bitmap Heap Scan on usage_2017_06 (cost=1.51..10.03 rows=1 width=87) (actual time=0.001..0.001 rows=0 loops=5)
Recheck Cond: (time_id = "time".id)
Filter: ((geo_id = ANY ('{1,753}'::integer[])) AND (clienturi_id = ANY ('{288119418,559795958}'::bigint[])) AND (useragent_id = ANY ('{1,4176}'::integer[])) AND (backend_id = ANY ('{86,210}'::integer[])) AND (proto_id = ANY ('{1,68}'::integer[])) AND (referrer_id = ANY ('{1,11713775}'::integer[])))
-> Bitmap Index Scan on usage_2017_06_time_id_clienturi_parent_id_geo_id_useragent__idx (cost=0.00..1.51 rows=4 width=0) (actual time=0.001..0.001 rows=0 loops=5)
Index Cond: (time_id = "time".id)
-> Bitmap Heap Scan on usage_2017_07 (cost=1.51..10.03 rows=1 width=87) (actual time=0.001..0.001 rows=0 loops=5)
Recheck Cond: (time_id = "time".id)
Filter: ((geo_id = ANY ('{1,753}'::integer[])) AND (clienturi_id = ANY ('{288119418,559795958}'::bigint[])) AND (useragent_id = ANY ('{1,4176}'::integer[])) AND (backend_id = ANY ('{86,210}'::integer[])) AND (proto_id = ANY ('{1,68}'::integer[])) AND (referrer_id = ANY ('{1,11713775}'::integer[])))
-> Bitmap Index Scan on usage_2017_07_time_id_clienturi_parent_id_geo_id_useragent__idx (cost=0.00..1.51 rows=4 width=0) (actual time=0.001..0.001 rows=0 loops=5)
Index Cond: (time_id = "time".id)
-> Bitmap Heap Scan on usage_2017_08 (cost=1.51..10.03 rows=1 width=87) (actual time=0.001..0.001 rows=0 loops=5)
Recheck Cond: (time_id = "time".id)
Filter: ((geo_id = ANY ('{1,753}'::integer[])) AND (clienturi_id = ANY ('{288119418,559795958}'::bigint[])) AND (useragent_id = ANY ('{1,4176}'::integer[])) AND (backend_id = ANY ('{86,210}'::integer[])) AND (proto_id = ANY ('{1,68}'::integer[])) AND (referrer_id = ANY ('{1,11713775}'::integer[])))
-> Bitmap Index Scan on usage_2017_08_time_id_clienturi_parent_id_geo_id_useragent__idx (cost=0.00..1.51 rows=4 width=0) (actual time=0.001..0.001 rows=0 loops=5)
Index Cond: (time_id = "time".id)
-> Bitmap Heap Scan on usage_2017_09 (cost=1.51..10.03 rows=1 width=87) (actual time=0.001..0.001 rows=0 loops=5)
Recheck Cond: (time_id = "time".id)
Filter: ((geo_id = ANY ('{1,753}'::integer[])) AND (clienturi_id = ANY ('{288119418,559795958}'::bigint[])) AND (useragent_id = ANY ('{1,4176}'::integer[])) AND (backend_id = ANY ('{86,210}'::integer[])) AND (proto_id = ANY ('{1,68}'::integer[])) AND (referrer_id = ANY ('{1,11713775}'::integer[])))
-> Bitmap Index Scan on usage_2017_09_time_id_clienturi_parent_id_geo_id_useragent__idx (cost=0.00..1.51 rows=4 width=0) (actual time=0.001..0.001 rows=0 loops=5)
Index Cond: (time_id = "time".id)
-> Bitmap Heap Scan on usage_2017_10 (cost=1.51..10.03 rows=1 width=87) (actual time=0.001..0.001 rows=0 loops=5)
Recheck Cond: (time_id = "time".id)
Filter: ((geo_id = ANY ('{1,753}'::integer[])) AND (clienturi_id = ANY ('{288119418,559795958}'::bigint[])) AND (useragent_id = ANY ('{1,4176}'::integer[])) AND (backend_id = ANY ('{86,210}'::integer[])) AND (proto_id = ANY ('{1,68}'::integer[])) AND (referrer_id = ANY ('{1,11713775}'::integer[])))
-> Bitmap Index Scan on usage_2017_10_time_id_clienturi_parent_id_geo_id_useragent__idx (cost=0.00..1.51 rows=4 width=0) (actual time=0.001..0.001 rows=0 loops=5)
Index Cond: (time_id = "time".id)
-> Bitmap Heap Scan on usage_2017_11 (cost=1.51..10.03 rows=1 width=87) (actual time=0.001..0.001 rows=0 loops=5)
Recheck Cond: (time_id = "time".id)
Filter: ((geo_id = ANY ('{1,753}'::integer[])) AND (clienturi_id = ANY ('{288119418,559795958}'::bigint[])) AND (useragent_id = ANY ('{1,4176}'::integer[])) AND (backend_id = ANY ('{86,210}'::integer[])) AND (proto_id = ANY ('{1,68}'::integer[])) AND (referrer_id = ANY ('{1,11713775}'::integer[])))
-> Bitmap Index Scan on usage_2017_11_time_id_clienturi_parent_id_geo_id_useragent__idx (cost=0.00..1.51 rows=4 width=0) (actual time=0.000..0.000 rows=0 loops=5)
Index Cond: (time_id = "time".id)
-> Bitmap Heap Scan on usage_2017_12 (cost=1.51..10.03 rows=1 width=87) (actual time=0.001..0.001 rows=0 loops=5)
Recheck Cond: (time_id = "time".id)
Filter: ((geo_id = ANY ('{1,753}'::integer[])) AND (clienturi_id = ANY ('{288119418,559795958}'::bigint[])) AND (useragent_id = ANY ('{1,4176}'::integer[])) AND (backend_id = ANY ('{86,210}'::integer[])) AND (proto_id = ANY ('{1,68}'::integer[])) AND (referrer_id = ANY ('{1,11713775}'::integer[])))
-> Bitmap Index Scan on usage_2017_12_time_id_clienturi_parent_id_geo_id_useragent__idx (cost=0.00..1.51 rows=4 width=0) (actual time=0.001..0.001 rows=0 loops=5)
Index Cond: (time_id = "time".id)
-> Append (cost=0.00..4.45 rows=3 width=6) (actual time=0.004..0.005 rows=1 loops=4)
-> Seq Scan on backend (cost=0.00..0.00 rows=1 width=6) (actual time=0.000..0.000 rows=0 loops=4)
Filter: (usage.backend_id = id)
-> Index Scan using backend_2016_pkey on backend_2016 (cost=0.14..2.22 rows=1 width=6) (actual time=0.002..0.003 rows=1 loops=4)
Index Cond: (id = usage.backend_id)
-> Index Scan using backend_2017_pkey on backend_2017 (cost=0.14..2.22 rows=1 width=6) (actual time=0.002..0.002 rows=0 loops=4)
Index Cond: (id = usage.backend_id)
-> Append (cost=0.00..13.20 rows=3 width=28) (actual time=0.004..0.006 rows=1 loops=4)
-> Seq Scan on geo (cost=0.00..0.00 rows=1 width=66) (actual time=0.000..0.000 rows=0 loops=4)
Filter: (usage.geo_id = id)
-> Index Scan using geo_2016_pkey on geo_2016 (cost=0.28..6.54 rows=1 width=9) (actual time=0.002..0.003 rows=1 loops=4)
Index Cond: (id = usage.geo_id)
-> Index Scan using geo_2017_pkey on geo_2017 (cost=0.28..6.66 rows=1 width=9) (actual time=0.002..0.002 rows=0 loops=4)
Index Cond: (id = usage.geo_id)
-> Append (cost=0.00..7.44 rows=3 width=34) (actual time=0.006..0.009 rows=1 loops=4)
-> Seq Scan on proto (cost=0.00..0.00 rows=1 width=34) (actual time=0.000..0.000 rows=0 loops=4)
Filter: (usage.proto_id = id)
-> Seq Scan on proto_2016 (cost=0.00..1.61 rows=1 width=34) (actual time=0.004..0.007 rows=1 loops=4)
Filter: (usage.proto_id = id)
Rows Removed by Filter: 48
-> Index Scan using proto_2017_pkey on proto_2017 (cost=0.15..5.83 rows=1 width=34) (actual time=0.001..0.001 rows=0 loops=4)
Index Cond: (id = usage.proto_id)
-> Append (cost=0.00..14.59 rows=3 width=40) (actual time=0.004..0.006 rows=1 loops=4)
-> Seq Scan on useragent (cost=0.00..0.00 rows=1 width=66) (actual time=0.000..0.000 rows=0 loops=4)
Filter: (usage.useragent_id = id)
-> Index Scan using useragent_2016_pkey on useragent_2016 (cost=0.28..7.93 rows=1 width=33) (actual time=0.002..0.002 rows=1 loops=4)
Index Cond: (id = usage.useragent_id)
-> Index Scan using useragent_2017_pkey on useragent_2017 (cost=0.27..6.66 rows=1 width=21) (actual time=0.002..0.002 rows=0 loops=4)
Index Cond: (id = usage.useragent_id)
-> Append (cost=0.00..16.90 rows=3 width=29) (actual time=0.005..0.008 rows=1 loops=4)
-> Seq Scan on referrer (cost=0.00..0.00 rows=1 width=36) (actual time=0.000..0.000 rows=0 loops=4)
Filter: (usage.referrer_id = id)
-> Index Scan using referrer_2016_pkey on referrer_2016 (cost=0.43..8.45 rows=1 width=26) (actual time=0.004..0.004 rows=1 loops=4)
Index Cond: (id = usage.referrer_id)
-> Index Scan using referrer_2017_pkey on referrer_2017 (cost=0.43..8.45 rows=1 width=25) (actual time=0.003..0.003 rows=0 loops=4)
Index Cond: (id = usage.referrer_id)
-> Append (cost=0.00..17.05 rows=3 width=86) (actual time=0.008..0.009 rows=1 loops=4)
-> Seq Scan on clienturi (cost=0.00..0.00 rows=1 width=84) (actual time=0.000..0.000 rows=0 loops=4)
Filter: (usage.clienturi_id = id)
-> Index Scan using clienturi_2016_pkey1 on clienturi_2016 (cost=0.57..8.59 rows=1 width=89) (actual time=0.006..0.006 rows=1 loops=4)
Index Cond: (id = usage.clienturi_id)
-> Index Scan using clienturi_2017_pkey on clienturi_2017 (cost=0.43..8.45 rows=1 width=85) (actual time=0.002..0.002 rows=0 loops=4)
Index Cond: (id = usage.clienturi_id)
-> Append (cost=0.00..17.05 rows=3 width=86) (actual time=0.004..0.008 rows=1 loops=4)
-> Seq Scan on clienturi t9 (cost=0.00..0.00 rows=1 width=84) (actual time=0.000..0.000 rows=0 loops=4)
Filter: (usage.clienturi_parent_id = id)
-> Index Scan using clienturi_2016_pkey1 on clienturi_2016 t9_1 (cost=0.57..8.59 rows=1 width=89) (actual time=0.004..0.005 rows=1 loops=4)
Index Cond: (id = usage.clienturi_parent_id)
-> Index Scan using clienturi_2017_pkey on clienturi_2017 t9_2 (cost=0.43..8.45 rows=1 width=85) (actual time=0.003..0.003 rows=0 loops=4)
Index Cond: (id = usage.clienturi_parent_id)
Planning time: 429.148 ms
Execution time: 22.804 ms
Сделал тест, на котором вопроизводится эта проблема. Пробовал на Postgres 9.6. тест 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. 63. 64. 65. 66. 67. 68. 69. 70. 71. 72. 73.
rollback;
begin;
create table dim1 (id serial primary key);
create table dim2 (id serial primary key);
create table dim3 (id serial primary key);
create table dim4 (id serial primary key);
create table dim5 (id serial primary key);
create table dim6 (id serial primary key);
create table usage (
id serial primary key,
dim1_id int not null,
dim2_id int not null,
dim3_id int not null,
dim4_id int not null,
dim5_id int not null,
dim6_id int not null
);
create index on usage (dim1_id, dim2_id, dim3_id, dim4_id, dim5_id, dim6_id);
create index on usage (dim2_id, dim3_id, dim4_id, dim5_id, dim6_id, dim1_id);
create index on usage (dim3_id, dim4_id, dim5_id, dim6_id, dim1_id, dim2_id);
create index on usage (dim4_id, dim5_id, dim6_id, dim1_id, dim2_id, dim3_id);
create index on usage (dim5_id, dim6_id, dim1_id, dim2_id, dim3_id, dim4_id);
create index on usage (dim6_id, dim1_id, dim2_id, dim3_id, dim4_id, dim5_id);
create table usage_2017_01(like usage including indexes) inherits(usage);
create table usage_2017_02(like usage including indexes) inherits(usage);
create table usage_2017_03(like usage including indexes) inherits(usage);
create table usage_2017_04(like usage including indexes) inherits(usage);
create table usage_2017_05(like usage including indexes) inherits(usage);
create table usage_2017_06(like usage including indexes) inherits(usage);
create table usage_2017_07(like usage including indexes) inherits(usage);
create table usage_2017_08(like usage including indexes) inherits(usage);
create table usage_2017_09(like usage including indexes) inherits(usage);
create table usage_2017_10(like usage including indexes) inherits(usage);
create table usage_2017_11(like usage including indexes) inherits(usage);
create table usage_2017_12(like usage including indexes) inherits(usage);
create table usage_2018_01(like usage including indexes) inherits(usage);
create table usage_2018_02(like usage including indexes) inherits(usage);
create table usage_2018_03(like usage including indexes) inherits(usage);
create table usage_2018_04(like usage including indexes) inherits(usage);
create table usage_2018_05(like usage including indexes) inherits(usage);
create table usage_2018_06(like usage including indexes) inherits(usage);
create table usage_2018_07(like usage including indexes) inherits(usage);
create table usage_2018_08(like usage including indexes) inherits(usage);
create table usage_2018_09(like usage including indexes) inherits(usage);
create table usage_2018_10(like usage including indexes) inherits(usage);
create table usage_2018_11(like usage including indexes) inherits(usage);
create table usage_2018_12(like usage including indexes) inherits(usage);
explain
(analyze)
select
*
from
usage
inner join dim1 on (usage.dim1_id = dim1.id)
inner join dim2 on (usage.dim2_id = dim2.id)
inner join dim3 on (usage.dim3_id = dim3.id)
inner join dim4 on (usage.dim4_id = dim4.id)
inner join dim5 on (usage.dim5_id = dim5.id)
inner join dim6 on (usage.dim6_id = dim6.id)
where
usage.dim1_id in (1, 2) and
usage.dim2_id in (2, 3) and
usage.dim3_id in (3, 4) and
usage.dim4_id in (4, 5) and
usage.dim5_id in (5, 6) and
usage.dim6_id in (6, 7)
;
-- rollback;
план 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. 63. 64. 65. 66. 67. 68. 69. 70. 71. 72. 73. 74. 75. 76. 77. 78. 79. 80. 81. 82. 83. 84. 85. 86. 87. 88. 89. 90. 91. 92. 93. 94. 95. 96. 97. 98. 99. 100. 101. 102. 103. 104. 105. 106. 107. 108. 109. 110. 111. 112. 113. 114. 115. 116. 117. 118. 119. 120. 121. 122. 123. 124. 125. 126. 127. 128. 129. 130. 131. 132. 133. 134. 135. 136. 137. 138. 139. 140. 141. 142. 143. 144. 145. 146. 147. 148. 149. 150. 151. 152. 153. 154. 155. 156. 157. 158. 159. 160. 161. 162. 163. 164. 165. 166. 167. 168. 169. 170. 171. 172. 173. 174. 175. 176. 177. 178. 179. 180. 181. 182. 183. 184. 185. 186. 187. 188. 189. 190. 191. 192. 193. 194. 195. 196. 197. 198. 199. 200. 201. 202. 203. 204. 205. 206. 207. 208. 209. 210. 211. 212. 213. 214. 215. 216. 217. 218. 219. 220. 221. 222.
QUERY PLAN
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Nested Loop (cost=0.93..605.67 rows=25 width=52) (actual time=0.089..0.089 rows=0 loops=1)
-> Nested Loop (cost=0.78..557.10 rows=25 width=48) (actual time=0.089..0.089 rows=0 loops=1)
-> Nested Loop (cost=0.62..508.54 rows=25 width=44) (actual time=0.089..0.089 rows=0 loops=1)
-> Nested Loop (cost=0.46..459.98 rows=25 width=40) (actual time=0.089..0.089 rows=0 loops=1)
-> Nested Loop (cost=0.31..411.42 rows=25 width=36) (actual time=0.089..0.089 rows=0 loops=1)
-> Nested Loop (cost=0.15..362.85 rows=25 width=32) (actual time=0.087..0.087 rows=0 loops=1)
-> Append (cost=0.00..314.29 rows=25 width=28) (actual time=0.087..0.087 rows=0 loops=1)
-> Seq Scan on usage (cost=0.00..0.00 rows=1 width=28) (actual time=0.002..0.002 rows=0 loops=1)
Filter: ((dim1_id = ANY ('{1,2}'::integer[])) AND (dim2_id = ANY ('{2,3}'::integer[])) AND (dim3_id = ANY ('{3,4}'::integer[])) AND (dim4_id = ANY ('{4,5}'::integer[])) AND (dim5_id = ANY ('{5,6}'::integer[])) AND (dim6_id = ANY ('{6,7}'::integer[])))
-> Bitmap Heap Scan on usage_2017_01 (cost=9.07..13.10 rows=1 width=28) (actual time=0.009..0.009 rows=0 loops=1)
Recheck Cond: ((dim4_id = ANY ('{4,5}'::integer[])) AND (dim1_id = ANY ('{1,2}'::integer[])))
Filter: ((dim2_id = ANY ('{2,3}'::integer[])) AND (dim3_id = ANY ('{3,4}'::integer[])) AND (dim5_id = ANY ('{5,6}'::integer[])) AND (dim6_id = ANY ('{6,7}'::integer[])))
-> BitmapAnd (cost=9.07..9.07 rows=1 width=0) (actual time=0.008..0.008 rows=0 loops=1)
-> Bitmap Index Scan on usage_2017_01_dim4_id_dim5_id_dim6_id_dim1_id_dim2_id_dim3__idx (cost=0.00..4.41 rows=14 width=0) (actual time=0.008..0.008 rows=0 loops=1)
Index Cond: (dim4_id = ANY ('{4,5}'::integer[]))
-> Bitmap Index Scan on usage_2017_01_dim1_id_dim2_id_dim3_id_dim4_id_dim5_id_dim6__idx (cost=0.00..4.41 rows=14 width=0) (never executed)
Index Cond: (dim1_id = ANY ('{1,2}'::integer[]))
-> Bitmap Heap Scan on usage_2017_02 (cost=9.07..13.10 rows=1 width=28) (actual time=0.004..0.004 rows=0 loops=1)
Recheck Cond: ((dim4_id = ANY ('{4,5}'::integer[])) AND (dim1_id = ANY ('{1,2}'::integer[])))
Filter: ((dim2_id = ANY ('{2,3}'::integer[])) AND (dim3_id = ANY ('{3,4}'::integer[])) AND (dim5_id = ANY ('{5,6}'::integer[])) AND (dim6_id = ANY ('{6,7}'::integer[])))
-> BitmapAnd (cost=9.07..9.07 rows=1 width=0) (actual time=0.004..0.004 rows=0 loops=1)
-> Bitmap Index Scan on usage_2017_02_dim4_id_dim5_id_dim6_id_dim1_id_dim2_id_dim3__idx (cost=0.00..4.41 rows=14 width=0) (actual time=0.004..0.004 rows=0 loops=1)
Index Cond: (dim4_id = ANY ('{4,5}'::integer[]))
-> Bitmap Index Scan on usage_2017_02_dim1_id_dim2_id_dim3_id_dim4_id_dim5_id_dim6__idx (cost=0.00..4.41 rows=14 width=0) (never executed)
Index Cond: (dim1_id = ANY ('{1,2}'::integer[]))
-> Bitmap Heap Scan on usage_2017_03 (cost=9.07..13.10 rows=1 width=28) (actual time=0.003..0.003 rows=0 loops=1)
Recheck Cond: ((dim4_id = ANY ('{4,5}'::integer[])) AND (dim1_id = ANY ('{1,2}'::integer[])))
Filter: ((dim2_id = ANY ('{2,3}'::integer[])) AND (dim3_id = ANY ('{3,4}'::integer[])) AND (dim5_id = ANY ('{5,6}'::integer[])) AND (dim6_id = ANY ('{6,7}'::integer[])))
-> BitmapAnd (cost=9.07..9.07 rows=1 width=0) (actual time=0.002..0.002 rows=0 loops=1)
-> Bitmap Index Scan on usage_2017_03_dim4_id_dim5_id_dim6_id_dim1_id_dim2_id_dim3__idx (cost=0.00..4.41 rows=14 width=0) (actual time=0.002..0.002 rows=0 loops=1)
Index Cond: (dim4_id = ANY ('{4,5}'::integer[]))
-> Bitmap Index Scan on usage_2017_03_dim1_id_dim2_id_dim3_id_dim4_id_dim5_id_dim6__idx (cost=0.00..4.41 rows=14 width=0) (never executed)
Index Cond: (dim1_id = ANY ('{1,2}'::integer[]))
-> Bitmap Heap Scan on usage_2017_04 (cost=9.07..13.10 rows=1 width=28) (actual time=0.004..0.004 rows=0 loops=1)
Recheck Cond: ((dim4_id = ANY ('{4,5}'::integer[])) AND (dim1_id = ANY ('{1,2}'::integer[])))
Filter: ((dim2_id = ANY ('{2,3}'::integer[])) AND (dim3_id = ANY ('{3,4}'::integer[])) AND (dim5_id = ANY ('{5,6}'::integer[])) AND (dim6_id = ANY ('{6,7}'::integer[])))
-> BitmapAnd (cost=9.07..9.07 rows=1 width=0) (actual time=0.004..0.004 rows=0 loops=1)
-> Bitmap Index Scan on usage_2017_04_dim4_id_dim5_id_dim6_id_dim1_id_dim2_id_dim3__idx (cost=0.00..4.41 rows=14 width=0) (actual time=0.004..0.004 rows=0 loops=1)
Index Cond: (dim4_id = ANY ('{4,5}'::integer[]))
-> Bitmap Index Scan on usage_2017_04_dim1_id_dim2_id_dim3_id_dim4_id_dim5_id_dim6__idx (cost=0.00..4.41 rows=14 width=0) (never executed)
Index Cond: (dim1_id = ANY ('{1,2}'::integer[]))
-> Bitmap Heap Scan on usage_2017_05 (cost=9.07..13.10 rows=1 width=28) (actual time=0.004..0.004 rows=0 loops=1)
Recheck Cond: ((dim4_id = ANY ('{4,5}'::integer[])) AND (dim1_id = ANY ('{1,2}'::integer[])))
Filter: ((dim2_id = ANY ('{2,3}'::integer[])) AND (dim3_id = ANY ('{3,4}'::integer[])) AND (dim5_id = ANY ('{5,6}'::integer[])) AND (dim6_id = ANY ('{6,7}'::integer[])))
-> BitmapAnd (cost=9.07..9.07 rows=1 width=0) (actual time=0.002..0.002 rows=0 loops=1)
-> Bitmap Index Scan on usage_2017_05_dim4_id_dim5_id_dim6_id_dim1_id_dim2_id_dim3__idx (cost=0.00..4.41 rows=14 width=0) (actual time=0.002..0.002 rows=0 loops=1)
Index Cond: (dim4_id = ANY ('{4,5}'::integer[]))
-> Bitmap Index Scan on usage_2017_05_dim1_id_dim2_id_dim3_id_dim4_id_dim5_id_dim6__idx (cost=0.00..4.41 rows=14 width=0) (never executed)
Index Cond: (dim1_id = ANY ('{1,2}'::integer[]))
-> Bitmap Heap Scan on usage_2017_06 (cost=9.07..13.10 rows=1 width=28) (actual time=0.002..0.002 rows=0 loops=1)
Recheck Cond: ((dim4_id = ANY ('{4,5}'::integer[])) AND (dim1_id = ANY ('{1,2}'::integer[])))
Filter: ((dim2_id = ANY ('{2,3}'::integer[])) AND (dim3_id = ANY ('{3,4}'::integer[])) AND (dim5_id = ANY ('{5,6}'::integer[])) AND (dim6_id = ANY ('{6,7}'::integer[])))
-> BitmapAnd (cost=9.07..9.07 rows=1 width=0) (actual time=0.002..0.002 rows=0 loops=1)
-> Bitmap Index Scan on usage_2017_06_dim4_id_dim5_id_dim6_id_dim1_id_dim2_id_dim3__idx (cost=0.00..4.41 rows=14 width=0) (actual time=0.002..0.002 rows=0 loops=1)
Index Cond: (dim4_id = ANY ('{4,5}'::integer[]))
-> Bitmap Index Scan on usage_2017_06_dim1_id_dim2_id_dim3_id_dim4_id_dim5_id_dim6__idx (cost=0.00..4.41 rows=14 width=0) (never executed)
Index Cond: (dim1_id = ANY ('{1,2}'::integer[]))
-> Bitmap Heap Scan on usage_2017_07 (cost=9.07..13.10 rows=1 width=28) (actual time=0.004..0.004 rows=0 loops=1)
Recheck Cond: ((dim4_id = ANY ('{4,5}'::integer[])) AND (dim1_id = ANY ('{1,2}'::integer[])))
Filter: ((dim2_id = ANY ('{2,3}'::integer[])) AND (dim3_id = ANY ('{3,4}'::integer[])) AND (dim5_id = ANY ('{5,6}'::integer[])) AND (dim6_id = ANY ('{6,7}'::integer[])))
-> BitmapAnd (cost=9.07..9.07 rows=1 width=0) (actual time=0.002..0.002 rows=0 loops=1)
-> Bitmap Index Scan on usage_2017_07_dim4_id_dim5_id_dim6_id_dim1_id_dim2_id_dim3__idx (cost=0.00..4.41 rows=14 width=0) (actual time=0.002..0.002 rows=0 loops=1)
Index Cond: (dim4_id = ANY ('{4,5}'::integer[]))
-> Bitmap Index Scan on usage_2017_07_dim1_id_dim2_id_dim3_id_dim4_id_dim5_id_dim6__idx (cost=0.00..4.41 rows=14 width=0) (never executed)
Index Cond: (dim1_id = ANY ('{1,2}'::integer[]))
-> Bitmap Heap Scan on usage_2017_08 (cost=9.07..13.10 rows=1 width=28) (actual time=0.003..0.003 rows=0 loops=1)
Recheck Cond: ((dim4_id = ANY ('{4,5}'::integer[])) AND (dim1_id = ANY ('{1,2}'::integer[])))
Filter: ((dim2_id = ANY ('{2,3}'::integer[])) AND (dim3_id = ANY ('{3,4}'::integer[])) AND (dim5_id = ANY ('{5,6}'::integer[])) AND (dim6_id = ANY ('{6,7}'::integer[])))
-> BitmapAnd (cost=9.07..9.07 rows=1 width=0) (actual time=0.002..0.002 rows=0 loops=1)
-> Bitmap Index Scan on usage_2017_08_dim4_id_dim5_id_dim6_id_dim1_id_dim2_id_dim3__idx (cost=0.00..4.41 rows=14 width=0) (actual time=0.002..0.002 rows=0 loops=1)
Index Cond: (dim4_id = ANY ('{4,5}'::integer[]))
-> Bitmap Index Scan on usage_2017_08_dim1_id_dim2_id_dim3_id_dim4_id_dim5_id_dim6__idx (cost=0.00..4.41 rows=14 width=0) (never executed)
Index Cond: (dim1_id = ANY ('{1,2}'::integer[]))
-> Bitmap Heap Scan on usage_2017_09 (cost=9.07..13.10 rows=1 width=28) (actual time=0.003..0.003 rows=0 loops=1)
Recheck Cond: ((dim4_id = ANY ('{4,5}'::integer[])) AND (dim1_id = ANY ('{1,2}'::integer[])))
Filter: ((dim2_id = ANY ('{2,3}'::integer[])) AND (dim3_id = ANY ('{3,4}'::integer[])) AND (dim5_id = ANY ('{5,6}'::integer[])) AND (dim6_id = ANY ('{6,7}'::integer[])))
-> BitmapAnd (cost=9.07..9.07 rows=1 width=0) (actual time=0.002..0.002 rows=0 loops=1)
-> Bitmap Index Scan on usage_2017_09_dim4_id_dim5_id_dim6_id_dim1_id_dim2_id_dim3__idx (cost=0.00..4.41 rows=14 width=0) (actual time=0.002..0.002 rows=0 loops=1)
Index Cond: (dim4_id = ANY ('{4,5}'::integer[]))
-> Bitmap Index Scan on usage_2017_09_dim1_id_dim2_id_dim3_id_dim4_id_dim5_id_dim6__idx (cost=0.00..4.41 rows=14 width=0) (never executed)
Index Cond: (dim1_id = ANY ('{1,2}'::integer[]))
-> Bitmap Heap Scan on usage_2017_10 (cost=9.07..13.10 rows=1 width=28) (actual time=0.002..0.002 rows=0 loops=1)
Recheck Cond: ((dim4_id = ANY ('{4,5}'::integer[])) AND (dim1_id = ANY ('{1,2}'::integer[])))
Filter: ((dim2_id = ANY ('{2,3}'::integer[])) AND (dim3_id = ANY ('{3,4}'::integer[])) AND (dim5_id = ANY ('{5,6}'::integer[])) AND (dim6_id = ANY ('{6,7}'::integer[])))
-> BitmapAnd (cost=9.07..9.07 rows=1 width=0) (actual time=0.002..0.002 rows=0 loops=1)
-> Bitmap Index Scan on usage_2017_10_dim4_id_dim5_id_dim6_id_dim1_id_dim2_id_dim3__idx (cost=0.00..4.41 rows=14 width=0) (actual time=0.001..0.001 rows=0 loops=1)
Index Cond: (dim4_id = ANY ('{4,5}'::integer[]))
-> Bitmap Index Scan on usage_2017_10_dim1_id_dim2_id_dim3_id_dim4_id_dim5_id_dim6__idx (cost=0.00..4.41 rows=14 width=0) (never executed)
Index Cond: (dim1_id = ANY ('{1,2}'::integer[]))
-> Bitmap Heap Scan on usage_2017_11 (cost=9.07..13.10 rows=1 width=28) (actual time=0.003..0.003 rows=0 loops=1)
Recheck Cond: ((dim4_id = ANY ('{4,5}'::integer[])) AND (dim1_id = ANY ('{1,2}'::integer[])))
Filter: ((dim2_id = ANY ('{2,3}'::integer[])) AND (dim3_id = ANY ('{3,4}'::integer[])) AND (dim5_id = ANY ('{5,6}'::integer[])) AND (dim6_id = ANY ('{6,7}'::integer[])))
-> BitmapAnd (cost=9.07..9.07 rows=1 width=0) (actual time=0.003..0.003 rows=0 loops=1)
-> Bitmap Index Scan on usage_2017_11_dim4_id_dim5_id_dim6_id_dim1_id_dim2_id_dim3__idx (cost=0.00..4.41 rows=14 width=0) (actual time=0.003..0.003 rows=0 loops=1)
Index Cond: (dim4_id = ANY ('{4,5}'::integer[]))
-> Bitmap Index Scan on usage_2017_11_dim1_id_dim2_id_dim3_id_dim4_id_dim5_id_dim6__idx (cost=0.00..4.41 rows=14 width=0) (never executed)
Index Cond: (dim1_id = ANY ('{1,2}'::integer[]))
-> Bitmap Heap Scan on usage_2017_12 (cost=9.07..13.10 rows=1 width=28) (actual time=0.003..0.003 rows=0 loops=1)
Recheck Cond: ((dim4_id = ANY ('{4,5}'::integer[])) AND (dim1_id = ANY ('{1,2}'::integer[])))
Filter: ((dim2_id = ANY ('{2,3}'::integer[])) AND (dim3_id = ANY ('{3,4}'::integer[])) AND (dim5_id = ANY ('{5,6}'::integer[])) AND (dim6_id = ANY ('{6,7}'::integer[])))
-> BitmapAnd (cost=9.07..9.07 rows=1 width=0) (actual time=0.003..0.003 rows=0 loops=1)
-> Bitmap Index Scan on usage_2017_12_dim4_id_dim5_id_dim6_id_dim1_id_dim2_id_dim3__idx (cost=0.00..4.41 rows=14 width=0) (actual time=0.003..0.003 rows=0 loops=1)
Index Cond: (dim4_id = ANY ('{4,5}'::integer[]))
-> Bitmap Index Scan on usage_2017_12_dim1_id_dim2_id_dim3_id_dim4_id_dim5_id_dim6__idx (cost=0.00..4.41 rows=14 width=0) (never executed)
Index Cond: (dim1_id = ANY ('{1,2}'::integer[]))
-> Bitmap Heap Scan on usage_2018_01 (cost=9.07..13.10 rows=1 width=28) (actual time=0.004..0.004 rows=0 loops=1)
Recheck Cond: ((dim4_id = ANY ('{4,5}'::integer[])) AND (dim1_id = ANY ('{1,2}'::integer[])))
Filter: ((dim2_id = ANY ('{2,3}'::integer[])) AND (dim3_id = ANY ('{3,4}'::integer[])) AND (dim5_id = ANY ('{5,6}'::integer[])) AND (dim6_id = ANY ('{6,7}'::integer[])))
-> BitmapAnd (cost=9.07..9.07 rows=1 width=0) (actual time=0.004..0.004 rows=0 loops=1)
-> Bitmap Index Scan on usage_2018_01_dim4_id_dim5_id_dim6_id_dim1_id_dim2_id_dim3__idx (cost=0.00..4.41 rows=14 width=0) (actual time=0.003..0.003 rows=0 loops=1)
Index Cond: (dim4_id = ANY ('{4,5}'::integer[]))
-> Bitmap Index Scan on usage_2018_01_dim1_id_dim2_id_dim3_id_dim4_id_dim5_id_dim6__idx (cost=0.00..4.41 rows=14 width=0) (never executed)
Index Cond: (dim1_id = ANY ('{1,2}'::integer[]))
-> Bitmap Heap Scan on usage_2018_02 (cost=9.07..13.10 rows=1 width=28) (actual time=0.002..0.002 rows=0 loops=1)
Recheck Cond: ((dim4_id = ANY ('{4,5}'::integer[])) AND (dim1_id = ANY ('{1,2}'::integer[])))
Filter: ((dim2_id = ANY ('{2,3}'::integer[])) AND (dim3_id = ANY ('{3,4}'::integer[])) AND (dim5_id = ANY ('{5,6}'::integer[])) AND (dim6_id = ANY ('{6,7}'::integer[])))
-> BitmapAnd (cost=9.07..9.07 rows=1 width=0) (actual time=0.002..0.002 rows=0 loops=1)
-> Bitmap Index Scan on usage_2018_02_dim4_id_dim5_id_dim6_id_dim1_id_dim2_id_dim3__idx (cost=0.00..4.41 rows=14 width=0) (actual time=0.002..0.002 rows=0 loops=1)
Index Cond: (dim4_id = ANY ('{4,5}'::integer[]))
-> Bitmap Index Scan on usage_2018_02_dim1_id_dim2_id_dim3_id_dim4_id_dim5_id_dim6__idx (cost=0.00..4.41 rows=14 width=0) (never executed)
Index Cond: (dim1_id = ANY ('{1,2}'::integer[]))
-> Bitmap Heap Scan on usage_2018_03 (cost=9.07..13.10 rows=1 width=28) (actual time=0.003..0.003 rows=0 loops=1)
Recheck Cond: ((dim4_id = ANY ('{4,5}'::integer[])) AND (dim1_id = ANY ('{1,2}'::integer[])))
Filter: ((dim2_id = ANY ('{2,3}'::integer[])) AND (dim3_id = ANY ('{3,4}'::integer[])) AND (dim5_id = ANY ('{5,6}'::integer[])) AND (dim6_id = ANY ('{6,7}'::integer[])))
-> BitmapAnd (cost=9.07..9.07 rows=1 width=0) (actual time=0.003..0.003 rows=0 loops=1)
-> Bitmap Index Scan on usage_2018_03_dim4_id_dim5_id_dim6_id_dim1_id_dim2_id_dim3__idx (cost=0.00..4.41 rows=14 width=0) (actual time=0.003..0.003 rows=0 loops=1)
Index Cond: (dim4_id = ANY ('{4,5}'::integer[]))
-> Bitmap Index Scan on usage_2018_03_dim1_id_dim2_id_dim3_id_dim4_id_dim5_id_dim6__idx (cost=0.00..4.41 rows=14 width=0) (never executed)
Index Cond: (dim1_id = ANY ('{1,2}'::integer[]))
-> Bitmap Heap Scan on usage_2018_04 (cost=9.07..13.10 rows=1 width=28) (actual time=0.005..0.005 rows=0 loops=1)
Recheck Cond: ((dim4_id = ANY ('{4,5}'::integer[])) AND (dim1_id = ANY ('{1,2}'::integer[])))
Filter: ((dim2_id = ANY ('{2,3}'::integer[])) AND (dim3_id = ANY ('{3,4}'::integer[])) AND (dim5_id = ANY ('{5,6}'::integer[])) AND (dim6_id = ANY ('{6,7}'::integer[])))
-> BitmapAnd (cost=9.07..9.07 rows=1 width=0) (actual time=0.001..0.001 rows=0 loops=1)
-> Bitmap Index Scan on usage_2018_04_dim4_id_dim5_id_dim6_id_dim1_id_dim2_id_dim3__idx (cost=0.00..4.41 rows=14 width=0) (actual time=0.001..0.001 rows=0 loops=1)
Index Cond: (dim4_id = ANY ('{4,5}'::integer[]))
-> Bitmap Index Scan on usage_2018_04_dim1_id_dim2_id_dim3_id_dim4_id_dim5_id_dim6__idx (cost=0.00..4.41 rows=14 width=0) (never executed)
Index Cond: (dim1_id = ANY ('{1,2}'::integer[]))
-> Bitmap Heap Scan on usage_2018_05 (cost=9.07..13.10 rows=1 width=28) (actual time=0.002..0.002 rows=0 loops=1)
Recheck Cond: ((dim4_id = ANY ('{4,5}'::integer[])) AND (dim1_id = ANY ('{1,2}'::integer[])))
Filter: ((dim2_id = ANY ('{2,3}'::integer[])) AND (dim3_id = ANY ('{3,4}'::integer[])) AND (dim5_id = ANY ('{5,6}'::integer[])) AND (dim6_id = ANY ('{6,7}'::integer[])))
-> BitmapAnd (cost=9.07..9.07 rows=1 width=0) (actual time=0.002..0.002 rows=0 loops=1)
-> Bitmap Index Scan on usage_2018_05_dim4_id_dim5_id_dim6_id_dim1_id_dim2_id_dim3__idx (cost=0.00..4.41 rows=14 width=0) (actual time=0.002..0.002 rows=0 loops=1)
Index Cond: (dim4_id = ANY ('{4,5}'::integer[]))
-> Bitmap Index Scan on usage_2018_05_dim1_id_dim2_id_dim3_id_dim4_id_dim5_id_dim6__idx (cost=0.00..4.41 rows=14 width=0) (never executed)
Index Cond: (dim1_id = ANY ('{1,2}'::integer[]))
-> Bitmap Heap Scan on usage_2018_06 (cost=9.07..13.10 rows=1 width=28) (actual time=0.005..0.005 rows=0 loops=1)
Recheck Cond: ((dim4_id = ANY ('{4,5}'::integer[])) AND (dim1_id = ANY ('{1,2}'::integer[])))
Filter: ((dim2_id = ANY ('{2,3}'::integer[])) AND (dim3_id = ANY ('{3,4}'::integer[])) AND (dim5_id = ANY ('{5,6}'::integer[])) AND (dim6_id = ANY ('{6,7}'::integer[])))
-> BitmapAnd (cost=9.07..9.07 rows=1 width=0) (actual time=0.002..0.002 rows=0 loops=1)
-> Bitmap Index Scan on usage_2018_06_dim4_id_dim5_id_dim6_id_dim1_id_dim2_id_dim3__idx (cost=0.00..4.41 rows=14 width=0) (actual time=0.002..0.002 rows=0 loops=1)
Index Cond: (dim4_id = ANY ('{4,5}'::integer[]))
-> Bitmap Index Scan on usage_2018_06_dim1_id_dim2_id_dim3_id_dim4_id_dim5_id_dim6__idx (cost=0.00..4.41 rows=14 width=0) (never executed)
Index Cond: (dim1_id = ANY ('{1,2}'::integer[]))
-> Bitmap Heap Scan on usage_2018_07 (cost=9.07..13.10 rows=1 width=28) (actual time=0.002..0.002 rows=0 loops=1)
Recheck Cond: ((dim4_id = ANY ('{4,5}'::integer[])) AND (dim1_id = ANY ('{1,2}'::integer[])))
Filter: ((dim2_id = ANY ('{2,3}'::integer[])) AND (dim3_id = ANY ('{3,4}'::integer[])) AND (dim5_id = ANY ('{5,6}'::integer[])) AND (dim6_id = ANY ('{6,7}'::integer[])))
-> BitmapAnd (cost=9.07..9.07 rows=1 width=0) (actual time=0.002..0.002 rows=0 loops=1)
-> Bitmap Index Scan on usage_2018_07_dim4_id_dim5_id_dim6_id_dim1_id_dim2_id_dim3__idx (cost=0.00..4.41 rows=14 width=0) (actual time=0.002..0.002 rows=0 loops=1)
Index Cond: (dim4_id = ANY ('{4,5}'::integer[]))
-> Bitmap Index Scan on usage_2018_07_dim1_id_dim2_id_dim3_id_dim4_id_dim5_id_dim6__idx (cost=0.00..4.41 rows=14 width=0) (never executed)
Index Cond: (dim1_id = ANY ('{1,2}'::integer[]))
-> Bitmap Heap Scan on usage_2018_08 (cost=9.07..13.10 rows=1 width=28) (actual time=0.004..0.004 rows=0 loops=1)
Recheck Cond: ((dim4_id = ANY ('{4,5}'::integer[])) AND (dim1_id = ANY ('{1,2}'::integer[])))
Filter: ((dim2_id = ANY ('{2,3}'::integer[])) AND (dim3_id = ANY ('{3,4}'::integer[])) AND (dim5_id = ANY ('{5,6}'::integer[])) AND (dim6_id = ANY ('{6,7}'::integer[])))
-> BitmapAnd (cost=9.07..9.07 rows=1 width=0) (actual time=0.002..0.002 rows=0 loops=1)
-> Bitmap Index Scan on usage_2018_08_dim4_id_dim5_id_dim6_id_dim1_id_dim2_id_dim3__idx (cost=0.00..4.41 rows=14 width=0) (actual time=0.002..0.002 rows=0 loops=1)
Index Cond: (dim4_id = ANY ('{4,5}'::integer[]))
-> Bitmap Index Scan on usage_2018_08_dim1_id_dim2_id_dim3_id_dim4_id_dim5_id_dim6__idx (cost=0.00..4.41 rows=14 width=0) (never executed)
Index Cond: (dim1_id = ANY ('{1,2}'::integer[]))
-> Bitmap Heap Scan on usage_2018_09 (cost=9.07..13.10 rows=1 width=28) (actual time=0.002..0.002 rows=0 loops=1)
Recheck Cond: ((dim4_id = ANY ('{4,5}'::integer[])) AND (dim1_id = ANY ('{1,2}'::integer[])))
Filter: ((dim2_id = ANY ('{2,3}'::integer[])) AND (dim3_id = ANY ('{3,4}'::integer[])) AND (dim5_id = ANY ('{5,6}'::integer[])) AND (dim6_id = ANY ('{6,7}'::integer[])))
-> BitmapAnd (cost=9.07..9.07 rows=1 width=0) (actual time=0.002..0.002 rows=0 loops=1)
-> Bitmap Index Scan on usage_2018_09_dim4_id_dim5_id_dim6_id_dim1_id_dim2_id_dim3__idx (cost=0.00..4.41 rows=14 width=0) (actual time=0.002..0.002 rows=0 loops=1)
Index Cond: (dim4_id = ANY ('{4,5}'::integer[]))
-> Bitmap Index Scan on usage_2018_09_dim1_id_dim2_id_dim3_id_dim4_id_dim5_id_dim6__idx (cost=0.00..4.41 rows=14 width=0) (never executed)
Index Cond: (dim1_id = ANY ('{1,2}'::integer[]))
-> Bitmap Heap Scan on usage_2018_10 (cost=9.07..13.10 rows=1 width=28) (actual time=0.003..0.003 rows=0 loops=1)
Recheck Cond: ((dim4_id = ANY ('{4,5}'::integer[])) AND (dim1_id = ANY ('{1,2}'::integer[])))
Filter: ((dim2_id = ANY ('{2,3}'::integer[])) AND (dim3_id = ANY ('{3,4}'::integer[])) AND (dim5_id = ANY ('{5,6}'::integer[])) AND (dim6_id = ANY ('{6,7}'::integer[])))
-> BitmapAnd (cost=9.07..9.07 rows=1 width=0) (actual time=0.003..0.003 rows=0 loops=1)
-> Bitmap Index Scan on usage_2018_10_dim4_id_dim5_id_dim6_id_dim1_id_dim2_id_dim3__idx (cost=0.00..4.41 rows=14 width=0) (actual time=0.003..0.003 rows=0 loops=1)
Index Cond: (dim4_id = ANY ('{4,5}'::integer[]))
-> Bitmap Index Scan on usage_2018_10_dim1_id_dim2_id_dim3_id_dim4_id_dim5_id_dim6__idx (cost=0.00..4.41 rows=14 width=0) (never executed)
Index Cond: (dim1_id = ANY ('{1,2}'::integer[]))
-> Bitmap Heap Scan on usage_2018_11 (cost=9.07..13.10 rows=1 width=28) (actual time=0.002..0.002 rows=0 loops=1)
Recheck Cond: ((dim4_id = ANY ('{4,5}'::integer[])) AND (dim1_id = ANY ('{1,2}'::integer[])))
Filter: ((dim2_id = ANY ('{2,3}'::integer[])) AND (dim3_id = ANY ('{3,4}'::integer[])) AND (dim5_id = ANY ('{5,6}'::integer[])) AND (dim6_id = ANY ('{6,7}'::integer[])))
-> BitmapAnd (cost=9.07..9.07 rows=1 width=0) (actual time=0.001..0.001 rows=0 loops=1)
-> Bitmap Index Scan on usage_2018_11_dim4_id_dim5_id_dim6_id_dim1_id_dim2_id_dim3__idx (cost=0.00..4.41 rows=14 width=0) (actual time=0.001..0.001 rows=0 loops=1)
Index Cond: (dim4_id = ANY ('{4,5}'::integer[]))
-> Bitmap Index Scan on usage_2018_11_dim1_id_dim2_id_dim3_id_dim4_id_dim5_id_dim6__idx (cost=0.00..4.41 rows=14 width=0) (never executed)
Index Cond: (dim1_id = ANY ('{1,2}'::integer[]))
-> Bitmap Heap Scan on usage_2018_12 (cost=9.07..13.10 rows=1 width=28) (actual time=0.003..0.003 rows=0 loops=1)
Recheck Cond: ((dim4_id = ANY ('{4,5}'::integer[])) AND (dim1_id = ANY ('{1,2}'::integer[])))
Filter: ((dim2_id = ANY ('{2,3}'::integer[])) AND (dim3_id = ANY ('{3,4}'::integer[])) AND (dim5_id = ANY ('{5,6}'::integer[])) AND (dim6_id = ANY ('{6,7}'::integer[])))
-> BitmapAnd (cost=9.07..9.07 rows=1 width=0) (actual time=0.003..0.003 rows=0 loops=1)
-> Bitmap Index Scan on usage_2018_12_dim4_id_dim5_id_dim6_id_dim1_id_dim2_id_dim3__idx (cost=0.00..4.41 rows=14 width=0) (actual time=0.003..0.003 rows=0 loops=1)
Index Cond: (dim4_id = ANY ('{4,5}'::integer[]))
-> Bitmap Index Scan on usage_2018_12_dim1_id_dim2_id_dim3_id_dim4_id_dim5_id_dim6__idx (cost=0.00..4.41 rows=14 width=0) (never executed)
Index Cond: (dim1_id = ANY ('{1,2}'::integer[]))
-> Index Only Scan using dim1_pkey on dim1 (cost=0.15..1.93 rows=1 width=4) (never executed)
Index Cond: (id = usage.dim1_id)
Heap Fetches: 0
-> Index Only Scan using dim2_pkey on dim2 (cost=0.15..1.93 rows=1 width=4) (never executed)
Index Cond: (id = usage.dim2_id)
Heap Fetches: 0
-> Index Only Scan using dim3_pkey on dim3 (cost=0.15..1.93 rows=1 width=4) (never executed)
Index Cond: (id = usage.dim3_id)
Heap Fetches: 0
-> Index Only Scan using dim4_pkey on dim4 (cost=0.15..1.93 rows=1 width=4) (never executed)
Index Cond: (id = usage.dim4_id)
Heap Fetches: 0
-> Index Only Scan using dim5_pkey on dim5 (cost=0.15..1.93 rows=1 width=4) (never executed)
Index Cond: (id = usage.dim5_id)
Heap Fetches: 0
-> Index Only Scan using dim6_pkey on dim6 (cost=0.15..1.93 rows=1 width=4) (never executed)
Index Cond: (id = usage.dim6_id)
Heap Fetches: 0
Planning time: 2017.584 ms
Execution time: 1.048 ms
Пробовал крутить настройки geqo, from_collapse_limit, join_collapse_limit, переформулировать запрос. Не помогает.
Как можно ускорить планирование этого запроса?
Не хотелось бы использовать prepared statements, потому что работаем через Django ORM.
Поможет ли здесь pg_pathman? Но check contraints в партиционировании не используем.
PS: При изменении условий теста замедление исчезает полностью или сокращается. Подробности ниже.
измененияисходный тест: Planning time: 2017.584 ms Execution time: 1.048 ms
без join dim*: Planning time: 14.284 ms Execution time: 1.893 ms
без индексов: Planning time: 18.578 ms Execution time: 0.447 ms
одна партиция: Planning time: 87.685 ms Execution time: 0.193 ms
без where: Planning time: 411.323 ms Execution time: 0.263 ms
|