User tests: Successful: Unsuccessful:
Pull Request for Issue #32019 .
Check if the query cache is available and enabled (variable query_cache_type
= 'ON') before trying to switch it off when connecting to the database (MySQL or MariaDB) with debug on.
While MySQL have removed the query cache with version 8.0.2, MariaDB still seem to support it and have even added another mode query_cache_type
= 'DEMAND' in past. In this mode, only queries with the SQL CACHE clause will be cached, see description here:
https://mariadb.com/kb/en/server-system-variables/#query_cache_type. Since Joomla doesn't set that SQL CACHE clause for its queries, there is no need to disable query cache on MariaDB if it is working in that 'DEMAND' mode, that's why this PR only checks for query_cache_type
= 'ON'.
This PR is only relevant for MySQL or MariaDB databases, not for PostgreSQL.
It needs tests for all available database drivers for these kinds of databases, which can be selected Database Settings in field "Database Type" on the "Server" tab of Global Configuration which can be one or more of these 3, depending on the available PHP extensions:
If you have 2 MySQL database servers, one with a version lower than 8, e.g. 5.7 where query cache is available if not using a special compilation, and another one with a version of 8.0.2 or later where query cache is not available, test with both of them.
If you have MariaDB where query cache is availably in any case if not using a special compilation, test with any version.
Please test with all you have, and report back which drivers you have tested with which kind of database with which version.
For reproducing the issue, it is enough to simply review the code places mentioned in the description of issue #32019 , so the following tests are all for the expected result AFTER applying this PR.
The effect of this PR is hard to test. To simplify that, it needs to add some debug log to the database drivers, as described in the following section "Preparation".
test-pr-32028.log
in folder administrator/logs
and make sure that the webserver user or group has read and write access to it.error_log
around following lines// DEBUG for PR 32028
error_log(date('Y-m-d H:i:s') . ' ' . basename(__FILE__) . ": Query cache is enabled.\n", 3, JPATH_ADMINISTRATOR . '/logs/test-pr-32028.log');
mysql_query('SET query_cache_type = 0;', $this->connection);
// DEBUG for PR 32028
if (!$this->hasQueryCacheEnabled())
{
error_log(date('Y-m-d H:i:s') . ' ' . basename(__FILE__) . ": Query cache has been disabled.\n", 3, JPATH_ADMINISTRATOR . '/logs/test-pr-32028.log');
}
SHOW VARIABLES LIKE 'have_query_cache';
Value
= 'YES', the database server supports query cache, otherwise ('NO' or no result) not.SHOW VARIABLES LIKE 'query_cache_type';
Value
= 'ON', the query cache is enabled. On a MariaDB database, if Value
= 'DEMAND', the query cache is enabled in 'DEMAND' mode. Otherwise the value is 'OFF', i.e. query cache is disabled.JPATH_ADMINISTRATOR . '/logs/test-pr-32028.log'
which you have created in step 5 of the preparation.JPATH_ADMINISTRATOR . '/logs/test-pr-32028.log'
which you have created in step 5 of the preparation.JPATH_ADMINISTRATOR . '/logs/test-pr-32028.log'
which you have created in step 5 of the preparation.2021-01-17 16:04:02 DEBUG from pdomysql.php: Query cache is enabled.
2021-01-17 16:04:02 DEBUG from pdomysql.php: Query cache has been disabled.
2021-01-17 16:08:02 DEBUG from pdomysql.php: Query cache is enabled.
2021-01-17 16:08:02 DEBUG from pdomysql.php: Query cache has been disabled.
2021-01-17 16:08:02 DEBUG from pdomysql.php: Query cache is enabled.
2021-01-17 16:08:02 DEBUG from pdomysql.php: Query cache has been disabled.
2021-01-17 16:09:11 DEBUG from pdomysql.php: Query cache is enabled.
2021-01-17 16:09:11 DEBUG from pdomysql.php: Query cache has been disabled.
2021-01-17 16:09:11 DEBUG from mysqli.php: Query cache is enabled.
2021-01-17 16:09:11 DEBUG from mysqli.php: Query cache has been disabled.
Don't forget to restore your database server's original configuration if you have modified it during the test.
If you have another database server available, import the database export created in step 3 of the preparation into that other database, change the database connection in Global Configuration to that database and repeat the test beginning with step 1.
When connecting to a MySQL or MariaDB database with "Debug System" switched on in Global Configuration, the database driver attempts to disable the query cache in any case, as you can see in the description of issue #32019 at the mentioned places in the database drivers' code.
When connecting to a MySQL or MariaDB database with "Debug System" switched on in Global Configuration, the database driver only attempts to disable the query cache if the query cache is available and enabled and in case of MariaDB also not in 'DEMAND' mode.
On MySQL databases with server versions 8.0.2 or later, query cache is not available, so it will for sure not be touched by the driver.
While working on this PR I've seen that function hasProfiling
for the check if profiling is available of the drivers is wrong.
The function checks only the isset
but not the value of the variable, so the driver would try to switch on profiling if the have_profiling
variable has value 'NO'. See following documentation:
This is a bug which has to be fixed with another PR.
In J4 thinks are completely different, so we don't have that problem with query cache handled by this PR, but we have the problem with not checking the value of have_profiling
here: https://github.com/joomla/joomla-cms/blob/4.0-dev/plugins/system/debug/debug.php#L444-L467 . This needs also to be fixed with another PR.
Another thing which may confuse people who do code review for this PR is that the check with SHOW VARIABLES LIKE
is done for a string result ('ON'), but the variable is then set with a numeric value 0 when the cache is disabled. But this is normal behaviour for (session) variables of type ENUM in both MySQL and MariaDB.
None.
Status | New | ⇒ | Pending |
Category | ⇒ | Libraries |
Title |
|
Title |
|
Title |
|
Title |
|
Labels |
Added:
?
|
Title |
|
Title |
|
before pr with 8.0.23
Exception has occurred. PDOException: SQLSTATE[HY000]: General error: 1193 Unknown system variable 'query_cache_type'
after pr no more Exception
Can be considered as successful test. When I created this PR, I didn’t have a PHP 8 environment for reproducing the issue, so I have created the testing instructions in that way as they are, to be able to test with other PHP versions.
8.0.23 was referred to mysql non php
Ah, my mistake, PHP would be 8.0.1. at maximum. Anyway, was that a successful test now or not?
i didn't test mariadb
but for me it's ok
as per #32019 (comment)
my test are not valid
Well, I guess this PR here won't ever be tested and merged then.
I have tested this item
Status | Pending | ⇒ | Fixed in Code Base |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2021-02-24 21:37:19 |
Closed_By | ⇒ | HLeithner |
Thanks
Thanks
before pr with 8.0.23
Exception has occurred. PDOException: SQLSTATE[HY000]: General error: 1193 Unknown system variable 'query_cache_type'
after pr no more Exception