The fastest and most optimized way between the two methods is the first one:
- using the SQL query with the WHERE clause checking both columns at once.
Why is that?
- the database can use indexes on both columns (username and email) directly to quickly locate the exact matching row,
- the filtering is done entirely within the database, which minimizes the data transferred and processing done in the PHP application,
- this avoids fetching extra rows or data that would require additional checks in application code
- if a composite index on (username, email) exists, the query is even more efficient.
In second method:
- fetches data filtering only by username
- then compares the hashed email in PHP, which moves some filtering outside the database and potentially causes unnecessary data to be fetched
- this can be slower, especially if many rows share the same username, or if the email comparison is complex
However I agree the difference between your two methods will be very little and probably you do not need to worry about this.