plans.txt

text/plain

Filename: plans.txt
Type: text/plain
Part: 0
Message: Re: strange slow query - lost lot of time somewhere
(2022-05-03 06:11:55) prd_aukro=# explain select itembo0_.id as col_0_0_, itembo0_.seller_id as col_1_0_
from item itembo0_
where (itembo0_.status_id in (1, 4, 5)) and
        itembo0_.starting_time<=current_timestamp and
    (itembo0_.ending_time is null or current_timestamp<itembo0_.ending_time) and
    not (exists (select itemmissin1_.id from item_missing_attribute itemmissin1_ where itemmissin1_.item_id=itembo0_.id)) and
    not (exists (
            select itemsharei2_.id
            from item_share_image itemsharei2_
                     cross join item_image itemimageb3_
            where itemsharei2_.item_image_id=itemimageb3_.id and itemsharei2_.item_id=itembo0_.id and itemimageb3_.thumbnail_ready=false)
        ) and
    exists (
            select itemsharei2_.id
            from item_share_image itemsharei2_
                     cross join item_image itemimageb3_
            where itemsharei2_.item_image_id=itemimageb3_.id and itemsharei2_.item_id=itembo0_.id)
        and
    (itembo0_.to_expose_date is null);
┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│                                                                                                  QUERY PLAN                                                                                                  │
├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ Nested Loop Anti Join  (cost=59.62..3166.65 rows=1 width=16)                                                                                                                                                 │
│   ->  Nested Loop Anti Join  (cost=59.34..3163.73 rows=1 width=16)                                                                                                                                           │
│         ->  Nested Loop Semi Join  (cost=58.48..3131.58 rows=1 width=16)                                                                                                                                     │
│               ->  Bitmap Heap Scan on item itembo0_  (cost=57.34..2706.71 rows=11 width=16)                                                                                                                  │
│                     Recheck Cond: ((ending_time IS NULL) OR ((status_id = ANY ('{1,4,5}'::bigint[])) AND (CURRENT_TIMESTAMP < ending_time) AND (starting_time <= CURRENT_TIMESTAMP)))                        │
│                     Filter: ((to_expose_date IS NULL) AND (status_id = ANY ('{1,4,5}'::bigint[])) AND (starting_time <= CURRENT_TIMESTAMP) AND ((ending_time IS NULL) OR (CURRENT_TIMESTAMP < ending_time))) │
│                     ->  BitmapOr  (cost=57.34..57.34 rows=1750 width=0)                                                                                                                                      │
│                           ->  Bitmap Index Scan on stehule354  (cost=0.00..2.08 rows=1 width=0)                                                                                                              │
│                                 Index Cond: (ending_time IS NULL)                                                                                                                                            │
│                           ->  Bitmap Index Scan on stehule1010  (cost=0.00..55.26 rows=1750 width=0)                                                                                                         │
│                                 Index Cond: ((status_id = ANY ('{1,4,5}'::bigint[])) AND (ending_time > CURRENT_TIMESTAMP) AND (starting_time <= CURRENT_TIMESTAMP))                                         │
│               ->  Nested Loop  (cost=1.14..37.71 rows=91 width=8)                                                                                                                                            │
│                     ->  Index Only Scan using uq_isi_itemid_itemimageid on item_share_image itemsharei2__1  (cost=0.57..3.80 rows=91 width=16)                                                               │
│                           Index Cond: (item_id = itembo0_.id)                                                                                                                                                │
│                     ->  Memoize  (cost=0.57..2.09 rows=1 width=8)                                                                                                                                            │
│                           Cache Key: itemsharei2__1.item_image_id                                                                                                                                            │
│                           Cache Mode: logical                                                                                                                                                                │
│                           ->  Index Only Scan using pk_item_image on item_image itemimageb3__1  (cost=0.56..2.08 rows=1 width=8)                                                                             │
│                                 Index Cond: (id = itemsharei2__1.item_image_id)                                                                                                                              │
│         ->  Nested Loop  (cost=0.85..32.14 rows=1 width=8)                                                                                                                                                   │
│               ->  Index Only Scan using uq_isi_itemid_itemimageid on item_share_image itemsharei2_  (cost=0.57..3.80 rows=91 width=16)                                                                       │
│                     Index Cond: (item_id = itembo0_.id)                                                                                                                                                      │
│               ->  Memoize  (cost=0.29..1.72 rows=1 width=8)                                                                                                                                                  │
│                     Cache Key: itemsharei2_.item_image_id                                                                                                                                                    │
│                     Cache Mode: logical                                                                                                                                                                      │
│                     ->  Index Only Scan using stehule3001 on item_image itemimageb3_  (cost=0.28..1.71 rows=1 width=8)                                                                                       │
│                           Index Cond: (id = itemsharei2_.item_image_id)                                                                                                                                      │
│   ->  Index Only Scan using ixfk_ima_itemid on item_missing_attribute itemmissin1_  (cost=0.28..1.66 rows=1 width=8)                                                                                         │
│         Index Cond: (item_id = itembo0_.id)                                                                                                                                                                  │
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
(29 řádek)

Čas: 604,447 ms

(2022-05-03 06:13:26) prd_aukro=# explain execute xx;
┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│                                                                                                  QUERY PLAN                                                                                                  │
├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ Nested Loop Anti Join  (cost=59.62..3166.65 rows=1 width=16)                                                                                                                                                 │
│   ->  Nested Loop Anti Join  (cost=59.34..3163.73 rows=1 width=16)                                                                                                                                           │
│         ->  Nested Loop Semi Join  (cost=58.48..3131.58 rows=1 width=16)                                                                                                                                     │
│               ->  Bitmap Heap Scan on item itembo0_  (cost=57.34..2706.71 rows=11 width=16)                                                                                                                  │
│                     Recheck Cond: ((ending_time IS NULL) OR ((status_id = ANY ('{1,4,5}'::bigint[])) AND (CURRENT_TIMESTAMP < ending_time) AND (starting_time <= CURRENT_TIMESTAMP)))                        │
│                     Filter: ((to_expose_date IS NULL) AND (status_id = ANY ('{1,4,5}'::bigint[])) AND (starting_time <= CURRENT_TIMESTAMP) AND ((ending_time IS NULL) OR (CURRENT_TIMESTAMP < ending_time))) │
│                     ->  BitmapOr  (cost=57.34..57.34 rows=1750 width=0)                                                                                                                                      │
│                           ->  Bitmap Index Scan on stehule354  (cost=0.00..2.08 rows=1 width=0)                                                                                                              │
│                                 Index Cond: (ending_time IS NULL)                                                                                                                                            │
│                           ->  Bitmap Index Scan on stehule1010  (cost=0.00..55.26 rows=1750 width=0)                                                                                                         │
│                                 Index Cond: ((status_id = ANY ('{1,4,5}'::bigint[])) AND (ending_time > CURRENT_TIMESTAMP) AND (starting_time <= CURRENT_TIMESTAMP))                                         │
│               ->  Nested Loop  (cost=1.14..37.71 rows=91 width=8)                                                                                                                                            │
│                     ->  Index Only Scan using uq_isi_itemid_itemimageid on item_share_image itemsharei2__1  (cost=0.57..3.80 rows=91 width=16)                                                               │
│                           Index Cond: (item_id = itembo0_.id)                                                                                                                                                │
│                     ->  Memoize  (cost=0.57..2.09 rows=1 width=8)                                                                                                                                            │
│                           Cache Key: itemsharei2__1.item_image_id                                                                                                                                            │
│                           Cache Mode: logical                                                                                                                                                                │
│                           ->  Index Only Scan using pk_item_image on item_image itemimageb3__1  (cost=0.56..2.08 rows=1 width=8)                                                                             │
│                                 Index Cond: (id = itemsharei2__1.item_image_id)                                                                                                                              │
│         ->  Nested Loop  (cost=0.85..32.14 rows=1 width=8)                                                                                                                                                   │
│               ->  Index Only Scan using uq_isi_itemid_itemimageid on item_share_image itemsharei2_  (cost=0.57..3.80 rows=91 width=16)                                                                       │
│                     Index Cond: (item_id = itembo0_.id)                                                                                                                                                      │
│               ->  Memoize  (cost=0.29..1.72 rows=1 width=8)                                                                                                                                                  │
│                     Cache Key: itemsharei2_.item_image_id                                                                                                                                                    │
│                     Cache Mode: logical                                                                                                                                                                      │
│                     ->  Index Only Scan using stehule3001 on item_image itemimageb3_  (cost=0.28..1.71 rows=1 width=8)                                                                                       │
│                           Index Cond: (id = itemsharei2_.item_image_id)                                                                                                                                      │
│   ->  Index Only Scan using ixfk_ima_itemid on item_missing_attribute itemmissin1_  (cost=0.28..1.66 rows=1 width=8)                                                                                         │
│         Index Cond: (item_id = itembo0_.id)                                                                                                                                                                  │
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
(29 řádek)

Čas: 767,565 ms