Tip #4 - Don't use vertex set memory if you don't have to

This is a tiny one.

Often we want to perform a SELECT with side effects, and don’t care what is returned.

We can exploit the HAVING clause to do this, rather than allocate the memory and clear it.

The old way (works and is explicit, but we can do better):

  NoNeed = SELECT s FROM G:s-(:e)->:t 
	ACCUM @@allE += e;

  NoNeed.clear(); // We allocated it, and now we clear it

The sneakier (and I think better) way:

NoNeed = SELECT s FROM G:s-(:e)->:t 
	ACCUM @@allE += e;
	HAVING 1==0;

See what we did there? The having clause prevents anything from being returned to the output vertex set, and so we avoid allocating memory only to have to clear it later.

1 Like

Seed Sets like NoNeed takes very few memory resources in general situation.

For Example,

NoNeed = {ANY};
NoNeed = {SomeVertexType.*};

And HAVING 1==0; will execute #result_size(after where clause) times vertex_reduce action (1==0 ), if result_size is to large, i will take times to do this.

So need to balance Seed Set Size and vertex_reduce execute time.

1 Like