daniilak

Untitled

Jun 4th, 2021 (edited)
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 1) psql (PostgreSQL) 11.9 (Debian 11.9-0+deb10u1)
  2. ___________________________________________________________________________________________________
  3. ___________________________________________________________________________________________________
  4. ___________________________________________________________________________________________________
  5. ___________________________________________________________________________________________________
  6. ___________________________________________________________________________________________________
  7. 2) Запрос
  8. SELECT "t1"."index_id" FROM "cache_table" AS "t1" INNER JOIN "houses" AS "t2" ON ("t1"."id_house" = "t2"."id") WHERE
  9. (("t2"."id_addresses""t1"."index_id" DESC LIMIT 100 OFFSET 0
  10. ___________________________________________________________________________________________________
  11. ___________________________________________________________________________________________________
  12. ___________________________________________________________________________________________________
  13. ___________________________________________________________________________________________________
  14. ___________________________________________________________________________________________________
  15. daniilak=# \d houses
  16.                                     Table "public.houses"
  17.     Column     |       Type       | Collation | Nullable |              Default
  18. ---------------+------------------+-----------+----------+------------------------------------
  19.  id            | integer          |           | not null | nextval('houses_id_seq'::regclass)
  20.  id_addresses  | integer          |           | not null |
  21.  object_type   | integer          |           | not null |
  22.  building_type | integer          |           | not null |
  23.  level         | integer          |           | not null |
  24.  levels        | integer          |           | not null |
  25.  rooms         | integer          |           | not null |
  26.  area          | double precision |           | not null |
  27.  kitchen_area  | double precision |           | not null |
  28.  cache         | text             |           |          |
  29. Indexes:
  30.     "houses_pkey" PRIMARY KEY, btree (id)
  31.     "houses_index" btree (id_addresses)
  32.     "houses_index_bt" btree (building_type)
  33.     "houses_index_level" btree (level)
  34.     "houses_index_levels" btree (levels)
  35.     "houses_index_ot" btree (object_type)
  36.     "houses_index_rooms" btree (rooms)
  37. ___________________________________________________________________________________________________
  38. ___________________________________________________________________________________________________
  39. ___________________________________________________________________________________________________
  40. daniilak=# \d cache_table
  41.                               Table "public.cache_table"
  42.   Column   |   Type   | Collation | Nullable |                 Default
  43. -----------+----------+-----------+----------+-----------------------------------------
  44.  id        | integer  |           | not null | nextval('cache_table_id_seq'::regclass)
  45.  id_house  | integer  |           |          |
  46.  index_id  | integer  |           |          |
  47.  year      | smallint |           |          |
  48.  month     | smallint |           |          |
  49.  day       | smallint |           |          |
  50.  is_actual | smallint |           |          |
  51. Indexes:
  52.     "cache_table_pkey" PRIMARY KEY, btree (id)
  53.     "cache_id_house" btree (id_house)
  54.     "cache_index_id" btree (index_id)
  55.     "cache_table_house_id_index_id" btree (id_house, index_id)
  56.     "cache_year" btree (year)
  57.  
  58. daniilak=#
  59.  
  60. ___________________________________________________________________________________________________
  61. ___________________________________________________________________________________________________
  62. ___________________________________________________________________________________________________
  63. ___________________________________________________________________________________________________
  64. ___________________________________________________________________________________________________
  65. 4) EXPLAIN (ANALYZE, BUFFERS).
  66. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  67.  Limit  (cost=1001.16..14871.56 rows=100 width=4) (actual time=1053.867..2323.809 rows=100 loops=1)
  68.    Buffers: shared hit=1799709 read=297868
  69.    ->  Gather Merge  (cost=1001.16..520607739.31 rows=3753366 width=4) (actual time=1053.865..2323.786 rows=100 loops=1)
  70.          Workers Planned: 2
  71.          Workers Launched: 2
  72.          Buffers: shared hit=1799709 read=297868
  73.          ->  Nested Loop  (cost=1.14..520173507.72 rows=1563902 width=4) (actual time=1019.601..2001.823 rows=46 loops=3)
  74.                Buffers: shared hit=1799709 read=297868
  75.                ->  Parallel Index Scan Backward using cache_index_id on cache_table t1  (cost=0.57..118451325.04 rows=62600747 width=8) (actual time=0.035..139.189 rows=124142 loops=3)
  76.                      Buffers: shared hit=124767 read=108346
  77.                ->  Index Scan using houses_pkey on houses t2  (cost=0.56..6.42 rows=1 width=4) (actual time=0.015..0.015 rows=0 loops=372426)
  78.                      Index Cond: (id = t1.id_house)
  79.                      Filter: (id_addresses = ANY ('{1300337,17473466,721185,17619259,619419,2732564,1192743,1338491,2220830,2499588,2295809,1400032,2999239,1826678,2937551,238916,1627147,1098697,722126,11702520,975851,11702689,11675572,11733586,752619,1721555,1048003,17567056,334995,...,17572575}'::integer[]))
  80.                      Rows Removed by Filter: 1
  81.                      Buffers: shared hit=1674942 read=189522
  82.  Planning Time: 4.559 ms
  83.  Execution Time: 2323.861 ms
  84. (17 rows)
  85. ___________________________________________________________________________________________________
  86. ___________________________________________________________________________________________________
  87. ___________________________________________________________________________________________________
  88. ___________________________________________________________________________________________________
  89. ___________________________________________________________________________________________________
  90. 5) создал индекс
  91. CREATE INDEX cache_table_house_id_index_id ON public.cache_table USING btree (id_house, index_id);
  92. Сделал vacuum full verbose houses;
  93. Сделал vacuum full verbose cache_table;
  94. 6) 
Add Comment
Please, Sign In to add comment