You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Without explain/analyze plans over realistic large datasets to show it's more performant, it's unlikely I can approve. I can't tell you if it would be more performant by looking at it unfortunately
I'm also seeing this behavior.
On a table with 120K rows, the current version with subselect takes about 20 seconds, while the variant with LAG takes 800ms.
--- EDIT ---
It looks like this is not quite as black and white as I initially thought: Apparently the window function can cause a lot of overhead in some situations.
--- EDIT 2 ---
I found another part of the query that overshadows the LAG vs subselect clause. The query I'm currently analyzing is the one that provides the data for the admin list-view of Events, so basically the "main" query of that page.
I found out that, if the ordering of the CTE aligns with the ordering of the primary query, there is a significant speedup. Apparently in that case the limit on the primary query also effects the CTE and the database can avoid building all rows of the CTE.
So I moved to using persistent diffs instead like here: #236
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Would this be an improvement? With the subquery approach there's the risk of having N+1 queries where the LAG might be more efficient?
I don't have any real world data in my pghistory tables yet to test, but I though it might be good to pop the question here.