本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
將標準資料表轉換為無限資料表
您可以將標準資料表轉換為碎片或參考資料表。在轉換期間,資料會從標準資料表移至分散式資料表,然後刪除來源標準資料表。使用 INSERT INTO SELECT FROM
命令移動資料。
建立碎片資料表
您可以在標準資料表上執行 rds_aurora.limitless_alter_table_type_sharded
程序,以建立碎片資料表。此程序會採用標準資料表和資料欄清單,然後使用資料欄清單做為碎片索引鍵來分配指定的資料表。程序會同步執行,並在資料表上取得ACCESS EXCLUSIVE
鎖定。
程序成功完成後,會刪除來源標準資料表,並可使用具有相同名稱的碎片資料表。
程序rds_aurora.limitless_alter_table_type_sharded
使用以下語法:
postgres=>
CALL rds_aurora.limitless_alter_table_type_sharded('schema
.table
', ARRAY['shard_key1
', 'shard_key2
', ... 'shard_keyn
']);
程序需要下列參數:
-
schema
– 包含要碎片之資料表的資料庫結構描述。如果未指定結構描述,程序會使用search_path
。 -
table
– 要碎片的資料表。 -
shard_keyn
– 要用作碎片索引鍵的資料表資料欄陣列。碎片索引鍵值是字串常值,因此區分大小寫。如果碎片索引鍵包含單一引號 ('),請使用另一個單一引號來逸出它。例如,如果資料表欄名為
customer's id
,請使用customer''s id
做為碎片索引鍵。反斜線 (\) 和雙引號 (") 不需要逸出。
注意
建立碎片資料表
下列範例示範如何使用customer
碎片索引鍵 建立碎片資料表customer_id
。
-
建立標準資料表。
CREATE TABLE customer (customer_id INT PRIMARY KEY NOT NULL, zipcode INT, email VARCHAR);
-
將標準資料表轉換為碎片資料表。
postgres=>
CALL rds_aurora.limitless_alter_table_type_sharded('public.customer', ARRAY['customer_id']);postgres=>
\d List of relations Schema | Name | Type | Owner --------+--------------+-------------------+-------------------- public | customer | partitioned table | postgres_limitless public | customer_fs1 | foreign table | postgres_limitless public | customer_fs2 | foreign table | postgres_limitless public | customer_fs3 | foreign table | postgres_limitless public | customer_fs4 | foreign table | postgres_limitless public | customer_fs5 | foreign table | postgres_limitless (6 rows)
建立共置資料表
如果使用相同的碎片索引鍵分割兩個以上的資料表,您可以明確對齊 (串連) 那些資料表。當兩個或多個資料表共置時,具有相同碎片索引鍵值的資料表資料列會放置在相同的碎片上。Collocation 有助於將某些操作限制為單一碎片,進而獲得更好的效能。
您可以使用 rds_aurora.limitless_alter_table_type_sharded
程序搭配下列語法:
postgres=>
CALL rds_aurora.limitless_alter_table_type_sharded('schema
.collocated_table
', ARRAY['shard_key1
', 'shard_key2
', ... 'shard_keyn
'], 'schema
.sharded_table
');
程序需要下列參數:
-
schema
– 資料庫結構描述,其中包含要共置的資料表。如果未指定結構描述,程序會使用search_path
。 -
collocated_table
– 要共置的資料表。 -
shard_keyn
– 要用作碎片索引鍵的資料表資料欄陣列。您必須使用與原始碎片資料表相同的碎片金鑰,包括相同的欄名稱和欄類型。
-
sharded_table
– 您要與 串連的碎片資料表collocated_table
。
建立共置資料表
-
遵循中的程序建立第一個碎片資料表建立碎片資料表。
-
建立並行資料表的標準資料表。
CREATE TABLE mytable2 (customer_id INT PRIMARY KEY NOT NULL, column1 INT, column2 VARCHAR);
-
將標準資料表轉換為並置資料表。
postgres=>
CALL rds_aurora.limitless_alter_table_type_sharded('public.mytable2', ARRAY['customer_id'], 'public.customer');postgres=>
\d List of relations Schema | Name | Type | Owner --------+--------------+-------------------+-------------------- public | customer | partitioned table | postgres_limitless public | customer_fs1 | foreign table | postgres_limitless public | customer_fs2 | foreign table | postgres_limitless public | customer_fs3 | foreign table | postgres_limitless public | customer_fs4 | foreign table | postgres_limitless public | customer_fs5 | foreign table | postgres_limitless public | mytable2 | partitioned table | postgres_limitless public | mytable2_fs1 | foreign table | postgres_limitless public | mytable2_fs2 | foreign table | postgres_limitless public | mytable2_fs3 | foreign table | postgres_limitless public | mytable2_fs4 | foreign table | postgres_limitless public | mytable2_fs5 | foreign table | postgres_limitless (12 rows)
建立參考資料表
您可以在標準資料表上執行 rds_aurora.limitless_alter_table_type_reference
程序來建立參考資料表。此程序會將指定的資料表複寫至資料庫碎片群組中的所有碎片,並將資料表類型變更為參考。程序會同步執行,並在資料表上取得ACCESS EXCLUSIVE
鎖定。
程序成功完成後,會刪除來源標準資料表,並可使用相同名稱的參考資料表。
程序rds_aurora.limitless_alter_table_type_reference
使用以下語法:
postgres=>
CALL rds_aurora.limitless_alter_table_type_reference('schema
.table
');
預存程序需要下列參數:
-
schema
– 包含要複寫之資料表的資料庫結構描述。如果未指定結構描述,程序會使用search_path
。 -
table
– 要複寫的資料表。
注意
您建立參考資料表的標準資料表必須具有主索引鍵。
在參考資料表中,CHECK
限制條件不支援表達式。
先前的函數 limitless_table_alter_type_reference
已棄用。
建立參考資料表
下列範例示範如何建立zipcodes
參考資料表。
-
建立標準資料表。
CREATE TABLE zipcodes (zipcode INT PRIMARY KEY, details VARCHAR);
-
將標準資料表轉換為參考資料表。
CALL rds_aurora.limitless_alter_table_type_reference('public.zipcodes');
postgres=>
\d List of relations Schema | Name | Type | Owner --------+--------------+-------------------+-------------------- public | customer | partitioned table | postgres_limitless public | customer_fs1 | foreign table | postgres_limitless public | customer_fs2 | foreign table | postgres_limitless public | customer_fs3 | foreign table | postgres_limitless public | customer_fs4 | foreign table | postgres_limitless public | customer_fs5 | foreign table | postgres_limitless public | zipcodes | foreign table | postgres_limitless (7 rows)輸出會顯示
customer
碎片資料表和zipcodes
參考資料表。