Skip to content

Conversation

@wezell
Copy link
Contributor

@wezell wezell commented Jan 30, 2026

ref: #34454

BEFORE:

prod_1_db=> explain SELECT COUNT(working_inode) AS value 
FROM contentlet_version_info, contentlet
WHERE contentlet.inode = contentlet_version_info.working_inode AND
contentlet.mod_date  > now() - interval '1 month';
                                                          QUERY PLAN
-------------------------------------------------------------------------------------------------------------------------------
 Finalize Aggregate  (cost=11170340.22..11170340.23 rows=1 width=8)
   ->  Gather  (cost=11170340.01..11170340.22 rows=2 width=8)
         Workers Planned: 2
         ->  Partial Aggregate  (cost=11169340.01..11169340.02 rows=1 width=8)
               ->  Parallel Hash Join  (cost=10954188.47..11168776.29 rows=225487 width=37)
                     Hash Cond: ((contentlet_version_info.working_inode)::text = (contentlet.inode)::text)
                     ->  Parallel Seq Scan on contentlet_version_info  (cost=0.00..163402.49 rows=1857649 width=37)
                     ->  Parallel Hash  (cost=10909253.80..10909253.80 rows=2212134 width=37)
                           ->  Parallel Bitmap Heap Scan on contentlet  (cost=178538.26..10909253.80 rows=2212134 width=37)
                                 Recheck Cond: (mod_date > (now() - '1 mon'::interval))
                                 ->  Bitmap Index Scan on idx_contentlet_mod_date  (cost=0.00..177210.98 rows=5309121 width=0)
                                       Index Cond: (mod_date > (now() - '1 mon'::interval))

AFTER:

prod_1_db=> explain SELECT COUNT(working_inode) AS value 
FROM contentlet_version_info 
WHERE version_ts > now() - interval '1 month';
                                                 QUERY PLAN
-------------------------------------------------------------------------------------------------------------
 Finalize Aggregate  (cost=179089.09..179089.10 rows=1 width=8)
   ->  Gather  (cost=179088.87..179089.08 rows=2 width=8)
         Workers Planned: 2
         ->  Partial Aggregate  (cost=178088.87..178088.88 rows=1 width=8)
               ->  Parallel Seq Scan on contentlet_version_info  (cost=0.00..177334.85 rows=301607 width=37)
                     Filter: (version_ts > (now() - '1 mon'::interval))

BEFORE:

_prod_1_db=> explain select cvi.working_inode as inode
from contentlet_version_info cvi, tree t, contentlet c
where t.parent= 'f1d378c9-b784-45d0-a43c-9790af678f13' and
t.relation_type = 'Blog.blogComment' and
t.child = cvi.identifier  and
cvi.working_inode = c.inode
order by c.sort_order;
                                                                QUERY PLAN
------------------------------------------------------------------------------------------------------------------------------------------
 Sort  (cost=24.88..24.89 rows=1 width=41)
   Sort Key: c.sort_order
   ->  Nested Loop  (cost=1.68..24.87 rows=1 width=41)
         ->  Nested Loop  (cost=1.11..17.19 rows=1 width=37)
               ->  Index Only Scan using idx_tree_4 on tree t  (cost=0.56..8.60 rows=1 width=35)
                     Index Cond: ((parent = 'f1d378c9-b784-45d0-a43c-9790af678f13'::text) AND (relation_type = 'Blog.blogComment'::text))
               ->  Index Scan using contentlet_version_info_pkey on contentlet_version_info cvi  (cost=0.56..8.57 rows=1 width=71)
                     Index Cond: ((identifier)::text = (t.child)::text)
         ->  Index Scan using idx_contentlet_3 on contentlet c  (cost=0.56..7.68 rows=1 width=41)
               Index Cond: ((inode)::text = (cvi.working_inode)::text)                                       

AFTER:

prod_1_db-> explain select cvi.working_inode as inode 
from contentlet_version_info cvi, tree t
where t.parent= 'f1d378c9-b784-45d0-a43c-9790af678f13' and 
t.relation_type = 'Blog.blogComment' and 
t.child = cvi.identifier 
order by t.tree_order;
                                                                     QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------------------------
 Sort  (cost=17.20..17.21 rows=1 width=41)
   Sort Key: t.tree_order
   ->  Nested Loop  (cost=1.11..17.19 rows=1 width=41)
         ->  Index Scan using idx_tree_4 on tree t  (cost=0.56..8.60 rows=1 width=39)
               Index Cond: (((parent)::text = 'f1d378c9-b784-45d0-a43c-9790af678f13'::text) AND ((relation_type)::text = 'Blog.blogComment'::text))
         ->  Index Scan using contentlet_version_info_pkey on contentlet_version_info cvi  (cost=0.56..8.57 rows=1 width=71)
               Index Cond: ((identifier)::text = (t.child)::text)
(7 rows)

This PR fixes: #34454

@wezell wezell requested a review from erickgonzalez January 31, 2026 13:39
@wezell wezell added this pull request to the merge queue Feb 2, 2026
Merged via the queue into main with commit 3e9629d Feb 2, 2026
38 checks passed
@wezell wezell deleted the issue-34454-query-performance branch February 2, 2026 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

[TASK] Optimize heavy SQL queries

4 participants