Problem/Motivation
Comments in Drupal\Core\Database\Connection state:
Database::RETURN_AFFECTED: Return the number of rows affected by an UPDATE or DELETE query. Be aware that means the number of rows actually changed, not the number of rows matched by the WHERE clause.
Meanwhile Drupal\Core\Database\Driver\mysql\Connection states:
Make sure MySQL returns all matched rows on update queries including rows that actually didn't have to be updated because the values didn't change. This matches common behavior among other database systems.
and enables PDO::MYSQL_ATTR_FOUND_ROWS, which causes the number of matched rows to be returned rather than the number of affected rows.
Steps to reproduce
Something like ./vendor/bin/drush php:eval 'echo Drupal::database()->update("users")->fields(["uid" => 0])->condition("uid", 0)->execute()'
returns 1 row matched/found, even though 0 rows were affected/changed (on MySQL, sqlite and postgres).
Proposed resolution
Update documentation to explain that number of rows matched is returned, not number of rows affected?