Skip to content
This repository was archived by the owner on Mar 24, 2026. It is now read-only.
This repository was archived by the owner on Mar 24, 2026. It is now read-only.

Rules clarification on retrieving World object #5167

Closed

Description

@bgrainger

I'm requesting a rules clarification for Single Database Query https://github.com/TechEmpower/FrameworkBenchmarks/wiki/Project-Information-Framework-Tests-Overview#single-database-query and Multiple Database Queries.

The wiki states:

For every request, a single row from a World table must be retrieved from a database table.
...
The row should be converted to an object using an object-relational mapping (ORM) tool.
...
Use of an in-memory cache of World objects or rows by the application is not permitted.

I have noticed two different approaches to achieving this. The first approach selects the whole row, e.g., with SELECT id, randomnumber from WORLD where id=$1 then reads both returned fields and converts them to an object. Some examples:

"SELECT ID, RANDOMNUMBER FROM WORLD WHERE ID = ?", ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_READ_ONLY)) {
statement.setInt(1, ThreadLocalRandom.current().nextInt(1, 10001));
ResultSet resultSet = statement.executeQuery();
resultSet.next();
World world = new World(resultSet.getInt(1), resultSet.getInt(2));

.query('SELECT id, randomnumber FROM world WHERE id = @id;', { 'id': _RANDOM.nextInt(_WORLD_TABLE_SIZE) + 1 })
.single
.then((row) =>new World(row[0], row[1]))

$res = $db->exec('SELECT id, randomNumber FROM World WHERE id = ?',$id,0,false);
$result = array(
'id' => (int) $res[0]['id'],
'randomNumber' => (int) $res[0]['randomNumber'],
);

The second approach selects just the randomnumber field and relies on id being the same as the query parameter. Some examples:

*client << "select randomnumber from world where id=$1" << id >>
[callbackPtr, id](const Result &rows) {
auto resp = HttpResponse::newHttpResponse();
char json[64];
auto size = sprintf(json,
"{\"id\":%d,\"randomnumber\":%s}",
id,
rows[0]["randomnumber"].c_str());

$db->db_test = $db->db_test ?? $db->prepare('SELECT randomNumber FROM World WHERE id = ?');
// For each query, store the result set values in the response array
while ($query_count--) {
$id = mt_rand(1, 10000);
$ret = $db->db_test->execute([$id]);
// Store result in array.
$arr[] = ['id' => $id, 'randomNumber' => $ret[0]['randomNumber']];

string query = "SELECT randomNumber FROM world WHERE id = " ~ id.to!string;
ResultSet rs = dbConnection.query(query);
JSONValue js = JSONValue(["id" : JSONValue(id), "randomNumber"
: JSONValue(to!int(rs.front()[0]))]);

The second approach seems like it would substantially reduce the required bandwidth from the database to the application (returning just one field, not two) and require less deserialisation; I haven't tested both approaches side by side in the same application to prove there's a performance difference, but I assume it could have a material impact on the results.

Additionally, the second approach feels like it's violating the spirit of the rules: it is not retrieving "a single row", the (whole) row is not being converted, and (arguably) in-memory caching (of the ID) is being used.

Can there be an official clarification of whether this approach to the problem is permitted or not? (If it's disallowed, several dozen frameworks may need to be updated to comply.)

Activity

  1. NateBrady23 commented on Oct 21, 2019

    @NateBrady23
    Member

    Hey @bgrainger,

    You're right and I've updated the rules for test #2 to clarify that reading just the random number is not acceptable. We should identify the implementations that are doing that here and try and get them addressed.

    There may have been some confusion, since the updates test does allow it:

    6. At least the `randomNumber` field must be read from the database result set.
    

    Thanks for pointing that out!

  2. bhauer commented on Oct 21, 2019

    @bhauer
    Contributor

    @bgrainger Thanks for doing the legwork necessary to identify this and for bringing it to our attention.

    I agree with your assessment that selecting only the randomNumber column does not seem to align well with the spirit of the test. However, as @nbrady-techempower points out, we had previously conceded in the Updates test that reading just the randomNumber field was sufficient.

    For the Multi-queries test, Nate has decided (and I agree) that we should stick with the original vision of requiring that the full row (including the id column) is read.

    Some background: When we originally conceived of our database tests, we had assumed an ORM would be used. When we broadened the database tests to allow non-ORM implementations (which was a very long time ago), we should have been more clear about expectations. It's no surprise that a lack of specificity led to (unintended) flexibility.

  3. NateBrady23 commented on Jun 1, 2020

    @NateBrady23
    Member

    I don't see it in the requirements now.

    Which requirement is missing?

    For every request, a single row from a World table must be retrieved from a database table. It is not acceptable to read just the randomNumber.

    This is in the single requirements test and also in the multi requirements test is:

    Each row must be selected randomly in the same fashion as the single database query test (Test #2 above)

    I might be missing what you're talking about. It is Monday morning here. 🥱

  4. NateBrady23 commented on Jun 1, 2020

    @NateBrady23
    Member

    I think we can close this, now. Thanks all!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions