更新时间:2026-07-28 GMT+08:00
分享

DML

HTAP通过实时事务单元TMU记录DML操作带来的增量数据变更,并维护IMCV列查询的数据新鲜度,保障列存与行存实时数据的一致性。

示例:

htapdb=# CREATE TABLE htap_test(
          id int,
          dept_id int,
          salary int,
          name varchar(20),
          comments varchar(30)) with (storage_type = ustore) DISTRIBUTE BY HASH(id);
CREATE TABLE

htapdb=# INSERT INTO htap_test VALUES (1, 1, 2000, 'Allen', 'for test');
INSERT 0 1

htapdb=# INSERT INTO htap_test VALUES (2, 2, 3000, 'Lily', 'for test');
INSERT 0 1

htapdb=# INSERT INTO htap_test VALUES (3, 2, 4000, 'Ann', 'for test');
INSERT 0 1

--加载IMCV。
htapdb=# ALTER TABLE htap_test COLVIEW;
ALTER TABLE

htapdb=# SELECT reloid, relname, dbname, username, parentoid, imcvispart, imcvnattr, imcvkey, priority FROM gs_imcv;
 reloid |  relname  | dbname | username | parentoid | imcvispart | imcvnattr |  imcvkey  | priority
--------+-----------+--------+----------+-----------+------------+-----------+-----------+----------
  17949 | htap_test | test   | dbdev    |         0 | f          |         5 | 1 2 3 4 5 |        1
(1 row)

--向表中插入新数据。
htapdb=# INSERT INTO htap_test VALUES (4, 2, 3000, 'Bob', 'for test');
INSERT 0 1

htapdb=# SET enable_stream_operator=on; 
SET

htapdb=# SET enable_fast_query_shipping=off;
SET

--生成并选择执行IMCV执行计划。
htapdb=# EXPLAIN SELECT /*+imcvscan(htap_test)*/  * FROM htap_test;
                                 QUERY PLAN                                  
-----------------------------------------------------------------------------
 Row Adapter  (cost=36.74..36.74 rows=100 width=27)
   ->  Vector Streaming (type: GATHER)  (cost=3.12..36.74 rows=100 width=27)
         Node/s: All datanodes
         ->  Imcv Scan on htap_test  (cost=0.00..32.05 rows=100 width=27)
(4 rows)

--获取IMCV查询结果,与行存数据一致。
htapdb=# SELECT /*+imcvscan(htap_test)*/  * FROM htap_test;
 id | dept_id | salary | name  | comments
----+---------+--------+-------+----------
  1 |       1 |   2000 | Allen | for test
  2 |       2 |   3000 | Lily  | for test
  3 |       2 |   4000 | Ann   | for test
  4 |       2 |   3000 | Bob   | for test
(4 rows)

htapdb=# DROP TABLE htap_test;
DROP TABLE

相关文档