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
Fix optimize read in order from a view. #54628
Fix optimize read in order from a view. #54628
Conversation
This is an automated comment for commit b1bddae with description of existing statuses. It's updated for the latest CI running ❌ Click here to open a full report in a separate page Successful checks
|
/// Depending on the argument the function materialize() is either a constant or works as identity(). | ||
/// In both cases this function is monotonic and non-decreasing. | ||
return {.is_monotonic = true, .is_always_monotonic = true}; | ||
} |
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.
StorageView
implicitly applies the materialize()
function to each column of the result of an internal query (see StorageView::read). And then optimize_read_in_order checks the monotonicity of applied functions (see matchTrees()). So if materialize()
becomes monotonic then the optimization optimize_read_in_order
can work for views.
Also Before:
After:
|
|
||
SYSTEM FLUSH LOGS; | ||
|
||
SELECT concat('read_rows=', if(read_rows<40, 'ok', toString(read_rows))) FROM system.query_log WHERE current_database = currentDatabase() AND query LIKE '%test 02877, query 1%' AND type='QueryFinish'; |
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.
imo it is better to check the query plan
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.
Ok, I've rewritten the test.
Changelog category:
Changelog entry:
Enable ORDER BY optimization for reading data in corresponding order from a MergeTree table in case that the table is behind a view.
For example, the following SELECT
must understand that the table is already ordered and read only a few rows from the table (before this PR this query used to read the full table).