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

perf: Speed up parsing of a huge query with a lot of conditional mutations #7871

Merged
merged 4 commits into from
Sep 23, 2021
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions edgraph/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,10 @@ func buildUpsertQuery(qc *queryContext) string {
}

qc.condVars = make([]string, len(qc.req.Mutations))
upsertQuery := strings.TrimSuffix(qc.req.Query, "}")

var b strings.Builder
b.WriteString(strings.TrimSuffix(qc.req.Query, "}"))
Phill240 marked this conversation as resolved.
Show resolved Hide resolved

for i, gmu := range qc.gmuList {
isCondUpsert := strings.TrimSpace(gmu.Cond) != ""
if isCondUpsert {
Expand All @@ -852,13 +855,13 @@ func buildUpsertQuery(qc *queryContext) string {
// The variable __dgraph_0__ will -
// * be empty if the condition is true
// * have 1 UID (the 0 UID) if the condition is false
upsertQuery += qc.condVars[i] + ` as var(func: uid(0)) ` + cond + `
`
b.WriteString(qc.condVars[i] + ` as var(func: uid(0)) ` + cond + `
`)
}
}
upsertQuery += `}`
b.WriteString(`}`)

return upsertQuery
return b.String()
}

// updateMutations updates the mutation and replaces uid(var) and val(var) with
Expand Down