Skip to content
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

increase mysql load in 2.0.14.2 version #16265

Open
sepidemahmoodi opened this issue May 12, 2018 · 11 comments
Open

increase mysql load in 2.0.14.2 version #16265

sepidemahmoodi opened this issue May 12, 2018 · 11 comments
Labels
MySQL status:to be verified Needs to be reproduced and validated. type:bug Bug

Comments

@sepidemahmoodi
Copy link

sepidemahmoodi commented May 12, 2018

Hi,
i was updated my core to 2.0.14.2 version,
then mysql load was increased while cache is enabled,
it seems this query makes it

   Id: 180216
   User: portal
   Host: localhost
     db: portal
Command: Query
   Time: 20
  State: Opening tables

   Info: SELECT
    `kcu`.`CONSTRAINT_NAME` AS `name`,
    `kcu`.`COLUMN_NAME` AS `column_name`,
    `tc`.`CONSTRAINT_TYPE` AS `type`,

    CASE

        WHEN NULL IS NULL AND `kcu`.`REFERENCED_TABLE_SCHEMA` = DATABASE() THEN NULL
        ELSE `kcu`.`REFERENCED_TABLE_SCHEMA`
    END AS `foreign_table_schema`,
    `kcu`.`REFERENCED_TABLE_NAME` AS `foreign_table_name`,
    `kcu`.`REFERENCED_COLUMN_NAME` AS `foreign_column_name`,
    `rc`.`UPDATE_RULE` AS `on_update`,
    `rc`.`DELETE_RULE` AS `on_delete`,
    `kcu`.`ORDINAL_POSITION` AS `position`
FROM

    `information_schema`.`KEY_COLUMN_USAGE` AS `kcu`,
    `information_schema`.`REFERENTIAL_CONSTRAINTS` AS `rc`,
    `information_schema`.`TABLE_CONSTRAINTS` AS `tc`
WHERE

    `kcu`.`TABLE_SCHEMA` = COALESCE(NULL, DATABASE()) AND `kcu`.`CONSTRAINT_SCHEMA` = `kcu`.`TABLE_SCHEMA` AND `kcu`.`TABLE_NAME` = 'session'
    AND `rc`.`CONSTRAINT_SCHEMA` = `kcu`.`TABLE_SCHEMA` AND `rc`.`TABLE_NAME` = 'session' AND `rc`.`CONSTRAINT_NAME` = `kcu`.`CONSTRAINT_NAME`
    AND `tc`.`TABLE_SCHEMA` = `kcu`.`TABLE_SCHEMA` AND `tc`.`TABLE_NAME` = 'session' AND `tc`.`CONSTRAINT_NAME` = `kcu`.`CONSTRAINT_NAME` AND `tc`.`CONSTRAINT_TYPE` = 'FOREIGN KEY'

UNION

SELECT

    `kcu`.`CONSTRAINT_NAME` AS `name`,
    `kcu`.`COLUMN_NAME` AS `column_name`,
    `tc`.`CONSTRAINT_TYPE` AS `type`,
    NULL AS `foreign_table_schema`,
    NULL AS `foreign_table_name`,
    NULL AS `foreign_column_name`,
    NULL AS `on_update`,
    NULL AS `on_delete`,
    `kcu`.`ORDINAL_POSITION` AS `position`

FROM

    `information_schema`.`KEY_COLUMN_USAGE` AS `kcu`,
    `information_schema`.`TABLE_CONSTRAINTS` AS `tc`

WHERE

    `kcu`.`TABLE_SCHEMA` = COALESCE(NULL, DATABASE()) AND `kcu`.`TABLE_NAME` = 'session'
    AND `tc`.`TABLE_SCHEMA` = `kcu`.`TABLE_SCHEMA` AND `tc`.`TABLE_NAME` = 'session' AND `tc`.`CONSTRAINT_NAME` = `kcu`.`CONSTRAINT_NAME` AND `tc`.`CONSTRAINT_TYPE` IN ('PRIMARY KEY', 'UNIQUE')
ORDER BY `position` ASC

how to solve it?

@samdark
Copy link
Member

samdark commented May 12, 2018

That's schema cache. If caching schema is enabled, this query should not happen more than once. Check your config.

@samdark samdark closed this as completed May 12, 2018
@sepidemahmoodi
Copy link
Author

yes, schema cache is enable but it takes too much time to load page for first time, actually in previous yii version i didnt have this problem. this query makes down my website

@sepidemahmoodi
Copy link
Author

@samdark please reopen the issue

@samdark
Copy link
Member

samdark commented May 12, 2018

Would you please try code from master first?

@sepidemahmoodi
Copy link
Author

sepidemahmoodi commented May 12, 2018

same problem was happened :(
cache process takes long time and cause down my website

@samdark samdark reopened this May 12, 2018
@samdark samdark added MySQL type:bug Bug status:to be verified Needs to be reproduced and validated. labels May 12, 2018
@samdark samdark added this to the 2.0.17 milestone May 12, 2018
@sepidemahmoodi
Copy link
Author

my application has thousand subdomain and each of them has own database,
when application loaded for first time in mysql process list that query has shown.
so a large number of databases and load all of them cause this problem.

@samdark
Copy link
Member

samdark commented May 12, 2018

As a workaround, you can try warming up these DBs one by one. That's one time action and should not cause issues as long as cache is filled.

@sepidemahmoodi
Copy link
Author

this query in 2.0.13.1 version of yii2 has no problem and this query took 0.0004(s) in mysql,

SELECT kcu.constraint_name, kcu.column_name, kcu.referenced_table_name, kcu.referenced_column_name FROM information_schema.referential_constraints AS rc JOIN information_schema.key_column_usage AS kcu ON ( kcu.constraint_catalog = rc.constraint_catalog OR (kcu.constraint_catalog IS NULL AND rc.constraint_catalog IS NULL) ) AND kcu.constraint_schema = rc.constraint_schema AND kcu.constraint_name = rc.constraint_name WHERE rc.constraint_schema = database() AND kcu.table_schema = database() AND rc.table_name = 'session' AND kcu.table_name = 'session'

but query of version 2.0.14.2 took 12.64(s) time in mysql.
im checking thats warming up databases solution,

@samdark
Copy link
Member

samdark commented May 13, 2018

What's your MySQL version btw?

@sepidemahmoodi
Copy link
Author

5.7.22

@mahsa92
Copy link

mahsa92 commented Sep 16, 2018

I have the same problem and I didn't have problem in 2.0.13.1.
It seems it's getting all Ram capacity and even swap memory and it increasing server load caused by mysql.scheme caching is slow and because it's running for multi database at the same time, it causes overloading.

@samdark samdark removed this from the 2.0.17 milestone Mar 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
MySQL status:to be verified Needs to be reproduced and validated. type:bug Bug
Projects
None yet
Development

No branches or pull requests

3 participants