-
Notifications
You must be signed in to change notification settings - Fork 421
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
Simple query takes long time to run #1974
Comments
@Kobaruon How long a query takes, or is expected to take, depends on the dataset, the query, and machine it is running on. This particular query, while looking simple, searches for a match regardless of direction |
@jrgemignani it takes around 3 minutes to run, we expect around 1 second execution time. DB vm has 8 cores 32GB memory, but the data size is small ~600mb. We have a very similar query, same table structure and same indexes. On that table, query below runs under 1 second.
I mean yes without LIMIT it takes ages to run, but with LIMIT we expect fast execution. |
@Kobaruon The first relevant article hinted at disabling this, but with caution, that it should only applied locally to specific query. |
@MironAtHome I am using postgresql 16.3
Explain analyze of the fast query
I tried your recommendation and it seems to make the query faster, however the query itself is already faster without making any changes for some reason. It's still slower than what we expected, but it's a great improvement. Original: Takes 19.8sec Tweaked: 2.7sec
|
Please see additional link, forcing single threaded execution. |
Sorry completely missed that, but it seems to increase execution time.
|
Ok, looks like experiment hints that
Query 2:
Seeing row counts askew in the query plan, depending on direction of relationship, provoked my curiosity, so, I would like to confirm. |
I restarted the server and tried again with If you give any direction query runs much much faster and yes seems like these two produce idential output. |
Since 100 rows do produce identical output, I would suggest running without limit ( I would expect to produce also, identical output ) once.
|
@Kobaruon As I mentioned earlier While you may have a similar query that runs faster, and is also directionless, the runtime depends on the total number of vertices and edges that are selected and how connected they are. It could be that the faster query involves a less connected set than the slower one. Just a thought without seeing the actual data. Edit: I should mention that the match logic is likely inefficient for directionless edges as AGE only builds digraphs. This is something our team should look into, in the future, given time. |
After studying closely behavior of operators ()-[]-() and ()-[]->() it is evident, that data will be presented as following: Match (v1)-[:knows]-(v2) We will get back Now, if we were to issue query However, for the name producing query, there would be no difference. In other words, Behaves as To summarise, looking at the last query just one line above, it's 2x the number of rows stored, with the same relationship listed twice, except switching the sides of the data. In case producing rows once with relationship going left to right is acceptable, query can be expressed as Hope this helps. |
Thanks everyone for the quick help and detailed analysis. |
This simple query takes about 3 minutes to run. Is this normal behaviour? Is there a room for improvement here in terms of indexing or rewriting the query?
Explain Analyze
The text was updated successfully, but these errors were encountered: