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 |
<s>[INST] Review this cloud deployment for both infrastructure security issues and SQL performance anti-patterns. The infrastructure manages an ETL pipeline, and the SQL query processes data through it. Identify all issues across both domains.
### Infrastructure Configuration
```hcl
resource "aws_s3_bucket" "analytics... | Review this cloud deployment for both infrastructure security issues and SQL performance anti-patterns. The infrastructure manages an ETL pipeline, and the SQL query processes data through it. Identify all issues across both domains. | ### Infrastructure Configuration
```hcl
resource "aws_s3_bucket" "analytics_bucket" {
bucket = "analytics-ingestion"
acl = "public-read"
tags = {
Environment = "production"
Purpose = "ETL data staging"
}
}
resource "aws_iam_role" "analytics_etl_role" {
name = "analytics-etl-role"
assume_rol... | ## Infrastructure Security Audit
CRITICAL [{"id": "CIS-AWS-2.1.5", "title": "S3 bucket is publicly accessible"}]
CRITICAL [{"id": "CIS-AWS-1.22", "title": "IAM policy grants full admin access"}]
HIGH [{"id": "CIS-AWS-2.1.1", "title": "S3 bucket missing server-side encryption"}]
**Infrastructure Issues:**
1. **PUBLIC... | cross_domain | 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" "primary_dat... | 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" "primary_dataset" {
dataset_id = "processed"
project = "prod-dwh"
location = "US"
description = "Analytics dataset for primary"
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 Terraform configuration for security misconfigurations. Identify all issues by severity, explain each risk, and provide the complete fixed configuration.
```hcl
resource "aws_instance" "backup" {
ami = "ami-03566bc4"
instance_type = "t3.medium"
key_name = "backup-keypair"
s... | 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" "backup" {
ami = "ami-03566bc4"
instance_type = "t3.medium"
key_name = "backup-keypair"
subnet_id = "subnet-017bfa9c"
root_block_device {
volume_size = 20
volume_type = "gp2"
}
user_data = <<-EOF
#!/bin/bash
curl http://169.254.169.254/la... | **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
t.log_id,
t.service_name,
(SELECT name FROM `cloud-analytics.staging.merchants` u WHERE u.id = t.service_name) AS user_... | 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.log_id,
t.service_name,
(SELECT name FROM `cloud-analytics.staging.merchants` u WHERE u.id = t.service_name) AS user_name,
t.log_id
FROM `data-ops.mart.logs` t
WHERE DATE(log_timestamp) = '2023-12-25'
``` | **Optimized Query:**
```sql
SELECT
t.log_id,
t.service_name,
u.name AS user_name,
t.log_id
FROM `data-ops.mart.logs` t
LEFT JOIN `cloud-analytics.staging.merchants` u ON u.id = t.service_name
WHERE t.log_timestamp >= '2023-12-25 00:00:00' AND t.log_timestamp < '2023-12-26 00:00:00'
```
**Issues Found & Fixes A... | sql_optimization | correlated_subquery | 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_ebs_volume" "backup_vol" {
availability_zone = "us-east-2a"
size = 50
type = "io1"
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" "backup_vol" {
availability_zone = "us-east-2a"
size = 50
type = "io1"
tags = {
Name = "backup-volume"
Environment = "development"
Team = "analytics"
}
}
resource "aws_volume_attachment" "backup_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 50GB io1 volume... | iac_security | null | null |
<s>[INST] This query runs on BigQuery and costs too much. Identify the performance anti-patterns and rewrite it efficiently.
```sql
SELECT *
FROM `prod-dwh.processed.page_views`
WHERE DATE(event_timestamp) = '2024-04-22'
AND (event_category = 'refunded' OR event_category = 'shipped' OR event_category = 'completed')
... | This query runs on BigQuery and costs too much. Identify the performance anti-patterns and rewrite it efficiently. | ```sql
SELECT *
FROM `prod-dwh.processed.page_views`
WHERE DATE(event_timestamp) = '2024-04-22'
AND (event_category = 'refunded' OR event_category = 'shipped' OR event_category = 'completed')
ORDER BY time_on_page DESC
``` | **Optimized Query:**
```sql
SELECT session_id, user_id, page_url, time_on_page, device_type
FROM `prod-dwh.processed.page_views`
WHERE event_timestamp >= '2024-04-22 00:00:00'
AND event_timestamp < '2024-04-23 00:00:00'
AND event_category IN ('refunded', 'shipped', 'completed')
ORDER BY time_on_page DESC
LIMIT 100
... | sql_optimization | or_instead_of_in | page_views |
<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" "primary_es" {
domain_name = "primary-search"
elasticsearch_version = "7.10"
cluste... | 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" "primary_es" {
domain_name = "primary-search"
elasticsearch_version = "7.10"
cluster_config {
instance_type = "t3.small.search"
instance_count = 1
}
ebs_options {
ebs_enabled = true
volume_size = 50
volume_type = "gp2"
}
access_po... | **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] 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.log_id,
t.service_name,
(SELECT name FROM `prod-dwh.processed.users` u WHERE u.id = t.service_name) AS user_name,
t... | 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.log_id,
t.service_name,
(SELECT name FROM `prod-dwh.processed.users` u WHERE u.id = t.service_name) AS user_name,
t.log_id
FROM `analytics-prod.curated.logs` t
WHERE DATE(log_timestamp) = '2024-08-10'
``` | **Optimized Query:**
```sql
SELECT
t.log_id,
t.service_name,
u.name AS user_name,
t.log_id
FROM `analytics-prod.curated.logs` t
LEFT JOIN `prod-dwh.processed.users` u ON u.id = t.service_name
WHERE t.log_timestamp >= '2024-08-10 00:00:00' AND t.log_timestamp < '2024-08-11 00:00:00'
```
**Issues Found & Fixes A... | sql_optimization | correlated_subquery | logs |
<s>[INST] This query runs on BigQuery and costs too much. Identify the performance anti-patterns and rewrite it efficiently.
```sql
SELECT
a.session_id,
a.user_id,
b.name,
a.time_on_page
FROM `my-project.analytics.page_views` a, `reporting-hub.curated.users` b
WHERE DATE(a.event_timestamp) = '2023-12-25'
AND... | This query runs on BigQuery and costs too much. Identify the performance anti-patterns and rewrite it efficiently. | ```sql
SELECT
a.session_id,
a.user_id,
b.name,
a.time_on_page
FROM `my-project.analytics.page_views` a, `reporting-hub.curated.users` b
WHERE DATE(a.event_timestamp) = '2023-12-25'
AND b.name IS NOT NULL
``` | **Optimized Query:**
```sql
SELECT
a.session_id,
a.user_id,
b.name,
a.time_on_page
FROM `my-project.analytics.page_views` a
INNER JOIN `reporting-hub.curated.users` b ON a.user_id = b.id
WHERE a.event_timestamp >= '2023-12-25 00:00:00'
AND a.event_timestamp < '2023-12-26 00:00:00'
AND b.name IS NOT NULL
```... | sql_optimization | cross_join_accidental | page_views |
<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" "primary_vol" {
availability_zone = "us-east-2c"
size = 100
type = "gp2"
ta... | 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" "primary_vol" {
availability_zone = "us-east-2c"
size = 100
type = "gp2"
tags = {
Name = "primary-volume"
Environment = "development"
Team = "sre"
}
}
resource "aws_volume_attachment" "primary_att" {
device_name = "/dev/s... | **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 gp2 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 with a cost impact estimate.
```sql
SELECT
log_level,
COUNT(*) as total_count,
SUM(lat) as total_value
FROM `data-platform.raw_events.events`
WHERE DATE(event_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(lat) as total_value
FROM `data-platform.raw_events.events`
WHERE DATE(event_time) = '2024-02-14'
GROUP BY log_level
ORDER BY total_count DESC
``` | **Optimized Query:**
```sql
SELECT
log_level,
COUNT(event_id) as total_count,
SUM(lat) as total_value
FROM `data-platform.raw_events.events`
WHERE event_time >= '2024-02-14 00:00:00' AND event_time < '2024-02-15 00:00:00'
GROUP BY log_level
ORDER BY total_count DESC
LIMIT 50
```
**Issues Found & Fixes Applied:**... | sql_optimization | count_star_no_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 with a cost impact estimate.
```sql
SELECT
log_level,
COUNT(*) as total_count,
SUM(time_on_page) as total_value
FROM `data-ops.mart.page_views`
WHERE DATE(event_t... | 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(time_on_page) as total_value
FROM `data-ops.mart.page_views`
WHERE DATE(event_timestamp) = '2023-12-25'
GROUP BY log_level
ORDER BY total_count DESC
``` | **Optimized Query:**
```sql
SELECT
log_level,
COUNT(session_id) as total_count,
SUM(time_on_page) as total_value
FROM `data-ops.mart.page_views`
WHERE event_timestamp >= '2023-12-25 00:00:00' AND event_timestamp < '2023-12-26 00:00:00'
GROUP BY log_level
ORDER BY total_count DESC
LIMIT 50
```
**Issues Found & Fi... | sql_optimization | count_star_no_filter | page_views |
<s>[INST] Help optimize this BigQuery SQL query. It's scanning too much data. What changes would reduce the bytes processed?
```sql
SELECT *
FROM `data-ops.raw_events.orders`
WHERE DATE(created_at) = '2023-12-25'
AND order_id NOT IN (
SELECT order_id
FROM `data-ops.dwh.page_views`
WHERE status = 'cancell... | Help optimize this BigQuery SQL query. It's scanning too much data. What changes would reduce the bytes processed? | ```sql
SELECT *
FROM `data-ops.raw_events.orders`
WHERE DATE(created_at) = '2023-12-25'
AND order_id NOT IN (
SELECT order_id
FROM `data-ops.dwh.page_views`
WHERE status = 'cancelled'
)
``` | **Optimized Query:**
```sql
SELECT a.order_id, a.customer_id, a.amount, a.status, a.region
FROM `data-ops.raw_events.orders` a
LEFT JOIN `data-ops.dwh.page_views` b
ON a.order_id = b.order_id
AND b.status = 'cancelled'
WHERE a.created_at >= '2023-12-25 00:00:00'
AND a.created_at < '2023-12-26 00:00:00'
AND b.or... | sql_optimization | not_in_with_nulls | 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
t.log_id,
t.service_name,
(SELECT name FROM `reporting-hub.raw_events.users` u WHERE u.id = t.service_name) AS user_nam... | 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.log_id,
t.service_name,
(SELECT name FROM `reporting-hub.raw_events.users` u WHERE u.id = t.service_name) AS user_name,
t.log_id
FROM `bi-warehouse.analytics.logs` t
WHERE DATE(log_timestamp) = '2024-03-01'
``` | **Optimized Query:**
```sql
SELECT
t.log_id,
t.service_name,
u.name AS user_name,
t.log_id
FROM `bi-warehouse.analytics.logs` t
LEFT JOIN `reporting-hub.raw_events.users` u ON u.id = t.service_name
WHERE t.log_timestamp >= '2024-03-01 00:00:00' AND t.log_timestamp < '2024-03-02 00:00:00'
```
**Issues Found & F... | sql_optimization | correlated_subquery | 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
log_level,
COUNT(*) as total_count,
SUM(log_id) as total_value
FROM `my-project.reporting.logs`
WHERE DATE(log_timestam... | 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 `my-project.reporting.logs`
WHERE DATE(log_timestamp) = '2024-04-22'
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 `my-project.reporting.logs`
WHERE log_timestamp >= '2024-04-22 00:00:00' AND log_timestamp < '2024-04-23 00:00:00'
GROUP BY log_level
ORDER BY total_count DESC
LIMIT 50
```
**Issues Found & Fixes Applied:*... | sql_optimization | count_star_no_filter | logs |
<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" "main_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" "main_rds" {
identifier = "main-db"
engine = "postgres"
engine_version = "15.4"
instance_class = "db.t3.small"
allocated_storage = 50
db_name = "main_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_s3_bucket" "app" {
bucket = "config-store"
acl = "public-read-write"
region = "us-east-2"
tags = {
Envir... | 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" "app" {
bucket = "config-store"
acl = "public-read-write"
region = "us-east-2"
tags = {
Environment = "testing"
Team = "analytics"
}
}
``` | **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] 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 txn_id, user_id, amount, currency
FROM `data-ops.dwh.transactions`
WHERE transaction_date = '2024-06-30'
UNION
SELECT txn_i... | 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 txn_id, user_id, amount, currency
FROM `data-ops.dwh.transactions`
WHERE transaction_date = '2024-06-30'
UNION
SELECT txn_id, user_id, amount, currency
FROM `analytics-prod.mart.transactions`
WHERE transaction_date = '2024-04-22'
``` | **Optimized Query:**
```sql
SELECT txn_id, user_id, amount, currency
FROM `data-ops.dwh.transactions`
WHERE transaction_date = '2024-06-30'
UNION ALL
SELECT txn_id, user_id, amount, currency
FROM `analytics-prod.mart.transactions`
WHERE transaction_date = '2024-04-22'
```
**Issues Found & Fixes Applied:**
1. **UNIO... | sql_optimization | union_vs_union_all | 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_ebs_volume" "primary_vol" {
availability_zone = "us-west-2b"
size = 100
type = "io2"
ta... | 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" "primary_vol" {
availability_zone = "us-west-2b"
size = 100
type = "io2"
tags = {
Name = "primary-volume"
Environment = "testing"
Team = "analytics"
}
}
resource "aws_volume_attachment" "primary_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] Review this SQL query for BigQuery cost optimization opportunities.
```sql
SELECT
APPROX_COUNT_DISTINCT(user_id) AS unique_users
FROM `prod-dwh.staging.page_views`
WHERE event_timestamp >= '2024-08-10 00:00:00'
AND event_timestamp < '2024-08-11 00:00:00'
``` [/INST] **Query Analysis:**
This query is **w... | Review this SQL query for BigQuery cost optimization opportunities. | ```sql
SELECT
APPROX_COUNT_DISTINCT(user_id) AS unique_users
FROM `prod-dwh.staging.page_views`
WHERE event_timestamp >= '2024-08-10 00:00:00'
AND event_timestamp < '2024-08-11 00:00:00'
``` | **Query Analysis:**
This query is **well-optimized** and follows BigQuery best practices:
1. **Column selection** β β Only necessary columns are selected (no `SELECT *`).
2. **Partition filter** β β Direct range comparison on TIMESTAMP column `event_timestamp` enables partition pruning.
3. **Result limiting** β β Agg... | sql_optimization | none_optimized | page_views |
<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.micro"
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 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" "app_dataset... | 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" "app_dataset" {
dataset_id = "reporting"
project = "analytics-prod"
location = "US"
description = "Analytics dataset for app"
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] 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.reporting.inventory`
WHERE snapshot_date = '2024-08-10'
AND log_level = 'eu-central'
``` [/INST] **Optimiz... | 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.reporting.inventory`
WHERE snapshot_date = '2024-08-10'
AND log_level = 'eu-central'
``` | **Optimized Query:**
```sql
SELECT sku_id, warehouse_id, quantity, unit_cost
FROM `prod-dwh.reporting.inventory`
WHERE snapshot_date = '2024-08-10'
AND log_level = 'eu-central'
```
**Issues Found & Fixes Applied:**
1. **SELECT * removed** β The `inventory` table has 11 columns but only 4 are needed. Selecting all c... | sql_optimization | select_star_no_partition_filter | inventory |
<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 `cloud-analytics.curated.page_views`
WHERE DATE(event_timestamp) = '2024-01-15'
ORDER BY time_on_page DESC
``` [/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 `cloud-analytics.curated.page_views`
WHERE DATE(event_timestamp) = '2024-01-15'
ORDER BY time_on_page DESC
``` | **Optimized Query:**
```sql
SELECT session_id, user_id, page_url, time_on_page
FROM `cloud-analytics.curated.page_views`
WHERE event_timestamp >= '2024-01-15 00:00:00' AND event_timestamp < '2024-01-16 00:00:00'
ORDER BY time_on_page DESC
LIMIT 10
```
**Issues Found & Fixes Applied:**
1. **SELECT * removed** β Replac... | sql_optimization | order_without_limit | page_views |
<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" "assets" {
bucket = "media-files"
acl = "public-read"
region = "ap-northeast-1"
tags = {
Envi... | 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" "assets" {
bucket = "media-files"
acl = "public-read"
region = "ap-northeast-1"
tags = {
Environment = "production"
Team = "data-engineering"
}
}
``` | **Security Audit Result:**
HIGH [{"id": "CIS-AWS-2.1.5", "title": "Ensure S3 bucket is not publicly accessible"}]
HIGH [{"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:**
1. **PU... | 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 `reporting-hub.processed.transactions`
WHERE transaction_date = '2023-12-25'
``` ... | 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 `reporting-hub.processed.transactions`
WHERE transaction_date = '2023-12-25'
``` | **Optimized Query:**
```sql
SELECT
txn_id,
user_id,
amount
FROM `reporting-hub.processed.transactions`
WHERE transaction_date = '2023-12-25'
```
**Issues Found & Fixes Applied:**
1. **DISTINCT removed** β `DISTINCT` forces BigQuery to deduplicate the entire result set, which requires a full sort or hash operati... | sql_optimization | unnecessary_distinct | transactions |
<s>[INST] Perform a query cost review on this BigQuery SQL. Find all inefficiencies and provide the optimized query with cost impact estimates.
```sql
SELECT *
FROM `data-platform.mart.events`
WHERE DATE(event_time) = '2024-01-15'
AND event_id NOT IN (
SELECT event_id
FROM `my-project.mart.orders`
WHERE ... | Perform a query cost review on this BigQuery SQL. Find all inefficiencies and provide the optimized query with cost impact estimates. | ```sql
SELECT *
FROM `data-platform.mart.events`
WHERE DATE(event_time) = '2024-01-15'
AND event_id NOT IN (
SELECT event_id
FROM `my-project.mart.orders`
WHERE status = 'cancelled'
)
``` | **Optimized Query:**
```sql
SELECT a.event_id, a.user_id, a.event_name, a.event_category, a.session_id
FROM `data-platform.mart.events` a
LEFT JOIN `my-project.mart.orders` b
ON a.event_id = b.event_id
AND b.status = 'cancelled'
WHERE a.event_time >= '2024-01-15 00:00:00'
AND a.event_time < '2024-01-16 00:00:00'
... | sql_optimization | not_in_with_nulls | 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
t.txn_id,
t.user_id,
(SELECT name FROM `bi-warehouse.curated.merchants` u WHERE u.id = t.user_id) AS user_name,
t.amo... | 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.txn_id,
t.user_id,
(SELECT name FROM `bi-warehouse.curated.merchants` u WHERE u.id = t.user_id) AS user_name,
t.amount
FROM `reporting-hub.reporting.transactions` t
WHERE transaction_date = '2023-12-25'
``` | **Optimized Query:**
```sql
SELECT
t.txn_id,
t.user_id,
u.name AS user_name,
t.amount
FROM `reporting-hub.reporting.transactions` t
LEFT JOIN `bi-warehouse.curated.merchants` u ON u.id = t.user_id
WHERE t.transaction_date = '2023-12-25'
```
**Issues Found & Fixes Applied:**
1. **Correlated subquery in SELECT ... | sql_optimization | correlated_subquery | transactions |
<s>[INST] Review this Kubernetes/Terraform configuration for security misconfigurations. Identify all issues by severity, explain each risk, and provide the complete fixed configuration.
```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: primary-deployment
namespace: default
spec:
replicas: 2
selecto... | Review this Kubernetes/Terraform configuration for security misconfigurations. Identify all issues by severity, explain each risk, and provide the complete fixed configuration. | ```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: primary-deployment
namespace: default
spec:
replicas: 2
selector:
matchLabels:
app: primary
template:
metadata:
labels:
app: primary
spec:
hostNetwork: true
hostPID: true
hostIPC: true
containe... | **Security Audit Result:**
CRITICAL [{"id": "CIS-K8S-5.2.2", "title": "Do not admit containers with hostNetwork"}]
CRITICAL [{"id": "CIS-K8S-5.2.3", "title": "Do not admit containers with hostPID or hostIPC"}]
CRITICAL [{"id": "CIS-K8S-5.2.7", "title": "Do not admit containers that mount host filesystem root"}]
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_s3_bucket" "assets" {
bucket = "company-data-lake"
acl = "public-read"
region = "us-west-2"
tags = {
Env... | 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" "assets" {
bucket = "company-data-lake"
acl = "public-read"
region = "us-west-2"
tags = {
Environment = "production"
Team = "infrastructure"
}
}
``` | **Security Audit Result:**
HIGH [{"id": "CIS-AWS-2.1.5", "title": "Ensure S3 bucket is not publicly accessible"}]
HIGH [{"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:**
1. **PU... | iac_security | 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: main-api
namespace: default
spec:
replicas: 3
selector:
matchLabels:
app: main-api
template:
metadata:
labels:
app: main-api
spec:
containers:
- name: main-api
image: node... | ## 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 sku_id, warehouse_id, quantity, unit_cost
FROM `prod-dwh.mart.inventory`
WHERE snapshot_date = '2023-12-25'
UNION
SELECT sk... | 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 sku_id, warehouse_id, quantity, unit_cost
FROM `prod-dwh.mart.inventory`
WHERE snapshot_date = '2023-12-25'
UNION
SELECT sku_id, warehouse_id, quantity, unit_cost
FROM `data-ops.dwh.inventory`
WHERE snapshot_date = '2024-12-31'
``` | **Optimized Query:**
```sql
SELECT sku_id, warehouse_id, quantity, unit_cost
FROM `prod-dwh.mart.inventory`
WHERE snapshot_date = '2023-12-25'
UNION ALL
SELECT sku_id, warehouse_id, quantity, unit_cost
FROM `data-ops.dwh.inventory`
WHERE snapshot_date = '2024-12-31'
```
**Issues Found & Fixes Applied:**
1. **UNION ... | sql_optimization | union_vs_union_all | inventory |
<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" "data_vol" {
availability_zone = "us-east-1b"
size = 200
type = "gp3"
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" "data_vol" {
availability_zone = "us-east-1b"
size = 200
type = "gp3"
tags = {
Name = "data-volume"
Environment = "testing"
Team = "infrastructure"
}
}
resource "aws_volume_attachment" "data_att" {
device_name = "/dev/sdh... | **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 200GB gp3 volum... | iac_security | null | null |
<s>[INST] Check this BigQuery SQL query for anti-patterns. Is it well-optimized?
```sql
SELECT order_id, customer_id, amount, status, region
FROM `reporting-hub.processed.orders`
WHERE created_at >= '2024-11-01 00:00:00'
AND created_at < '2024-11-02 00:00:00'
LIMIT 500
``` [/INST] **Query Analysis:**
This query is ... | Check this BigQuery SQL query for anti-patterns. Is it well-optimized? | ```sql
SELECT order_id, customer_id, amount, status, region
FROM `reporting-hub.processed.orders`
WHERE created_at >= '2024-11-01 00:00:00'
AND created_at < '2024-11-02 00:00:00'
LIMIT 500
``` | **Query Analysis:**
This query is **well-optimized** and follows BigQuery best practices:
1. **Column selection** β β Only necessary columns are selected (no `SELECT *`).
2. **Partition filter** β β Direct range comparison on TIMESTAMP column `created_at` enables partition pruning.
3. **Result limiting** β β LIMIT cl... | sql_optimization | none_optimized | 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 `data-platform.analytics.events`
WHERE DATE(event_time) = '2024-11-01'
AND log_level = 'sa-east'
``` [/INST] **Optim... | 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-platform.analytics.events`
WHERE DATE(event_time) = '2024-11-01'
AND log_level = 'sa-east'
``` | **Optimized Query:**
```sql
SELECT event_id, user_id, event_name, event_category
FROM `data-platform.analytics.events`
WHERE event_time >= '2024-11-01 00:00:00'
AND event_time < '2024-11-02 00:00:00'
AND log_level = 'sa-east'
```
**Issues Found & Fixes Applied:**
1. **SELECT * removed** β The `events` table has 1... | 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 with a cost impact estimate.
```sql
SELECT *
FROM `analytics-prod.analytics.orders`
WHERE DATE(created_at) = '2024-12-31'
AND status = 'processing'
``` [/INST] **Opti... | 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 `analytics-prod.analytics.orders`
WHERE DATE(created_at) = '2024-12-31'
AND status = 'processing'
``` | **Optimized Query:**
```sql
SELECT order_id, customer_id, product_id, amount, status
FROM `analytics-prod.analytics.orders`
WHERE created_at >= '2024-12-31 00:00:00'
AND created_at < '2025-01-01 00:00:00'
AND status = 'processing'
```
**Issues Found & Fixes Applied:**
1. **SELECT * removed** β The `orders` table ... | sql_optimization | select_star_no_partition_filter | 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 DISTINCT
event_id,
user_id,
event_name
FROM `my-project.dwh.events`
WHERE DATE(event_time) = '2024-01-15'
``` [/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
event_id,
user_id,
event_name
FROM `my-project.dwh.events`
WHERE DATE(event_time) = '2024-01-15'
``` | **Optimized Query:**
```sql
SELECT
event_id,
user_id,
event_name
FROM `my-project.dwh.events`
WHERE event_time >= '2024-01-15 00:00:00' AND event_time < '2024-01-16 00:00:00'
```
**Issues Found & Fixes Applied:**
1. **DISTINCT removed** β `DISTINCT` forces BigQuery to deduplicate the entire result set, which re... | sql_optimization | unnecessary_distinct | 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" "assets_es" {
domain_name = "assets-search"
elasticsearch_version = "7.10"
cluster_... | 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" "assets_es" {
domain_name = "assets-search"
elasticsearch_version = "7.10"
cluster_config {
instance_type = "r5.large.search"
instance_count = 1
}
ebs_options {
ebs_enabled = true
volume_size = 50
volume_type = "gp2"
}
access_poli... | **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] Review this Kubernetes/Terraform configuration for security misconfigurations. Identify all issues by severity, explain each risk, and provide the complete fixed configuration.
```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: backend-deployment
namespace: default
spec:
replicas: 3
selecto... | Review this Kubernetes/Terraform configuration for security misconfigurations. Identify all issues by severity, explain each risk, and provide the complete fixed configuration. | ```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: backend-deployment
namespace: default
spec:
replicas: 3
selector:
matchLabels:
app: backend
template:
metadata:
labels:
app: backend
spec:
containers:
- name: backend
image: rabbitmq:3.12
p... | **Security Audit Result:**
CRITICAL [{"id": "CIS-K8S-5.2.1", "title": "Do not admit privileged containers"}]
CRITICAL [{"id": "CIS-K8S-5.2.6", "title": "Do not allow containers to run as root"}]
HIGH [{"id": "CIS-K8S-5.2.5", "title": "Do not allow privilege escalation"}]
HIGH [{"id": "CIS-K8S-5.2.4", "title": "Do not ... | iac_security | null | null |
<s>[INST] Perform a query cost review on this BigQuery SQL. Find all inefficiencies and provide the optimized query with cost impact estimates.
```sql
SELECT
txn_id,
COUNT(DISTINCT user_id) AS unique_count
FROM `bi-warehouse.processed.transactions`
WHERE transaction_date = '2023-12-25'
GROUP BY txn_id
ORDER BY uni... | Perform a query cost review on this BigQuery SQL. Find all inefficiencies and provide the optimized query with cost impact estimates. | ```sql
SELECT
txn_id,
COUNT(DISTINCT user_id) AS unique_count
FROM `bi-warehouse.processed.transactions`
WHERE transaction_date = '2023-12-25'
GROUP BY txn_id
ORDER BY unique_count DESC
``` | **Optimized Query:**
```sql
SELECT
txn_id,
APPROX_COUNT_DISTINCT(user_id) AS unique_count
FROM `bi-warehouse.processed.transactions`
WHERE transaction_date = '2023-12-25'
GROUP BY txn_id
ORDER BY unique_count DESC
LIMIT 50
```
**Issues Found & Fixes Applied:**
1. **COUNT(DISTINCT) replaced with APPROX_COUNT_DISTI... | sql_optimization | approx_count_distinct | 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
t.event_id,
t.user_id,
(SELECT name FROM `data-ops.processed.users` u WHERE u.id = t.user_id) AS user_name,
t.lat
FRO... | 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 `data-ops.processed.users` u WHERE u.id = t.user_id) AS user_name,
t.lat
FROM `bi-warehouse.mart.events` t
WHERE DATE(event_time) = '2024-06-30'
``` | **Optimized Query:**
```sql
SELECT
t.event_id,
t.user_id,
u.name AS user_name,
t.lat
FROM `bi-warehouse.mart.events` t
LEFT JOIN `data-ops.processed.users` u ON u.id = t.user_id
WHERE t.event_time >= '2024-06-30 00:00:00' AND t.event_time < '2024-07-01 00:00:00'
```
**Issues Found & Fixes Applied:**
1. **Corr... | sql_optimization | correlated_subquery | events |
<s>[INST] Help optimize this BigQuery SQL query. It's scanning too much data. What changes would reduce the bytes processed?
```sql
SELECT *
FROM `data-ops.processed.events`
WHERE DATE(event_time) = '2024-02-14'
AND status LIKE '%timeout%'
``` [/INST] **Optimized Query:**
```sql
SELECT event_id, user_id, event_name,... | Help optimize this BigQuery SQL query. It's scanning too much data. What changes would reduce the bytes processed? | ```sql
SELECT *
FROM `data-ops.processed.events`
WHERE DATE(event_time) = '2024-02-14'
AND status LIKE '%timeout%'
``` | **Optimized Query:**
```sql
SELECT event_id, user_id, event_name, event_category, session_id
FROM `data-ops.processed.events`
WHERE event_time >= '2024-02-14 00:00:00'
AND event_time < '2024-02-15 00:00:00'
AND REGEXP_CONTAINS(status, r'(?i)timeout')
```
**Issues Found & Fixes Applied:**
1. **Leading wildcard LIK... | sql_optimization | leading_wildcard_like | events |
<s>[INST] Review this Kubernetes/Terraform configuration for security misconfigurations. Identify all issues by severity, explain each risk, and provide the complete fixed configuration.
```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: staging-deployment
namespace: default
spec:
replicas: 2
selecto... | Review this Kubernetes/Terraform configuration for security misconfigurations. Identify all issues by severity, explain each risk, and provide the complete fixed configuration. | ```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: staging-deployment
namespace: default
spec:
replicas: 2
selector:
matchLabels:
app: staging
template:
metadata:
labels:
app: staging
spec:
containers:
- name: staging
image: node:18
ports:
... | **Security Audit Result:**
CRITICAL [{"id": "CIS-K8S-5.2.1", "title": "Do not admit privileged containers"}]
CRITICAL [{"id": "CIS-K8S-5.2.6", "title": "Do not allow containers to run as root"}]
HIGH [{"id": "CIS-K8S-5.2.5", "title": "Do not allow privilege escalation"}]
HIGH [{"id": "CIS-K8S-5.2.4", "title": "Do not ... | iac_security | null | null |
<s>[INST] This query runs on BigQuery and costs too much. Identify the performance anti-patterns and rewrite it efficiently.
```sql
SELECT *
FROM `data-ops.reporting.transactions`
WHERE transaction_date = '2024-03-01'
AND event_name LIKE '%warning%'
``` [/INST] **Optimized Query:**
```sql
SELECT txn_id, user_id, amo... | This query runs on BigQuery and costs too much. Identify the performance anti-patterns and rewrite it efficiently. | ```sql
SELECT *
FROM `data-ops.reporting.transactions`
WHERE transaction_date = '2024-03-01'
AND event_name LIKE '%warning%'
``` | **Optimized Query:**
```sql
SELECT txn_id, user_id, amount, currency, status
FROM `data-ops.reporting.transactions`
WHERE transaction_date = '2024-03-01'
AND REGEXP_CONTAINS(event_name, r'(?i)warning')
```
**Issues Found & Fixes Applied:**
1. **Leading wildcard LIKE** β `LIKE '%warning%'` with a leading `%` prevent... | sql_optimization | leading_wildcard_like | transactions |
<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 `prod-dwh.analytics.events`
WHERE DATE(event_time) = '2023-12-25'
AND event_id NOT IN (
SELECT event_id
FROM `cloud-analytics.analytics.... | Optimize this BigQuery SQL query for cost and performance. Identify all anti-patterns, explain each issue, and provide the optimized version. | ```sql
SELECT *
FROM `prod-dwh.analytics.events`
WHERE DATE(event_time) = '2023-12-25'
AND event_id NOT IN (
SELECT event_id
FROM `cloud-analytics.analytics.orders`
WHERE status = 'cancelled'
)
``` | **Optimized Query:**
```sql
SELECT a.event_id, a.user_id, a.event_name, a.event_category, a.session_id
FROM `prod-dwh.analytics.events` a
LEFT JOIN `cloud-analytics.analytics.orders` b
ON a.event_id = b.event_id
AND b.status = 'cancelled'
WHERE a.event_time >= '2023-12-25 00:00:00'
AND a.event_time < '2023-12-26 ... | sql_optimization | not_in_with_nulls | 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_security_group" "primary_sg" {
name = "primary-security-group"
description = "Security group for primary"
vpc... | 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" "primary_sg" {
name = "primary-security-group"
description = "Security group for primary"
vpc_id = aws_vpc.default.id
ingress {
from_port = 6379
to_port = 6379
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port ... | **Security Audit Result:**
CRITICAL [{"id": "CIS-AWS-5.2", "title": "Ensure no security groups allow unrestricted Redis 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 DISTINCT
event_id,
user_id,
event_name
FROM `cloud-analytics.analytics.events`
WHERE DATE(event_time) = '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
event_id,
user_id,
event_name
FROM `cloud-analytics.analytics.events`
WHERE DATE(event_time) = '2024-01-15'
``` | **Optimized Query:**
```sql
SELECT
event_id,
user_id,
event_name
FROM `cloud-analytics.analytics.events`
WHERE event_time >= '2024-01-15 00:00:00' AND event_time < '2024-01-16 00:00:00'
```
**Issues Found & Fixes Applied:**
1. **DISTINCT removed** β `DISTINCT` forces BigQuery to deduplicate the entire result se... | sql_optimization | unnecessary_distinct | 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
t.session_id,
t.user_id,
(SELECT name FROM `analytics-prod.dwh.users` u WHERE u.id = t.user_id) AS user_name,
t.time_... | 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.session_id,
t.user_id,
(SELECT name FROM `analytics-prod.dwh.users` u WHERE u.id = t.user_id) AS user_name,
t.time_on_page
FROM `data-ops.raw_events.page_views` t
WHERE DATE(event_timestamp) = '2024-04-22'
``` | **Optimized Query:**
```sql
SELECT
t.session_id,
t.user_id,
u.name AS user_name,
t.time_on_page
FROM `data-ops.raw_events.page_views` t
LEFT JOIN `analytics-prod.dwh.users` u ON u.id = t.user_id
WHERE t.event_timestamp >= '2024-04-22 00:00:00' AND t.event_timestamp < '2024-04-23 00:00:00'
```
**Issues Found & ... | sql_optimization | correlated_subquery | 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.processed.orders`
WHERE DATE(created_at) = '2024-08-10'
AND status = 'pending'
``` [/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 `bi-warehouse.processed.orders`
WHERE DATE(created_at) = '2024-08-10'
AND status = 'pending'
``` | **Optimized Query:**
```sql
SELECT order_id, customer_id, product_id, amount, status
FROM `bi-warehouse.processed.orders`
WHERE created_at >= '2024-08-10 00:00:00'
AND created_at < '2024-08-11 00:00:00'
AND status = 'pending'
```
**Issues Found & Fixes Applied:**
1. **SELECT * removed** β The `orders` table has 1... | sql_optimization | select_star_no_partition_filter | orders |
<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" "pipeline_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" "pipeline_fn" {
filename = "lambda.zip"
function_name = "pipeline-query-service"
role = aws_iam_role.pipeline_lambda_role.arn
handler = "index.handler"
runtime = "python3.11"
memory_size = 25... | ## 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_ebs_volume" "assets_vol" {
availability_zone = "us-east-1a"
size = 500
type = "io2"
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" "assets_vol" {
availability_zone = "us-east-1a"
size = 500
type = "io2"
tags = {
Name = "assets-volume"
Environment = "development"
Team = "security"
}
}
resource "aws_volume_attachment" "assets_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 500GB 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 with a cost impact estimate.
```sql
SELECT DISTINCT
event_id,
user_id,
event_name
FROM `cloud-analytics.curated.events`
WHERE DATE(event_time) = '2024-02-14'
``` ... | 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
event_id,
user_id,
event_name
FROM `cloud-analytics.curated.events`
WHERE DATE(event_time) = '2024-02-14'
``` | **Optimized Query:**
```sql
SELECT
event_id,
user_id,
event_name
FROM `cloud-analytics.curated.events`
WHERE event_time >= '2024-02-14 00:00:00' AND event_time < '2024-02-15 00:00:00'
```
**Issues Found & Fixes Applied:**
1. **DISTINCT removed** β `DISTINCT` forces BigQuery to deduplicate the entire result set,... | sql_optimization | unnecessary_distinct | 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
t.txn_id,
t.user_id,
(SELECT name FROM `data-ops.staging.products` u WHERE u.id = t.user_id) AS user_name,
t.amount
F... | 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.txn_id,
t.user_id,
(SELECT name FROM `data-ops.staging.products` u WHERE u.id = t.user_id) AS user_name,
t.amount
FROM `reporting-hub.analytics.transactions` t
WHERE transaction_date = '2024-03-01'
``` | **Optimized Query:**
```sql
SELECT
t.txn_id,
t.user_id,
u.name AS user_name,
t.amount
FROM `reporting-hub.analytics.transactions` t
LEFT JOIN `data-ops.staging.products` u ON u.id = t.user_id
WHERE t.transaction_date = '2024-03-01'
```
**Issues Found & Fixes Applied:**
1. **Correlated subquery in SELECT remov... | sql_optimization | correlated_subquery | transactions |
<s>[INST] Review this Terraform configuration for security misconfigurations.
```hcl
resource "aws_security_group" "backend_sg" {
name = "backend-sg"
description = "Restricted security group for backend application"
vpc_id = aws_vpc.main.id
ingress {
description = "HTTPS from internal network"... | Review this Terraform configuration for security misconfigurations. | ```hcl
resource "aws_security_group" "backend_sg" {
name = "backend-sg"
description = "Restricted security group for backend application"
vpc_id = aws_vpc.main.id
ingress {
description = "HTTPS from internal network"
from_port = 443
to_port = 443
protocol = "tcp"
cidr_b... | **Security Audit Result:**
β
**No security issues found.** This security group configuration follows AWS security best practices:
1. **Restricted Ingress** β β Inbound access limited to HTTPS (443) from internal VPC CIDR (`10.0.0.0/16`) only. No public internet access.
2. **Restricted Egress** β β Outbound traffic li... | 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 *
FROM `data-platform.curated.transactions`
WHERE transaction_date = '2023-12-25'
ORDER BY amount DESC
``` [/INST] **Optimize... | 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-platform.curated.transactions`
WHERE transaction_date = '2023-12-25'
ORDER BY amount DESC
``` | **Optimized Query:**
```sql
SELECT txn_id, user_id, amount, currency, status
FROM `data-platform.curated.transactions`
WHERE transaction_date = '2023-12-25'
ORDER BY amount DESC
LIMIT 25
```
**Issues Found & Fixes Applied:**
1. **SELECT * removed** β Replaced with specific columns needed for this analysis. Reduces by... | sql_optimization | order_without_limit | 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 = "mariadb"
engine_version = "10.11"... | 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 = "mariadb"
engine_version = "10.11"
instance_class = "db.m5.large"
allocated_storage = 20
db_name = "app_db"
username = "admin"
password = "MyPassword123!"
availabili... | **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] 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 `prod-dwh.staging.transactions`
WHERE transaction_date = '2024-12-31'
``` [/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 `prod-dwh.staging.transactions`
WHERE transaction_date = '2024-12-31'
``` | **Optimized Query:**
```sql
SELECT
txn_id,
user_id,
amount
FROM `prod-dwh.staging.transactions`
WHERE transaction_date = '2024-12-31'
```
**Issues Found & Fixes Applied:**
1. **DISTINCT removed** β `DISTINCT` forces BigQuery to deduplicate the entire result set, which requires a full sort or hash operation. Sin... | sql_optimization | unnecessary_distinct | transactions |
<s>[INST] Review this Kubernetes/Terraform configuration for security misconfigurations. Identify all issues by severity, explain each risk, and provide the complete fixed configuration.
```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: app-deployment
namespace: default
spec:
replicas: 3
selector:
... | Review this Kubernetes/Terraform configuration for security misconfigurations. Identify all issues by severity, explain each risk, and provide the complete fixed configuration. | ```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: app-deployment
namespace: default
spec:
replicas: 3
selector:
matchLabels:
app: app
template:
metadata:
labels:
app: app
spec:
hostNetwork: true
hostPID: true
hostIPC: true
containers:
- ... | **Security Audit Result:**
CRITICAL [{"id": "CIS-K8S-5.2.2", "title": "Do not admit containers with hostNetwork"}]
CRITICAL [{"id": "CIS-K8S-5.2.3", "title": "Do not admit containers with hostPID or hostIPC"}]
CRITICAL [{"id": "CIS-K8S-5.2.7", "title": "Do not admit containers that mount host filesystem root"}]
HIGH [... | 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 order_id, customer_id, product_id, amount
FROM `cloud-analytics.mart.orders`
WHERE DATE(created_at) = '2024-11-01'
UNION
SE... | 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 `cloud-analytics.mart.orders`
WHERE DATE(created_at) = '2024-11-01'
UNION
SELECT order_id, customer_id, product_id, amount
FROM `data-ops.processed.orders`
WHERE DATE(created_at) = '2024-02-14'
``` | **Optimized Query:**
```sql
SELECT order_id, customer_id, product_id, amount
FROM `cloud-analytics.mart.orders`
WHERE created_at >= '2024-11-01 00:00:00' AND created_at < '2024-11-02 00:00:00'
UNION ALL
SELECT order_id, customer_id, product_id, amount
FROM `data-ops.processed.orders`
WHERE created_at >= '2024-02-14 0... | sql_optimization | union_vs_union_all | orders |
<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: main-api
namespace: default
spec:
replicas: 2
selector:
matchLabels:
app: main-api
template:
metadata:
labels:
app: main-api
spec:
containers:
- name: main-api
image: pyth... | ## 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] This query runs on BigQuery and costs too much. Identify the performance anti-patterns and rewrite it efficiently.
```sql
SELECT *
FROM `cloud-analytics.reporting.events`
WHERE user_id IN (
SELECT id
FROM `my-project.dwh.users`
WHERE region IN (
SELECT DISTINCT region
FROM `cloud-analytics.cura... | This query runs on BigQuery and costs too much. Identify the performance anti-patterns and rewrite it efficiently. | ```sql
SELECT *
FROM `cloud-analytics.reporting.events`
WHERE user_id IN (
SELECT id
FROM `my-project.dwh.users`
WHERE region IN (
SELECT DISTINCT region
FROM `cloud-analytics.curated.orders`
WHERE amount > 1000
)
)
``` | **Optimized Query:**
```sql
WITH high_value_regions AS (
SELECT DISTINCT region
FROM `cloud-analytics.curated.orders`
WHERE amount > 1000
),
target_users AS (
SELECT u.id
FROM `my-project.dwh.users` u
INNER JOIN high_value_regions r ON u.region = r.region
)
SELECT a.event_id, a.user_id, a.event_name, a.even... | sql_optimization | nested_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 `prod-dwh.dwh.logs`
WHERE DATE(log_timestamp) = '20... | 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 `prod-dwh.dwh.logs`
WHERE DATE(log_timestamp) = '2024-12-31'
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 `prod-dwh.dwh.logs`
WHERE log_timestamp >= '2024-12-31 00:00:00' AND log_timestamp < '2025-01-01 00:00:00'
GROUP BY log_level
ORDER BY total_count DESC
LIMIT 50
```
**Issues Found & Fixes Applied:**
1. **... | sql_optimization | count_star_no_filter | 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
t.order_id,
t.customer_id,
(SELECT name FROM `reporting-hub.raw_events.products` u WHERE u.id = t.customer_id) AS user_... | 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.raw_events.products` u WHERE u.id = t.customer_id) AS user_name,
t.amount
FROM `data-ops.analytics.orders` t
WHERE DATE(created_at) = '2024-04-22'
``` | **Optimized Query:**
```sql
SELECT
t.order_id,
t.customer_id,
u.name AS user_name,
t.amount
FROM `data-ops.analytics.orders` t
LEFT JOIN `reporting-hub.raw_events.products` u ON u.id = t.customer_id
WHERE t.created_at >= '2024-04-22 00:00:00' AND t.created_at < '2024-04-23 00:00:00'
```
**Issues Found & Fixes ... | sql_optimization | correlated_subquery | orders |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.