Optimize materialized column lookup for expression aliases#1959
Conversation
Improve the materialized column optimization by allowing it to be applied when `WITH` clauses are expression aliases (i.e., `isSubquery: false`). Previously, any `WITH` clause would disable this optimization. This change ensures that materialized columns are still considered for performance benefits when the `WITH` clause does not represent a subquery.
|
@vinzee is attempting to deploy a commit to the HyperDX Team on Vercel. A member of the Team first needs to authorize it. |
🦋 Changeset detectedLatest commit: 677b768 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
PR Review✅ No critical issues found. The core change is minimal and correct:
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
wrn14897
left a comment
There was a problem hiding this comment.
Please run yarn changeset to add a changeset
| await renderChartConfig(config, mockMetadata, querySettings); | ||
| expect( | ||
| mockMetadata.getMaterializedColumnsLookupTable, | ||
| ).toHaveBeenCalled(); |
There was a problem hiding this comment.
it would be nice to verify the rendered SQL has pipe_id
| // supported for queries using CTEs so skip the metadata fetch if there are CTE objects in the config. | ||
| // supported for queries using subquery CTEs so skip the metadata fetch if there are subquery CTE | ||
| // objects in the config. Expression aliases (isSubquery: false) do not affect the base table. | ||
| const hasSubqueryCte = chartConfig.with?.some(w => w.isSubquery !== false); |
There was a problem hiding this comment.
nit: can we move this logic to a shared method?
Extract a shared hasSubqueryCte() helper that only skips the optimization for true subquery CTEs, and fix unit tests verifying both paths.
wrn14897
left a comment
There was a problem hiding this comment.
Thanks for the contribution!
|
@claude fix linting error |
|
I'll analyze this and get back to you. |
|
@vinzee there is a lint error in the test file. could you fix it? https://github.com/hyperdxio/hyperdx/actions/runs/23395356725/job/68092930851?pr=1959 |
This commit refactors several E2E tests by adding blank lines for improved readability and consistency. It also updates the .gitignore file to ignore `package-lock.json`, preventing it from being committed to the repository. [Generated via Zoox Intelligence / `zi-gcm --edit`]
## Summary
Improve the materialized column optimization by allowing it to be applied when `WITH` clauses are expression aliases (i.e., `isSubquery: false`). Previously, any `WITH` clause would disable this optimization. This change ensures that materialized columns are still considered for performance benefits when the `WITH` clause does not represent a subquery.
### Screenshots or video
| Before | After |
| :----- | :---- |
| | |
### How to test locally or on Vercel
1. Create a ClickHouse table with a materialized column, e.g.:
```sql
ALTER TABLE otel_logs ADD COLUMN awesome_attribute String MATERIALIZED LogAttributes['awesome_attribute']
```
2. Open the Explore view for logs (`/search`)
3. Add a filter for `awesome_attribute` (or `LogAttributes['awesome_attribute']`)
4. Inspect the POST body of `/clickhouse-proxy` requests in the network tab:
- Before fix: The histogram (time chart) query contains `LogAttributes['awesome_attribute']` (full map scan), while the search results query correctly uses `awesome_attribute`.
- After fix: Both the histogram and search results queries use `awesome_attribute` (the materialized column).
### References
- Linear Issue: #1957
- Related PRs:
## Summary
Improve the materialized column optimization by allowing it to be applied when `WITH` clauses are expression aliases (i.e., `isSubquery: false`). Previously, any `WITH` clause would disable this optimization. This change ensures that materialized columns are still considered for performance benefits when the `WITH` clause does not represent a subquery.
### Screenshots or video
| Before | After |
| :----- | :---- |
| | |
### How to test locally or on Vercel
1. Create a ClickHouse table with a materialized column, e.g.:
```sql
ALTER TABLE otel_logs ADD COLUMN awesome_attribute String MATERIALIZED LogAttributes['awesome_attribute']
```
2. Open the Explore view for logs (`/search`)
3. Add a filter for `awesome_attribute` (or `LogAttributes['awesome_attribute']`)
4. Inspect the POST body of `/clickhouse-proxy` requests in the network tab:
- Before fix: The histogram (time chart) query contains `LogAttributes['awesome_attribute']` (full map scan), while the search results query correctly uses `awesome_attribute`.
- After fix: Both the histogram and search results queries use `awesome_attribute` (the materialized column).
### References
- Linear Issue: #1957
- Related PRs:
Co-authored-by: peter-leonov-ch <209667683+peter-leonov-ch@users.noreply.github.com>

Summary
Improve the materialized column optimization by allowing it to be applied when
WITHclauses are expression aliases (i.e.,isSubquery: false). Previously, anyWITHclause would disable this optimization. This change ensures that materialized columns are still considered for performance benefits when theWITHclause does not represent a subquery.Screenshots or video
How to test locally or on Vercel
/search)awesome_attribute(orLogAttributes['awesome_attribute'])/clickhouse-proxyrequests in the network tab:LogAttributes['awesome_attribute'](full map scan), while the search results query correctly usesawesome_attribute.awesome_attribute(the materialized column).References