Skip to content

Commit

Permalink
Ssandler upstream changes (#88)
Browse files Browse the repository at this point in the history
* perf optimization in ColumnExpression, avoid expensive Str\split call

* perf optimization in FromClause to avoid nested loops when strictSchemaMode is enabled
  • Loading branch information
Scott Sandler authored Aug 8, 2022
1 parent aa0afaa commit 236abf8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
14 changes: 2 additions & 12 deletions src/Expressions/ColumnExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,9 @@ public function evaluateImpl(row $row, AsyncMysqlConnection $_conn): mixed {
// didn't find row by alias, so search without alias instead
// but only if the column expression didn't have an explicit table name on it
// OR if we are explicitly allowing fallthrough to the full row, which we do in the ORDER BY clause
$dot_column_name = '.'.$this->columnName;
foreach ($row as $key => $col) {
$parts = Str\split($key, '.');

// find the last part of the string - as an optimization, we deliberately don't call C\lastx
$did_iterate = false;
$last_part = null;
foreach ($parts as $part) {
$did_iterate = true;
$last_part = $part;
}
invariant($did_iterate, 'Column name was empty');

if ($last_part === $this->columnName) {
if (Str\ends_with($key, $dot_column_name)) {
return $col;
}
}
Expand Down
11 changes: 10 additions & 1 deletion src/Query/FromClause.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,16 @@ public function process(AsyncMysqlConnection $conn, string $sql): dataset {
invariant($res is KeyedContainer<_, _>, 'evaluated result of SubqueryExpression must be dataset');

$new_dataset = vec[];
if ($schema !== null) {
if ($schema is nonnull && QueryContext::$strictSchemaMode) {
foreach ($res as $row) {
$row as dict<_, _>;
$m = dict[];
foreach ($row as $field => $val) {
$m["{$name}.{$field}"] = $val;
}
$new_dataset[] = $m;
}
} else if ($schema is nonnull) {
// if schema is set, order the fields in the right order on each row
$ordered_fields = keyset[];
foreach ($schema['fields'] as $field) {
Expand Down

0 comments on commit 236abf8

Please sign in to comment.