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

fix(backend): timeout when querying mentions #11799

Merged
merged 1 commit into from
Sep 7, 2023

Conversation

zekexy
Copy link
Contributor

@zekexy zekexy commented Sep 7, 2023

What

I use a trick to avoid using primary key to solve a slow query problem. Is there any other better way?

Why

For queries like this, postgresql sometimes decides to scan the primary key instead of using the index on "visibleUserIds" field

EXPLAIN
SELECT
	"note"."id" AS "note_id"
FROM
	"note" "note"
WHERE
	'{"01GWCS86KKFQX39VH79KMD48JS"}' <@"note"."visibleUserIds"
ORDER BY
	"note"."id" DESC
LIMIT 10

However, postgresql doesn't know that sometimes users' data distribution is very uneven, which is the reason for the timeout problems some people have.

Additional info (optional)

Expected to be fast, actually very slow :
image

Satisfactory speed :
image

Checklist

  • Read the contribution guide
  • Test working in a local environment
  • (If needed) Add story of storybook
  • (If needed) Update CHANGELOG.md
  • (If possible) Add tests

@github-actions github-actions bot added the packages/backend Server side specific issue/PR label Sep 7, 2023
@zekexy zekexy changed the title fix: timeout when querying mentions fix(backend): timeout when querying mentions Sep 7, 2023
@codecov
Copy link

codecov bot commented Sep 7, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.06% 🎉

Comparison is base (90b058e) 78.70% compared to head (022f99c) 78.77%.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #11799      +/-   ##
===========================================
+ Coverage    78.70%   78.77%   +0.06%     
===========================================
  Files          926      924       -2     
  Lines        97860    97693     -167     
  Branches      7752     7777      +25     
===========================================
- Hits         77025    76960      -65     
+ Misses       20835    20733     -102     
Files Changed Coverage Δ
...backend/src/server/api/endpoints/notes/mentions.ts 94.73% <100.00%> (+0.11%) ⬆️

... and 19 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@syuilo syuilo merged commit af7e129 into misskey-dev:develop Sep 7, 2023
14 of 15 checks passed
@syuilo
Copy link
Member

syuilo commented Sep 7, 2023

🙏🙏🙏

@zekexy
Copy link
Contributor Author

zekexy commented Sep 10, 2023

#7632 may be solved

@zekexy zekexy mentioned this pull request Sep 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
packages/backend Server side specific issue/PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants