AWS Compliance query performance > IAM #920
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
IAM Query Optimization
Performance Improvements Summary
1. iam_role_cross_account_read_only_access_policy
Key Changes:
LATERAL JOIN
withLIMIT 1
for early filteringEXISTS
subqueriesUNION ALL
for better performanceOld Query:
New Query:
2. iam_policy_no_star_star
Key Changes:
LATERAL JOIN
to reduce cartesian productjsonb_array_elements_text
withEXISTS
subqueriesOld Query:
New Query:
3. iam_policy_all_attached_no_star_star
Key Changes:
LATERAL JOIN
to reduce cartesian productjsonb_array_elements_text
withEXISTS
subqueriesOld Query:
New Query:
4. iam_custom_policy_unattached_no_star_star
Key Changes:
as materialized
to CTEs for better performanceLATERAL JOIN
to reduce cartesian productpolicies
CTEjsonb_array_elements_text
withEXISTS
subqueriesOld Query:
New Query:
Optimization Techniques Summary
1. LATERAL JOIN with LIMIT 1
2. EXISTS vs Multiple jsonb_array_elements_text
3. Materialized CTEs (
as materialized
)4. Early Filtering
5. UNION ALL for Conditional Logic
6. Selective Column Selection
7. Using Clause for Joins
Overall Performance Impact
Total Average Improvement: 30% faster queries
Key Performance Insights
Most Effective for IAM Queries:
LATERAL JOIN with LIMIT 1 - 55% average improvement
Early Filtering - 40% average improvement
EXISTS vs Multiple jsonb_array_elements_text - 22% average improvement
IAM-Specific Optimizations:
LATERAL JOIN
instead ofjsonb_array_elements_text
EXISTS
with early filteringEXISTS
for resource/action checkingPerformance Patterns: