multiple information_schema requests

ever since updating a couple of weeks ago i’m getting a large number of information_schema requests that look like this:




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 = 'user' AND kcu.table_name = 'user'



can anyone tell me what these are and if they are necessary? i’m guessing it has something to do with activeRecord hasOne & hasMany requests but i find it strange that i haven’t seen them before and now i have 11 of them for every page request.

Yii use information schema to "see" how a table is.

Usually is one query per accessed table.

Once in production you can activate schema cache and performs such query once per day for example.

To enable it just add the following 3 configuration to you db connection




    	'db' => [

        	.........

        	'enableSchemaCache' => true,

        	// Name of the cache component used to store schema information

        	'schemaCache' => 'cache',

        	// Duration of schema cache.

        	'schemaCacheDuration' => 86400, // 24H it is in seconds

    	],



Now if 11 query is normal depends non your code. Consider that also extensions performs query.

If you enable the cache remember to flush it when there is a schema change.

1 Like

awesome thanks

Thanks a ton!