Table Storage Format Definitions

更新时间:
复制 MD 格式

AnalyticDB for PostgreSQL supports three storage models: row-oriented, column-oriented, and hybrid row-column. Choose the right model when you create a table.

Choose a storage model

The model you choose affects write throughput, query performance, and compression ratio. Use the following criteria to decide.

Criteria

Row-oriented

Column-oriented

Hybrid row-column

Write pattern

Frequent updates, real-time INSERT

Batch loading (COPY, INSERT INTO SELECT)

Mixed: both real-time writes and batch loads

Query pattern

Point queries, full-row access

Aggregations on a few columns, e.g., SELECT SUM(amount) ... WHERE region = 'us'

Both

Compression

Standard

3–5x higher than row-oriented

Automatic based on write method

Version requirement

All versions

All versions

V7.0 only

Data Transmission Service (DTS) compatibility

Required (destination tables must be row-oriented)

Not supported

Not supported

Note

Hybrid row-column storage is available only in AnalyticDB for PostgreSQL V7.0.

Specify the storage model

Use the WITH clause in CREATE TABLE to set the storage model and configure compression. The following parameters are supported.

Parameter

Description

Default

Valid values

orientation

Storage model. Hybrid row-column storage cannot be set here — use USING beam instead.

row

row, column

appendonly

Enables append-optimized storage. Required for column-oriented tables.

false

true, false

compresstype

Compression algorithm.

V4.3 and V6.0: none; V7.0: auto

See Data compression

compresslevel

Compression level. Higher values achieve better compression at lower speed.

1

19 (integer)

Row-oriented tables

By default, AnalyticDB for PostgreSQL creates row-oriented tables using the PostgreSQL heap storage model. Row-oriented tables are optimized for:

  • Real-time writes via INSERT

  • Frequent UPDATE and DELETE operations

  • Point queries with a B-tree index

Heap table (default)

CREATE TABLE foo (a int, b text) DISTRIBUTED BY (a);

Append-optimized row-oriented (AORO) table

CREATE TABLE bar (a int, b text)
WITH (appendonly=true, orientation=row)
DISTRIBUTED BY (a);
Note

When using Data Transmission Service (DTS) to write data to AnalyticDB for PostgreSQL, the destination tables must be row-oriented. DTS supports near-real-time synchronization for INSERT, UPDATE, and DELETE operations.

Column-oriented tables

Column-oriented tables store data by column, reading only the columns referenced in a query. This makes them well-suited for data warehouse workloads — particularly queries that aggregate a small number of columns, such as:

SELECT SUM(revenue), AVG(cost) FROM orders WHERE region = 'us';

Column-oriented tables provide a compression ratio 3–5 times that of row-oriented tables. They are less efficient for frequent row-level inserts or updates — use batch loading methods like COPY for best performance.

Column-oriented tables must be append-optimized. Set appendonly=true when creating one.

CREATE TABLE bar (a int, b text)
WITH (appendonly=true, orientation=column)
DISTRIBUTED BY (a);

Hybrid row-column storage tables

Important

Hybrid row-column storage is supported only in AnalyticDB for PostgreSQL V7.0 instances.

The hybrid row-column storage model uses the Beam storage engine, which combines two internal storage layers:

  • Delta storage (row-oriented): handles real-time streaming writes via INSERT INTO ... VALUES. Delivers write performance comparable to row-oriented tables.

  • Base storage (PAX-based, column-oriented): handles batch writes via COPY or INSERT INTO ... SELECT. Delivers higher throughput for bulk data.

Beam automatically routes incoming data to the appropriate layer based on the write method.

Non-partitioned tables

Create a table with the beam storage engine

CREATE TABLE testtable (a int) USING beam;

Change an existing table to use the beam storage engine

ALTER TABLE testtable SET ACCESS METHOD beam;

Partitioned tables

The following examples use a base partitioned table created with heap storage:

CREATE TABLE am_partitioned(x INT, y INT)
PARTITION BY HASH (x) USING heap;

Specify the storage model when creating a partition

Create a partition with append-optimized column-oriented (AOCO) storage:

CREATE TABLE am_partitioned_1 PARTITION OF am_partitioned
FOR VALUES WITH (MODULUS 3, REMAINDER 0) USING ao_column;

Create a partition with hybrid row-column (beam) storage:

CREATE TABLE amm_partitioned_2 PARTITION OF amm_partitioned
FOR VALUES WITH (MODULUS 3, REMAINDER 1) USING beam;

Change the storage model of an existing partition

ALTER TABLE am_partitioned_1 SET ACCESS METHOD ao_row;

Data compression

Compression is available for column-oriented tables and append-optimized row-oriented (AORO) tables (appendonly=true). Two levels of compression are supported:

  • Table-level compression: applies a single algorithm to the entire table

  • Column-level compression: applies a unique compression algorithm to each column

Supported algorithms by version

Algorithm

V4.3

V6.0

V7.0

Notes

zstd

No

Yes

Yes

zlib

Yes

Yes

No

lz4

No

Yes

Yes

rle_type

Yes

Yes

No

Column-oriented tables only

none

Yes

Yes

Yes

No compression

auto

Yes

Yes

Yes

Default for V7.0; selects the algorithm based on data attributes

Note

If you specify the QuickLZ algorithm, it is automatically replaced with zlib. The rle_type algorithm applies only to column-oriented tables.

Examples

Create a column-oriented table with default compression settings:

CREATE TABLE am_testtable(x INT, y INT)
WITH (orientation=column);

Create a column-oriented table with zlib compression at level 5:

CREATE TABLE foo (a int, b text)
WITH (appendonly=true, orientation=column, compresstype=zlib, compresslevel=5);

Create a column-oriented table with zstd compression at level 9:

CREATE TABLE foo (a int, b text)
WITH (appendonly=true, orientation=column, compresstype=zstd, compresslevel=9);