GQL Query for Existence: Get vs. Key Query vs. Entity Query
<p>While the Google Cloud Client Library has a lot of built-in functionality, I haven't found anything to use when querying for an Entitys existence based on its id. From what I understand, it is much more efficient to make a key query, than an entity query like so. </p>

<pre><code>SELECT __key__ FROM User WHERE __key__ = Key(User, 1)
</code></pre>

<p>If possible from within a Java app, using the <code>get(Key key)</code> function would be even better.</p>

<pre><code>Datastore datastore = DatastoreOptions.getDefaultInstance().getService();
KeyFactory keyFactory = datastore.newKeyFactory().setKind(User);
Key key = keyFactory.newKey(1);
Entity entity = datastore.get(key);
</code></pre>

<p>If I have an instance where my Entity has ancestors as well, which would be more efficient of the three when querying for the existence of an ancestor with just the parent ID?
I assume that the entity query (<code>SELECT * From Parent WHERE __key__ = Key(Parent, 1)</code>) will always be slower than a key query, but how about when compared to the get? </p>

<p>What about when the ancestor paths are chained even longer?
Then the key queries may become something along the likes of:</p>

<pre><code>SELECT __key__ FROM Grandchild WHERE __key__ = Key(Parent, 1, Child, 1, Grandchild, 1)
</code></pre>