Skip to content

GraphQL API perf optimizations#2252

Open
peferron wants to merge 7 commits into
DataJunction:mainfrom
peferron:optimizations
Open

GraphQL API perf optimizations#2252
peferron wants to merge 7 commits into
DataJunction:mainfrom
peferron:optimizations

Conversation

@peferron

@peferron peferron commented Jun 11, 2026

Copy link
Copy Markdown

This PR optimizes the performance of fetching cubes via GraphQL.

  • Extends the existing optimization for name to sibling fields. That's the largest gain; around 2x faster when running locally against a copy of our database. I didn't measure a significant perf regression for name-only use cases.
  • Adds an index to node.type, which is useful when fetching cubes since they only represent a small fraction of the overall nodes.
  • Avoids a DB round-trip & materializing a potentially long list of node IDs by using an EXISTS subquery instead, which the Postgres planner will optimize as needed.
  • Remove an apparently obsolete LIKE '%_DOT_% filter which couldn't use indexes—I'll need confirmation that this is indeed safe to remove.

Also adds support for @include and @skip directives; before clients would have to alter the query string itself to get the expected perf gains, which is inconvenient.

Finally, fixes an existing bug (happening on main) where metrics and dimensions within revisions are empty unless non-name fields are also selected. For example, the query below returns empty metrics and dimensions, unless you uncomment some of the fields:

{
  findNodes(nodeTypes: [CUBE], limit: 1) {
    revisions {
      cubeMetrics {
        name
        # columns {
        #   name
        # }
      }
      cubeDimensions {
        name
        # attribute
      }
    }
  }
}

@netlify

netlify Bot commented Jun 11, 2026

Copy link
Copy Markdown

Deploy Preview for thriving-cassata-78ae72 canceled.

Name Link
🔨 Latest commit d173030
🔍 Latest deploy log https://app.netlify.com/projects/thriving-cassata-78ae72/deploys/6a2b54817dd4c700085608f6

@peferron peferron force-pushed the optimizations branch 2 times, most recently from 39c0039 to 43c78de Compare June 11, 2026 23:55

@shangyian shangyian left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this @peferron!

Remove an apparently obsolete LIKE '%DOT% filter which couldn't use indexes—I'll need confirmation that this is indeed safe to remove.

I just ran some confirmation queries in Postgres and this looks like a reasonable assumption:

dj=> SELECT cr.cube_id, col.name, col.node_revision_id, nr.type
FROM cube cr
JOIN "column" col       ON col.id = cr.cube_element_id
LEFT JOIN noderevision nr ON nr.id = col.node_revision_id
WHERE (col.name LIKE '%\_DOT\_%' ESCAPE '\')
   <> (col.node_revision_id IS NOT NULL AND nr.type = 'METRIC')
LIMIT 50;
 cube_id | name | node_revision_id | type
---------+------+------------------+------
(0 rows)

@peferron peferron marked this pull request as ready for review June 12, 2026 00:45
@peferron peferron changed the title Optimizations GraphQL API perf optimizations Jun 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants