Pergunta

A common issue in app development is avoiding over-fetching of data, such as in this naive (pseudocode) example:

get_user(id) {
  return sql_query("SELECT * FROM users WHERE id=$1", id);
}

render_some_webpage() {
  // ...
  print get_user(session.user_id).username;
  // ...
}

While this would work, it requires the database to send back a bunch of user fields when only the username is used (it's not a big deal in this trivial example, but gets much worse when associations/joins are involved). This problem is normally solved via adding an additional argument to get_user with a list of required fields, but that's far from a perfect solution. It seems the language could infer which fields of the user were actually used and allow get_user to act on this information (by only fetching the username).

Is this a known concept? Are there languages that implement this idea?

Nenhuma solução correta

Licenciado em: CC-BY-SA com atribuição
Não afiliado a cs.stackexchange
scroll top