Skip to content
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

Example of projection from documentations is not work #50093

Closed
alexsubota opened this issue May 22, 2023 · 3 comments · Fixed by #52327
Closed

Example of projection from documentations is not work #50093

alexsubota opened this issue May 22, 2023 · 3 comments · Fixed by #52327

Comments

@alexsubota
Copy link

alexsubota commented May 22, 2023

ClickHouse v.23.3.2.37

Trying to work with projections example from ClickHouse documentation, but its not work.
Link to example from doc:
https://clickhouse.com/docs/en/sql-reference/statements/alter/projection#example-filtering-without-using-primary-keys

code:

CREATE TABLE visits_order
(
   `user_id` UInt64,
   `user_name` String,
   `pages_visited` Nullable(Float64),
   `user_agent` String
)
ENGINE = MergeTree()
PRIMARY KEY user_agent;

ALTER TABLE visits_order ADD PROJECTION user_name_projection (SELECT * ORDER BY user_name)

ALTER TABLE visits_order MATERIALIZE PROJECTION user_name_projection;

INSERT INTO visits_order SELECT
    number,
    'test',
    1.5 * (number / 2),
    'Android'
FROM numbers(1, 100);


SELECT
    *
FROM visits_order
WHERE user_name='test'
LIMIT 2;

SELECT query, projections FROM system.query_log WHERE query_id='<query_id>'

So, when i try to check projections column from query_log, i see nothing ([])
What i do wrong?

@tavplubix
Copy link
Member

cc: @amosbird

@den-crane
Copy link
Contributor

https://fiddle.clickhouse.com/4b0ce12f-9353-4c39-9e4a-d72070f1f75a

Interesting that
WHERE user_name='test' does not use the projection, it looks like CBO
WHERE user_name='1test' uses the projection but system.query_log is empty anyway

@amosbird
Copy link
Collaborator

WHERE user_name='test' does not use the projection, it looks like CBO

Yes, it's because all user_name equal to test and projection won't help.

WHERE user_name='1test' uses the projection but system.query_log is empty anyway

It's an issue when query_plan_optimize_projection = 1. It's also an issue when selected projection doesn't return any data. Will fix it this week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants