走进 Redshift 仓库

Redshift 入门

Jason Myers

Principal Architect

议程

  • Redshift 集群内部原理
    • 节点类型
    • Leader 专用函数
    • Redshift 集群存储
  • 谓词
  • Redshift Spectrum
    • 数据库组件
    • 外部表
Redshift 入门

Redshift 集群架构

Leader 节点

  • 提供连接
  • 构建并分发查询执行计划
  • 可执行整条查询
  • 具有专用函数

计算节点

  • 提供数据存储
  • 在本地数据上执行来自 Leader 的代码

Redshift 集群

Redshift 入门

Leader 专用函数

  • 仅在 Leader 上运行
-- Selecting the substr, starting at 
-- position 11 of 'chocolate chip'
SELECT SUBSTR('chocolate chip', 11);
chip
  • SUBSTR 用于表列时会报错
-- Selecting the substr from position 1
-- of the column named field on table
SELECT SUBSTR(field, 1) FROM table;
ERROR: SUBSTR() function is not 
supported (Hint: use SUBSTRING 
instead)
Redshift 入门

跨节点查看数据

SELECT host, 
       -- Calculate the percentage of used space
       -- using the used minus tossed or ready to be reclaimed
       -- divided by the capacity
       (used - tossed) / capacity * 100 as percent_used 
  FROM STV_PARTITIONS;
 host |  percent_used
======+==============
  0   |  24.9
  1   |  24.8
Redshift 入门

谓词

SELECT table_A.columnX,
       table_B.columnY,
  FROM table_A
       INNER JOIN table_B 
          -- predicate
       ON table_B.foreign_key = table_A.primary_key 
       -- predicate
 WHERE table_B.columnZ = 'value';
  • 通常为布尔表达式,出现在 WHERE、HAVING 或 ON 子句中
Redshift 入门

谓词下推

下推

Redshift 入门

典型内部数据库组件

数据库组件

元数据目录

  • 保存架构信息(列、键等)
  • 引用存储位置

查询引擎

  • 规划并执行查询
  • 提供连接

存储

  • 保存表数据
  • 支持多种文件与表格式
Redshift 入门

Redshift Spectrum 架构

AWS Glue 数据目录

  • 存储"外部"表的信息

AWS S3 存储桶

  • 存放表示表的数据文件
  • 支持 CSV、JSON、Text、Parquet 等多种类型

Redshift Spectrum 架构

Redshift 入门

Passons à la pratique !

Redshift 入门

Preparing Video For Download...