Updated on 2025-03-13 GMT+08:00

Append

Description

Append is used to append multiple relationship sets and process the linked list that contains one or more subplans.

Typical Scenarios

  • SQL statements with UNION.
  • SQL statements with UNION ALL.

Examples

Example 1: SQL statement with UNION.

-- Prepare data.
gaussdb=# DROP TABLE IF EXISTS t1;
gaussdb=# DROP TABLE IF EXISTS t2;
gaussdb=# CREATE TABLE t1(c1 number, c2 number, c3 number); 
CREATE TABLE 
gaussdb=# INSERT INTO t1 VALUES(generate_series(1, 100), 2, 3); 
INSERT 0 100 
gaussdb=# CREATE TABLE t2(c1 number, c2 number, c3 number); 
CREATE TABLE 
gaussdb=# INSERT INTO t2 VALUES(generate_series(1, 100), 2, 3); 
INSERT 0 100

-- Execution result.
gaussdb=# EXPLAIN SELECT * FROM t1 UNION SELECT * FROM t2; 
                              QUERY PLAN
-----------------------------------------------------------------------
 Streaming (type: GATHER)  (cost=28.03..28.94 rows=42 width=96)
   Node/s: All datanodes
   ->  HashAggregate  (cost=26.72..26.98 rows=42 width=96)
         Group By Key: t1.c1, t1.c2, t1.c3
         ->  Append  (cost=0.00..26.52 rows=42 width=96)
               ->  Seq Scan on t1  (cost=0.00..13.13 rows=20 width=96)
               ->  Seq Scan on t2  (cost=0.00..13.13 rows=20 width=96)
(7 rows)

Example 2: SQL statement with UNION ALL.

gaussdb=# EXPLAIN SELECT * FROM t1 UNION ALL SELECT * FROM t2; 
                              QUERY PLAN
-----------------------------------------------------------------------
 Streaming (type: GATHER)  (cost=1.62..28.70 rows=40 width=96)
   Node/s: All datanodes
   ->  Result  (cost=0.00..26.26 rows=40 width=96)
         ->  Append  (cost=0.00..26.26 rows=40 width=96)
               ->  Seq Scan on t1  (cost=0.00..13.13 rows=20 width=96)
               ->  Seq Scan on t2  (cost=0.00..13.13 rows=20 width=96)
(6 rows)

-- Drop the table.
gaussdb=# DROP TABLE t1,t2;