Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request for better performance on paging and lees memory usage on database #31752

Closed
somera opened this issue Aug 1, 2024 · 23 comments · Fixed by #31821
Closed

Feature Request for better performance on paging and lees memory usage on database #31752

somera opened this issue Aug 1, 2024 · 23 comments · Fixed by #31821
Labels
performance/speed performance issues with slow downs type/proposal The new feature has not been accepted yet but needs to be discussed first.

Comments

@somera
Copy link

somera commented Aug 1, 2024

Feature Description

I'm again. The gitea user with 3655 organisations and 22573 repos.

I wondered that my paging is slow. Not on the first pages.

First page need 1-3 seconds. 1 second if the data is precached.

image

On the last pages ...

image

But this is after my 1st optimisation.

You made this queries

  1. SELECT count(*) FROM "action" INNER JOIN "repository" ON "repository".id = "action".repo_id WHERE user_id=$1 AND is_deleted=$2
  2. SELECT action.* FROM action INNER JOIN repository ON repository.id = action.repo_id WHERE user_id='1' AND is_deleted='f' ORDER BY action.created_unix DESC LIMIT 20 OFFSET 2043740

on pagging.

Explain for the count query is

image

And than I changed the query to

SELECT count(action.id) FROM "action" INNER JOIN "repository" ON "repository".id = "action".repo_id WHERE user_id=$1 AND is_deleted=$2

and ...

image

it's faster.

Explain for the SELECT query is

image

very bad. I increased work_mem to 6GB and it's better now

image

After this fix it need ~11 seconds.

But it can be better. Cause the problem is this

SELECT action.* FROM action INNER JOIN repository ON repository.id = action.repo_id WHERE user_id='1' AND is_deleted='f' ORDER BY action.created_unix DESC LIMIT 20 OFFSET 2043740

query. When you change it to

SELECT action.id FROM action INNER JOIN repository ON repository.id = action.repo_id WHERE user_id='1' AND is_deleted='f' ORDER BY action.created_unix DESC LIMIT 20 OFFSET 2043740

-> you will get 20 action.id's than explain is

image

and need ~5 seconds and a very less memory on the database.

Than gitea should get the action.* infos only for the 20 id's in the new query.

This optimisation will be good for all gitea users.

Screenshots

No response

@somera somera added the type/proposal The new feature has not been accepted yet but needs to be discussed first. label Aug 1, 2024
@somera
Copy link
Author

somera commented Aug 1, 2024

I know why it's getting slower.

https://readyset.io/blog/optimizing-sql-pagination-in-postgres

@lunny lunny added the performance/speed performance issues with slow downs label Aug 1, 2024
@somera
Copy link
Author

somera commented Aug 1, 2024

On slow paging I see this "cache context ..." log entries

