-
Notifications
You must be signed in to change notification settings - Fork 327
Refactor queries_grouped by hash and 2 additional optimization scripts from PR #471 #517
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
Merged
danieldeleo
merged 11 commits into
GoogleCloudPlatform:master
from
Andres-Ayala1:optimization-additions
Feb 17, 2026
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
3a661ab
refactor optimization scripts add 4 additional scripts
afleisc facc0ee
chore: remove newline at end of file
Andres-Ayala1 26408f5
feat: consolidate duration percentiles into query hash org and proj l…
Andres-Ayala1 31788ba
chore: remove old duration scripts and update README.md
Andres-Ayala1 eb1968e
chore: remove newline in queries by hash org
Andres-Ayala1 0aaa621
chore: update license year and descriptions
Andres-Ayala1 7c44804
fix: remove ORDER BY from table creation script + add readme example
Andres-Ayala1 0f6f8e6
fix: remove ORDER BY and limit from queries_grouped_by_hash_project +…
Andres-Ayala1 055e86b
chore: move bi engine tables into Query analysis section + add exampl…
Andres-Ayala1 a30f626
chore: add description for bi_engine_disabled_reasons
Andres-Ayala1 3904a9c
fix: license years on existing scripts
Andres-Ayala1 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
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
2 changes: 1 addition & 1 deletion
2
scripts/optimization/actively_read_tables_with_partitioning_clustering_info.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
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,36 @@ | ||
| /* | ||
| * Copyright 2026 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| /* | ||
| * This script creates a table named, bi_engine_disabled_reasons, | ||
| * which groups queries by their BI Engine Disabled reason and counts them by reason. | ||
| * This table helps identify the most common reasons why BI Engine is disabled | ||
| * for your queries so that you can tune your queries to be BI Engine friendly. | ||
| * | ||
| * 30 days is the default timeframe, but you can change this by setting the | ||
| * num_days_to_scan variable to a different value. | ||
| */ | ||
|
|
||
|
|
||
| DECLARE num_days_to_scan INT64 DEFAULT 30; | ||
|
|
||
| CREATE SCHEMA IF NOT EXISTS optimization_workshop; | ||
| CREATE OR REPLACE TABLE optimization_workshop.bi_engine_disabled_reasons AS | ||
| SELECT reasons.code, count(*) | ||
| FROM `region-us`.INFORMATION_SCHEMA.JOBS as jbo, UNNEST(bi_engine_statistics.bi_engine_reasons) AS reasons | ||
| WHERE DATE(jbo.creation_time) >= CURRENT_DATE - num_days_to_scan | ||
| AND bi_engine_statistics.bi_engine_mode = 'DISABLED' | ||
| GROUP BY reasons.code; |
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,62 @@ | ||
| /* | ||
| * Copyright 2026 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| DECLARE num_days_to_scan INT64 DEFAULT 30; | ||
|
|
||
| CREATE SCHEMA IF NOT EXISTS optimization_workshop; | ||
| CREATE OR REPLACE TABLE optimization_workshop.bi_engine_mode_duration AS | ||
| SELECT | ||
| day, | ||
| bi_engine_mode, | ||
| COUNT(*) as job_count, | ||
| AVG(time_ms) avg_time_ms, | ||
| MAX(median_time_ms) median_time_ms, | ||
| MAX(p75_time_ms) p75_time_ms, | ||
| MAX(p80_time_ms) p80_time_ms, | ||
| MAX(p90_time_ms) p90_time_ms, | ||
| MAX(p95_time_ms) p95_time_ms, | ||
| MAX(p99_time_ms) p99_time_ms, | ||
| FROM | ||
| ( | ||
| SELECT | ||
| day, | ||
| bi_engine_mode, | ||
| time_ms, | ||
| PERCENTILE_CONT(time_ms, 0.5) OVER (PARTITION BY day, bi_engine_mode) as median_time_ms, | ||
| PERCENTILE_CONT(time_ms, 0.75) OVER (PARTITION BY day, bi_engine_mode) as p75_time_ms, | ||
| PERCENTILE_CONT(time_ms, 0.8) OVER (PARTITION BY day, bi_engine_mode) as p80_time_ms, | ||
| PERCENTILE_CONT(time_ms, 0.90) OVER (PARTITION BY day, bi_engine_mode) as p90_time_ms, | ||
| PERCENTILE_CONT(time_ms, 0.95) OVER (PARTITION BY day, bi_engine_mode) as p95_time_ms, | ||
| PERCENTILE_CONT(time_ms, 0.99) OVER (PARTITION BY day, bi_engine_mode) as p99_time_ms, | ||
| FROM | ||
| ( | ||
| SELECT | ||
| DATE(jbo.creation_time) AS day, | ||
| bi_engine_statistics.bi_engine_mode as bi_engine_mode, | ||
| job_id, | ||
| TIMESTAMP_DIFF(jbo.end_time, jbo.creation_time, MILLISECOND) time_ms | ||
| FROM | ||
| FROM `region-us`.INFORMATION_SCHEMA.JOBS jbo | ||
| WHERE | ||
| DATE(creation_time) >= CURRENT_DATE - num_days_to_scan | ||
| AND jbo.end_time > jbo.start_time | ||
| AND jbo.error_result IS NULL | ||
| AND jbo.statement_type != 'SCRIPT' | ||
| ) | ||
| ) | ||
| GROUP BY | ||
| 1, | ||
| 2 |
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
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
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
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
16 changes: 16 additions & 0 deletions
16
scripts/optimization/hourly_slot_consumption_by_labels.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
16 changes: 16 additions & 0 deletions
16
scripts/optimization/hourly_slot_consumption_by_query_hash.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
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
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
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.