Skip to content

Conversation

@genematx
Copy link
Contributor

@genematx genematx commented Aug 20, 2025

This pull request adds a new PostgreSQL covering index to the nodes table to improve query performance for key lookups. The changes include updating the migration history, introducing a new Alembic migration for the index, and modifying the ORM model to define the index.

EXPLAIN ANALYZE SELECT nodes.key FROM nodes WHERE nodes.parent = 0::INTEGER ORDER BY nodes.time_created, nodes.id LIMIT 10::INTEGER OFFSET 0::INTEGER;

Before:


                                                                  QUERY PLAN                                                                  
----------------------------------------------------------------------------------------------------------------------------------------------
 Limit  (cost=18586.51..18586.53 rows=10 width=26) (actual time=110.079..110.082 rows=10 loops=1)
   ->  Sort  (cost=18586.51..18699.39 rows=45153 width=26) (actual time=110.078..110.079 rows=10 loops=1)
         Sort Key: time_created, id
         Sort Method: top-N heapsort  Memory: 26kB
         ->  Bitmap Heap Scan on nodes  (cost=778.36..17610.77 rows=45153 width=26) (actual time=4.395..104.736 rows=45895 loops=1)
               Recheck Cond: (parent = 0)
               Heap Blocks: exact=16268
               ->  Bitmap Index Scan on ix_nodes_parent  (cost=0.00..767.07 rows=45153 width=0) (actual time=2.647..2.647 rows=47294 loops=1)
                     Index Cond: (parent = 0)
 Planning Time: 0.107 ms
 Execution Time: 110.103 ms
(11 rows)

After:


                                                                       QUERY PLAN                                                                       
--------------------------------------------------------------------------------------------------------------------------------------------------------
 Limit  (cost=0.42..2.83 rows=10 width=26) (actual time=0.032..0.033 rows=10 loops=1)
   ->  Index Only Scan using ix_nodes_parent_time_id_key on nodes  (cost=0.42..11778.21 rows=48825 width=26) (actual time=0.032..0.033 rows=10 loops=1)
         Index Cond: (parent = 0)
         Heap Fetches: 0
 Planning Time: 0.370 ms
 Execution Time: 0.041 ms
(6 rows)

Checklist

  • Add a Changelog entry
  • Add the ticket number which this PR closes to the comment section

@danielballan
Copy link
Member

I can see how this would probably be useful, but can you give examples of HTTP requests that would exercise it?

@genematx
Copy link
Contributor Author

genematx commented Aug 20, 2025

I can see how this would probably be useful, but can you give examples of HTTP requests that would exercise it?

of course! any /api/v1/search/?page[offset]=0&fields=&sort= does this when the clients builds a __repr__ for a container. Maybe it shouldn't, though..

@danielballan
Copy link
Member

Will that query also pull the access_blob column, to apply authorization-related filtering, as well as time_created and id for default sorting?

@genematx
Copy link
Contributor Author

yes, most likely. I had a single user in my example.

@danielballan danielballan modified the milestone: v0.1.0 release Aug 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants