-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
Unexpected scan when using projections + order by on replacingmergetree #47333
Comments
multiple threads
Projections are not used for |
Technically, the EXPLAIN I added at the end of my post shows that Clickhouse is indeed reading from the projection, but instead of reading in order like regular tables (which, if the projection is like a hidden table, it should be able to do) it reads all the rows for Apart from this, is there a way to achieve what I want (i.e. find the most recent events for a given user) using projections then or do I have to resort to Materialized views? If projections cannot be used for these use cases, I suppose che docs for clickhouse cloud should probably be updated to reflect this difference, because by reading this
My assumption is that projections are functionally equivalent to materialized views, while instead they're not. |
It's expected. By design. No such feature.
You have to resort to Materialized views.
Yes, they should. Please make a pull request. |
Relevant github issue: ClickHouse/ClickHouse#47333
Thanks @den-crane for the quick answer, as usual 😄 . I opened a PR for the docs |
see also #33678 |
Describe the unexpected behaviour
Clickhouse version: Clickhouse cloud (version 22.13)
We have the following test table setup:
We have created the additional projection to support filtering the events by
user_id
.We populate the table with sample data
Everything is fine if we run
But things get weird if we start writing queries that use the projection.
Shouldn't this still read ~2k rows since the projection is ordered by
user_id, timestamp
?Same as above, this should read only the first ~2k rows since it's exactly along the projection ORDER BY, instead it's reading all of the entries for user
user_a
.Additional context
EXPLAINs for the above queries
We are currently using materialized views to achieve the same goal but I was trying out if projection could be a fit for our use case (as it looked much more ergonomic in terms of maintenance and consistency), after going through https://clickhouse.com/blog/clickhouse-faster-queries-with-projections-and-primary-indexes
Could be linked to:
The text was updated successfully, but these errors were encountered: