RoundSparrow

“Finnegans Wake is the greatest guidebook to media study ever fashioned by man.” - Marshall McLuhan, Newsweek Magazine, page 56, February 28, 1966.

I have never done LSD or any other illegal drugs, but I have read FInnegans Wake: www.LazyWake.com

Lemmy tester, “RocketDerp” is my username on GitHub

  • 4 Posts
  • 9 Comments
Joined 2 years ago
cake
Cake day: June 2nd, 2023

help-circle





  • Good results with this approach. I hadn’t considered the RANK OVER PARTITION BY criteria_a values and it works like a champ. It moves the ORDER BY into the realm of focus (criteria_a) and performance seems decent enough… and it isn’t difficult to read the short statement.

    SELECT COUNT(ranked_recency.*) AS post_row_count
    FROM
      (
         SELECT id, post_id, community_id, published,
            rank() OVER (
               PARTITION BY community_id
               ORDER BY published DESC, id DESC
               )
         FROM post_aggregates) ranked_recency
    WHERE rank <= 1000
    ;
    

    Gives me the expected results over the 5+ million test rows I ran it against.

    If you could elaborate on your idea of TOP, please do. I’m hoping there might be a way to wall the LIMIT 1000 into the inner query and not have the outer query need to WHERE filter rank on so many results?







  • given it traverses all the comment X comment space every time a comment is added.

    The second query I shared is only referenced for maintenance rebuild. The routine update of count does target only the tree that the reply is to:

     select c.id, c.path, count(c2.id) as child_count from comment c
     join comment c2 on c2.path <@ c.path and c2.path != c.path
     and c.path  <@ '0.1'
    group by c.id
    

    I found a particularly complex tree with 300 comments. In production database (with generated test data added for this particular comment tree), it is taking .371 seconds every time a new comment is added, here is the result of the SELECT pulled out without the UPDATE:

    Obviously with the UPDATE it will take longer than .371 seconds to execute.