-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
Super slow schema queries with MySQL 8.0.16 #17444
Comments
I'd be surprised if the issue is with Yii. I'm on PHP 7.3.7 and MySQL 8.0.16. Can you run some of the schema queries directly in MySQL and see how long they take? |
Hello @alex-code You can notice the huge difference with time!
That was done already and its not the issue as you can see from the previous query. |
@samdark what type of extra info do you need? |
@alex-code can you measure performance with your DB instance? |
OK. @alex-code, @alaa007 would you please provide:
Thanks. |
My setup
|
|
OK. So...
phpmyadmin uses mysql/mysqli to connect to database while Yii uses PDO. That likely means that there's something wrong with certain PDO version bundled with PHP 7.2.20 installed via brew. @alaa007 can you upgrade/downgrade? |
@samdark I tried php versions 7.1.30 and 7.3.7 and still getting the same numbers. no change. |
Super-weird. Just another wild guess. If you have connection host specified as |
@samdark same results. |
OK. Another idea. Can you create a PHP script that connects to MySQL via PDO and does the same query? |
Another question for @alex-code and @alaa007 is about number of tables in your DB. |
Currently I've got 27, also using the utf8mb4 charset if that could make a difference. |
My DB has 43 tables. I tried the following code as you suggested through a direct script and it took a lot of time 0.30296200
|
Could you show the result of this query? SHOW VARIABLES WHERE Variable_name LIKE 'information_schema_stats_expiry' Not sure if it could make a difference but MySQL 8 caches schema stats by default, not sure if that would happen with an upgrade. |
Have some problem on low cost hosting provider: hes changed MySQL version from 5.7.23 to 8.0.16 and i get fail. What i have:
I cant change SQL timeout (PDO::ATTR_TIMEOUT ignoring) - as i understand, it set to 120 seconds, so in log file (app.log) i have:
|
@almaz-free do you have PHPMyAdmin? |
Yes, i run SQL code (from my above app.log) in phpMyAdmin and after ~ 100 seconds get that:
In front panel phpMyAdmin v4.9.0.1:
|
@alex-code |
Could you add |
i cut SQL query for phpMyAdmin to this:
and get fail "Gateway Time-out (rejected)" after ~100 sec EXPLAIN for tis SQL:
but if i cut from SQL query this expression:
all work ok (and fast - 0.0173 sec) EXPLAIN for SQL without "AND kcu.constraint_name = rc.constraint_name":
|
@hirenbhut93 Is it possible to get exact version of MySQL and database dump to finally reproduce it? |
@samdark mysql Ver 8.0.15 for Linux on x86_64 (MySQL Community Server - GPL) |
This question has some config options that may be worth trying. |
I tested with docker:
my local hosted mysql 5.7 vs 8.0.17: 0.0006 (one table)
Though bigger times in 8.0.17 (possibly due to the docker), it never exceeded 50ms / table. Obviously, with 90 tables, this is quite a few seconds. |
The goal pursued so far is not necessarily right: delay time minimization. Need it at all? I'm thinking here that normally SELECT is the majority of the requests, but I don't really see what it is used for for INSERT, UPDATE and DELETE. If, for example, only needed to edit or get the table schema, why not run it only then? |
Have the problem in a backend yii2 site. If the user is not logged in, no db queries are done and the page if rendered immediately. After log in, the first query regards the user. Then the schema information will be queried:
That takes about 8 sec for each request. And CPU usage increases in that time. MySQL 8.0.17 with about 200 databases on a RHEL 8 system. Yii 2.0.22. This query executed in phpMyAdmin takes the same time. What I read was that those schema tables are not real ones. And when a query is done with them, all databases and tables gets taken into account somehow. That would mean the query will be slower the more databases exist. Not sure if this correct. I have another solution with another MySQL 8 instance with only 3 databases. When I execute the same query there, it is much faster ('no' delay, so I did not find this problem with that system). What could be a workaround? |
@robsch schema caching should solve the issue for production environments. |
@samdark Thanks. This is a workaround, right? Especially when there are many tables, the cache has to be populated before the solution gets live. So it would be necessary to do this for all tables on deployment. Will and can there be a fix from the Yii side? Can the issue be seen as a bug in MySQL? I'm wondering how Yii will deal with that issue in the long term.. |
Yes.
There can be a fix but we're not actively working on it focusing on Yii 3. There were multiple attempts to fix it but none succeeded yet. If you want to spent some time looking for a solution, that would be helpful. |
@samdark Alright. Is there a solution in Yii3? One additional reason to upgrade... |
@robsch Yii 3 isn't ready yet. We're using Cycle ORM there instead of our own active record. At least for now. |
Doctrine's affected by the same issue: doctrine/dbal#4015 |
MySQL 8.0.21 could have a fix for this: |
Closing since fixed and tested yiisoft/yii2-gii#409 (comment) |
After updating to MySQL 8, I have noticed how super slow Yii2 has become.
After using the Yii Debugger, I have found the following 6 queries consuming more than 95% of total loading time:
The only way I was able to fix the issue is by adding
'enableSchemaCache' => true,
to the database component and enabling cachingclass' => 'yii\caching\FileCache',
But since I'm using my machine for development I don't want to enable caching.
Note: I tried the same code with MySQL version 5 and it was working fine. Seems an issue with MySQL 8 and Yii2, I'm not sure.
Additional info
The text was updated successfully, but these errors were encountered: