|
|
|
Огромная разница по времени выполнения запроса
|
|||
|---|---|---|---|
|
#18+
Доброго дня всем, Помогите, пожалуйста, разобраться. При примерно одинаковом количестве строк на выводе, при разных входящих данных один и тот-же запрос выполняется либо 1-2 секунды, либо 25 МИНУТ! Меняется только WHERE LA_ART_ID = 1359385 на 1359418. В одиночные кавычки ставить пробовал, таблицы проиндексированы. Заранее огромное спасибо. Вот сам запрос: SELECT TYP_ID, MFA_BRAND, DES_TEXTS7.TEX_TEXT AS MOD_CDS_TEXT, TOF_DES_TEXTS.TEX_TEXT AS TYP_CDS_TEXT, TYP_PCON_START, TYP_PCON_END, TYP_CCM, TYP_KW_FROM, TYP_KW_UPTO, TYP_HP_FROM, TYP_HP_UPTO, TYP_CYLINDERS, string_agg(TOF_ENGINES.ENG_CODE, ', '), DES_TEXTS2.TEX_TEXT AS TYP_ENGINE_DES_TEXT, DES_TEXTS3.TEX_TEXT AS TYP_FUEL_DES_TEXT, CASE WHEN DES_TEXTS4.TEX_TEXT IS NULL THEN DES_TEXTS5.TEX_TEXT ELSE DES_TEXTS4.TEX_TEXT END AS TYP_BODY_DES_TEXT, DES_TEXTS6.TEX_TEXT AS TYP_AXLE_DES_TEXT, TYP_MAX_WEIGHT FROM TOF_LINK_ART INNER JOIN TOF_LINK_LA_TYP ON LAT_LA_ID = LA_ID AND SUBSTRING(lat_ctm FROM 249 FOR 1)='1' INNER JOIN TOF_TYPES ON TYP_ID = LAT_TYP_ID AND SUBSTRING(typ_ctm FROM 249 FOR 1)='1' INNER JOIN TOF_COUNTRY_DESIGNATIONS ON TOF_COUNTRY_DESIGNATIONS.CDS_ID = TYP_CDS_ID INNER JOIN TOF_DES_TEXTS ON TOF_DES_TEXTS.TEX_ID = TOF_COUNTRY_DESIGNATIONS.CDS_TEX_ID INNER JOIN TOF_MODELS ON MOD_ID = TYP_MOD_ID INNER JOIN TOF_MANUFACTURERS ON MFA_ID = MOD_MFA_ID INNER JOIN TOF_COUNTRY_DESIGNATIONS AS COUNTRY_DESIGNATIONS2 ON COUNTRY_DESIGNATIONS2.CDS_ID = MOD_CDS_ID AND SUBSTRING(COUNTRY_DESIGNATIONS2.cds_ctm FROM 249 FOR 1)='1' INNER JOIN TOF_DES_TEXTS AS DES_TEXTS7 ON DES_TEXTS7.TEX_ID = COUNTRY_DESIGNATIONS2.CDS_TEX_ID LEFT JOIN TOF_DESIGNATIONS ON TOF_DESIGNATIONS.DES_ID = TYP_KV_ENGINE_DES_ID LEFT JOIN TOF_DES_TEXTS AS DES_TEXTS2 ON DES_TEXTS2.TEX_ID = TOF_DESIGNATIONS.DES_TEX_ID LEFT JOIN TOF_DESIGNATIONS AS DESIGNATIONS2 ON DESIGNATIONS2.DES_ID = TYP_KV_FUEL_DES_ID LEFT JOIN TOF_DES_TEXTS AS DES_TEXTS3 ON DES_TEXTS3.TEX_ID = DESIGNATIONS2.DES_TEX_ID LEFT JOIN TOF_LINK_TYP_ENG ON LTE_TYP_ID = TYP_ID LEFT JOIN TOF_ENGINES ON ENG_ID = LTE_ENG_ID LEFT JOIN TOF_DESIGNATIONS AS DESIGNATIONS3 ON DESIGNATIONS3.DES_ID = TYP_KV_BODY_DES_ID LEFT JOIN TOF_DES_TEXTS AS DES_TEXTS4 ON DES_TEXTS4.TEX_ID = DESIGNATIONS3.DES_TEX_ID LEFT JOIN TOF_DESIGNATIONS AS DESIGNATIONS4 ON DESIGNATIONS4.DES_ID = TYP_KV_MODEL_DES_ID LEFT JOIN TOF_DES_TEXTS AS DES_TEXTS5 ON DES_TEXTS5.TEX_ID = DESIGNATIONS4.DES_TEX_ID LEFT JOIN TOF_DESIGNATIONS AS DESIGNATIONS5 ON DESIGNATIONS5.DES_ID = TYP_KV_AXLE_DES_ID LEFT JOIN TOF_DES_TEXTS AS DES_TEXTS6 ON DES_TEXTS6.TEX_ID = DESIGNATIONS5.DES_TEX_ID WHERE LA_ART_ID = 1359385 AND TOF_COUNTRY_DESIGNATIONS.CDS_LNG_ID = 37 AND COUNTRY_DESIGNATIONS2.CDS_LNG_ID = 37 AND (TOF_DESIGNATIONS.DES_LNG_ID IS NULL OR TOF_DESIGNATIONS.DES_LNG_ID = 37) AND (DESIGNATIONS2.DES_LNG_ID IS NULL OR DESIGNATIONS2.DES_LNG_ID = 37) AND (DESIGNATIONS3.DES_LNG_ID IS NULL OR DESIGNATIONS3.DES_LNG_ID = 37) AND (DESIGNATIONS4.DES_LNG_ID IS NULL OR DESIGNATIONS4.DES_LNG_ID = 37) AND (DESIGNATIONS5.DES_LNG_ID IS NULL OR DESIGNATIONS5.DES_LNG_ID = 37) AND SUBSTRING(la_ctm FROM 249 FOR 1)='1' GROUP BY tof_types.typ_id, tof_manufacturers.mfa_brand, des_texts7.tex_text, tof_des_texts.tex_text, TYP_PCON_START, TYP_PCON_END, TYP_CCM, TYP_KW_FROM, TYP_KW_UPTO, TYP_HP_FROM, TYP_HP_UPTO, TYP_CYLINDERS , des_texts2.tex_text, des_texts3.tex_text, des_texts4.tex_text, des_texts5.tex_text, des_texts6.tex_text ORDER BY MFA_BRAND, MOD_CDS_TEXT, TYP_CDS_TEXT, TYP_PCON_START, TYP_CCM ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 05.11.2014, 16:53:15 |
|
||
|
Огромная разница по времени выполнения запроса
|
|||
|---|---|---|---|
|
#18+
sabbath66Доброго дня всем, Помогите, пожалуйста, разобраться. При примерно одинаковом количестве строк на выводе, при разных входящих данных один и тот-же запрос выполняется либо 1-2 секунды, либо 25 МИНУТ! Меняется только WHERE LA_ART_ID = 1359385 на 1359418. В одиночные кавычки ставить пробовал, таблицы проиндексированы. Заранее огромное спасибо. Вот сам запрос: поправил Код: sql 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. планы где ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 05.11.2014, 17:03:53 |
|
||
|
Огромная разница по времени выполнения запроса
|
|||
|---|---|---|---|
|
#18+
>> планы где В смысле?... Я не слишком большой знаток :) ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 05.11.2014, 17:35:39 |
|
||
|
Огромная разница по времени выполнения запроса
|
|||
|---|---|---|---|
|
#18+
... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 05.11.2014, 17:38:12 |
|
||
|
Огромная разница по времени выполнения запроса
|
|||
|---|---|---|---|
|
#18+
Планы для быстрого запроса "Sort (cost=2139.20..2139.20 rows=1 width=315)" " Sort Key: tof_manufacturers.mfa_brand, des_texts7.tex_text, tof_des_texts.tex_text, tof_types.typ_pcon_start, tof_types.typ_ccm" " -> HashAggregate (cost=2139.17..2139.19 rows=1 width=315)" " -> Nested Loop Left Join (cost=19.06..2139.13 rows=1 width=315)" " -> Nested Loop Left Join (cost=18.63..2130.75 rows=1 width=282)" " Filter: ((designations5.des_lng_id IS NULL) OR (designations5.des_lng_id = 37))" " -> Nested Loop Left Join (cost=18.21..2121.62 rows=1 width=282)" " -> Nested Loop Left Join (cost=17.78..2113.24 rows=1 width=249)" " Filter: ((designations4.des_lng_id IS NULL) OR (designations4.des_lng_id = 37))" " -> Nested Loop Left Join (cost=17.36..2104.10 rows=1 width=249)" " -> Nested Loop Left Join (cost=16.93..2095.73 rows=1 width=216)" " Filter: ((designations3.des_lng_id IS NULL) OR (designations3.des_lng_id = 37))" " -> Nested Loop Left Join (cost=16.50..2086.59 rows=1 width=216)" " -> Nested Loop Left Join (cost=16.22..2078.39 rows=1 width=212)" " -> Nested Loop Left Join (cost=15.93..2070.15 rows=1 width=208)" " -> Nested Loop Left Join (cost=15.50..2061.77 rows=1 width=175)" " Filter: ((designations2.des_lng_id IS NULL) OR (designations2.des_lng_id = 37))" " -> Nested Loop Left Join (cost=15.07..2052.63 rows=1 width=175)" " -> Nested Loop Left Join (cost=14.65..2044.26 rows=1 width=142)" " Filter: ((tof_designations.des_lng_id IS NULL) OR (tof_designations.des_lng_id = 37))" " -> Nested Loop (cost=14.22..2035.12 rows=1 width=142)" " -> Nested Loop (cost=13.79..2026.73 rows=1 width=109)" " Join Filter: (tof_models.mod_mfa_id = tof_manufacturers.mfa_id)" " -> Nested Loop (cost=13.79..2004.00 rows=1 width=102)" " -> Nested Loop (cost=13.37..1995.62 rows=1 width=69)" " -> Nested Loop (cost=12.93..1985.83 rows=1 width=69)" " -> Nested Loop (cost=12.50..1975.78 rows=1 width=69)" " -> Nested Loop (cost=12.22..1967.62 rows=1 width=67)" " -> Nested Loop (cost=11.92..1959.38 rows=1 width=4)" " -> Index Scan using tof_link_art_la_art_id_idx on tof_link_art (cost=0.44..405.35 rows=1 width=4)" " Index Cond: (la_art_id = 1359385)" " Filter: ("substring"((la_ctm)::"bit", 249, 1) = B'1'::"bit")" " -> Bitmap Heap Scan on tof_link_la_typ (cost=11.49..1554.01 rows=2 width=8)" " Recheck Cond: (lat_la_id = tof_link_art.la_id)" " Filter: ("substring"((lat_ctm)::"bit", 249, 1) = B'1'::"bit")" " -> Bitmap Index Scan on tof_link_la_typ_lat_la_id_idx (cost=0.00..11.49 rows=389 width=0)" " Index Cond: (lat_la_id = tof_link_art.la_id)" " -> Index Scan using tof_types_typ_id_idx on tof_types (cost=0.29..8.24 rows=1 width=67)" " Index Cond: (typ_id = tof_link_la_typ.lat_typ_id)" " Filter: ("substring"((typ_ctm)::"bit", 249, 1) = B'1'::"bit")" " -> Index Scan using tof_models_mod_id_idx on tof_models (cost=0.29..8.15 rows=1 width=10)" " Index Cond: (mod_id = tof_types.typ_mod_id)" " -> Index Scan using tof_country_designations_cds_id_idx on tof_country_designations country_designations2 (cost=0.43..10.03 rows=1 width=8)" " Index Cond: (cds_id = tof_models.mod_cds_id)" " Filter: ((cds_lng_id = 37) AND ("substring"((cds_ctm)::"bit", 249, 1) = B'1'::"bit"))" " -> Index Scan using tof_country_designations_cds_id_idx on tof_country_designations (cost=0.43..9.77 rows=2 width=8)" " Index Cond: (cds_id = tof_types.typ_cds_id)" " Filter: (cds_lng_id = 37)" " -> Index Scan using tof_des_texts_tex_id_idx on tof_des_texts (cost=0.43..8.37 rows=1 width=41)" " Index Cond: (tex_id = tof_country_designations.cds_tex_id)" " -> Seq Scan on tof_manufacturers (cost=0.00..15.66 rows=566 width=11)" " -> Index Scan using tof_des_texts_tex_id_idx on tof_des_texts des_texts7 (cost=0.43..8.38 rows=1 width=41)" " Index Cond: (tex_id = country_designations2.cds_tex_id)" " -> Index Scan using tof_designations_des_id_idx on tof_designations (cost=0.42..8.81 rows=26 width=10)" " Index Cond: (des_id = tof_types.typ_kv_engine_des_id)" " -> Index Scan using tof_des_texts_tex_id_idx on tof_des_texts des_texts2 (cost=0.43..8.37 rows=1 width=41)" " Index Cond: (tex_id = tof_designations.des_tex_id)" " -> Index Scan using tof_designations_des_id_idx on tof_designations designations2 (cost=0.42..8.81 rows=26 width=10)" " Index Cond: (des_id = tof_types.typ_kv_fuel_des_id)" " -> Index Scan using tof_des_texts_tex_id_idx on tof_des_texts des_texts3 (cost=0.43..8.37 rows=1 width=41)" " Index Cond: (tex_id = designations2.des_tex_id)" " -> Index Scan using tof_link_typ_eng_lte_typ_id_idx on tof_link_typ_eng (cost=0.29..8.23 rows=1 width=8)" " Index Cond: (lte_typ_id = tof_types.typ_id)" " -> Index Scan using tof_engines_eng_id_idx on tof_engines (cost=0.29..8.19 rows=1 width=12)" " Index Cond: (eng_id = tof_link_typ_eng.lte_eng_id)" " -> Index Scan using tof_designations_des_id_idx on tof_designations designations3 (cost=0.42..8.81 rows=26 width=10)" " Index Cond: (des_id = tof_types.typ_kv_body_des_id)" " -> Index Scan using tof_des_texts_tex_id_idx on tof_des_texts des_texts4 (cost=0.43..8.37 rows=1 width=41)" " Index Cond: (tex_id = designations3.des_tex_id)" " -> Index Scan using tof_designations_des_id_idx on tof_designations designations4 (cost=0.42..8.81 rows=26 width=10)" " Index Cond: (des_id = tof_types.typ_kv_model_des_id)" " -> Index Scan using tof_des_texts_tex_id_idx on tof_des_texts des_texts5 (cost=0.43..8.37 rows=1 width=41)" " Index Cond: (tex_id = designations4.des_tex_id)" " -> Index Scan using tof_designations_des_id_idx on tof_designations designations5 (cost=0.42..8.81 rows=26 width=10)" " Index Cond: (des_id = tof_types.typ_kv_axle_des_id)" " -> Index Scan using tof_des_texts_tex_id_idx on tof_des_texts des_texts6 (cost=0.43..8.37 rows=1 width=41)" " Index Cond: (tex_id = designations5.des_tex_id)" для медленного запроса "Sort (cost=9526.92..9526.93 rows=1 width=315)" " Sort Key: tof_manufacturers.mfa_brand, des_texts7.tex_text, tof_des_texts.tex_text, tof_types.typ_pcon_start, tof_types.typ_ccm" " -> HashAggregate (cost=9526.90..9526.91 rows=1 width=315)" " -> Nested Loop Left Join (cost=433.74..9526.85 rows=1 width=315)" " -> Nested Loop Left Join (cost=433.32..9518.48 rows=1 width=282)" " Filter: ((designations5.des_lng_id IS NULL) OR (designations5.des_lng_id = 37))" " -> Nested Loop Left Join (cost=432.89..9509.34 rows=1 width=282)" " -> Nested Loop Left Join (cost=432.46..9500.96 rows=1 width=249)" " Filter: ((designations4.des_lng_id IS NULL) OR (designations4.des_lng_id = 37))" " -> Nested Loop Left Join (cost=432.04..9491.83 rows=1 width=249)" " -> Nested Loop Left Join (cost=431.61..9483.45 rows=1 width=216)" " Filter: ((designations3.des_lng_id IS NULL) OR (designations3.des_lng_id = 37))" " -> Nested Loop Left Join (cost=431.19..9474.31 rows=1 width=216)" " -> Nested Loop Left Join (cost=430.90..9466.11 rows=1 width=212)" " -> Nested Loop Left Join (cost=430.61..9457.87 rows=1 width=208)" " -> Nested Loop Left Join (cost=430.18..9449.50 rows=1 width=175)" " Filter: ((designations2.des_lng_id IS NULL) OR (designations2.des_lng_id = 37))" " -> Nested Loop Left Join (cost=429.76..9440.36 rows=1 width=175)" " -> Nested Loop Left Join (cost=429.33..9431.98 rows=1 width=142)" " Filter: ((tof_designations.des_lng_id IS NULL) OR (tof_designations.des_lng_id = 37))" " -> Nested Loop (cost=428.90..9422.84 rows=1 width=142)" " -> Nested Loop (cost=428.48..9414.46 rows=1 width=109)" " -> Nested Loop (cost=428.20..9407.55 rows=1 width=102)" " -> Nested Loop (cost=427.77..9399.17 rows=1 width=69)" " -> Nested Loop (cost=427.34..9389.38 rows=1 width=69)" " -> Nested Loop (cost=426.90..9120.60 rows=32 width=73)" " -> Nested Loop (cost=426.34..6765.70 rows=4 width=69)" " -> Hash Join (cost=425.90..3180.04 rows=357 width=69)" " Hash Cond: (tof_types.typ_mod_id = tof_models.mod_id)" " -> Seq Scan on tof_types (cost=0.00..2747.44 rows=357 width=67)" " Filter: ("substring"((typ_ctm)::"bit", 249, 1) = B'1'::"bit")" " -> Hash (cost=289.29..289.29 rows=10929 width=10)" " -> Seq Scan on tof_models (cost=0.00..289.29 rows=10929 width=10)" " -> Index Scan using tof_country_designations_cds_id_idx on tof_country_designations country_designations2 (cost=0.43..10.03 rows=1 w (...)" " Index Cond: (cds_id = tof_models.mod_cds_id)" " Filter: ((cds_lng_id = 37) AND ("substring"((cds_ctm)::"bit", 249, 1) = B'1'::"bit"))" " -> Index Scan using tof_link_la_typ_lat_typ_id_idx on tof_link_la_typ (cost=0.57..588.35 rows=38 width=8)" " Index Cond: (lat_typ_id = tof_types.typ_id)" " Filter: ("substring"((lat_ctm)::"bit", 249, 1) = B'1'::"bit")" " -> Index Scan using tof_link_art_la_id_idx on tof_link_art (cost=0.44..8.39 rows=1 width=4)" " Index Cond: (la_id = tof_link_la_typ.lat_la_id)" " Filter: ((la_art_id = 1359418) AND ("substring"((la_ctm)::"bit", 249, 1) = B'1'::"bit"))" " -> Index Scan using tof_country_designations_cds_id_idx on tof_country_designations (cost=0.43..9.77 rows=2 width=8)" " Index Cond: (cds_id = tof_types.typ_cds_id)" " Filter: (cds_lng_id = 37)" " -> Index Scan using tof_des_texts_tex_id_idx on tof_des_texts (cost=0.43..8.37 rows=1 width=41)" " Index Cond: (tex_id = tof_country_designations.cds_tex_id)" " -> Index Scan using tof_manufacturers_mfa_id_idx on tof_manufacturers (cost=0.28..6.90 rows=1 width=11)" " Index Cond: (mfa_id = tof_models.mod_mfa_id)" " -> Index Scan using tof_des_texts_tex_id_idx on tof_des_texts des_texts7 (cost=0.43..8.38 rows=1 width=41)" " Index Cond: (tex_id = country_designations2.cds_tex_id)" " -> Index Scan using tof_designations_des_id_idx on tof_designations (cost=0.42..8.81 rows=26 width=10)" " Index Cond: (des_id = tof_types.typ_kv_engine_des_id)" " -> Index Scan using tof_des_texts_tex_id_idx on tof_des_texts des_texts2 (cost=0.43..8.37 rows=1 width=41)" " Index Cond: (tex_id = tof_designations.des_tex_id)" " -> Index Scan using tof_designations_des_id_idx on tof_designations designations2 (cost=0.42..8.81 rows=26 width=10)" " Index Cond: (des_id = tof_types.typ_kv_fuel_des_id)" " -> Index Scan using tof_des_texts_tex_id_idx on tof_des_texts des_texts3 (cost=0.43..8.37 rows=1 width=41)" " Index Cond: (tex_id = designations2.des_tex_id)" " -> Index Scan using tof_link_typ_eng_lte_typ_id_idx on tof_link_typ_eng (cost=0.29..8.23 rows=1 width=8)" " Index Cond: (lte_typ_id = tof_types.typ_id)" " -> Index Scan using tof_engines_eng_id_idx on tof_engines (cost=0.29..8.19 rows=1 width=12)" " Index Cond: (eng_id = tof_link_typ_eng.lte_eng_id)" " -> Index Scan using tof_designations_des_id_idx on tof_designations designations3 (cost=0.42..8.81 rows=26 width=10)" " Index Cond: (des_id = tof_types.typ_kv_body_des_id)" " -> Index Scan using tof_des_texts_tex_id_idx on tof_des_texts des_texts4 (cost=0.43..8.37 rows=1 width=41)" " Index Cond: (tex_id = designations3.des_tex_id)" " -> Index Scan using tof_designations_des_id_idx on tof_designations designations4 (cost=0.42..8.81 rows=26 width=10)" " Index Cond: (des_id = tof_types.typ_kv_model_des_id)" " -> Index Scan using tof_des_texts_tex_id_idx on tof_des_texts des_texts5 (cost=0.43..8.37 rows=1 width=41)" " Index Cond: (tex_id = designations4.des_tex_id)" " -> Index Scan using tof_designations_des_id_idx on tof_designations designations5 (cost=0.42..8.81 rows=26 width=10)" " Index Cond: (des_id = tof_types.typ_kv_axle_des_id)" " -> Index Scan using tof_des_texts_tex_id_idx on tof_des_texts des_texts6 (cost=0.43..8.37 rows=1 width=41)" " Index Cond: (tex_id = designations5.des_tex_id)" ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 05.11.2014, 17:55:15 |
|
||
|
Огромная разница по времени выполнения запроса
|
|||
|---|---|---|---|
|
#18+
sabbath66Планы для быстрого запроса поправил Код: sql 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. для медленного запроса поправил Код: sql 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. приведите explain analyze для медленного -- попробуйте запретить перед выполнением Код: sql 1. ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 05.11.2014, 18:09:12 |
|
||
|
Огромная разница по времени выполнения запроса
|
|||
|---|---|---|---|
|
#18+
explain analyze для быстрого запроса (Total runtime: 3211.937 ms) Код: sql 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. для медленного запроса (Total runtime: 2515331.458 ms) Код: sql 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. ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 05.11.2014, 20:00:27 |
|
||
|
Огромная разница по времени выполнения запроса
|
|||
|---|---|---|---|
|
#18+
sabbath66, Код: sql 1. такой индекс должен помочь планнеру выбрать более оптимальный план, а не бегать в цикле 150М раз. ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 05.11.2014, 20:31:36 |
|
||
|
Огромная разница по времени выполнения запроса
|
|||
|---|---|---|---|
|
#18+
Спасибо, но увы, не помогло :( ... ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 06.11.2014, 10:08:49 |
|
||
|
Огромная разница по времени выполнения запроса
|
|||
|---|---|---|---|
|
#18+
sabbath66Спасибо, но увы, не помогло :( ...а план где ? да, приведите план analyze и без SET enable-xxx TO OFF; (т.е. после RESET ALL;) И как -то расставьте везде в связках и т.п. табличные префиксы (алиасы), -- лениво, знаете ли, за вас высчитывать "кто на ком стоял". (есть идея, что там у вас агрегируется всего одно поле, и можно все прочее прикрутить после агрегирования, а не напрягать планер попусту вариантами. но читать вашу кашу бесконечно лениво). если условие 47 (или 73) -- константное -- ещё и условные индесы по нему могут сгодиццо, а где-то еше и по смеси 37 и декомпозиций типа AND SUBSTRING(la_ctm FROM 249 FOR 1)='1' . ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 06.11.2014, 10:19:23 |
|
||
|
Огромная разница по времени выполнения запроса
|
|||
|---|---|---|---|
|
#18+
sabbath66, странно. если сильно не вникать в запрос, можно еще посоветовать выкрутить для запроса: Код: sql 1. 2. а по-хорошему - нужно, конечно, переписать запрос в более понятном человеку и планировщику виде (используя CTE, подзапросы). ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 06.11.2014, 11:15:44 |
|
||
|
Огромная разница по времени выполнения запроса
|
|||
|---|---|---|---|
|
#18+
Вот, вроде все расставил... Запрос: Код: sql 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. план - быстрый - reset all Код: sql 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. план - быстрый - hashjoin off Код: sql 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. план - медленный - reset all Код: sql 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. план - медленный - hashjoin off Код: sql 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. Alexius >>а по-хорошему - нужно, конечно, переписать запрос в более понятном человеку и планировщику виде (используя CTE, подзапросы). Да в принципе запрос нормально работает в 99.99% случаев уже больше года, исполняясь сотни раз в день, такие тормоза - единичны, но все-таки иногда напрягают. А насчет переписать - тут еще подучиться надо ;) З.Ы. Код: sql 1. 2. Тоже не помогло... ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 06.11.2014, 16:09:18 |
|
||
|
Огромная разница по времени выполнения запроса
|
|||
|---|---|---|---|
|
#18+
sabbath66, Что-то со статистиками. Для быстро запроса ошибка по записям где-то в районе 4-8 тысяч, что в вашем случае не критично: Код: sql 1. Для медленного ошибка очень большая: Код: sql 1. 1. Какая версия Postgres? 2. Включен ли autovacuum? `SELECT name,setting FROM pg_settings WHERE name ~ 'autovacuum';` 3. Как настроена база? `SELECT name,setting FROM pg_settings WHERE source NOT IN ('default','override');` 4. Как давно анализировались/vacuum-ировались таблицы из запроса? `SELECT * FROM pg_stat_user_tables WHERE relname ~ '^tof';` ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 06.11.2014, 17:00:42 |
|
||
|
Огромная разница по времени выполнения запроса
|
|||
|---|---|---|---|
|
#18+
vyegorov, там у него по 150 000 000 loops-ов кое-где (кстати выводит планы скорее всего в пгадмине, а длина текстового поля ограничена примерно 255 -- самого интересного кое-где и не видно). ну и читать исходный запрос -- не подарок. ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 06.11.2014, 17:19:19 |
|
||
|
|

start [/forum/topic.php?fid=53&fpage=120&tid=1998373]: |
0ms |
get settings: |
7ms |
get forum list: |
13ms |
check forum access: |
2ms |
check topic access: |
2ms |
track hit: |
16ms |
get topic data: |
8ms |
get forum data: |
2ms |
get page messages: |
45ms |
get tp. blocked users: |
1ms |
| others: | 233ms |
| total: | 329ms |

| 0 / 0 |
