这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@lexi-lambda
Copy link
Contributor

Description

When multiplexing subscription queries, we lose out on significant opportunities to group multiple queries together because we only parameterize over SQL values that originally came from GraphQL variables. For ordinary queries, that makes sense, since parameterization only really helps us reuse query plans, and we can only reuse query plans if all values come from GraphQL variables (since the generated SQL won’t change).

For the purposes of live queries, however, it’s too pessimistic. For example, consider the following query:

subscription latest_tracks($condition: tracks_bool_exp!) {
  tracks(where: $tracks_bool_exp) {
    id
    title
  }
}

This query might be executed with similar values for $condition, such as {"album_id": {"_eq": "1"}} and {"album_id": {"_eq": "2"}}. Since all that changes in the generated SQL is the value being compared against, we can still take advantage of the similarity between the two queries by multiplexing them together.

As it was useful for implementing the test suite, this set of changes also adds support for explaining subscriptions, reusing some of the functionality from #2650 and otherwise subsuming it.

Affected components

  • Server

Related Issues

https://github.com/hasura/graphql-engine-internal/issues/260#issuecomment-532699211

Solution and Design

To implement this, multiplexed queries now have a third input, synthetic variables, in addition to query and session variables. Synthetic variables are collected from the generated SQL in the order they appear, and they are passed as a JSON array and accessed by index.

Synthetic variable values can be cached and reused by reusable query plans, so their validated values are also stored in ReusableLiveQueryPlan values.

Steps to test and verify

The test suite verifies the implementation by checking that the generated SQL is identical for two queries that previously generated different SQL.

@lexi-lambda lexi-lambda added the c/server Related to server label Sep 26, 2019
@lexi-lambda lexi-lambda requested a review from 0x777 September 26, 2019 04:21
@netlify
Copy link

netlify bot commented Sep 26, 2019

Deploy preview for hasura-docs ready!

Built with commit 1c91811

https://deploy-preview-2942--hasura-docs.netlify.com

@hasura-bot
Copy link
Contributor

Review app for commit 1c91811 deployed to Heroku: https://hge-ci-pull-2942.herokuapp.com
Docker image for server: hasura/graphql-engine:pull2942-1c918119

@lexi-lambda lexi-lambda merged commit 18e8fba into hasura:master Sep 30, 2019
@hasura-bot
Copy link
Contributor

Review app https://hge-ci-pull-2942.herokuapp.com is deleted

@lexi-lambda lexi-lambda deleted the more-subscription-parameterization branch September 30, 2019 19:51
lexi-lambda pushed a commit that referenced this pull request Oct 3, 2019
* fix incorrect references to result variables
* remove docs/code related to 'fallback' backend
polRk pushed a commit to polRk/graphql-engine that referenced this pull request Feb 12, 2020
…asura#2942)

Also, add support for explaining subscriptions while we’re at it.
polRk pushed a commit to polRk/graphql-engine that referenced this pull request Feb 12, 2020
…asura#3005)

* fix incorrect references to result variables
* remove docs/code related to 'fallback' backend
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c/server Related to server

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants