-
Notifications
You must be signed in to change notification settings - Fork 29
Allow disabling the MySQL/MariaDB query optimizer for history queries #1219
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
base: main
Are you sure you want to change the base?
Conversation
I think the config option should be documented. |
{ | ||
if ($q->getDb()->getAdapter() instanceof Mysql) { | ||
// Locates the first string column, prepends the optimizer hint, | ||
// and resets columns to ensure it appears first in the SELECT statement: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why the first string column? Does the query hint not work if placed before an (aliased) expression?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure it works, but it will also increase complexity. My thought was that the hint should work (or rather not add crap) for every query scenario, even if it can't be added at all as with SELECT 1
(unaliased expression). Considering that all other queries will select real columns, I decided to use this implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aye. But shouldn't it throw an error just in case the first column is not a string? I didn't try, but doubt that this works:
SELECT 1 + 1 as two, /*+ NO_BNL() */ STRAIGHT_JOIN test.name as test_name from test
Some versions of these RDBMS perform poorly with history queries, particularly when the optimizer changes join order or uses block nested loop joins. Ideally, testing across all RDBMS versions to identify when the optimizer fails and adjusting queries or using optimizer switches would be preferable, but this level of effort is not justified at the moment. Optimizer is disabled via config: `/etc/icingaweb2/modules/icingadb/config.ini`: ``` [icingadb] ... disable_optimizer_for_history_queries=1 ```
26f7b6b
to
d42be6b
Compare
{ | ||
if ($q->getDb()->getAdapter() instanceof Mysql) { | ||
// Locates the first string column, prepends the optimizer hint, | ||
// and resets columns to ensure it appears first in the SELECT statement: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aye. But shouldn't it throw an error just in case the first column is not a string? I didn't try, but doubt that this works:
SELECT 1 + 1 as two, /*+ NO_BNL() */ STRAIGHT_JOIN test.name as test_name from test
*/ | ||
protected static function shouldDisableOptimizerForHistoryQueries(): bool | ||
{ | ||
return Config::module('icingadb')->get('icingadb', 'disable_optimizer_for_history_queries', false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the settings
section fits better. There's a doc area for it as well already.
Some versions of these RDBMS perform poorly with history queries, particularly when the optimizer changes join order or uses block nested loop joins. Ideally, testing across all RDBMS versions to identify when the optimizer fails and adjusting queries or using optimizer switches would be preferable, but this level of effort is not justified at the moment.
Optimizer is disabled via config:
/etc/icingaweb2/modules/icingadb/config.ini
:refs #1187