Dataset Viewer
Auto-converted to Parquet Duplicate
text
stringlengths
789
6.17k
instruction
stringclasses
29 values
input
stringlengths
102
2.16k
output
stringlengths
469
4.3k
source_category
stringclasses
3 values
anti_pattern_type
stringclasses
13 values
table
stringclasses
6 values
<s>[INST] Optimize this BigQuery SQL query for cost and performance. Identify all anti-patterns, explain each issue, and provide the optimized version with a cost impact estimate. ```sql SELECT t.order_id, t.customer_id, (SELECT name FROM `reporting-hub.analytics.products` u WHERE u.id = t.customer_id) AS user_n...
Optimize this BigQuery SQL query for cost and performance. Identify all anti-patterns, explain each issue, and provide the optimized version with a cost impact estimate.
```sql SELECT t.order_id, t.customer_id, (SELECT name FROM `reporting-hub.analytics.products` u WHERE u.id = t.customer_id) AS user_name, t.amount FROM `bi-warehouse.analytics.orders` t WHERE DATE(created_at) = '2024-11-01' ```
**Optimized Query:** ```sql SELECT t.order_id, t.customer_id, u.name AS user_name, t.amount FROM `bi-warehouse.analytics.orders` t LEFT JOIN `reporting-hub.analytics.products` u ON u.id = t.customer_id WHERE t.created_at >= '2024-11-01 00:00:00' AND t.created_at < '2024-11-02 00:00:00' ``` **Issues Found & Fix...
sql_optimization
correlated_subquery
orders
<s>[INST] Optimize this BigQuery SQL query for cost and performance. Identify all anti-patterns, explain each issue, and provide the optimized version with a cost impact estimate. ```sql SELECT order_id, customer_id, product_id, amount FROM `analytics-prod.raw_events.orders` WHERE DATE(created_at) = '2024-06-30' UNIO...
Optimize this BigQuery SQL query for cost and performance. Identify all anti-patterns, explain each issue, and provide the optimized version with a cost impact estimate.
```sql SELECT order_id, customer_id, product_id, amount FROM `analytics-prod.raw_events.orders` WHERE DATE(created_at) = '2024-06-30' UNION SELECT order_id, customer_id, product_id, amount FROM `prod-dwh.reporting.orders` WHERE DATE(created_at) = '2024-08-10' ```
**Optimized Query:** ```sql SELECT order_id, customer_id, product_id, amount FROM `analytics-prod.raw_events.orders` WHERE created_at >= '2024-06-30 00:00:00' AND created_at < '2024-07-01 00:00:00' UNION ALL SELECT order_id, customer_id, product_id, amount FROM `prod-dwh.reporting.orders` WHERE created_at >= '2024-08...
sql_optimization
union_vs_union_all
orders
<s>[INST] Optimize this BigQuery SQL query for cost and performance. Identify all anti-patterns, explain each issue, and provide the optimized version with a cost impact estimate. ```sql SELECT session_id, user_id, page_url, time_on_page FROM `bi-warehouse.dwh.page_views` WHERE DATE(event_timestamp) = '2024-01-15' UN...
Optimize this BigQuery SQL query for cost and performance. Identify all anti-patterns, explain each issue, and provide the optimized version with a cost impact estimate.
```sql SELECT session_id, user_id, page_url, time_on_page FROM `bi-warehouse.dwh.page_views` WHERE DATE(event_timestamp) = '2024-01-15' UNION SELECT session_id, user_id, page_url, time_on_page FROM `analytics-prod.raw_events.page_views` WHERE DATE(event_timestamp) = '2024-02-14' ```
**Optimized Query:** ```sql SELECT session_id, user_id, page_url, time_on_page FROM `bi-warehouse.dwh.page_views` WHERE event_timestamp >= '2024-01-15 00:00:00' AND event_timestamp < '2024-01-16 00:00:00' UNION ALL SELECT session_id, user_id, page_url, time_on_page FROM `analytics-prod.raw_events.page_views` WHERE ev...
sql_optimization
union_vs_union_all
page_views
<s>[INST] Optimize this BigQuery SQL query for cost and performance. Identify all anti-patterns, explain each issue, and provide the optimized version with a cost impact estimate. ```sql SELECT * FROM `my-project.staging.events` WHERE DATE(event_time) = '2024-03-01' AND log_level = 'us-east' ``` [/INST] **Optimized ...
Optimize this BigQuery SQL query for cost and performance. Identify all anti-patterns, explain each issue, and provide the optimized version with a cost impact estimate.
```sql SELECT * FROM `my-project.staging.events` WHERE DATE(event_time) = '2024-03-01' AND log_level = 'us-east' ```
**Optimized Query:** ```sql SELECT event_id, user_id, event_name, event_category FROM `my-project.staging.events` WHERE event_time >= '2024-03-01 00:00:00' AND event_time < '2024-03-02 00:00:00' AND log_level = 'us-east' ``` **Issues Found & Fixes Applied:** 1. **SELECT * removed** — The `events` table has 12 col...
sql_optimization
select_star_no_partition_filter
events
<s>[INST] Optimize this BigQuery SQL query for cost and performance. Identify all anti-patterns, explain each issue, and provide the optimized version. ```sql SELECT * FROM `analytics-prod.processed.page_views` WHERE DATE(event_timestamp) = '2024-01-15' AND session_id NOT IN ( SELECT session_id FROM `data-pl...
Optimize this BigQuery SQL query for cost and performance. Identify all anti-patterns, explain each issue, and provide the optimized version.
```sql SELECT * FROM `analytics-prod.processed.page_views` WHERE DATE(event_timestamp) = '2024-01-15' AND session_id NOT IN ( SELECT session_id FROM `data-platform.reporting.events` WHERE status = 'cancelled' ) ```
**Optimized Query:** ```sql SELECT a.session_id, a.user_id, a.page_url, a.time_on_page, a.device_type FROM `analytics-prod.processed.page_views` a LEFT JOIN `data-platform.reporting.events` b ON a.session_id = b.session_id AND b.status = 'cancelled' WHERE a.event_timestamp >= '2024-01-15 00:00:00' AND a.event_tim...
sql_optimization
not_in_with_nulls
page_views
<s>[INST] Optimize this BigQuery SQL query for cost and performance. Identify all anti-patterns, explain each issue, and provide the optimized version with a cost impact estimate. ```sql SELECT * FROM `bi-warehouse.reporting.events` WHERE DATE(event_time) = '2023-12-25' AND log_level = 'eu-west' ``` [/INST] **Optimi...
Optimize this BigQuery SQL query for cost and performance. Identify all anti-patterns, explain each issue, and provide the optimized version with a cost impact estimate.
```sql SELECT * FROM `bi-warehouse.reporting.events` WHERE DATE(event_time) = '2023-12-25' AND log_level = 'eu-west' ```
**Optimized Query:** ```sql SELECT event_id, user_id, event_name, event_category FROM `bi-warehouse.reporting.events` WHERE event_time >= '2023-12-25 00:00:00' AND event_time < '2023-12-26 00:00:00' AND log_level = 'eu-west' ``` **Issues Found & Fixes Applied:** 1. **SELECT * removed** — The `events` table has 12...
sql_optimization
select_star_no_partition_filter
events
<s>[INST] Review this cloud deployment for both infrastructure security issues and SQL performance anti-patterns. The Terraform deploys an RDS database, and the SQL query runs on it. Identify all issues across both domains. ### Infrastructure Configuration ```hcl resource "aws_db_instance" "data_rds" { identifier ...
Review this cloud deployment for both infrastructure security issues and SQL performance anti-patterns. The Terraform deploys an RDS database, and the SQL query runs on it. Identify all issues across both domains.
### Infrastructure Configuration ```hcl resource "aws_db_instance" "data_rds" { identifier = "data-db" engine = "postgres" engine_version = "15.4" instance_class = "db.t3.small" allocated_storage = 50 db_name = "data_production" username = "admin" password ...
## Infrastructure Security Audit CRITICAL [{"id": "HARDCODED-SECRET", "title": "Database password hardcoded in Terraform"}] CRITICAL [{"id": "CIS-AWS-5.2", "title": "Security group allows unrestricted postgres access"}] HIGH [{"id": "CIS-AWS-2.3.3", "title": "RDS instance is publicly accessible"}] HIGH [{"id": "CIS-AW...
cross_domain
null
null
<s>[INST] Review this Terraform configuration for security misconfigurations. Identify all issues by severity, explain each risk, and provide the complete fixed configuration. ```hcl resource "aws_instance" "backend" { ami = "ami-047ca5ea" instance_type = "t3.micro" key_name = "backend-keypair" ...
Review this Terraform configuration for security misconfigurations. Identify all issues by severity, explain each risk, and provide the complete fixed configuration.
```hcl resource "aws_instance" "backend" { ami = "ami-047ca5ea" instance_type = "t3.micro" key_name = "backend-keypair" subnet_id = "subnet-051f2bdf" root_block_device { volume_size = 20 volume_type = "gp2" } user_data = <<-EOF #!/bin/bash curl http://169.254.169.254/l...
**Security Audit Result:** CRITICAL [{"id": "CIS-AWS-5.6", "title": "Ensure EC2 instance metadata service version 2 (IMDSv2) is enabled"}] HIGH [{"id": "SSRF-RISK", "title": "EC2 IMDS v1 is vulnerable to SSRF-based credential theft"}] HIGH [{"id": "CIS-AWS-2.2.1", "title": "Ensure EBS volumes are encrypted"}] MEDIUM [...
iac_security
null
null
<s>[INST] Optimize this BigQuery SQL query for cost and performance. Identify all anti-patterns, explain each issue, and provide the optimized version with a cost impact estimate. ```sql SELECT DISTINCT log_id, service_name, log_level FROM `data-ops.analytics.logs` WHERE DATE(log_timestamp) = '2024-01-15' ``` [/...
Optimize this BigQuery SQL query for cost and performance. Identify all anti-patterns, explain each issue, and provide the optimized version with a cost impact estimate.
```sql SELECT DISTINCT log_id, service_name, log_level FROM `data-ops.analytics.logs` WHERE DATE(log_timestamp) = '2024-01-15' ```
**Optimized Query:** ```sql SELECT log_id, service_name, log_level FROM `data-ops.analytics.logs` WHERE log_timestamp >= '2024-01-15 00:00:00' AND log_timestamp < '2024-01-16 00:00:00' ``` **Issues Found & Fixes Applied:** 1. **DISTINCT removed** — `DISTINCT` forces BigQuery to deduplicate the entire result set...
sql_optimization
unnecessary_distinct
logs
<s>[INST] Review this SQL query for BigQuery cost optimization opportunities. What anti-patterns are present and how should they be fixed? ```sql SELECT * FROM `analytics-prod.mart.transactions` WHERE transaction_date = '2024-03-01' AND txn_id NOT IN ( SELECT txn_id FROM `analytics-prod.processed.transaction...
Review this SQL query for BigQuery cost optimization opportunities. What anti-patterns are present and how should they be fixed?
```sql SELECT * FROM `analytics-prod.mart.transactions` WHERE transaction_date = '2024-03-01' AND txn_id NOT IN ( SELECT txn_id FROM `analytics-prod.processed.transactions` WHERE status = 'cancelled' ) ```
**Optimized Query:** ```sql SELECT a.txn_id, a.user_id, a.amount, a.currency, a.status FROM `analytics-prod.mart.transactions` a LEFT JOIN `analytics-prod.processed.transactions` b ON a.txn_id = b.txn_id AND b.status = 'cancelled' WHERE a.transaction_date = '2024-03-01' AND b.txn_id IS NULL ``` **Issues Found & ...
sql_optimization
not_in_with_nulls
transactions
<s>[INST] Optimize this BigQuery SQL query for cost and performance. Identify all anti-patterns, explain each issue, and provide the optimized version with a cost impact estimate. ```sql SELECT status, COUNT(*) as total_count, SUM(amount) as total_value FROM `data-ops.processed.transactions` WHERE transaction_da...
Optimize this BigQuery SQL query for cost and performance. Identify all anti-patterns, explain each issue, and provide the optimized version with a cost impact estimate.
```sql SELECT status, COUNT(*) as total_count, SUM(amount) as total_value FROM `data-ops.processed.transactions` WHERE transaction_date = '2024-08-10' GROUP BY status ORDER BY total_count DESC ```
**Optimized Query:** ```sql SELECT status, COUNT(txn_id) as total_count, SUM(amount) as total_value FROM `data-ops.processed.transactions` WHERE transaction_date = '2024-08-10' GROUP BY status ORDER BY total_count DESC LIMIT 50 ``` **Issues Found & Fixes Applied:** 1. **COUNT(*) replaced with COUNT(specific_col...
sql_optimization
count_star_no_filter
transactions
<s>[INST] Analyze this BigQuery query for performance issues. Provide the optimized version with explanations for each change. ```sql SELECT a.event_id, a.user_id, b.name, a.event_id FROM `prod-dwh.dwh.events` a, `data-ops.staging.users` b WHERE DATE(a.event_time) = '2024-11-01' AND b.name IS NOT NULL ``` [/...
Analyze this BigQuery query for performance issues. Provide the optimized version with explanations for each change.
```sql SELECT a.event_id, a.user_id, b.name, a.event_id FROM `prod-dwh.dwh.events` a, `data-ops.staging.users` b WHERE DATE(a.event_time) = '2024-11-01' AND b.name IS NOT NULL ```
**Optimized Query:** ```sql SELECT a.event_id, a.user_id, b.name, a.event_id FROM `prod-dwh.dwh.events` a INNER JOIN `data-ops.staging.users` b ON a.user_id = b.id WHERE a.event_time >= '2024-11-01 00:00:00' AND a.event_time < '2024-11-02 00:00:00' AND b.name IS NOT NULL ``` **Issues Found & Fixes Applied:...
sql_optimization
cross_join_accidental
events
<s>[INST] Review this Terraform configuration for security misconfigurations. Identify all issues by severity, explain each risk, and provide the complete fixed configuration. ```hcl resource "aws_s3_bucket" "staging" { bucket = "analytics-exports" acl = "public-read-write" region = "us-west-1" tags = { ...
Review this Terraform configuration for security misconfigurations. Identify all issues by severity, explain each risk, and provide the complete fixed configuration.
```hcl resource "aws_s3_bucket" "staging" { bucket = "analytics-exports" acl = "public-read-write" region = "us-west-1" tags = { Environment = "production" Team = "backend" } } ```
**Security Audit Result:** CRITICAL [{"id": "CIS-AWS-2.1.5", "title": "Ensure S3 bucket is not publicly accessible"}] CRITICAL [{"id": "CIS-AWS-2.1.1", "title": "Ensure S3 bucket has server-side encryption enabled"}] HIGH [{"id": "CIS-AWS-2.1.3", "title": "Ensure S3 bucket has versioning enabled"}] **Issues Found:** ...
iac_security
null
null
<s>[INST] Review this Terraform configuration for security misconfigurations. Identify all issues by severity, explain each risk, and provide the complete fixed configuration. ```hcl resource "aws_ebs_volume" "main_vol" { availability_zone = "us-east-2c" size = 100 type = "io2" tags ...
Review this Terraform configuration for security misconfigurations. Identify all issues by severity, explain each risk, and provide the complete fixed configuration.
```hcl resource "aws_ebs_volume" "main_vol" { availability_zone = "us-east-2c" size = 100 type = "io2" tags = { Name = "main-volume" Environment = "development" Team = "infrastructure" } } resource "aws_volume_attachment" "main_att" { device_name = "/dev...
**Security Audit Result:** CRITICAL [{"id": "CIS-AWS-2.2.1", "title": "Ensure EBS volume encryption is enabled"}] HIGH [{"id": "BEST-PRACTICE", "title": "Use customer-managed KMS keys for EBS encryption"}] **Issues Found:** 1. **NO EBS ENCRYPTION** — `encrypted` is not set (defaults to `false`). This 100GB io2 volum...
iac_security
null
null
<s>[INST] Optimize this BigQuery SQL query for cost and performance. Identify all anti-patterns, explain each issue, and provide the optimized version. ```sql SELECT * FROM `analytics-prod.processed.events` WHERE DATE(event_time) = '2024-03-01' AND page_url LIKE '%critical%' ``` [/INST] **Optimized Query:** ```sql S...
Optimize this BigQuery SQL query for cost and performance. Identify all anti-patterns, explain each issue, and provide the optimized version.
```sql SELECT * FROM `analytics-prod.processed.events` WHERE DATE(event_time) = '2024-03-01' AND page_url LIKE '%critical%' ```
**Optimized Query:** ```sql SELECT event_id, user_id, event_name, event_category, session_id FROM `analytics-prod.processed.events` WHERE event_time >= '2024-03-01 00:00:00' AND event_time < '2024-03-02 00:00:00' AND REGEXP_CONTAINS(page_url, r'(?i)critical') ``` **Issues Found & Fixes Applied:** 1. **Leading wil...
sql_optimization
leading_wildcard_like
events
<s>[INST] Review this Terraform configuration for security misconfigurations. Identify all issues by severity, explain each risk, and provide the complete fixed configuration. ```hcl resource "aws_elasticsearch_domain" "app_es" { domain_name = "app-search" elasticsearch_version = "7.10" cluster_config...
Review this Terraform configuration for security misconfigurations. Identify all issues by severity, explain each risk, and provide the complete fixed configuration.
```hcl resource "aws_elasticsearch_domain" "app_es" { domain_name = "app-search" elasticsearch_version = "7.10" cluster_config { instance_type = "t3.small.search" instance_count = 1 } ebs_options { ebs_enabled = true volume_size = 100 volume_type = "gp2" } access_policies ...
**Security Audit Result:** CRITICAL [{"id": "CIS-AWS-ES-1", "title": "Elasticsearch domain should not be publicly accessible"}] CRITICAL [{"id": "CIS-AWS-ES-2", "title": "Elasticsearch domain access policy allows public access"}] HIGH [{"id": "CIS-AWS-ES-3", "title": "Elasticsearch domain should encrypt data at rest"}...
iac_security
null
null
<s>[INST] Help optimize this BigQuery SQL query. It's scanning too much data. What changes would reduce the bytes processed? ```sql SELECT * FROM `my-project.processed.transactions` WHERE user_id IN ( SELECT id FROM `prod-dwh.raw_events.users` WHERE region IN ( SELECT DISTINCT region FROM `prod-dwh.stagi...
Help optimize this BigQuery SQL query. It's scanning too much data. What changes would reduce the bytes processed?
```sql SELECT * FROM `my-project.processed.transactions` WHERE user_id IN ( SELECT id FROM `prod-dwh.raw_events.users` WHERE region IN ( SELECT DISTINCT region FROM `prod-dwh.staging.orders` WHERE amount > 1000 ) ) ```
**Optimized Query:** ```sql WITH high_value_regions AS ( SELECT DISTINCT region FROM `prod-dwh.staging.orders` WHERE amount > 1000 ), target_users AS ( SELECT u.id FROM `prod-dwh.raw_events.users` u INNER JOIN high_value_regions r ON u.region = r.region ) SELECT a.txn_id, a.user_id, a.amount, a.currency FRO...
sql_optimization
nested_subquery
transactions
<s>[INST] Review this Terraform configuration for security misconfigurations. Identify all issues by severity, explain each risk, and provide the complete fixed configuration. ```hcl resource "aws_db_instance" "app_db" { identifier = "app-database" engine = "mysql" engine_version = "8.0" i...
Review this Terraform configuration for security misconfigurations. Identify all issues by severity, explain each risk, and provide the complete fixed configuration.
```hcl resource "aws_db_instance" "app_db" { identifier = "app-database" engine = "mysql" engine_version = "8.0" instance_class = "db.m5.large" allocated_storage = 20 db_name = "app_db" username = "admin" password = "MyPassword123!" availability_z...
**Security Audit Result:** CRITICAL [{"id": "CIS-AWS-2.3.1", "title": "Ensure RDS instances are encrypted at rest"}] CRITICAL [{"id": "HARDCODED-SECRET", "title": "Hardcoded database password in Terraform configuration"}] HIGH [{"id": "CIS-AWS-2.3.3", "title": "Ensure RDS instances are not publicly accessible"}] HIGH ...
iac_security
null
null
<s>[INST] Review this cloud deployment for both infrastructure security issues and SQL performance anti-patterns. The Terraform deploys an RDS database, and the SQL query runs on it. Identify all issues across both domains. ### Infrastructure Configuration ```hcl resource "aws_db_instance" "prod_rds" { identifier ...
Review this cloud deployment for both infrastructure security issues and SQL performance anti-patterns. The Terraform deploys an RDS database, and the SQL query runs on it. Identify all issues across both domains.
### Infrastructure Configuration ```hcl resource "aws_db_instance" "prod_rds" { identifier = "prod-db" engine = "mysql" engine_version = "8.0" instance_class = "db.t3.small" allocated_storage = 50 db_name = "prod_production" username = "admin" password ...
## Infrastructure Security Audit CRITICAL [{"id": "HARDCODED-SECRET", "title": "Database password hardcoded in Terraform"}] CRITICAL [{"id": "CIS-AWS-5.2", "title": "Security group allows unrestricted mysql access"}] HIGH [{"id": "CIS-AWS-2.3.3", "title": "RDS instance is publicly accessible"}] HIGH [{"id": "CIS-AWS-2...
cross_domain
null
null
<s>[INST] Review this cloud deployment for both infrastructure security issues and SQL performance anti-patterns. The Kubernetes deployment runs an API service, and the SQL query is executed by that service. Identify all issues across both domains. ### Kubernetes Deployment ```yaml apiVersion: apps/v1 kind: Deployment...
Review this cloud deployment for both infrastructure security issues and SQL performance anti-patterns. The Kubernetes deployment runs an API service, and the SQL query is executed by that service. Identify all issues across both domains.
### Kubernetes Deployment ```yaml apiVersion: apps/v1 kind: Deployment metadata: name: pipeline-api namespace: default spec: replicas: 3 selector: matchLabels: app: pipeline-api template: metadata: labels: app: pipeline-api spec: containers: - name: pipeline-api ...
## Infrastructure Security Audit CRITICAL [{"id": "CIS-K8S-5.4.1", "title": "Secrets stored as environment variables in plaintext"}] CRITICAL [{"id": "CIS-K8S-5.2.1", "title": "Privileged container running as root"}] HIGH [{"id": "CIS-K8S-5.2.3", "title": "No resource limits defined"}] HIGH [{"id": "CIS-K8S-5.7.1", "t...
cross_domain
null
null
<s>[INST] Review this Terraform configuration for security misconfigurations. Identify all issues by severity, explain each risk, and provide the complete fixed configuration. ```hcl resource "aws_ebs_volume" "default_vol" { availability_zone = "us-east-2a" size = 50 type = "gp2" tag...
Review this Terraform configuration for security misconfigurations. Identify all issues by severity, explain each risk, and provide the complete fixed configuration.
```hcl resource "aws_ebs_volume" "default_vol" { availability_zone = "us-east-2a" size = 50 type = "gp2" tags = { Name = "default-volume" Environment = "production" Team = "infrastructure" } } resource "aws_volume_attachment" "default_att" { device_name ...
**Security Audit Result:** CRITICAL [{"id": "CIS-AWS-2.2.1", "title": "Ensure EBS volume encryption is enabled"}] HIGH [{"id": "BEST-PRACTICE", "title": "Use customer-managed KMS keys for EBS encryption"}] **Issues Found:** 1. **NO EBS ENCRYPTION** — `encrypted` is not set (defaults to `false`). This 50GB gp2 volume...
iac_security
null
null
<s>[INST] Optimize this BigQuery SQL query for cost and performance. Identify all anti-patterns, explain each issue, and provide the optimized version with a cost impact estimate. ```sql SELECT DISTINCT log_id, service_name, log_level FROM `analytics-prod.curated.logs` WHERE DATE(log_timestamp) = '2024-01-15' ``...
Optimize this BigQuery SQL query for cost and performance. Identify all anti-patterns, explain each issue, and provide the optimized version with a cost impact estimate.
```sql SELECT DISTINCT log_id, service_name, log_level FROM `analytics-prod.curated.logs` WHERE DATE(log_timestamp) = '2024-01-15' ```
**Optimized Query:** ```sql SELECT log_id, service_name, log_level FROM `analytics-prod.curated.logs` WHERE log_timestamp >= '2024-01-15 00:00:00' AND log_timestamp < '2024-01-16 00:00:00' ``` **Issues Found & Fixes Applied:** 1. **DISTINCT removed** — `DISTINCT` forces BigQuery to deduplicate the entire result...
sql_optimization
unnecessary_distinct
logs
<s>[INST] Optimize this BigQuery SQL query for cost and performance. Identify all anti-patterns, explain each issue, and provide the optimized version with a cost impact estimate. ```sql SELECT * FROM `data-ops.analytics.page_views` WHERE DATE(event_timestamp) = '2024-11-01' ORDER BY time_on_page DESC ``` [/INST] **Op...
Optimize this BigQuery SQL query for cost and performance. Identify all anti-patterns, explain each issue, and provide the optimized version with a cost impact estimate.
```sql SELECT * FROM `data-ops.analytics.page_views` WHERE DATE(event_timestamp) = '2024-11-01' ORDER BY time_on_page DESC ```
**Optimized Query:** ```sql SELECT session_id, user_id, page_url, time_on_page FROM `data-ops.analytics.page_views` WHERE event_timestamp >= '2024-11-01 00:00:00' AND event_timestamp < '2024-11-02 00:00:00' ORDER BY time_on_page DESC LIMIT 50 ``` **Issues Found & Fixes Applied:** 1. **SELECT * removed** — Replaced wi...
sql_optimization
order_without_limit
page_views
<s>[INST] Review this cloud deployment for both infrastructure security issues and SQL performance anti-patterns. The Lambda function executes BigQuery analytics queries. Identify all issues across both domains. ### Infrastructure Configuration ```hcl resource "aws_lambda_function" "primary_fn" { filename = ...
Review this cloud deployment for both infrastructure security issues and SQL performance anti-patterns. The Lambda function executes BigQuery analytics queries. Identify all issues across both domains.
### Infrastructure Configuration ```hcl resource "aws_lambda_function" "primary_fn" { filename = "lambda.zip" function_name = "primary-query-service" role = aws_iam_role.primary_lambda_role.arn handler = "index.handler" runtime = "python3.11" memory_size = 128 ...
## Infrastructure Security Audit CRITICAL [{"id": "HARDCODED-SECRET", "title": "API key hardcoded in Lambda environment variables"}] CRITICAL [{"id": "CIS-AWS-1.22", "title": "Lambda IAM role has full admin access"}] HIGH [{"id": "LAMBDA-AUTH", "title": "Lambda function URL has no authentication"}] **Infrastructure I...
cross_domain
null
null
<s>[INST] Review this cloud deployment for both infrastructure security issues and SQL performance anti-patterns. The Kubernetes deployment runs an API service, and the SQL query is executed by that service. Identify all issues across both domains. ### Kubernetes Deployment ```yaml apiVersion: apps/v1 kind: Deployment...
Review this cloud deployment for both infrastructure security issues and SQL performance anti-patterns. The Kubernetes deployment runs an API service, and the SQL query is executed by that service. Identify all issues across both domains.
### Kubernetes Deployment ```yaml apiVersion: apps/v1 kind: Deployment metadata: name: primary-api namespace: default spec: replicas: 2 selector: matchLabels: app: primary-api template: metadata: labels: app: primary-api spec: containers: - name: primary-api ...
## Infrastructure Security Audit CRITICAL [{"id": "CIS-K8S-5.4.1", "title": "Secrets stored as environment variables in plaintext"}] CRITICAL [{"id": "CIS-K8S-5.2.1", "title": "Privileged container running as root"}] HIGH [{"id": "CIS-K8S-5.2.3", "title": "No resource limits defined"}] HIGH [{"id": "CIS-K8S-5.7.1", "t...
cross_domain
null
null
<s>[INST] Optimize this BigQuery SQL query for cost and performance. Identify all anti-patterns, explain each issue, and provide the optimized version with a cost impact estimate. ```sql SELECT t.event_id, t.user_id, (SELECT name FROM `my-project.mart.merchants` u WHERE u.id = t.user_id) AS user_name, t.lat FR...
Optimize this BigQuery SQL query for cost and performance. Identify all anti-patterns, explain each issue, and provide the optimized version with a cost impact estimate.
```sql SELECT t.event_id, t.user_id, (SELECT name FROM `my-project.mart.merchants` u WHERE u.id = t.user_id) AS user_name, t.lat FROM `data-platform.processed.events` t WHERE DATE(event_time) = '2024-02-14' ```
**Optimized Query:** ```sql SELECT t.event_id, t.user_id, u.name AS user_name, t.lat FROM `data-platform.processed.events` t LEFT JOIN `my-project.mart.merchants` u ON u.id = t.user_id WHERE t.event_time >= '2024-02-14 00:00:00' AND t.event_time < '2024-02-15 00:00:00' ``` **Issues Found & Fixes Applied:** 1....
sql_optimization
correlated_subquery
events
<s>[INST] Optimize this BigQuery SQL query for cost and performance. Identify all anti-patterns, explain each issue, and provide the optimized version with a cost impact estimate. ```sql SELECT log_level, COUNT(*) as total_count, SUM(log_id) as total_value FROM `analytics-prod.raw_events.logs` WHERE DATE(log_tim...
Optimize this BigQuery SQL query for cost and performance. Identify all anti-patterns, explain each issue, and provide the optimized version with a cost impact estimate.
```sql SELECT log_level, COUNT(*) as total_count, SUM(log_id) as total_value FROM `analytics-prod.raw_events.logs` WHERE DATE(log_timestamp) = '2024-06-30' GROUP BY log_level ORDER BY total_count DESC ```
**Optimized Query:** ```sql SELECT log_level, COUNT(log_id) as total_count, SUM(log_id) as total_value FROM `analytics-prod.raw_events.logs` WHERE log_timestamp >= '2024-06-30 00:00:00' AND log_timestamp < '2024-07-01 00:00:00' GROUP BY log_level ORDER BY total_count DESC LIMIT 50 ``` **Issues Found & Fixes Appl...
sql_optimization
count_star_no_filter
logs
<s>[INST] Review this Terraform configuration for security misconfigurations. Identify all issues by severity, explain each risk, and provide the complete fixed configuration. ```hcl resource "aws_security_group" "app_sg" { name = "app-security-group" description = "Security group for app" vpc_id = a...
Review this Terraform configuration for security misconfigurations. Identify all issues by severity, explain each risk, and provide the complete fixed configuration.
```hcl resource "aws_security_group" "app_sg" { name = "app-security-group" description = "Security group for app" vpc_id = aws_vpc.app.id ingress { from_port = 3306 to_port = 3306 protocol = "tcp" cidr_blocks = ["0.0.0.0/0"] } ingress { from_port = 0 to_port...
**Security Audit Result:** CRITICAL [{"id": "CIS-AWS-5.2", "title": "Ensure no security groups allow unrestricted MySQL access"}] CRITICAL [{"id": "CIS-AWS-5.1", "title": "Ensure no security groups allow unrestricted inbound access on all ports"}] MEDIUM [{"id": "BEST-PRACTICE", "title": "Restrict outbound traffic to ...
iac_security
null
null
<s>[INST] Optimize this BigQuery SQL query for cost and performance. Identify all anti-patterns, explain each issue, and provide the optimized version with a cost impact estimate. ```sql SELECT event_id, user_id, event_name, event_category FROM `data-platform.staging.events` WHERE DATE(event_time) = '2023-12-25' UNIO...
Optimize this BigQuery SQL query for cost and performance. Identify all anti-patterns, explain each issue, and provide the optimized version with a cost impact estimate.
```sql SELECT event_id, user_id, event_name, event_category FROM `data-platform.staging.events` WHERE DATE(event_time) = '2023-12-25' UNION SELECT event_id, user_id, event_name, event_category FROM `cloud-analytics.raw_events.events` WHERE DATE(event_time) = '2024-12-31' ```
**Optimized Query:** ```sql SELECT event_id, user_id, event_name, event_category FROM `data-platform.staging.events` WHERE event_time >= '2023-12-25 00:00:00' AND event_time < '2023-12-26 00:00:00' UNION ALL SELECT event_id, user_id, event_name, event_category FROM `cloud-analytics.raw_events.events` WHERE event_time...
sql_optimization
union_vs_union_all
events
<s>[INST] Optimize this BigQuery SQL query for cost and performance. Identify all anti-patterns, explain each issue, and provide the optimized version with a cost impact estimate. ```sql SELECT order_id, customer_id, product_id, amount FROM `reporting-hub.dwh.orders` WHERE DATE(created_at) = '2023-12-25' UNION SELEC...
Optimize this BigQuery SQL query for cost and performance. Identify all anti-patterns, explain each issue, and provide the optimized version with a cost impact estimate.
```sql SELECT order_id, customer_id, product_id, amount FROM `reporting-hub.dwh.orders` WHERE DATE(created_at) = '2023-12-25' UNION SELECT order_id, customer_id, product_id, amount FROM `data-ops.curated.orders` WHERE DATE(created_at) = '2024-02-14' ```
**Optimized Query:** ```sql SELECT order_id, customer_id, product_id, amount FROM `reporting-hub.dwh.orders` WHERE created_at >= '2023-12-25 00:00:00' AND created_at < '2023-12-26 00:00:00' UNION ALL SELECT order_id, customer_id, product_id, amount FROM `data-ops.curated.orders` WHERE created_at >= '2024-02-14 00:00:...
sql_optimization
union_vs_union_all
orders
<s>[INST] Optimize this BigQuery SQL query for cost and performance. Identify all anti-patterns, explain each issue, and provide the optimized version with a cost impact estimate. ```sql SELECT * FROM `prod-dwh.curated.logs` WHERE DATE(log_timestamp) = '2024-04-22' ORDER BY log_id DESC ``` [/INST] **Optimized Query:**...
Optimize this BigQuery SQL query for cost and performance. Identify all anti-patterns, explain each issue, and provide the optimized version with a cost impact estimate.
```sql SELECT * FROM `prod-dwh.curated.logs` WHERE DATE(log_timestamp) = '2024-04-22' ORDER BY log_id DESC ```
**Optimized Query:** ```sql SELECT log_id, service_name, log_level, message FROM `prod-dwh.curated.logs` WHERE log_timestamp >= '2024-04-22 00:00:00' AND log_timestamp < '2024-04-23 00:00:00' ORDER BY log_id DESC LIMIT 10 ``` **Issues Found & Fixes Applied:** 1. **SELECT * removed** — Replaced with specific columns n...
sql_optimization
order_without_limit
logs
<s>[INST] Review this Terraform configuration for security misconfigurations. Identify all issues by severity, explain each risk, and provide the complete fixed configuration. ```hcl resource "aws_security_group" "main_sg" { name = "main-security-group" description = "Security group for main" vpc_id ...
Review this Terraform configuration for security misconfigurations. Identify all issues by severity, explain each risk, and provide the complete fixed configuration.
```hcl resource "aws_security_group" "main_sg" { name = "main-security-group" description = "Security group for main" vpc_id = aws_vpc.app.id ingress { from_port = 27017 to_port = 27017 protocol = "tcp" cidr_blocks = ["0.0.0.0/0"] } ingress { from_port = 0 to...
**Security Audit Result:** CRITICAL [{"id": "CIS-AWS-5.2", "title": "Ensure no security groups allow unrestricted MongoDB access"}] CRITICAL [{"id": "CIS-AWS-5.1", "title": "Ensure no security groups allow unrestricted inbound access on all ports"}] MEDIUM [{"id": "BEST-PRACTICE", "title": "Restrict outbound traffic t...
iac_security
null
null
<s>[INST] Review this cloud deployment for both infrastructure security issues and SQL performance anti-patterns. The Terraform creates a BigQuery dataset, and the SQL query runs against it. Identify all issues across both domains. ### Infrastructure Configuration ```hcl resource "google_bigquery_dataset" "data_datase...
Review this cloud deployment for both infrastructure security issues and SQL performance anti-patterns. The Terraform creates a BigQuery dataset, and the SQL query runs against it. Identify all issues across both domains.
### Infrastructure Configuration ```hcl resource "google_bigquery_dataset" "data_dataset" { dataset_id = "curated" project = "reporting-hub" location = "US" description = "Analytics dataset for data" access { role = "OWNER" special_group = "projectOwners" } access { role ...
## Infrastructure Security Audit CRITICAL [{"id": "BQ-PUBLIC-ACCESS", "title": "BigQuery dataset grants access to allAuthenticatedUsers"}] HIGH [{"id": "BQ-NO-ENCRYPTION", "title": "BigQuery dataset missing customer-managed encryption key"}] MEDIUM [{"id": "BQ-NO-DELETE-PROTECT", "title": "BigQuery table has deletion ...
cross_domain
null
null
<s>[INST] Review this cloud deployment for both infrastructure security issues and SQL performance anti-patterns. The Lambda function executes BigQuery analytics queries. Identify all issues across both domains. ### Infrastructure Configuration ```hcl resource "aws_lambda_function" "app_fn" { filename = "lam...
Review this cloud deployment for both infrastructure security issues and SQL performance anti-patterns. The Lambda function executes BigQuery analytics queries. Identify all issues across both domains.
### Infrastructure Configuration ```hcl resource "aws_lambda_function" "app_fn" { filename = "lambda.zip" function_name = "app-query-service" role = aws_iam_role.app_lambda_role.arn handler = "index.handler" runtime = "nodejs18.x" memory_size = 256 timeout ...
## Infrastructure Security Audit CRITICAL [{"id": "HARDCODED-SECRET", "title": "API key hardcoded in Lambda environment variables"}] CRITICAL [{"id": "CIS-AWS-1.22", "title": "Lambda IAM role has full admin access"}] HIGH [{"id": "LAMBDA-AUTH", "title": "Lambda function URL has no authentication"}] **Infrastructure I...
cross_domain
null
null
<s>[INST] Review this Terraform configuration for security misconfigurations. Identify all issues by severity, explain each risk, and provide the complete fixed configuration. ```hcl resource "aws_db_instance" "backup_db" { identifier = "backup-database" engine = "postgres" engine_version = ...
Review this Terraform configuration for security misconfigurations. Identify all issues by severity, explain each risk, and provide the complete fixed configuration.
```hcl resource "aws_db_instance" "backup_db" { identifier = "backup-database" engine = "postgres" engine_version = "15.4" instance_class = "db.t3.micro" allocated_storage = 20 db_name = "backup_db" username = "admin" password = "admin123" availab...
**Security Audit Result:** CRITICAL [{"id": "CIS-AWS-2.3.1", "title": "Ensure RDS instances are encrypted at rest"}] CRITICAL [{"id": "HARDCODED-SECRET", "title": "Hardcoded database password in Terraform configuration"}] HIGH [{"id": "CIS-AWS-2.3.3", "title": "Ensure RDS instances are not publicly accessible"}] HIGH ...
iac_security
null
null
<s>[INST] Review this Terraform configuration for security misconfigurations. Identify all issues by severity, explain each risk, and provide the complete fixed configuration. ```hcl resource "aws_security_group" "frontend_sg" { name = "frontend-security-group" description = "Security group for frontend" ...
Review this Terraform configuration for security misconfigurations. Identify all issues by severity, explain each risk, and provide the complete fixed configuration.
```hcl resource "aws_security_group" "frontend_sg" { name = "frontend-security-group" description = "Security group for frontend" vpc_id = aws_vpc.primary.id ingress { from_port = 5432 to_port = 5432 protocol = "tcp" cidr_blocks = ["0.0.0.0/0"] } ingress { from_por...
**Security Audit Result:** CRITICAL [{"id": "CIS-AWS-5.2", "title": "Ensure no security groups allow unrestricted PostgreSQL access"}] CRITICAL [{"id": "CIS-AWS-5.1", "title": "Ensure no security groups allow unrestricted inbound access on all ports"}] MEDIUM [{"id": "BEST-PRACTICE", "title": "Restrict outbound traffi...
iac_security
null
null
<s>[INST] Optimize this BigQuery SQL query for cost and performance. Identify all anti-patterns, explain each issue, and provide the optimized version with a cost impact estimate. ```sql SELECT DISTINCT txn_id, user_id, amount FROM `analytics-prod.staging.transactions` WHERE transaction_date = '2024-08-10' ``` [...
Optimize this BigQuery SQL query for cost and performance. Identify all anti-patterns, explain each issue, and provide the optimized version with a cost impact estimate.
```sql SELECT DISTINCT txn_id, user_id, amount FROM `analytics-prod.staging.transactions` WHERE transaction_date = '2024-08-10' ```
**Optimized Query:** ```sql SELECT txn_id, user_id, amount FROM `analytics-prod.staging.transactions` WHERE transaction_date = '2024-08-10' ``` **Issues Found & Fixes Applied:** 1. **DISTINCT removed** — `DISTINCT` forces BigQuery to deduplicate the entire result set, which requires a full sort or hash operatio...
sql_optimization
unnecessary_distinct
transactions
End of preview. Expand in Data Studio
README.md exists but content is empty.
Downloads last month
24