Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize creating preview queries on the FE #42831

Closed
ranquild opened this issue May 17, 2024 · 0 comments · Fixed by #42836
Closed

Optimize creating preview queries on the FE #42831

ranquild opened this issue May 17, 2024 · 0 comments · Fixed by #42836
Assignees
Labels
.Task Not a part of any Epic, used by the Task Issue Template
Milestone

Comments

@ranquild
Copy link
Contributor

ranquild commented May 17, 2024

Currently the FE constructs preview queries by dropping clauses from the main query

This is very inefficient and caused significant performance issues in the fast. We added a workaround by computing the preview query for each step only when the user clicks the preview button. It's no longer the case now because we need to compute preview queries upfront to calculate whether the query is valid for previewing. So now performance issues are back.

We need a performant way to construct preview queries. It should be straightforward to add a MBQL lib function for this:

type ClauseType = 
  | "data"
  | "joins"
  | "expressions"
  | "filter"
  | "aggregation"
  | "breakout"
  | "order-by"
  | "limit";

function previewQuery(query: Query, stageIndex: number, clauseType: ClauseType, clauseIndex: number | null): Query

The function should return a query with all the stages after stageIndex dropped, and all the clauses after clauseType dropped. Also clauseIndex can be optionally provided; in this case only clauses of this type in the range [0, clauseIndex] should remain.

Examples:

const query = {
  "source-table": 1,
  "joins": [join1, join2],
  "expressions: { ... },
  "filter": ["and, filter1, filter],
  "aggregation": [aggregation1, aggregation2],
  "breakout": [breakout1, breakout2],
  ...
}

previewQuery(query, 0, "data") =>
{
  "source-table": 1,
}

previewQuery(query, 0, "joins") =>
{
  "source-table": 1,
  "joins": [join1, join2]
}

previewQuery(query, 0, "joins", 0) =>
{
  "source-table": 1,
  "joins": [join1]
}

previewQuery(query, 0, "expressions") =>
{
  "source-table": 1,
  "joins": [join1, join2],
  "expressions": { ... }
}
@ranquild ranquild added the .Task Not a part of any Epic, used by the Task Issue Template label May 17, 2024
@ranquild ranquild added this to the 0.50 milestone May 17, 2024
bshepherdson added a commit that referenced this issue May 29, 2024
…ew (#42836)

Fixes #42831.

Co-authored-by: Alexander Polyankin <alexander.polyankin@metabase.com>
bshepherdson added a commit that referenced this issue May 29, 2024
…ew (#42836)

Fixes #42831.

Co-authored-by: Alexander Polyankin <alexander.polyankin@metabase.com>
bshepherdson added a commit that referenced this issue May 30, 2024
…ew (#42836) (#43327)

Fixes #42831.

Co-authored-by: Braden Shepherdson <braden@metabase.com>
Co-authored-by: Alexander Polyankin <alexander.polyankin@metabase.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
.Task Not a part of any Epic, used by the Task Issue Template
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants