0Pricing
Advanced PostgreSQL: Indexing, Partitioning, Replication · レッスン

サブパーティショニングの技法

サブパーティショニングを実装してパーティショニング方式を組み合わせ、よりきめ細かくデータを整理します。

「サブパーティショニングの技法」はCoddyKit上の無料Advanced PostgreSQL: Indexing, Partitioning, Replicationレッスンです。 これはレッスン2/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはAdvanced PostgreSQL: Indexing, Partitioning, Replication学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Advanced PostgreSQL: Indexing, Partitioning, Replicationコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

Deeper Data Organization

Welcome! In this lesson, we'll explore sub-partitioning, an advanced technique to combine different partitioning methods in PostgreSQL.

It allows you to organize your data with even finer granularity, creating a powerful hierarchical structure for very large tables.

Why Use Sub-Partitioning?

Sub-partitioning offers several key advantages for managing and querying massive datasets:

  • Finer Granularity: Break down large partitions into smaller, more manageable units.
  • Targeted Management: Easier to perform operations (e.g., attach, detach, archive) on specific data subsets.
  • Improved Query Performance: The database can prune even more irrelevant data blocks, significantly speeding up queries on specific sub-sections.

How Nested Partitions Work

With sub-partitioning, you define a primary partitioning strategy for your main table. Then, for each individual partition of that main table, you define a secondary partitioning strategy.

Think of it as partitioning a table by year, and then partitioning each year's data further by region. It's a 'partition of a partition' concept.

Strategy: Range by Date, List by Region

A common and effective sub-partitioning pattern is to first partition a table by a date range (e.g., year or quarter), and then sub-partition each date range by a list of discrete values (e.g., region, department, status).

This is ideal for time-series data that also has important categorical attributes, allowing you to quickly filter by both.

Code: Main Table (Range)

Let's create an orders table. This will be our top-level parent, partitioned by order_date using RANGE partitioning.

CREATE TABLE orders (
    order_id INT,
    order_date DATE,
    region TEXT,
    amount DECIMAL
) PARTITION BY RANGE (order_date);

Code: Level 1 Partition (Range & List Parent)

Now, we create a partition for the year 2023. Crucially, we add PARTITION BY LIST (region) to this partition definition.

This makes orders_2023 itself a parent table, ready for its own sub-partitions.

CREATE TABLE orders_2023
PARTITION OF orders
FOR VALUES FROM ('2023-01-01') TO ('2024-01-01')
PARTITION BY LIST (region);

Code: Level 2 Sub-Partitions & Insert

Finally, we create the actual sub-partitions for specific regions within the orders_2023 partition. Data for 'North' goes into orders_2023_north, etc. We'll also insert some data to see it in action.

CREATE TABLE orders_2023_north
PARTITION OF orders_2023
FOR VALUES IN ('North');

CREATE TABLE orders_2023_south
PARTITION OF orders_2023
FOR VALUES IN ('South');

INSERT INTO orders VALUES
(1, '2023-03-15', 'North', 150.00),
(2, '2023-07-22', 'South', 200.50),
(3, '2023-11-01', 'North', 75.25);

SELECT tableoid::regclass, * FROM orders ORDER BY order_id;

Strategy: List by Category, Range by Year

You can also reverse the strategy: partition first by a list of categories (e.g., 'Electronics', 'Books'), and then sub-partition each category by a date range (e.g., release year).

This is useful when your primary access pattern is by category, and then you need to filter within categories by time.

Quick Check: Sub-Partitioning

Sub-partitioning offers powerful ways to organize data. Which of the following statements correctly describe its characteristics or benefits?

Recap & Next Steps

You've now learned about PostgreSQL sub-partitioning!

  • We saw how to combine RANGE and LIST partitioning to create deeply organized tables.
  • This technique provides finer data granularity and can significantly boost query performance by enabling more precise partition pruning.
  • Understanding sub-partitioning is crucial for managing extremely large and complex datasets effectively.

Next, we'll dive into managing partitioned tables, including adding, dropping, and altering partitions efficiently.

よくある質問

「サブパーティショニングの技法」レッスンは無料ですか?

はい。「サブパーティショニングの技法」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Advanced PostgreSQL: Indexing, Partitioning, Replicationコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Advanced PostgreSQL: Indexing, Partitioning, Replicationコースには全4レッスンが含まれています。

「サブパーティショニングの技法」で何を学びますか?

サブパーティショニングを実装してパーティショニング方式を組み合わせ、よりきめ細かくデータを整理します。 ブラウザで直接実行するハンズオンコードでAdvanced PostgreSQL: Indexing, Partitioning, Replicationを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Advanced PostgreSQL: Indexing, Partitioning, Replicationを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのAdvanced PostgreSQL: Indexing, Partitioning, Replicationは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン2/4です。

「サブパーティショニングの技法」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このAdvanced PostgreSQL: Indexing, Partitioning, Replicationレッスンでコードを書いて実行できますか?

はい。すべてのAdvanced PostgreSQL: Indexing, Partitioning, Replicationレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. 分散のためのハッシュパーティショニング
  2. サブパーティショニングの技法
  3. パーティションテーブルの管理
  4. 時間による範囲パーティショニング
← Advanced PostgreSQL: Indexing, Partitioning, Replicationに戻る