2024/08/01 23:49:01 ...eb/routing/logger.go:68:func1() [W] router: slow      GET /?page=90000&date= for 192.168.178.21:0, elapsed 3969.6ms @ web/home.go:32(web.Home)
2024/08/01 23:49:07 ...activities/action.go:461:GetFeeds() [W] [Slow SQL Query] SELECT "action".* FROM "action" INNER JOIN "repository" ON "repository".id = "action".repo_id WHERE user_id=$1 AND is_deleted=$2 ORDER BY "action"."created_unix" DESC LIMIT 20 OFFSET 1799980 [1 false] - 9.526588923s
2024/08/01 23:49:08 ...les/cache/context.go:134:GetContextData() [W] cache context is expired, may be misused for long-life tasks: &{map[] {{0 0} 0 0 {{} 0} {{} 0}} {13953029684656701459 22593705060787 0x6a1a080} false}
2024/08/01 23:49:08 ...les/cache/context.go:147:SetContextData() [W] cache context is expired, may be misused for long-life tasks: &{map[] {{0 0} 0 0 {{} 0} {{} 0}} {13953029684656701459 22593705060787 0x6a1a080} false}
2024/08/01 23:49:08 ...les/cache/context.go:134:GetContextData() [W] cache context is expired, may be misused for long-life tasks: &{map[] {{0 0} 0 0 {{} 0} {{} 0}} {13953029684656701459 22593705060787 0x6a1a080} false}
2024/08/01 23:49:08 ...les/cache/context.go:147:SetContextData() [W] cache context is expired, may be misused for long-life tasks: &{map[] {{0 0} 0 0 {{} 0} {{} 0}} {13953029684656701459 22593705060787 0x6a1a080} false}
2024/08/01 23:49:08 ...les/cache/context.go:134:GetContextData() [W] cache context is expired, may be misused for long-life tasks: &{map[] {{0 0} 0 0 {{} 0} {{} 0}} {13953029684656701459 22593705060787 0x6a1a080} false}
2024/08/01 23:49:08 ...les/cache/context.go:147:SetContextData() [W] cache context is expired, may be misused for long-life tasks: &{map[] {{0 0} 0 0 {{} 0} {{} 0}} {13953029684656701459 22593705060787 0x6a1a080} false}
2024/08/01 23:49:08 ...les/cache/context.go:134:GetContextData() [W] cache context is expired, may be misused for long-life tasks: &{map[] {{0 0} 0 0 {{} 0} {{} 0}} {13953029684656701459 22593705060787 0x6a1a080} false}
2024/08/01 23:49:08 ...les/cache/context.go:147:SetContextData() [W] cache context is expired, may be misused for long-life tasks: &{map[] {{0 0} 0 0 {{} 0} {{} 0}} {13953029684656701459 22593705060787 0x6a1a080} false}
2024/08/01 23:49:08 ...les/cache/context.go:134:GetContextData() [W] cache context is expired, may be misused for long-life tasks: &{map[] {{0 0} 0 0 {{} 0} {{} 0}} {13953029684656701459 22593705060787 0x6a1a080} false}
2024/08/01 23:49:08 ...les/cache/context.go:147:SetContextData() [W] cache context is expired, may be misused for long-life tasks: &{map[] {{0 0} 0 0 {{} 0} {{} 0}} {13953029684656701459 22593705060787 0x6a1a080} false}
2024/08/01 23:49:08 ...les/cache/context.go:134:GetContextData() [W] cache context is expired, may be misused for long-life tasks: &{map[] {{0 0} 0 0 {{} 0} {{} 0}} {13953029684656701459 22593705060787 0x6a1a080} false}
2024/08/01 23:49:08 ...les/cache/context.go:147:SetContextData() [W] cache context is expired, may be misused for long-life tasks: &{map[] {{0 0} 0 0 {{} 0} {{} 0}} {13953029684656701459 22593705060787 0x6a1a080} false}
2024/08/01 23:49:08 ...les/cache/context.go:134:GetContextData() [W] cache context is expired, may be misused for long-life tasks: &{map[] {{0 0} 0 0 {{} 0} {{} 0}} {13953029684656701459 22593705060787 0x6a1a080} false}
2024/08/01 23:49:08 ...les/cache/context.go:147:SetContextData() [W] cache context is expired, may be misused for long-life tasks: &{map[] {{0 0} 0 0 {{} 0} {{} 0}} {13953029684656701459 22593705060787 0x6a1a080} false}
2024/08/01 23:49:08 ...les/cache/context.go:134:GetContextData() [W] cache context is expired, may be misused for long-life tasks: &{map[] {{0 0} 0 0 {{} 0} {{} 0}} {13953029684656701459 22593705060787 0x6a1a080} false}
2024/08/01 23:49:08 ...les/cache/context.go:147:SetContextData() [W] cache context is expired, may be misused for long-life tasks: &{map[] {{0 0} 0 0 {{} 0} {{} 0}} {13953029684656701459 22593705060787 0x6a1a080} false}
2024/08/01 23:49:08 ...les/cache/context.go:134:GetContextData() [W] cache context is expired, may be misused for long-life tasks: &{map[] {{0 0} 0 0 {{} 0} {{} 0}} {13953029684656701459 22593705060787 0x6a1a080} false}
2024/08/01 23:49:08 ...les/cache/context.go:147:SetContextData() [W] cache context is expired, may be misused for long-life tasks: &{map[] {{0 0} 0 0 {{} 0} {{} 0}} {13953029684656701459 22593705060787 0x6a1a080} false}
2024/08/01 23:49:08 ...les/cache/context.go:134:GetContextData() [W] cache context is expired, may be misused for long-life tasks: &{map[] {{0 0} 0 0 {{} 0} {{} 0}} {13953029684656701459 22593705060787 0x6a1a080} false}
2024/08/01 23:49:08 ...les/cache/context.go:147:SetContextData() [W] cache context is expired, may be misused for long-life tasks: &{map[] {{0 0} 0 0 {{} 0} {{} 0}} {13953029684656701459 22593705060787 0x6a1a080} false}
2024/08/01 23:49:08 ...les/cache/context.go:134:GetContextData() [W] cache context is expired, may be misused for long-life tasks: &{map[] {{0 0} 0 0 {{} 0} {{} 0}} {13953029684656701459 22593705060787 0x6a1a080} false}
2024/08/01 23:49:08 ...les/cache/context.go:147:SetContextData() [W] cache context is expired, may be misused for long-life tasks: &{map[] {{0 0} 0 0 {{} 0} {{} 0}} {13953029684656701459 22593705060787 0x6a1a080} false}
2024/08/01 23:49:08 ...les/cache/context.go:134:GetContextData() [W] cache context is expired, may be misused for long-life tasks: &{map[] {{0 0} 0 0 {{} 0} {{} 0}} {13953029684656701459 22593705060787 0x6a1a080} false}
2024/08/01 23:49:08 ...les/cache/context.go:147:SetContextData() [W] cache context is expired, may be misused for long-life tasks: &{map[] {{0 0} 0 0 {{} 0} {{} 0}} {13953029684656701459 22593705060787 0x6a1a080} false}
2024/08/01 23:49:08 ...les/cache/context.go:134:GetContextData() [W] cache context is expired, may be misused for long-life tasks: &{map[] {{0 0} 0 0 {{} 0} {{} 0}} {13953029684656701459 22593705060787 0x6a1a080} false}
2024/08/01 23:49:08 ...les/cache/context.go:147:SetContextData() [W] cache context is expired, may be misused for long-life tasks: &{map[] {{0 0} 0 0 {{} 0} {{} 0}} {13953029684656701459 22593705060787 0x6a1a080} false}
2024/08/01 23:49:08 ...les/cache/context.go:134:GetContextData() [W] cache context is expired, may be misused for long-life tasks: &{map[] {{0 0} 0 0 {{} 0} {{} 0}} {13953029684656701459 22593705060787 0x6a1a080} false}
2024/08/01 23:49:08 ...les/cache/context.go:147:SetContextData() [W] cache context is expired, may be misused for long-life tasks: &{map[] {{0 0} 0 0 {{} 0} {{} 0}} {13953029684656701459 22593705060787 0x6a1a080} false}
2024/08/01 23:49:08 ...les/cache/context.go:134:GetContextData() [W] cache context is expired, may be misused for long-life tasks: &{map[] {{0 0} 0 0 {{} 0} {{} 0}} {13953029684656701459 22593705060787 0x6a1a080} false}
2024/08/01 23:49:08 ...les/cache/context.go:147:SetContextData() [W] cache context is expired, may be misused for long-life tasks: &{map[] {{0 0} 0 0 {{} 0} {{} 0}} {13953029684656701459 22593705060787 0x6a1a080} false}
2024/08/01 23:49:08 ...les/cache/context.go:134:GetContextData() [W] cache context is expired, may be misused for long-life tasks: &{map[] {{0 0} 0 0 {{} 0} {{} 0}} {13953029684656701459 22593705060787 0x6a1a080} false}
2024/08/01 23:49:08 ...les/cache/context.go:147:SetContextData() [W] cache context is expired, may be misused for long-life tasks: &{map[] {{0 0} 0 0 {{} 0} {{} 0}} {13953029684656701459 22593705060787 0x6a1a080} false}
2024/08/01 23:49:08 ...les/cache/context.go:134:GetContextData() [W] cache context is expired, may be misused for long-life tasks: &{map[] {{0 0} 0 0 {{} 0} {{} 0}} {13953029684656701459 22593705060787 0x6a1a080} false}
2024/08/01 23:49:08 ...les/cache/context.go:147:SetContextData() [W] cache context is expired, may be misused for long-life tasks: &{map[] {{0 0} 0 0 {{} 0} {{} 0}} {13953029684656701459 22593705060787 0x6a1a080} false}
2024/08/01 23:49:08 ...les/cache/context.go:134:GetContextData() [W] cache context is expired, may be misused for long-life tasks: &{map[] {{0 0} 0 0 {{} 0} {{} 0}} {13953029684656701459 22593705060787 0x6a1a080} false}
2024/08/01 23:49:08 ...les/cache/context.go:147:SetContextData() [W] cache context is expired, may be misused for long-life tasks: &{map[] {{0 0} 0 0 {{} 0} {{} 0}} {13953029684656701459 22593705060787 0x6a1a080} false}
2024/08/01 23:49:17 ...eb/routing/logger.go:68:func1() [W] router: slow      GET /?page=89999&date= for 192.168.178.21:0, elapsed 3604.4ms @ web/home.go:32(web.Home)
2024/08/01 23:49:23 ...activities/action.go:461:GetFeeds() [W] [Slow SQL Query] SELECT "action".* FROM "action" INNER JOIN "repository" ON "repository".id = "action".repo_id WHERE user_id=$1 AND is_deleted=$2 ORDER BY "action"."created_unix" DESC LIMIT 20 OFFSET 1799960 [1 false] - 9.456084079s
2024/08/01 23:49:24 ...les/cache/context.go:134:GetContextData() [W] cache context is expired, may be misused for long-life tasks: &{map[] {{0 0} 0 0 {{} 0} {{} 0}} {13953029702275280671 22610070028993 0x6a1a080} false}
2024/08/01 23:49:24 ...les/cache/context.go:147:SetContextData() [W] cache context is expired, may be misused for long-life tasks: &{map[] {{0 0} 0 0 {{} 0} {{} 0}} {13953029702275280671 22610070028993 0x6a1a080} false}
2024/08/01 23:49:24 ...les/cache/context.go:134:GetContextData() [W] cache context is expired, may be misused for long-life tasks: &{map[] {{0 0} 0 0 {{} 0} {{} 0}} {13953029702275280671 22610070028993 0x6a1a080} false}
2024/08/01 23:49:24 ...les/cache/context.go:147:SetContextData() [W] cache context is expired, may be misused for long-life tasks: &{map[] {{0 0} 0 0 {{} 0} {{} 0}} {13953029702275280671 22610070028993 0x6a1a080} false}
2024/08/01 23:49:24 ...les/cache/context.go:134:GetContextData() [W] cache context is expired, may be misused for long-life tasks: &{map[] {{0 0} 0 0 {{} 0} {{} 0}} {13953029702275280671 22610070028993 0x6a1a080} false}
2024/08/01 23:49:24 ...les/cache/context.go:147:SetContextData() [W] cache context is expired, may be misused for long-life tasks: &{map[] {{0 0} 0 0 {{} 0} {{} 0}} {13953029702275280671 22610070028993 0x6a1a080} false}
2024/08/01 23:49:24 ...les/cache/context.go:134:GetContextData() [W] cache context is expired, may be misused for long-life tasks: &{map[] {{0 0} 0 0 {{} 0} {{} 0}} {13953029702275280671 22610070028993 0x6a1a080} false}
2024/08/01 23:49:24 ...les/cache/context.go:147:SetContextData() [W] cache context is expired, may be misused for long-life tasks: &{map[] {{0 0} 0 0 {{} 0} {{} 0}} {13953029702275280671 22610070028993 0x6a1a080} false}
2024/08/01 23:49:24 ...les/cache/context.go:134:GetContextData() [W] cache context is expired, may be misused for long-life tasks: &{map[] {{0 0} 0 0 {{} 0} {{} 0}} {13953029702275280671 22610070028993 0x6a1a080} false}
2024/08/01 23:49:24 ...les/cache/context.go:147:SetContextData() [W] cache context is expired, may be misused for long-life tasks: &{map[] {{0 0} 0 0 {{} 0} {{} 0}} {13953029702275280671 22610070028993 0x6a1a080} false}
2024/08/01 23:49:24 ...les/cache/context.go:134:GetContextData() [W] cache context is expired, may be misused for long-life tasks: &{map[] {{0 0} 0 0 {{} 0} {{} 0}} {13953029702275280671 22610070028993 0x6a1a080} false}
2024/08/01 23:49:24 ...les/cache/context.go:147:SetContextData() [W] cache context is expired, may be misused for long-life tasks: &{map[] {{0 0} 0 0 {{} 0} {{} 0}} {13953029702275280671 22610070028993 0x6a1a080} false}
2024/08/01 23:49:24 ...les/cache/context.go:134:GetContextData() [W] cache context is expired, may be misused for long-life tasks: &{map[] {{0 0} 0 0 {{} 0} {{} 0}} {13953029702275280671 22610070028993 0x6a1a080} false}
2024/08/01 23:49:24 ...les/cache/context.go:147:SetContextData() [W] cache context is expired, may be misused for long-life tasks: &{map[] {{0 0} 0 0 {{} 0} {{} 0}} {13953029702275280671 22610070028993 0x6a1a080} false}
2024/08/01 23:49:24 ...les/cache/context.go:134:GetContextData() [W] cache context is expired, may be misused for long-life tasks: &{map[] {{0 0} 0 0 {{} 0} {{} 0}} {13953029702275280671 22610070028993 0x6a1a080} false}
2024/08/01 23:49:24 ...les/cache/context.go:147:SetContextData() [W] cache context is expired, may be misused for long-life tasks: &{map[] {{0 0} 0 0 {{} 0} {{} 0}} {13953029702275280671 22610070028993 0x6a1a080} false}
2024/08/01 23:49:24 ...les/cache/context.go:134:GetContextData() [W] cache context is expired, may be misused for long-life tasks: &{map[] {{0 0} 0 0 {{} 0} {{} 0}} {13953029702275280671 22610070028993 0x6a1a080} false}
2024/08/01 23:49:24 ...les/cache/context.go:147:SetContextData() [W] cache context is expired, may be misused for long-life tasks: &{map[] {{0 0} 0 0 {{} 0} {{} 0}} {13953029702275280671 22610070028993 0x6a1a080} false}
2024/08/01 23:49:24 ...les/cache/context.go:134:GetContextData() [W] cache context is expired, may be misused for long-life tasks: &{map[] {{0 0} 0 0 {{} 0} {{} 0}} {13953029702275280671 22610070028993 0x6a1a080} false}
2024/08/01 23:49:24 ...les/cache/context.go:147:SetContextData() [W] cache context is expired, may be misused for long-life tasks: &{map[] {{0 0} 0 0 {{} 0} {{} 0}} {13953029702275280671 22610070028993 0x6a1a080} false}
2024/08/01 23:49:24 ...les/cache/context.go:134:GetContextData() [W] cache context is expired, may be misused for long-life tasks: &{map[] {{0 0} 0 0 {{} 0} {{} 0}} {13953029702275280671 22610070028993 0x6a1a080} false}
2024/08/01 23:49:24 ...les/cache/context.go:147:SetContextData() [W] cache context is expired, may be misused for long-life tasks: &{map[] {{0 0} 0 0 {{} 0} {{} 0}} {13953029702275280671 22610070028993 0x6a1a080} false}
2024/08/01 23:49:24 ...les/cache/context.go:134:GetContextData() [W] cache context is expired, may be misused for long-life tasks: &{map[] {{0 0} 0 0 {{} 0} {{} 0}} {13953029702275280671 22610070028993 0x6a1a080} false}
2024/08/01 23:49:24 ...les/cache/context.go:147:SetContextData() [W] cache context is expired, may be misused for long-life tasks: &{map[] {{0 0} 0 0 {{} 0} {{} 0}} {13953029702275280671 22610070028993 0x6a1a080} false}
2024/08/01 23:49:24 ...les/cache/context.go:134:GetContextData() [W] cache context is expired, may be misused for long-life tasks: &{map[] {{0 0} 0 0 {{} 0} {{} 0}} {13953029702275280671 22610070028993 0x6a1a080} false}

@somera
Copy link
Author

somera commented Aug 12, 2024

Step 1:

OLD:
SELECT count(*) FROM "action" INNER JOIN "repository" ON "repository".id = "action".repo_id WHERE user_id=$1 AND is_deleted=$2

NEW:
SELECT count(action.id) FROM "action" INNER JOIN "repository" ON "repository".id = "action".repo_id WHERE user_id=$1 AND is_deleted=$2

Step 2:

OLD (expample with LIMIT and OFFSET -> SELECT action.* uses too much memory on database):
SELECT action.* FROM action INNER JOIN repository ON repository.id = action.repo_id WHERE user_id='1' AND is_deleted='f' ORDER BY action.created_unix DESC LIMIT 20 OFFSET 2043740

NEW:

  1. get XX action.id's (SELECT action.id -> uses less memory on database and it's faster)
    SELECT action.id FROM action INNER JOIN repository ON repository.id = action.repo_id WHERE user_id='1' AND is_deleted='f' ORDER BY action.created_unix DESC LIMIT 20 OFFSET 2043740
  2. Select for XX action.id's
    SELECT action.* FROM action WHERE action.id IN (....)

@lunny
Copy link
Member

lunny commented Aug 12, 2024

Please can you help to confirm #31821 will resolve this issue?

@somera
Copy link
Author

