Performance issue with large-ish nested query
See original GitHub issueHasura version: v1.0.0-alpha23
I have a 40k row table I’m joining to a 5.5m row table. Querying with Hasura is exceptionally slow, but Postgres isn’t.
The GraphQL query looks like this:
{
blocksummary_total (limit: 10){
total_payments
amount_due
blockYearly {
year
violation_code
violation_description
}
}
}
I’ve limited it to 10 results because much more than that and Hasura just hangs for so long I’m forced to give up. Running with a limit of 10 takes between 10-20seconds. Here’s an example log line for this query:
{"timestamp":"2018-10-11T15:07:54.667+0000","level":"info","type":"http-log","detail":{"status":200,"query_hash":"476106a5c31616b2b50f3e59cfb2d6874135ce56","http_version":"HTTP/1.1","query_execution_time":13.5884354,"request_id":null,"url":"/v1alpha1/graphql","hasura_metadata":null,"ip":"172.17.0.1","response_size":592159,"method":"POST","hasura_role":null,"detail":null}}
What I believe is the equivalent SQL-native query (forgive my ignorance for not yet having figured out how to access the query Hasura is constructing):
explain analyze select
t.geocoded_address,
t.total_payments,
t.amount_due,
y.year,
y.violation_code,
y.violation_description
from blocksummary_total t
join blocksummary_yearly y
on t.geocoded_address = y.geocoded_address
limit 10;
The query plan and actual execution for this query:
-> Nested Loop (cost=0.41..2553486.26 rows=5510465 width=105) (actual time=0.353..0.849 rows=10 loops=1)
-> Seq Scan on blocksummary_yearly y (cost=0.00..166756.65 rows=5510465 width=90) (actual time=0.011..0.012 rows=10 loops=1)
-> Index Scan using blocksummary_total_pk on blocksummary_total t (cost=0.41..0.43 rows=1 width=57) (actual time=0.082..0.082 rows=1 loops=10)
Index Cond: ((geocoded_address)::text = (y.geocoded_address)::text)
Planning time: 3.180 ms
Execution time: 1.417 ms
The same query on the full dataset in Postgres takes about 5 seconds. I haven’t been able to get it to work at all in Hasura.
Am I doing something wrong? Did I find a bug?
Use case: I’m using Hasura with GatsbyJS to generate tens of thousands of pages for a news application about parking tickets in Chicago.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:15 (6 by maintainers)
Is it possible for you to add an index on
geocoded_address
column ofblocksummary_yearly
?@eads Hang tight. @0x777 will look into this and get back to you asap.
We’re also adding a “View SQL” button on the console to make getting the SQL easier 😃