Why is Cakephp calling SQL queries for information_scheme?


#1

I’m using Cakephp 3.3 and DebugKit is enabled. I have noticed that ‘some’ of the controller actions are issuing many additional SQL queries related to information_scheme like these:

SHOW FULL COLUMNS
FROM
businesses

SHOW INDEXES
FROM
businesses

SELECT
*
FROM
information_schema.key_column_usage AS kcu
INNER JOIN information_schema.referential_constraints AS rc ON (
kcu.CONSTRAINT_NAME = rc.CONSTRAINT_NAME
AND kcu.CONSTRAINT_SCHEMA = rc.CONSTRAINT_SCHEMA
)
WHERE
kcu.TABLE_SCHEMA = 'myschema’
AND kcu.TABLE_NAME = 'businesses’
AND rc.TABLE_NAME = ‘businesses’

Questions:

  1. Why is this happening ?
  2. Is this there a way to stop Cakephp from doing this ?
  3. Is it happening because of DebugKit ?

#2

There is a benefit from it - if you add some columns to your SQL table, then they automatic show in your php variable.


#3

How to prevent it ? And does it have anything to do with DebugKit ?


#4

I saw this when debug kit is on, but never try to check what happens in "production: it never disturbs me. You can set some sql log options in config turn debug to false and check.
But I know that if you add some column in production mode, then before clear cache it can miss them, so I guess that in “production” there will be no schema check.


#5

Correct. In production mode, cache duration for the schema meta data is much higher by default. This metadata cache holds the results of the information_schema queries, and allows CakePHP to operate without emitting these queries.