-
Notifications
You must be signed in to change notification settings - Fork 228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes #7049: Performance issue with table existence query #7050
Fixes #7049: Performance issue with table existence query #7050
Conversation
Coverage summary from CodacySee diff coverage on Codacy
Coverage variation details
Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: Diff coverage details
Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: See your quality gate settings Change summary preferencesCodacy stopped sending the deprecated coverage status on June 5th, 2024. Learn more Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is this one to change as well
wp-rocket/inc/Engine/Common/Database/Queries/AbstractQuery.php
Lines 509 to 535 in d99bce0
protected function table_exists(): bool { | |
if ( self::$table_exists ) { | |
return true; | |
} | |
// Get the database interface. | |
$db = $this->get_db(); | |
// Bail if no database interface is available. | |
if ( ! $db ) { | |
return false; | |
} | |
// Query statement. | |
$query = 'SELECT table_name FROM information_schema.tables WHERE table_name = %s LIMIT 1'; | |
$prepared = $db->prepare( $query, $db->{$this->table_name} ); | |
$result = $db->get_var( $prepared ); | |
// Does the table exist? | |
$exists = $this->is_success( $result ); | |
if ( $exists ) { | |
self::$table_exists = $exists; | |
} | |
return $exists; | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For later: we should see how to avoid having duplicated code for this
Test plan:
|
Hello, |
Hello hello, I've been trying to reproduce the issue in a local environment. On this DB server, I've created 10 000 databases where each one of them has their own user and these aren't SUPER user and of course, there is a single SUPER User that has access to everything. So to make it short. 10 000 databases, they all have the same named tables. So in my example I'll use There is 1 SUPER User, otherwise, each database have a different user which isn't SUPER. From the SUPER User: Now, from a normal user from 1 db, and While the new query introduced by #7049 So we can see an improvement, as we are reducing the execution time of the query by almost 10. |
Description
This PR fixes the issue with user servers being impacted due to unoptimized query.
Fixes #7049
Type of change
Detailed scenario
Not able to reproduce on local at the moment.
Technical description
Documentation
The query that checks if table exists is now optimized to specifically target the current DB instead of recurrently checking tables in all the Databases on the server.
New dependencies
N/A
Risks
N/A
Mandatory Checklist
Code validation
Code style