投影命名

Vertica 根据以下约定标识投影,其中 proj‑basename 是由 CREATE PROJECTION 分配给此投影的名称。

未分段投影

未分段投影遵循以下命名约定:

分段投影

企业模式

在企业模式下,分段投影使用以下命名约定:

proj‑basename_boffset

此名称标识分段投影的伙伴实例投影,其中 offset 是投影相对于所有其他伙伴实例投影的节点位置。所有伙伴实例投影共享相同的投影基本名称。例如:

=> SELECT projection_basename, projection_name FROM projections WHERE anchor_table_name = 'store_orders';
 projection_basename | projection_name
---------------------+-----------------
 store_orders        | store_orders_b0
 store_orders        | store_orders_b1
(2 rows)

一个例外情况是:Vertica 使用以下约定来命名实时聚合投影:proj‑basenameproj‑basename_b1,依此类推。

Eon 模式

在 Eon 模式下,分段投影使用以下命名约定:

proj‑basename

重命名和复制的表的投影

Vertica 在以下两种情况下使用相同的逻辑重命名现有投影:

在这两种情况下,Vertica 使用以下算法重命名投影:

  1. 循环访问锚定在重命名表或新表上的所有投影,并检查其名称是否以原始表名称为前缀:

    • 否:保留投影名称

    • 是:重命名投影

  2. 如果是,比较原始表名称和投影基本名称:

    • 如果新的基本名称与原始表名称相同,则将基本名称替换为表和投影名称中的新表名称。

    • 如果新的基本名称以原始表名称为前缀,则将前缀替换为新的表名称,移除附加到旧基本名称的任何版本字符串(例如 old‑basename_v1),并使用新的基本名称生成投影名称。

  3. 检查新的投影名称是否已经存在。如果不存在,则保存它们。否则,通过根据需要将版本号附加到新的基本名称( new‑basename_v1new‑basename_v2,依此类推)来解决名称冲突。

示例

自动投影始终是超投影:

=> CREATE TABLE store.store_dimension
    store_key int NOT NULL,
    store_name varchar(64),
    ...
) UNSEGMENTED ALL NODES;
CREATE TABLE
=> COPY store.store_dim FROM '/home/dbadmin/store_dimension_data.txt';
50
=> SELECT anchor_table_name, projection_basename, projection_name FROM projections WHERE anchor_table_name = 'store_dimension';
 anchor_table_name | projection_basename |    projection_name
-------------------+---------------------+-----------------------
 store_dimension   | store_dimension     | store_dimension_super
 store_dimension   | store_dimension     | store_dimension_super
 store_dimension   | store_dimension     | store_dimension_super
(3 rows)

未分段投影名称在所有节点上都具有 _unseg 后缀:

=> CREATE TABLE store.store_dimension(     store_key int NOT NULL,        store_name varchar(64),     ... ); CREATE TABLE => CREATE PROJECTION store_dimension AS SELECT * FROM store.store_dimension UNSEGMENTED ALL NODES; WARNING 6922:  Projection name was changed to store_dimension_unseg because it conflicts with the basename of the table store_dimension CREATE PROJECTION => SELECT anchor_table_name, projection_basename, projection_name FROM projections WHERE anchor_table_name = 'store_dimension';  anchor_table_name | projection_basename |    projection_name -------------------+---------------------+-----------------------  store_dimension   | store_dimension     | store_dimension_unseg  store_dimension   | store_dimension     | store_dimension_unseg  store_dimension   | store_dimension     | store_dimension_unseg (3 rows)

以下示例创建分段表 testRenameSeg 并使用数据填充它:

=> CREATE TABLE testRenameSeg (a int, b int);
CREATE TABLE
dbadmin=> INSERT INTO testRenameSeg VALUES (1,2);
 OUTPUT
--------
      1
(1 row)

dbadmin=> COMMIT;
COMMIT

Vertica 会为此表自动创建两个伙伴实例超投影:

=> \dj testRename*
                          List of projections
 Schema |         Name          |  Owner  |       Node       | Comment
--------+-----------------------+---------+------------------+---------
 public | testRenameSeg_b0      | dbadmin |                  |
 public | testRenameSeg_b1      | dbadmin |                  |

以下 CREATE PROJECTION 语句显式为表创建额外的投影:


=> CREATE PROJECTION nameTestRenameSeg_p AS SELECT * FROM testRenameSeg;
=> CREATE PROJECTION testRenameSeg_p AS SELECT * FROM testRenameSeg;
=> CREATE PROJECTION testRenameSeg_pLap AS SELECT b, MAX(a) a FROM testRenameSeg GROUP BY b;
=> CREATE PROJECTION newTestRenameSeg AS SELECT * FROM testRenameSeg;
=> \dj *testRenameSeg*
                    List of projections
 Schema |          Name          |  Owner  | Node | Comment
--------+------------------------+---------+------+---------
 public | nameTestRenameSeg_p_b0 | dbadmin |      |
 public | nameTestRenameSeg_p_b1 | dbadmin |      |
 public | newTestRenameSeg_b0    | dbadmin |      |
 public | newTestRenameSeg_b1    | dbadmin |      |
 public | testRenameSeg_b0       | dbadmin |      |
 public | testRenameSeg_b1       | dbadmin |      |
 public | testRenameSeg_pLap     | dbadmin |      |
 public | testRenameSeg_pLap_b1  | dbadmin |      |
 public | testRenameSeg_p_b0     | dbadmin |      |
 public | testRenameSeg_p_b1     | dbadmin |      |
(10 rows)

如果重命名锚表,Vertica 还会重命名其投影:

=> ALTER TABLE testRenameSeg RENAME TO newTestRenameSeg;
ALTER TABLEn=> \dj *testRenameSeg*
                     List of projections
 Schema |           Name           |  Owner  | Node | Comment
--------+--------------------------+---------+------+---------
 public | nameTestRenameSeg_p_b0   | dbadmin |      |
 public | nameTestRenameSeg_p_b1   | dbadmin |      |
 public | newTestRenameSeg_b0      | dbadmin |      |
 public | newTestRenameSeg_b1      | dbadmin |      |
 public | newTestRenameSeg_pLap_b0 | dbadmin |      |
 public | newTestRenameSeg_pLap_b1 | dbadmin |      |
 public | newTestRenameSeg_p_b0    | dbadmin |      |
 public | newTestRenameSeg_p_b1    | dbadmin |      |
 public | newTestRenameSeg_v1_b0   | dbadmin |      |
 public | newTestRenameSeg_v1_b1   | dbadmin |      |
(10 rows)

两组伙伴实例投影未重命名,因为它们的名称不以原始表名称为前缀:

  • nameTestRenameSeg_p_b0

  • nameTestRenameSeg_p_b1

  • newTestRenameSeg_b0

  • newTestRenameSeg_b1

当重命名其他投影时,Vertica 发现表的超投影(最初是 testRenameSeg)与现有投影 newTestRenameSeg 之间存在潜在冲突。它通过将版本号 _v1_v2 附加到超投影的新名称解决了此冲突:

  • newTestRenameSeg_v1_b0

  • newTestRenameSeg_v1_b1