somera commented Aug 12, 2024

@lunny yes, I can help. I can check it on my 2nd instance with the same account of data like my main instance.

I need an executable gitea-1.21.*-linux-amd64? Nigtly?

@lunny
Copy link
Member

lunny commented Aug 12, 2024

@lunny yes, I can help. I can check it on my 2nd instance with the same account of data like my main instance.

I need an executable gitea-1.21.*-linux-amd64? Nigtly?

No. It's just a PR. I don't think you can easily replace it to do a test and revert back easily.

@somera
Copy link
Author

somera commented Aug 12, 2024

Means I should compile it?

Tell me what I have to do? Cause I didn't compile gitea for my use with PostgreSQL.

@lunny
Copy link
Member

lunny commented Aug 14, 2024

Means I should compile it?

Tell me what I have to do? Cause I didn't compile gitea for my use with PostgreSQL.

No. I can help to compile one but once your upgrade the version I provided, it's difficult for you to downgrade if there is no Gitea develop env for you.

@somera
Copy link
Author

somera commented Aug 14, 2024

I have 2nd gitea instance for testing. I can backup the database and after test restore the backup.

@lunny
Copy link
Member

lunny commented Aug 14, 2024

@somera
Copy link
Author

somera commented Aug 14, 2024

@lunny thx. I tested this PR.

My 24/7 NUC with main gitea instance has an Intel Pentium Silver J5005 (4) @ 2.800GHz. The results in this PR was made on this NUC.

My test now I run on a faster Intel NUC with an Intel i5-8259U (8) @ 3.800GHz. Has more cores/threads and it's faster.

How I made the test.

  1. I started the gitea-1.22.1-linux-amd64 release and I opened some pages.
  2. I started the gitea-pr-31821-amd64-linux from you and I opened the same pages. Cause I expected the same projects on the pages.

My expectation is:

  • The same order on the pages.
  • Slightly slower times on the lower pages (due to the 3rd query) and the further you scroll, the more positive the 3rd query will be.

I see same projects on the same pages. But the order is reverted. Project which are on the 1. place on the page are in the PR version on the last place. But I see same projects!!!

Times:

image

@somera
Copy link
Author

somera commented Aug 14, 2024

Sorry, but I didn't open more page at the beginning. But the new version need less memory or tmp files in PostgreSQL as I show it in my description,

@somera
Copy link
Author

somera commented Aug 14, 2024

Last page in 1.22.1

image

Last page in 1.22.0+PR

image

As you see the order is reverted.

@somera
Copy link
Author

somera commented Aug 14, 2024

And on my slower NUC I have 11233 more pages.

