云数据库 GaussDB-Enhanced Toast相关DDL操作

时间:2025-02-12 15:05:23

Enhanced Toast相关DDL操作

Enhanced Toast表的创建

建表时指定Toast表的存储类型为Enhanced Toast或者Toast:

gaussdb=#  CREATE TABLE test_toast (id int, content text) WITH(toast.toast_storage_type=toast);CREATE TABLEgaussdb=#  \d+ test_toast                       Table "public.test_toast" Column  |  Type   | Modifiers | Storage  | Stats target | Description---------+---------+-----------+----------+--------------+------------- id      | integer |           | plain    |              | content | text    |           | extended |              |Has OIDs: noOptions: orientation=row, compression=no, storage_type=USTORE, segment=off, toast.storage_type=USTORE, toast.toast_storage_type=toastgaussdb=#  drop table test_toast;DROP TABLEgaussdb=#  CREATE TABLE test_toast (id int, content text) WITH(toast.toast_storage_type=enhanced_toast);CREATE TABLEgaussdb=#  \d+ test_toast                       Table "public.test_toast" Column  |  Type   | Modifiers | Storage  | Stats target | Description---------+---------+-----------+----------+--------------+------------- id      | integer |           | plain    |              | content | text    |           | extended |              |Has OIDs: noOptions: orientation=row, compression=no, storage_type=USTORE, segment=off, toast.storage_type=USTORE, toast.toast_storage_type=enhanced_toastgaussdb=#  DROP TABLE test_toast;DROP TABLE

建表时不指定线外存储表的类型,则创建线外存储表类型依赖于GUC参数enable_enhance_toast_table:

gaussdb=#  show enable_enhance_toast_table; enable_enhance_toast_table---------------------------- on(1 row)gaussdb=#  CREATE TABLE test_toast (id int, content text);CREATE TABLEgaussdb=#   \d+ test_toast                       Table "public.test_toast" Column  |  Type   | Modifiers | Storage  | Stats target | Description---------+---------+-----------+----------+--------------+------------- id      | integer |           | plain    |              | content | text    |           | extended |              |Has OIDs: noOptions: orientation=row, compression=no, storage_type=USTORE, segment=off, toast.storage_type=USTORE, toast.toast_storage_type=enhanced_toastgaussdb=#   DROP TABLE test_toast;DROP TABLEgaussdb=#  SET enable_enhance_toast_table = off;SETgaussdb=#  show enable_enhance_toast_table; enable_enhance_toast_table---------------------------- off(1 row)gaussdb=#   CREATE TABLE test_toast (id int, content text);CREATE TABLEgaussdb=#  \d+ test_toast                       Table "public.test_toast" Column  |  Type   | Modifiers | Storage  | Stats target | Description---------+---------+-----------+----------+--------------+------------- id      | integer |           | plain    |              | content | text    |           | extended |              |Has OIDs: noOptions: orientation=row, compression=no, storage_type=USTORE, segment=off, toast.storage_type=USTORE, toast.toast_storage_type=toastgaussdb=#  DROP TABLE test_toast;DROP TABLE

线外存储表结构的升级

当GUC参数“enable_enhance_toast_table=on”时,线外存储表支持通过Vacuum Full操作将Toast升级为Enhanced Toast结构。

gaussdb=#   CREATE TABLE test_toast (id int, content text);CREATE TABLEgaussdb=#  \d+ test_toast                       Table "public.test_toast" Column  |  Type   | Modifiers | Storage  | Stats target | Description---------+---------+-----------+----------+--------------+------------- id      | integer |           | plain    |              | content | text    |           | extended |              |Has OIDs: noOptions: orientation=row, compression=no, storage_type=USTORE, segment=off, toast.storage_type=USTORE, toast.toast_storage_type=toastgaussdb=#  VACUUM FULL test_toast;VACUUMgaussdb=#  \d+ test_toast                       Table "public.test_toast" Column  |  Type   | Modifiers | Storage  | Stats target | Description---------+---------+-----------+----------+--------------+------------- id      | integer |           | plain    |              | content | text    |           | extended |              |Has OIDs: noOptions: orientation=row, compression=no, storage_type=USTORE, segment=off, toast.storage_type=USTORE, toast.toast_storage_type=enhanced_toastgaussdb=#  DROP TABLE test_toast;DROP TABLE

分区表merge操作

支持将分区表的分区间不同的线外存储表类型进行合并操作。

  • 对于相同类型的线外存储分区,合并与原有逻辑保持一致,进行物理合并。
  • 对于不同类型的线外存储分区,合并后的分区线外存储表为Enhanced Toast表,需要进行逻辑合并,性能劣于物理合并。
gaussdb=#  CREATE TABLE test_partition_table(a int, b text)PARTITION BY range(a)(partition p1 values less than (2000),partition p2 values less than (3000));gaussdb=# SELECT relfilenode FROM pg_partition WHERE relname='p1'; relfilenode-------------      17529(1 row)gaussdb=#  \d+ pg_toast.pg_toast_part_17529TOAST table "pg_toast.pg_toast_part_17529"   Column   |  Type   | Storage------------+---------+--------- chunk_id   | oid     | plain chunk_seq  | integer | plain chunk_data | bytea   | plainOptions: storage_type=ustore, toast_storage_type=toastgaussdb=# SELECT relfilenode from pg_partition WHERE relname='p2'; relfilenode-------------      17528(1 row)gaussdb=#  \d+ pg_toast.pg_toast_part_17528TOAST table "pg_toast.pg_toast_part_17528"   Column   |  Type   | Storage------------+---------+--------- chunk_seq  | integer | plain next_chunk | tid     | plain chunk_data | bytea   | plainOptions: storage_type=ustore, toast_storage_type=enhanced_toastgaussdb=#  ALTER TABLE test_partition_table MERGE PARTITIONS p1,p2 INTO partition p1_p2;ALTER TABLEgaussdb=#  SELECT reltoastrelid::regclass FROM pg_partition WHERE relname='p1_p2';        reltoastrelid------------------------------ pg_toast.pg_toast_part_17559(1 row)gaussdb=#  \d+ pg_toast.pg_toast_part_17559TOAST table "pg_toast.pg_toast_part_17559"   Column   |  Type   | Storage------------+---------+--------- chunk_seq  | integer | plain next_chunk | tid     | plain chunk_data | bytea   | plainOptions: storage_type=ustore, toast_storage_type=enhanced_toastgaussdb=# DROP TABLE test_partition_table;DROP TABLE
support.huaweicloud.com/fg-gaussdb-cent-v8/gaussdb-48-0195.html