-
Notifications
You must be signed in to change notification settings - Fork 208
chore: improve gql_schema_usage_5m_90d table #2432
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
Open
JivusAyrus
wants to merge
6
commits into
main
Choose a base branch
from
suvij/update-clickhouse-tables-to-optimize-queries
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+138
−0
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f96cebe
chore: improve gql_schema_usage_5m_90d table
JivusAyrus aa6b890
Merge branch 'main' into suvij/update-clickhouse-tables-to-optimize-q…
JivusAyrus 518660f
Merge branch 'main' into suvij/update-clickhouse-tables-to-optimize-q…
JivusAyrus 6e36804
Merge branch 'main' into suvij/update-clickhouse-tables-to-optimize-q…
JivusAyrus b9161a5
Merge branch 'main' into suvij/update-clickhouse-tables-to-optimize-q…
JivusAyrus 2a48e8a
Merge branch 'main' into suvij/update-clickhouse-tables-to-optimize-q…
JivusAyrus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
graphqlmetrics/migrations/20251223110743_new_graphql_schema_usage_table_5m_90d.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| -- migrate:up | ||
| CREATE TABLE gql_metrics_schema_usage_5m_90d_v2 | ||
| ( | ||
| Timestamp DateTime('UTC') CODEC(Delta(4), ZSTD(3)), | ||
| OrganizationID LowCardinality(String) CODEC(ZSTD(3)), | ||
| FederatedGraphID LowCardinality(String) CODEC(ZSTD(3)), | ||
| RouterConfigVersion LowCardinality(String) CODEC(ZSTD(3)), | ||
| OperationHash LowCardinality(String) CODEC(ZSTD(3)), | ||
| OperationName LowCardinality(String) CODEC(ZSTD(3)), | ||
| OperationType LowCardinality(String) CODEC(ZSTD(3)), | ||
| Path Array(String) CODEC(ZSTD(3)), | ||
| FieldName LowCardinality(String) CODEC(ZSTD(3)), | ||
| TypeNames Array(String) CODEC(ZSTD(3)), | ||
| NamedType LowCardinality(String) CODEC(ZSTD(3)), | ||
| ClientName LowCardinality(String) CODEC(ZSTD(3)), | ||
| ClientVersion LowCardinality(String) CODEC(ZSTD(3)), | ||
| SubgraphIDs Array(LowCardinality(String)) CODEC(ZSTD(3)), | ||
| IsArgument Bool CODEC(ZSTD(3)), | ||
| IsInput Bool CODEC(ZSTD(3)), | ||
| TotalUsages UInt64 CODEC(ZSTD(3)), | ||
| TotalErrors UInt64 CODEC(ZSTD(3)), | ||
| TotalClientErrors UInt64 CODEC(ZSTD(3)), | ||
| IsIndirectFieldUsage Bool DEFAULT false CODEC(ZSTD(3)), | ||
| IsNull Bool DEFAULT false CODEC(ZSTD(3)), | ||
| INDEX idx_path Path TYPE bloom_filter(0.01) GRANULARITY 4, | ||
| INDEX idx_source_ids SubgraphIDs TYPE bloom_filter(0.01) GRANULARITY 4, | ||
| INDEX idx_type_names TypeNames TYPE bloom_filter(0.01) GRANULARITY 4, | ||
| INDEX idx_total_usages TotalUsages TYPE minmax GRANULARITY 4, | ||
| INDEX idx_total_errors TotalErrors TYPE minmax GRANULARITY 4, | ||
| INDEX idx_total_client_errors TotalClientErrors TYPE minmax GRANULARITY 4 | ||
| ) | ||
| ENGINE = SummingMergeTree | ||
| PARTITION BY toDate(Timestamp) | ||
| ORDER BY (FederatedGraphID, Timestamp, OrganizationID, FieldName, NamedType, OperationHash, ClientName, ClientVersion) | ||
| TTL toDateTime(Timestamp) + toIntervalDay(90) | ||
| SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1 | ||
|
|
||
| -- migrate:down | ||
|
|
||
| DROP TABLE IF EXISTS gql_metrics_schema_usage_5m_90d_v2; | ||
10 changes: 10 additions & 0 deletions
10
graphqlmetrics/migrations/20251223131620_migrate_data_90_to_68_days.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| -- migrate:up | ||
|
|
||
| -- Step 1: Migrate data from 90 to 68 days ago | ||
| INSERT INTO gql_metrics_schema_usage_5m_90d_v2 | ||
| SELECT * FROM gql_metrics_schema_usage_5m_90d | ||
| WHERE Timestamp >= now() - INTERVAL 90 DAY | ||
| AND Timestamp < now() - INTERVAL 68 DAY; | ||
|
|
||
| -- migrate:down | ||
|
|
10 changes: 10 additions & 0 deletions
10
graphqlmetrics/migrations/20251223131621_migrate_data_68_to_46_days.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| -- migrate:up | ||
|
|
||
| -- Step 2: Migrate data from 68 to 46 days ago | ||
| INSERT INTO gql_metrics_schema_usage_5m_90d_v2 | ||
| SELECT * FROM gql_metrics_schema_usage_5m_90d | ||
| WHERE Timestamp >= now() - INTERVAL 68 DAY | ||
| AND Timestamp < now() - INTERVAL 46 DAY; | ||
|
|
||
| -- migrate:down | ||
|
|
10 changes: 10 additions & 0 deletions
10
graphqlmetrics/migrations/20251223131622_migrate_data_46_to_24_days.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| -- migrate:up | ||
|
|
||
| -- Step 3: Migrate data from 46 to 24 days ago | ||
| INSERT INTO gql_metrics_schema_usage_5m_90d_v2 | ||
| SELECT * FROM gql_metrics_schema_usage_5m_90d | ||
| WHERE Timestamp >= now() - INTERVAL 46 DAY | ||
| AND Timestamp < now() - INTERVAL 24 DAY; | ||
|
|
||
| -- migrate:down | ||
|
|
10 changes: 10 additions & 0 deletions
10
graphqlmetrics/migrations/20251223131623_migrate_data_24_to_1_day.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| -- migrate:up | ||
|
|
||
| -- Step 4: Migrate data from 24 to 1 day ago | ||
| INSERT INTO gql_metrics_schema_usage_5m_90d_v2 | ||
| SELECT * FROM gql_metrics_schema_usage_5m_90d | ||
| WHERE Timestamp >= now() - INTERVAL 24 DAY | ||
| AND Timestamp < now() - INTERVAL 1 DAY; | ||
|
|
||
| -- migrate:down | ||
|
|
9 changes: 9 additions & 0 deletions
9
graphqlmetrics/migrations/20251223131624_migrate_data_last_1_day.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| -- migrate:up | ||
|
|
||
| -- Step 5: Migrate data from the last 1 day | ||
| INSERT INTO gql_metrics_schema_usage_5m_90d_v2 | ||
| SELECT * FROM gql_metrics_schema_usage_5m_90d | ||
| WHERE Timestamp >= now() - INTERVAL 1 DAY; | ||
|
|
||
| -- migrate:down | ||
|
|
||
JivusAyrus marked this conversation as resolved.
Show resolved
Hide resolved
|
||
42 changes: 42 additions & 0 deletions
42
graphqlmetrics/migrations/20251223131629_drop_old_gql_metrics_schema_usage_5m_90d.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| -- migrate:up | ||
|
|
||
| DROP TABLE IF EXISTS gql_metrics_schema_usage_5m_90d; | ||
|
|
||
| -- migrate:down | ||
|
|
||
| CREATE TABLE gql_metrics_schema_usage_5m_90d | ||
| ( | ||
| Timestamp DateTime('UTC') CODEC(Delta(4), ZSTD(3)), | ||
| OrganizationID LowCardinality(String) CODEC(ZSTD(3)), | ||
| FederatedGraphID LowCardinality(String) CODEC(ZSTD(3)), | ||
| RouterConfigVersion LowCardinality(String) CODEC(ZSTD(3)), | ||
| OperationHash LowCardinality(String) CODEC(ZSTD(3)), | ||
| OperationName LowCardinality(String) CODEC(ZSTD(3)), | ||
| OperationType LowCardinality(String) CODEC(ZSTD(3)), | ||
| Path Array(String) CODEC(ZSTD(3)), | ||
| FieldName LowCardinality(String) CODEC(ZSTD(3)), | ||
| TypeNames Array(String) CODEC(ZSTD(3)), | ||
| NamedType LowCardinality(String) CODEC(ZSTD(3)), | ||
| ClientName LowCardinality(String) CODEC(ZSTD(3)), | ||
| ClientVersion LowCardinality(String) CODEC(ZSTD(3)), | ||
| SubgraphIDs Array(LowCardinality(String)) CODEC(ZSTD(3)), | ||
| IsArgument Bool CODEC(ZSTD(3)), | ||
| IsInput Bool CODEC(ZSTD(3)), | ||
| TotalUsages UInt64 CODEC(ZSTD(3)), | ||
| TotalErrors UInt64 CODEC(ZSTD(3)), | ||
| TotalClientErrors UInt64 CODEC(ZSTD(3)), | ||
| IsIndirectFieldUsage Bool DEFAULT false CODEC(ZSTD(3)), | ||
| IsNull Bool DEFAULT false CODEC(ZSTD(3)), | ||
| INDEX idx_operation_hash OperationHash TYPE bloom_filter(0.001) GRANULARITY 1, | ||
| INDEX idx_path Path TYPE bloom_filter(0.01) GRANULARITY 1, | ||
| INDEX idx_source_ids SubgraphIDs TYPE bloom_filter(0.01) GRANULARITY 1, | ||
| INDEX idx_type_names TypeNames TYPE bloom_filter(0.01) GRANULARITY 1, | ||
| INDEX idx_total_usages TotalUsages TYPE minmax GRANULARITY 1, | ||
| INDEX idx_total_errors TotalErrors TYPE minmax GRANULARITY 1, | ||
| INDEX idx_total_client_errors TotalClientErrors TYPE minmax GRANULARITY 1 | ||
| ) | ||
| ENGINE = SharedSummingMergeTree('/clickhouse/tables/{uuid}/{shard}', '{replica}') | ||
| PARTITION BY toDate(Timestamp) | ||
| ORDER BY (OrganizationID, FederatedGraphID, ClientName, ClientVersion, RouterConfigVersion, OperationHash, Path, FieldName, NamedType, TypeNames, SubgraphIDs, IsArgument, IsInput, toUnixTimestamp(Timestamp)) | ||
| TTL toDateTime(Timestamp) + toIntervalDay(90) | ||
| SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1 |
7 changes: 7 additions & 0 deletions
7
graphqlmetrics/migrations/20251223131720_rename_new_gql_metrics_schema_usage_5m_90d.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| -- migrate:up | ||
|
|
||
| RENAME TABLE gql_metrics_schema_usage_5m_90d_v2 TO gql_metrics_schema_usage_5m_90d; | ||
|
|
||
| -- migrate:down | ||
|
|
||
| RENAME TABLE gql_metrics_schema_usage_5m_90d TO gql_metrics_schema_usage_5m_90d_v2; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
ORDER BY change may alter aggregation semantics.
The new ORDER BY excludes columns present in the old table's ordering:
Path,TypeNames,SubgraphIDs(Array columns)RouterConfigVersion,IsArgument,IsInputWith
SummingMergeTree, rows matching on all ORDER BY columns are merged, summingTotalUsages,TotalErrors,TotalClientErrors. Rows that previously remained distinct (differing byPath,IsArgument, etc.) will now be merged together, potentially losing granularity.Please confirm this aggregation behavior change is intentional and won't impact downstream queries that rely on per-path or per-argument-type breakdowns.