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

Conversation

@0x777
Copy link
Member

@0x777 0x777 commented Aug 1, 2019

Currently the 'Analyze' button only works with queries. This PR adds support for subscriptions which lets one check

  1. If a subscription can be multiplexed (and why it if can't be).
  2. The underlying query
  3. The postgres plan.

Affected components

  • Server
  • Console

Related Issues

#2541

Solution and Design

This is part of the current v1/graphql/explain endpoint. For a subscription the response structure will be as follows:

{
  "is_multiplexable": true,
  "reason": null,
  "sql": "\n        select\n          _subs.result_id, _fld_resp.root as result\n          from\n            unnest(\n              $1::uuid[], $2::json[]\n            ) _subs (result_id, result_vars)\n          left outer join lateral\n            (\n        SELECT  coalesce(json_agg(\"root\" ), '[]' ) AS \"root\" FROM  (SELECT  row_to_json((SELECT  \"_1_e\"  FROM  (SELECT  \"_0_root.base\".\"id\" AS \"id\", \"_0_root.base\".\"name\" AS \"name\"       ) AS \"_1_e\"      ) ) AS \"root\" FROM  (SELECT  *  FROM \"public\".\"artists\"  WHERE ((\"public\".\"artists\".\"id\") = (((\"_subs\".\"result_vars\"#>>ARRAY['variables', 'artist_id']))::integer))     ) AS \"_0_root.base\"      ) AS \"_2_root\"      \n            ) _fld_resp ON ('true')\n        ",
  "plan": [
    "Nested Loop Left Join  (cost=2.40..243.00 rows=100 width=48)",
    "  ->  Function Scan on _subs  (cost=0.01..1.00 rows=100 width=48)",
    "  ->  Aggregate  (cost=2.39..2.40 rows=1 width=32)",
    "        ->  Index Scan using pk_artists on artists  (cost=0.15..2.37 rows=1 width=25)",
    "              Index Cond: (id = ((_subs.result_vars #>> '{variables,artist_id}'::text[]))::integer)",
    "        SubPlan 1",
    "          ->  Result  (cost=0.00..0.01 rows=1 width=32)"
  ]
}

The fields are:

  1. is_multiplexable: If true the subscription can be multiplexed.
  2. reason: Why the server thinks that the subscription cannot be multiplexed (null if is_multiplexed is true).
  3. sql: The sql used in fetching the results for the subscription. In case of multiplexed subscriptions, the query will be different (to accommodate fetching the results of multiple subscriptions in the same query).
  4. plan: Postgres's explain analyze for the above sql.

Steps to test and verify

Needs console changes

Limitations, known bugs & workarounds

None

@0x777 0x777 requested a review from lexi-lambda as a code owner August 1, 2019 08:06
@netlify
Copy link

netlify bot commented Aug 1, 2019

Deploy preview for hasura-docs ready!

Built with commit cc52320

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

@netlify
Copy link

netlify bot commented Aug 1, 2019

Deploy preview for hasura-docs ready!

Built with commit fdedb61

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

@hasura-bot
Copy link
Contributor

Review app for commit fdedb61 deployed to Heroku: https://hge-ci-pull-2650.herokuapp.com
Docker image for server: hasura/graphql-engine:pull2650-fdedb610

Copy link
Contributor

@lexi-lambda lexi-lambda left a comment

Choose a reason for hiding this comment

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

I’ve left a handful of minor questions/comments, but this generally LGTM.

, MonadIO m
)

-- | to validate arguments
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the syntax Haddock expects for documenting arguments is the -- ^ some description form (which goes under the type rather than above), and in fact I believe doing it this way actually causes Haddock to barf. I personally think it’s a bit silly, but oh well.

data LiveQueryOp
= LQMultiplexed !LQM.MxOp
| LQFallback !LQF.FallbackOp
data LiveQueryOpG f m
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you tell me what the G stands for in these types? “Grammar”? “General”?


type LiveQueryOpPartial = LiveQueryOpG FallbackOpPartial MultiplexedOpPartial

-- | Creates a partial live query operation, used in both
Copy link
Contributor

Choose a reason for hiding this comment

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

What exactly is a “partial” live query operation—which parts of a “full” live query does it include and which parts does it lack?

]
-- get the variables which don't conifrm to the
-- 'non-null scalar' rule
getNonConfirmingVariables usedVariables =
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be “conforming” rather than “confirming”?

data SubscriptionExplainOutput
= SubscriptionExplainOutput
{ _seoIsMultiplexable :: !Bool
-- only exists when subscription is not multiplexed
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar to the comment about function arguments above, you can make this comment show up in the haddocks if you put it beneath the field instead of above it and use the -- ^ syntax.

GR.UVSessVar ty sessVar ->
return $ fromResVars ty [ "user", T.toLower sessVar]
GR.UVSQL sqlExp -> return sqlExp
type FallbackOpPartial = (GR.QueryRootFldUnresolved, Set.HashSet G.Variable)
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor, mostly unimportant comment, but: I wonder if there’s a good way to encode into the type system that this HashSet must be non-empty.

@lexi-lambda
Copy link
Contributor

Integrated into/subsumed by 18e8fba.

@hasura-bot
Copy link
Contributor

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

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.

3 participants