A SELECT query that returns 10 rows, twice as expensive as 5 rows?

121 views
Skip to first unread message

Eurig Jones

unread,
Sep 8, 2011, 4:45:04 PM9/8/11
to Google App Engine
Hi,

I'm just trying to clarify here. Will a SELECT query on 10 rows be
exactly twice as expensive in terms of "datastore operations" as the
same SELECT query if it returned 5 rows?

Thanks!

Matt Jibson

unread,
Sep 8, 2011, 4:58:04 PM9/8/11
to google-a...@googlegroups.com
Yes. From http://code.google.com/appengine/kb/postpreviewpricing.html#operations_charged_for:

If I do db.get([key1, key2]), and two entities were fetched, how many
'operations' have I consumed?
2 entity fetches.

If key2 didn't exist and only one entity was fetched, what would be the cost?
2 entity fetches.

If db.get(key1) fetches a 5kb entity and db.get(key2) fetches a 500kb
entity, what's the difference in cost?

No difference.

> --
> You received this message because you are subscribed to the Google Groups "Google App Engine" group.
> To post to this group, send email to google-a...@googlegroups.com.
> To unsubscribe from this group, send email to google-appengi...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en.
>
>

Eurig Jones

unread,
Sep 8, 2011, 5:08:03 PM9/8/11
to Google App Engine
Yes, but what I'm asking here is SELECT queries, and not fetching by
multiple KEYS. I've seen the documentation you linked to, but it is
still not clear as this is using KEYS, not a basic SELECT with a
filter or two. fetching by key is different to doing so without..

"SELECT X FROM Y" returned 10 rows today, but tomorrow the exact same
query returs 5. Would it be half the price tomorrow in terms of
"Datastore Operations"?

On Sep 8, 9:58 pm, Matt Jibson <matt.jib...@gmail.com> wrote:
> Yes. Fromhttp://code.google.com/appengine/kb/postpreviewpricing.html#operation...

culov

unread,
Sep 8, 2011, 6:14:01 PM9/8/11
to Google App Engine
I would also like to know the answer to this question.

Eurig Jones

unread,
Sep 9, 2011, 5:54:59 AM9/9/11
to Google App Engine
Can anyone shed light on this? This seems like a very important thing
to understand to know how to optimise!

Simon Knott

unread,
Sep 9, 2011, 6:33:34 AM9/9/11
to google-a...@googlegroups.com
Hi,

Did you read the FAQ that was linked?  It's quite clear that if you fetch 10 entities, then this will be double the cost of fetching 5 entities.

  • Read operations (Query, Entity Fetch) Each of these operations will cost $0.07 per 100k operations.

"Under the new scheme, is it more economical to do a keys-only query that fetches 1000 keys, and then do a get() on the 500 of them that I need, or just do a regular (non keys-only) query for all 1000 directly?

The first is more economical. Fetching 1000 keys + fetching 500 entities = $0.0001 + 0.00035 = $0.00045; fetching 1000 entities = $0.0007. "


Therefore, the cost of a query which retrieves 5 entities is $0.0000035, whilst the cost of 10 entities is double this at $0.000007

Eurig Jones

unread,
Sep 9, 2011, 12:22:34 PM9/9/11
to Google App Engine
Exactly where in the text does it state the definition of a "Data
Operation" Simon?

You are assuming that a datastore operation = 1 entity. Maybe it is,
maybe it isn't. But nowhere in the text does it state this.

On Sep 9, 11:33 am, Simon Knott <knott.si...@gmail.com> wrote:
> Hi,
>
> Did you read the FAQ that was linked?  It's quite clear that if you fetch 10
> entities, then this will be double the cost of fetching 5 entities.
>
>    - *Read operations (Query, Entity Fetch)* Each of these operations will
>    cost $0.07 per 100k operations.
>
> *"Under the new scheme, is it more economical to do a keys-only query that
> fetches 1000 keys, and then do a get() on the 500 of them that I need, or
> just do a regular (non keys-only) query for all 1000 directly?*
>
> The first is more economical. Fetching 1000 keys + fetching 500 entities =
> $0.0001 + 0.00035 = $0.00045; *fetching 1000 entities = $0.0007.* "

Simon Knott

unread,
Sep 9, 2011, 3:19:13 PM9/9/11
to google-a...@googlegroups.com
Under the section "Which datastore operations incur charges? "

Eurig Jones

unread,
Sep 9, 2011, 4:40:30 PM9/9/11
to Google App Engine
Quoted from FAQ:

There are 3 categories of Datastore operations:
Write operations (Entity Put, Entity Delete, Index Write) Each of
these operations will cost $0.10 per 100k operations.
Read operations (Query, Entity Fetch) Each of these operations will
cost $0.07 per 100k operations.
Small operations (Key Fetch, Id Allocation) Each of these operations
will cost $0.01 per 100k operations.

So where from there exactly do you deduce that a data-store operation
= 1 entity? in a query. It states that a "Query" is one operation. It
also suggests that fetching one entity is one operation. It does not
however specify that 1 entity will cost a data operation as part of a
result of a query.

.. also, if a Query cost 1 op, and returned 2 results. What is the
cost of this? 3 or 2, or what?

Simon Knott

unread,
Sep 9, 2011, 5:22:54 PM9/9/11
to google-a...@googlegroups.com
The very last example in the datastore pricing section gives a comparison between a keys-only query, with key fetches, versus a normal query and gives the cost of that query for 1000 entities.
From their maths, it can be seen that the cost of a query is actually the cost of fetching the entities. That answers your original question - I would agree that it's not clear whether you pay for a query which has no results.

Steve

unread,
Sep 9, 2011, 6:35:39 PM9/9/11
to google-a...@googlegroups.com
My interpretation of the example is that a Query always uses 1 Read Operation. It also uses X Read Operations (or X Small Operations for a keys_only query) where X is the number of entities matching the query.  Conversely, GETing entities by key does NOT incur the 1 Query Read Operation but does charge you for every key fetched even if the corresponding entity does not exist.

--Steve

Reply all
Reply to author
Forward
0 new messages