GithubHelp home page GithubHelp logo

Comments (6)

Chocobozzz avatar Chocobozzz commented on June 23, 2024

Can you try to run the query with WHERE "userId" = $3 AND "read" IS FALSE?

from peertube.

kontrollanten avatar kontrollanten commented on June 23, 2024

It doesn't seem to affect the cost:

peertube_prod=# EXPLAIN UPDATE "userNotification" SET "read"=true,"updatedAt"='2024-05-03 17:03:28.649+00' WHERE "userId" = 1;
                                             QUERY PLAN
-----------------------------------------------------------------------------------------------------
 Update on "userNotification"  (cost=1112.06..52909.66 rows=35049 width=75)
   ->  Bitmap Heap Scan on "userNotification"  (cost=1112.06..52909.66 rows=35049 width=75)
         Recheck Cond: ("userId" = 1)
         ->  Bitmap Index Scan on user_notification_user_id  (cost=0.00..1103.30 rows=35049 width=0)
               Index Cond: ("userId" = 1)
(5 rows)

peertube_prod=# EXPLAIN UPDATE "userNotification" SET "read"=true,"updatedAt"='2024-05-03 17:03:28.649+00' WHERE "userId" = 1 AND read IS FALSE;
                                             QUERY PLAN
-----------------------------------------------------------------------------------------------------
 Update on "userNotification"  (cost=1111.05..52908.65 rows=30990 width=75)
   ->  Bitmap Heap Scan on "userNotification"  (cost=1111.05..52908.65 rows=30990 width=75)
         Recheck Cond: ("userId" = 1)
         Filter: (read IS FALSE)
         ->  Bitmap Index Scan on user_notification_user_id  (cost=0.00..1103.30 rows=35049 width=0)
               Index Cond: ("userId" = 1)
(6 rows)

from peertube.

Chocobozzz avatar Chocobozzz commented on June 23, 2024

It doesn't seem to affect the cost:

Can you try to just test the query? I think most of time is spent Updating rows and not finding them.

from peertube.

kontrollanten avatar kontrollanten commented on June 23, 2024

I ran with EXPLAIN ANALYZE and the difference in execution time is huge:

peertube_prod=# EXPLAIN ANALYZE UPDATE "userNotification" SET "read"=true,"updatedAt"='2024-05-03 17:03:28.649+00' WHERE "userId" = 1 AND read IS FALSE;
                                                                     QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------------------------------------
 Update on "userNotification"  (cost=1123.22..53718.19 rows=31466 width=75) (actual time=86.252..86.254 rows=0 loops=1)
   ->  Bitmap Heap Scan on "userNotification"  (cost=1123.22..53718.19 rows=31466 width=75) (actual time=86.250..86.251 rows=0 loops=1)
         Recheck Cond: ("userId" = 1)
         Filter: (read IS FALSE)
         Rows Removed by Filter: 31382
         Heap Blocks: exact=6925
         ->  Bitmap Index Scan on user_notification_user_id  (cost=0.00..1115.35 rows=35589 width=0) (actual time=12.815..12.815 rows=74747 loops=1)
               Index Cond: ("userId" = 1)
 Planning Time: 0.221 ms
 Execution Time: 86.434 ms
(10 rows)

peertube_prod=# EXPLAIN ANALYZE UPDATE "userNotification" SET "read"=true,"updatedAt"='2024-05-03 17:03:28.649+00' WHERE "userId" = 1;
                                                                     QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------------------------------------
 Update on "userNotification"  (cost=1124.25..53719.22 rows=35589 width=75) (actual time=1360.231..1360.232 rows=0 loops=1)
   ->  Bitmap Heap Scan on "userNotification"  (cost=1124.25..53719.22 rows=35589 width=75) (actual time=12.338..88.100 rows=31382 loops=1)
         Recheck Cond: ("userId" = 1)
         Heap Blocks: exact=6925
         ->  Bitmap Index Scan on user_notification_user_id  (cost=0.00..1115.35 rows=35589 width=0) (actual time=11.143..11.143 rows=74747 loops=1)
               Index Cond: ("userId" = 1)
 Planning Time: 0.166 ms
 Execution Time: 1360.387 ms
(8 rows)

Adding AND "read" IS FALSE looks like a success.

from peertube.

Chocobozzz avatar Chocobozzz commented on June 23, 2024

Thanks! Changed in 9ee1f7b

from peertube.

kontrollanten avatar kontrollanten commented on June 23, 2024

Thanks! For me it's okay to close this issue since the root issue has been solved.

from peertube.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.