

# PERF03-BP04 实施可提高数据存储查询性能的策略
<a name="perf_data_implement_strategies_to_improve_query_performance"></a>

 实施可优化数据和改进数据查询的策略，从而提高工作负载的可扩展性和性能效率。

 **常见反模式：**
+  没有对数据存储中的数据进行分区。
+  在数据存储中只以一种文件格式存储数据。
+  没有在数据存储中使用索引。

 **建立此最佳实践的好处：**优化数据和查询性能可以提高效率、降低成本并改善用户体验。

 **在未建立这种最佳实践的情况下暴露的风险等级：**中 

## 实施指导
<a name="implementation-guidance"></a>

数据优化和查询调整是提高数据存储性能效率的关键环节，因为这会影响整个云工作负载的性能和响应能力。如果查询未经优化，则会耗用更多的资源并产生更多的瓶颈，从而降低数据存储的整体效率。

数据优化会涵盖多种技术，旨在确保高效的数据存储和访问，同时还有助于改进在数据存储中的查询性能。关键策略包括数据分区、数据压缩和数据去规范化，这有助于针对存储和访问优化数据。

### 实施步骤
<a name="implementation-steps"></a>
+  了解并分析在数据存储中执行的关键数据查询。
+  识别数据存储中运行速度较慢的查询，并使用查询计划了解当前状态。
  +  [在 Amazon Redshift 中分析查询计划](https://docs.aws.amazon.com/redshift/latest/dg/c-analyzing-the-query-plan.html) 
  +  [在 Athena 中使用 EXPLAIN 和 EXPLAIN ANALYZE](https://docs.aws.amazon.com/athena/latest/ug/athena-explain-statement.html) 
+  实施可提高查询性能的策略。一些关键策略包括：
  +  使用[列式文件格式](https://docs.aws.amazon.com/athena/latest/ug/columnar-storage.html)（如 Parquet 或 ORC）。
  + 压缩数据存储中的数据，减少存储空间和 I/O 操作。
  +  进行数据分区，将数据分割成更小的部分，减少数据扫描时间。
    + [在 Athena 中对数据进行分区](https://docs.aws.amazon.com/athena/latest/ug/partitions.html)
    + [分区和数据分发](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.Partitions.html)
  +  对查询中的常用列编制数据索引。
  +  使用实体化视图频繁地进行查询。
    + [了解实体化视图](https://docs.aws.amazon.com/prescriptive-guidance/latest/materialized-views-redshift/understanding-materialized-views.html)
    + [在 Amazon Redshift 中创建实体化视图](https://docs.aws.amazon.com/redshift/latest/dg/materialized-view-overview.html)
  +  为查询选择合适的联接操作。联接两个表时，请在联接的左侧指定较大的表，在联接的右侧指定较小的表。
  +  实施分布式缓存解决方案，从而缩短延迟并减少数据库 I/O 操作次数。
  +  执行定期维护，例如 [vaccum](https://docs.aws.amazon.com/prescriptive-guidance/latest/postgresql-maintenance-rds-aurora/autovacuum.html) 操作、重新索引和[进行统计](https://docs.aws.amazon.com/redshift/latest/dg/t_Analyzing_tables.html)。
+  在非生产环境中试验和测试策略。

## 资源
<a name="resources"></a>

 **相关文档：**
+  [Amazon Aurora 最佳实践](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Aurora.BestPractices.html?ref=wellarchitected) 
+  [Amazon Redshift 性能](https://docs.aws.amazon.com/redshift/latest/dg/c_challenges_achieving_high_performance_queries.html?ref=wellarchitected) 
+  [Amazon Athena 十大性能技巧](https://aws.amazon.com/blogs/big-data/top-10-performance-tuning-tips-for-amazon-athena/?ref=wellarchitected) 
+  [AWS 数据库缓存](https://aws.amazon.com/caching/database-caching/?ref=wellarchitected) 
+  [实施 Amazon ElastiCache 的最佳实践](https://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/BestPractices.html) 
+  [在 Athena 中对数据进行分区](https://docs.aws.amazon.com/athena/latest/ug/partitions.html) 

 **相关视频：**
+ [AWS re:Invent 2023 - AWS storage cost-optimization best practices](https://www.youtube.com/watch?v=8LVKNHcA6RY)
+ [AWS re:Invent 2022 - Performance monitoring with Amazon RDS and Aurora, featuring Autodesk](https://www.youtube.com/watch?v=wokRbwK4YLo)
+  [Optimize Amazon Athena Queries with New Query Analysis Tools ](https://www.youtube.com/watch?v=7JUyTqglmNU&ab_channel=AmazonWebServices) 

 **相关示例：**
+ [AWS Purpose Built Databases 讲习会](https://catalog.us-east-1.prod.workshops.aws/workshops/93f64257-52be-4c12-a95b-c0a1ff3b7e2b/en-US)