-
Notifications
You must be signed in to change notification settings - Fork 45
Occasional syntax errors from well formed search queries #233
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 bisected this. On 0.7.7 running the above code succeeds, and looking at the searches table I can see that the |
Just for the record, we're experiencing this issue as well. |
@mrob95 So far I have not been able to replicate this using your script (or just running in parallel using the following bash script) even cranking the number of parallel processes up to 12.
If anything, I would guess that that bit of code that you found is the culprit. Can you see if you can replicate if you change the search_query function out to this which should ensure that the search variable doesn't get overwritten?
|
cc @drnextgis ☝️ |
Thanks, @bitner. I'll give it a look. I can replicate the issue easily following @mrob95's suggestion:
This occurs right after the initial execution. To reproduce it, I need to clear the |
@bitner, with the changes you suggested, I can't seem to reproduce the issue, so it looks like it did the trick. However, I have a question. After the initial execution, the value of
But after the subsequent execution, it increases by 1. Shouldn't it increase by 2?
|
Ideally, it should be starting at 1 and increase by 1 each time the same query comes. I do have a "skip locked" in the update, so if there is contention, it will just skip updating the usecount. The usecount is really a "nice to have" to get a general sense of what queries are being used the most and at least for my use cases, I'd rather just not update that column than need to wait for any locks to go away when there are concurrent identical queries. |
Thanks for tracking this down! |
@bitner, is there a way to prevent the |
@drnextgis I think that depends on the use case. If you are using with titiler-pgstac or anything else that is using the query hash to look up a query, clearing out the searches table would prevent being able to look those up. If you know that you are generally setting the metadata field when registering a search, you can likely safely get rid of anything that has metadata = {} or is null. The search_wheres table (if you are using context) can safely be cleared out on a cron using something like |
This is quite a tricky one to reproduce. We are running pgstac in production and very occasionally get
pq: syntax error at end of input
errors from pgstacsearch
queries. The queries look well formed when we log them.Looking at the database logs I can see:
We are running version 0.8.1, so that line is here - https://github.com/stac-utils/pgstac/blob/v0.8.1/src/pgstac/sql/004_search.sql#L497
I stared at this for a while and couldn't figure out how that where clause could be an empty string, so I started trying to reproduce it locally.
I ended up running
0.8.2
in a container with:Then:
main.go
go mod init pgstac_repro
go get github.com/lib/pq
go run main.go
This will spin up two threads and try to run the same search simultaneously on both. For me this gives the following pretty reliably:
One of them succeeds, the other gives a syntax error with the same query.
The postgres logs show
So, a different error but similar behaviour.
Again, I can't see exactly where the code this could be happening, but rerunning the same program again will not trigger it, you need to either change the query or restart the database to trigger the bug again. I guess this means the problem is related to the query cache/statistics tables.
Any help would be appreciated. Let me know if there are any other details I can provide.
The text was updated successfully, but these errors were encountered: