#1352 listTagged would benefit from additional index
Closed: Fixed 3 years ago by mikem. Opened 4 years ago by tkopecek.

EXPLAIN ANALYZE
 SELECT package.id, package.name, tag.id, tag.name, users.id, users.name, extra_arches, tag_packages.blocked
 FROM tag_packages
 JOIN tag on tag.id = tag_packages.tag_id
 JOIN package ON package.id = tag_packages.package_id
 JOIN users ON users.id = tag_packages.owner 
 WHERE (active = TRUE)
     AND tag.id = 20178;
                                                              QUERY PLAN                                                              
--------------------------------------------------------------------------------------------------------------------------------------
 Nested Loop  (cost=2253.58..91701.39 rows=1190 width=97) (actual time=9967.549..9967.549 rows=0 loops=1)
   ->  Hash Join  (cost=2253.30..91093.51 rows=1190 width=86) (actual time=9967.548..9967.548 rows=0 loops=1)
         Hash Cond: (tag_packages.package_id = package.id)
         ->  Nested Loop  (cost=0.29..88812.24 rows=1190 width=48) (actual time=9967.547..9967.547 rows=0 loops=1)
               ->  Index Scan using tag_pkey on tag  (cost=0.29..8.30 rows=1 width=36) (actual time=0.009..0.011 rows=1 loops=1)
                     Index Cond: (id = 20178)
               ->  Seq Scan on tag_packages  (cost=0.00..88792.04 rows=1190 width=16) (actual time=9967.519..9967.519 rows=0 loops=1)
                     Filter: (active AND (tag_id = 20178))
                     Rows Removed by Filter: 4257438
         ->  Hash  (cost=1363.56..1363.56 rows=71156 width=42) (never executed)
               ->  Seq Scan on package  (cost=0.00..1363.56 rows=71156 width=42) (never executed)
   ->  Index Scan using users_pkey on users  (cost=0.28..0.50 rows=1 width=15) (never executed)
         Index Cond: (id = tag_packages.owner)
 Planning time: 3.006 ms
 Execution time: 9967.656 ms


CREATE INDEX index tag_packages_active_tag_id ON tag_packages(active, tag_id);

EXPLAIN ANALYZE
 SELECT package.id, package.name, tag.id, tag.name, users.id, users.name, extra_arches, tag_packages.blocked
 FROM tag_packages
 JOIN tag on tag.id = tag_packages.tag_id
 JOIN package ON package.id = tag_packages.package_id
 JOIN users ON users.id = tag_packages.owner
 WHERE (active = TRUE)
     AND tag.id = 20178;
                                                                            QUERY PLAN                                                                            
------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Hash Join  (cost=2399.54..4564.91 rows=1190 width=97) (actual time=3.369..3.369 rows=0 loops=1)
   Hash Cond: (tag_packages.owner = users.id)
   ->  Hash Join  (cost=2253.73..4398.27 rows=1190 width=86) (actual time=0.166..0.166 rows=0 loops=1)
         Hash Cond: (tag_packages.package_id = package.id)
         ->  Nested Loop  (cost=0.72..2117.00 rows=1190 width=48) (actual time=0.164..0.164 rows=0 loops=1)
               ->  Index Scan using tag_pkey on tag  (cost=0.29..8.30 rows=1 width=36) (actual time=0.044..0.045 rows=1 loops=1)
                     Index Cond: (id = 20178)
               ->  Index Scan using tag_packages_active_tag_id on tag_packages  (cost=0.43..2096.80 rows=1190 width=16) (actual time=0.099..0.099 rows=0 loops=1)
                     Index Cond: ((active = true) AND (tag_id = 20178))
                     Filter: active
         ->  Hash  (cost=1363.56..1363.56 rows=71156 width=42) (never executed)
               ->  Seq Scan on package  (cost=0.00..1363.56 rows=71156 width=42) (never executed)
   ->  Hash  (cost=89.25..89.25 rows=4525 width=15) (actual time=3.195..3.195 rows=4531 loops=1)
         Buckets: 1024  Batches: 1  Memory Usage: 209kB
         ->  Seq Scan on users  (cost=0.00..89.25 rows=4525 width=15) (actual time=0.030..2.026 rows=4531 loops=1)
 Planning time: 2.204 ms
 Execution time: 3.509 ms

Metadata Update from @tkopecek:
- Issue tagged with: easyfix

4 years ago

Metadata Update from @tkopecek:
- Custom field Size adjusted to None
- Issue set to the milestone: 1.18

3 years ago

Login to comment on this ticket.

Metadata