-
Notifications
You must be signed in to change notification settings - Fork 264
Slow initial query on postgres backend when using enum columns #281
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
Comments
I don't think it's related to |
As I observed exactly the same results, I think you might be another victim of the introspection query in asyncpg. This issue was a major one already before: See a great article on real-life impact of this issue here: https://dev.to/xenatisch/cascade-of-doom-jit-and-how-a-postgres-update-led-to-70-failure-on-a-critical-national-service-3f2a As far as I understand from discussions around GH and SO, a lot of people think that enabling JIT by default in postgres is a good idea, while also a lot of people think otherwise (see for example this reddit thread). The summary of solutions I've encountered:
|
Very interesting thank you for the details it sounds like this can be closed as it is not a databases problem! |
Uh oh!
There was an error while loading. Please reload this page.
I haven't quite figured out why this is happening, but I have made a minimal test case where you can see the problem in action. I am hoping someone here may be able to help me debug further what is going on.
The problem appears to be to do with the Postgres Enum column type, and only occurs on the initial call of
fetch_all
after callingconnect
. After the initial call tofetch_all
all subsequent queries run at the expected speed, but the initial query has a ~2 second delay. Callingdisconnect
thenconnect
again appears to reset this.In our actual use case we only have one Enum column, but for the minimal test case it seems I need two Enum columns to trigger the delay.
Minimal test case:
When I run this I see:
scite-api-fastapi-BjBDzBrP-py3.8 > python -m testdb Using query: SELECT mytable.id, mytable.my_column_1, mytable.my_column_2 FROM mytable first fetch_all took: 2.0069031715393066 seconds Using query: SELECT mytable.id, mytable.my_column_1, mytable.my_column_2 FROM mytable second fetch_all took: 0.0011420249938964844 seconds
When I remove one of the Enum columns (delete the line
my_column_2 = Column(Enum(MyEnum2))
) I see:It runs much quicker!
Does anyone have an idea of what might be causing this?
The text was updated successfully, but these errors were encountered: