Introductie tot Redshift
Jason Myers
Principal Engineer
CREATE TABLE IDAHO_SITE_ID
(
'pk_siteid' INTEGER PRIMARY KEY,
'fk_monitoringlocation' INTEGER,
'organization_id' VARCHAR(31),
'organizationformalname' VARCHAR(68),
'organization' VARCHAR(16)
);

DISTKEY of PRIMARY KEY| Name | Description | Usage |
|---|---|---|
| ALL | Hele tabel op elke node | Kleine lookup-facttabellen, vaak nodig bij joins |
| KEY | Verdeeld op data in de DISTKEY-kolom | Als we aggregeren of joinen op DISTKEY |
| EVEN | Om-en-om verdeling per rij over nodes | Grote tabellen zonder geschikte keys |
| AUTO | Gebruikt ALL voor kleine tabellen. Wordt KEY als de tabel groeit (met geschikte DISTKEYS), anders EVEN | standaard |
CREATE TABLE IDAHO_SITE_ID
(
'pk_siteid' INTEGER PRIMARY KEY,
'fk_monitoringlocation' INTEGER,
'organization_id' VARCHAR(31),
'organizationformalname' VARCHAR(68),
'organization' VARCHAR(16)
)
-- Stelt de distributiesleutel in
-- op organization_id
DISTKEY(organization_id);
CREATE TABLE IDAHO_SITE_ID
(
'pk_siteid' INTEGER PRIMARY KEY,
'fk_monitoringlocation' INTEGER,
-- Stelt organization_id in als
-- distributiesleutel
'organization_id' VARCHAR(31) DISTKEY,
'organizationformalname' VARCHAR(68),
'organization' VARCHAR(16)
);
CREATE TABLE IDAHO_SITE_ID
(
'pk_siteid' INTEGER PRIMARY KEY,
'fk_monitoringlocation' INTEGER,
'organization_id' VARCHAR(31),
'organizationformalname' VARCHAR(68),
'organization' VARCHAR(16)
)
DISTKEY(organization_id)
-- Stelt de distributiestijl in op key
DISTSTYLE KEY;
CREATE TABLE IDAHO_SITE_ID
(
'pk_siteid' INTEGER PRIMARY KEY,
'fk_monitoringlocation' INTEGER,
'organization_id' VARCHAR(31),
'organizationformalname' VARCHAR(68),
'organization' VARCHAR(16)
)
DISTKEY(organization_id)
DISTSTYLE KEY
-- Stelt de sorteersleutel in
-- op fk_monitoringlocation
SORTKEY(fk_monitoringlocation);
CREATE TABLE IDAHO_SITE_ID
(
'pk_siteid' INTEGER PRIMARY KEY,
'fk_monitoringlocation' INTEGER,
'organization_id' VARCHAR(31),
'organizationformalname' VARCHAR(68),
'organization' VARCHAR(16)
)
-- Stelt fk_monitoringlocation, organization_id in als samengestelde sorteersleutels
COMPOUND SORTKEY(fk_monitoringlocation, organization_id);
-- Bekijk de dist- en sortkey-
-- status van een kolom
SELECT column_name,
distkey,
sortkey
FROM SVV_REDSHIFT_COLUMNS
-- Alleen in het schema spectrumdb
WHERE schema_name = 'spectrumdb'
-- Voor de tabel ecommerce_sales
AND table_name = 'ecommerce_sales';
Resultaten
column | distkey | sortkey
============|=========|========
year_qtr | t | 1
total_sales | f | 2
ecom_sales | f | 0
Distkey-kolom
SVV_TABLE_INFOtable | encoded | diststyle | sortkey1 | skew_sortkey1 | skew_rows
===============|=========|=================|==============|===============|===========
ecommerce_sales| N | KEY(year_qtr) | year_qtr | |
date | N | ALL | dateid | 1.00 |
SELECT table
diststyle
FROM SVV_TABLE_INFO
WHERE schema like 'spectrumdb';
table | diststyle
================|==============
ecommerce_sales | KEY(year_qtr)
Introductie tot Redshift