Skip to content

Conversation

@redwormik
Copy link
Contributor

Using structure like in https://github.com/nette/database/blob/master/tests/Database/files/mysql-nette_test1.sql and doing this:

$table = $context->table('book');
foreach ($table as $row) {
    $translator = $row->ref('author', 'translator_id');
}

These queries are performed:

SELECT * FROM `book`
SELECT * FROM `author` WHERE (`id` IN (11, 12))
SELECT * FROM `author` WHERE (`id` IN (11, 12))

i.e. authors are needlessly refetched.

It does this both on master and 2.3.0 (PHP 5.5.9-1ubuntu4.6, MySQL 5.5.41-0ubuntu0.14.04.1).

It all goes down to https://github.com/nette/database/blob/master/src/Database/Table/Selection.php#L849 - the NULL key is never stored, so it is never found and performs a needless fetch.

The solution would be either to remember the NULL key on first fetch, or never fetch on NULL key. Which is better?

@redwormik
Copy link
Contributor Author

Added attempt to fix this - Selection now doesn't REfetch when $row[$column] is NULL

dg added a commit that referenced this pull request Mar 13, 2015
Selection::getReferencedTable always reloads when $row[$column] is NULL
@dg dg merged commit c20bef3 into nette:master Mar 13, 2015
@dg
Copy link
Member

dg commented Mar 13, 2015

Thanks!

@redwormik redwormik deleted the table-ref-null branch November 11, 2019 17:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants