Repository navigation
Rules clarification on retrieving World object #5167
Description
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:
Lines 47 to 52 in a947058
| "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)); |
FrameworkBenchmarks/frameworks/Dart/start/server.dart
Lines 345 to 347 in a947058
| .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])) |
FrameworkBenchmarks/frameworks/PHP/fat-free/index.php
Lines 38 to 42 in a947058
| $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:
FrameworkBenchmarks/frameworks/C++/drogon/drogon_benchmark/controllers/DbCtrlRaw.cc
Lines 22 to 29 in a947058
| *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()); |
FrameworkBenchmarks/frameworks/PHP/swoole/swoole-server.php
Lines 33 to 41 in a947058
| $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']]; |
FrameworkBenchmarks/frameworks/D/hunt/mmap/DemoProcessor.d
Lines 169 to 173 in a947058
| 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
NateBrady23 commentedon Oct 21, 2019
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:
Thanks for pointing that out!
bhauer commentedon Oct 21, 2019
@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
randomNumbercolumn 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
idcolumn) 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.
Fix php frameworks to comply with #5167 (#5192)
joanhey commentedon Jun 1, 2020
I don't see it in the requirements now.
https://github.com/TechEmpower/FrameworkBenchmarks/wiki/Project-Information-Framework-Tests-Overview
NateBrady23 commentedon Jun 1, 2020
Which requirement is missing?
This is in the single requirements test and also in the multi requirements test is:
I might be missing what you're talking about. It is Monday morning here. 🥱
NateBrady23 commentedon Jun 1, 2020
I think we can close this, now. Thanks all!
Fix php frameworks to comply with TechEmpower#5167 (TechEmpower#5192)