question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Performance issue with large-ish nested query

See original GitHub issue

Hasura 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:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:15 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
0x777commented, Oct 12, 2018

Is it possible for you to add an index on geocoded_address column of blocksummary_yearly?

create index on blocksummary_yearly (geocoded_address);
1reaction
coco98commented, Oct 11, 2018

@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 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Query performance issue for large nested data in mongodb
I'm trying to query results from a large dataset called 'tasks' containing 187297 documents which are nested into another dataset called ...
Read more >
Nested View- Performance Issue - Microsoft Q&A
i got a issue to solve issue of performance of a Main view calling in SP, ... This can create a very large...
Read more >
Are there any known performance problems when using a ...
Do you know of any performance issues with nested tables that are cast as table() and used in sub-queries? Regards,.
Read more >
Memo: Avoid Nested Queries in MySQL at all costs
This article delves deeper into this issue, and why MySQL performs so poorly with nested subqueries, but not so deep as to drive...
Read more >
Inline Select Causing Incredibly slow query performance
Use temporary table. Temporary table extremely optimize your query performance. · Create Indexes. Esp on columns that you are using. · Run Individual...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found