Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions lib/Migration/Version010000001Date20250727094721.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
use Closure;
use Doctrine\DBAL\Schema\SchemaException;
use OCP\DB\ISchemaWrapper;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\DB\Types;
use OCP\IDBConnection;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;
use PDO;

final class Version010000001Date20250727094721 extends SimpleMigrationStep {

Expand Down Expand Up @@ -69,10 +71,16 @@ public function postSchemaChange(IOutput $output, Closure $schemaClosure, array
$query = $this->db->getQueryBuilder();
$query->update('recognize_face_detections')
->set('face_vector', 'vector')
->where($query->expr()->in('id', $query->createFunction('(' . $select->getSQL() .')')));
->where($query->expr()->in('id', $query->createParameter('ids')));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't you be able to update all with a single query?

Suggested change
->where($query->expr()->in('id', $query->createParameter('ids')));
->where($select->expr()->isNull('face_vector'));
$query->executeStatement()

if you are not doing any data manipulation that should work just fine.
No previous select or anything needed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't you be able to update all with a single query?

Doesn't seem work for large tables, sadly. See #1357

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put a transaction around it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But anyway, should also be good like this, but it will run much longer.

But also in this version a transaction should speed up the update I think

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mh, the issue in #1357 is due to a long running transaction, wouldn't wrapping the current state in this branch in a transaction introduce the issue of a long running transaction again?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can close the transaction after each chunk.
THe idea is to reduce the number of writes


do {
$updatedRows = $query->executeStatement();
$result = $select->executeQuery();
$ids = $result->fetchAll(PDO::FETCH_COLUMN);
$result->closeCursor();
if (empty($ids)) {
break;
}
$updatedRows = $query->setParameter('ids', $ids, IQueryBuilder::PARAM_INT_ARRAY)->executeStatement();
} while ($updatedRows > 0);
}
}
Loading