I wait for you feedback before I restore my DB backup.

@lunny
Copy link
Member

lunny commented Aug 14, 2024

And on my slower NUC I have 11233 more pages.

I wait for you feedback before I restore my DB backup.

Yes, it's a bug. Please try version 2 https://gitea.com/lunny/packages/src/branch/main/gitea-pr-31821-amd64-linux-2.tar.gz

@somera
Copy link
Author

somera commented Aug 14, 2024

I started this Version

1.22.0+rc1-415-gcd09625a76

and the sorting looks good. But I see the times are the same like in 1.22.1 and in PG log I see the action.* query

2024-08-15 00:09:56.653 CEST [6735] gitea@giteadb LOG: Dauer: 2259.538 ms Ausführen <unnamed>: SELECT "action".* FROM "action" INNER JOIN "repository" ON "repository".id = "action".repo_id WHERE user_id=$1 AND is_deleted=$2 ORDER BY "action"."created_unix" DESC LIMIT 20 OFFSET 1819340

The second statement should be SELECT action.id FROM ...

Like here #31752 (comment)

In the first version it was ok

postgresql-Wed.log:2024-08-14 21:55:59.113 CEST [3399] gitea@giteadb LOG:  Dauer: 1029.815 ms  Ausführen <unnamed>: SELECT "action".id FROM "action" INNER JOIN "repository" ON "repository".id = "action".repo_id WHERE user_id=$1 AND is_deleted=$2 ORDER BY "action"."created_unix" DESC LIMIT 20 OFFSET 1819420
postgresql-Wed.log:2024-08-14 21:56:04.272 CEST [3399] gitea@giteadb LOG:  Dauer: 1037.622 ms  Ausführen <unnamed>: SELECT "action".id FROM "action" INNER JOIN "repository" ON "repository".id = "action".repo_id WHERE user_id=$1 AND is_deleted=$2 ORDER BY "action"."created_unix" DESC LIMIT 20 OFFSET 1819400
postgresql-Wed.log:2024-08-14 21:56:10.563 CEST [3399] gitea@giteadb LOG:  Dauer: 1020.780 ms  Ausführen <unnamed>: SELECT "action".id FROM "action" INNER JOIN "repository" ON "repository".id = "action".repo_id WHERE user_id=$1 AND is_deleted=$2 ORDER BY "action"."created_unix" DESC LIMIT 20 OFFSET 1819380
postgresql-Wed.log:2024-08-14 21:56:21.066 CEST [3399] gitea@giteadb LOG:  Dauer: 1015.299 ms  Ausführen <unnamed>: SELECT "action".id FROM "action" INNER JOIN "repository" ON "repository".id = "action".repo_id WHERE user_id=$1 AND is_deleted=$2 ORDER BY "action"."created_unix" DESC LIMIT 20 OFFSET 1819360

@lunny
Copy link
Member

lunny commented Aug 15, 2024

In this version, it will use the old code when the page less than 10, otherwise it will use the new code.

@somera
Copy link
Author

somera commented Aug 15, 2024

@lunny sounds good, but when you see the OFFSET

2024-08-15 00:09:56.653 CEST [6735] gitea@giteadb LOG: Dauer: 2259.538 ms Ausführen <unnamed>: SELECT "action".* FROM "action" INNER JOIN "repository" ON "repository".id = "action".repo_id WHERE user_id=$1 AND is_deleted=$2 ORDER BY "action"."created_unix" DESC LIMIT 20 OFFSET 1819340

SELECT action.* should be uses, cause I'm over 10 pages. And the new method was not used.

@lunny
Copy link
Member

lunny commented Aug 16, 2024

@somera
Copy link
Author

somera commented Aug 16, 2024

Looks good.

Page 1-9 old method. Pages 10+ new method. It was good idea to do it.

And the sorting looks good too.

@somera
Copy link
Author

somera commented Aug 16, 2024

@lunny can I restore my datanse now? Or should I wait?

@lunny
Copy link
Member

lunny commented Aug 16, 2024

@lunny can I restore my datanse now? Or should I wait?

Yes, you can restore now. Thank you for your testing.

@somera
Copy link
Author

somera commented Aug 16, 2024

I have to thank you for the implementation of the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance/speed performance issues with slow downs type/proposal The new feature has not been accepted yet but needs to be discussed first.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants