vaticle / typeql

TypeQL: the polymorphic query language of TypeDB
https://typedb.com
Mozilla Public License 2.0
213 stars 45 forks source link

How to "exists" query? #206

Closed nicolamassarenti closed 3 years ago

nicolamassarenti commented 3 years ago

Hi,

I wanted to write a query to check if exists at least a thing (entity or relation) in my typeDB but I could find any way of doing that.

The workaround I found is the following query:

match $x isa token, has property "token-property";
get $x;
count;

then, if count > 0, it means that it exists at least a token. I believe that this query is inefficient because it has to search all the entities/relations in my DB. I wonder if exists a more efficient way of getting the same result, may with something like:

match $x isa token, has property "token-property";
get $x;
exists;

that returns the result as soon as it discovers the first match.

Do you have any suggestions?

vmax commented 3 years ago

@nicolamassarenti one way you could speed up such a query is add a limit clause:

match $x isa token, has property "token-property"; limit 1;

Then, as soon as a single entity is found, the query would terminate and return a result

haikalpribadi commented 3 years ago

This question is more appropriate to be posted in the discussion forum or in the community chat, @nicolamassarenti. GitHub issues are for feature request or bug reports. I will close this now.