Which one is fastest?

Let say I have 2 “tables”, User and Post. A user can have multiple posts.

user: default .
name: string .
post: uid @count .

Which one of these queries is the fastest? This one:

user(func: has(user)) @filter(uid(USER_ID)) {
	name
	posts: post {
		uid
	}
}

or this one:

user(func: has(user)) @filter(uid(USER_ID)) {
	name
}

var(func: has(user)) @filter(uid(USER_ID)) {
	P as post
}

posts(func: uid(P)) {
	uid
}

or this one (need to add @reverse in post schema):

user(func: has(user)) @filter(uid(USER_ID)) {
	name
}

posts(func: has(post)) @cascade {
	~post @filter(uid(USER_ID))
	uid
}

I prefer posts to be at same level with (not nested inside) user in the resulting JSON, but if the performance/disk storage difference is significant, I’m ok with the fastest/cheapest option.

This one will be pretty fast.

user(func: uid(USER_ID)) #@filter(has(user))
 {
	name
	posts: post {
		uid
	}
}

has func would never be fastest.There isn’t a lot difference between multiple blocks and nested blocks. But nested are better by various reasons.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.