Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8427199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:43:31+00:00 2026-06-10T04:43:31+00:00

Consider the following two alternatives. A) Storing the key in the struct. type Point

  • 0

Consider the following two alternatives.

A) Storing the key in the struct.

type Point struct {
    Place *datastore.Key
    Lat   float64
    Lon   float64
}

Then fetching using the key:

place := new(Place)
if err := datastore.Get(c, k, point.Place); err != nil {
    return err
} 

B) Storing the id

type Point struct {
    Place int64
    Lat   float64
    Lon   float64
}

Then fetching after creating the key.

k := datastore.NewKey(c, "Place", "", point.Place, nil)
place := new(Place)
if err := datastore.Get(c, k, place); err != nil {
    return err
} 

Storing the key instead of the id takes a bit more space. In order to see the tradeoff, it would be great to get a feeling for how much resources it takes to create a key. In other words, is it really cheap to create a key, or is it better to create it once and store it?

With a single key, it probably doesn’t matter much, but let’s say that I fetch a list of points, and for each point I want to retrieve the place (i.e. loop through the points to build an array of keys, and fetch them).

Edit: I am not thinking about allocating IDs or keys here, only using them (i.e. all points and places are already in the datastore, the question is just whether to store the id or the entire key).

Ex animo,
Alexander Yngling

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T04:43:32+00:00Added an answer on June 10, 2026 at 4:43 am

    Key is basically just a wrapper around a set of properties: kind, id/name, parent key(s), namespace.

    So creating a Key from a kind and ID costs nothing, as this is a local operation (does not require Datastore).

    OTOH, Key allocation does cost as this creates a Key with unique ID and this needs to Query a Datastore under the hood.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following two FFI structs: class A < FFI::Struct layout :data, :int end
Consider the following two struct : struct a { int a; }; struct b
Consider the following two alternatives: console.log("double"); console.log('single'); The former uses double quotes around the
Consider the following two structures: template <typename T> struct duplet{ QString str; T value;
Consider the following two EXPLAINs: EXPLAIN SELECT * FROM sales WHERE title != 'The'
Consider the following two Java files that contain a simplified version of my issue
Consider the following two toolbars that are in the same project of mine: Notice
Consider the following two snippets: Exhibit A : template<typename CalcFuncT> int perform_calc(CalcFuncT&& calcfunc) {
Do splitting fields into multiple tables ever yield faster queries? Consider the following two
I'm a bit puzzled about the conditional operator. Consider the following two lines: Float

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.