Updated on 2025-05-29 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=# 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                             
------------------------------------------------------------------ 
 HashAggregate  (cost=31.57..39.05 rows=748 width=85) 
   Group By Key: t1.c1, t1.c2, t1.c3 
   ->  Append  (cost=0.00..25.96 rows=748 width=85) 
         ->  Seq Scan on t1  (cost=0.00..2.00 rows=100 width=15) 
         ->  Seq Scan on t2  (cost=0.00..16.48 rows=648 width=96) 
(5 rows)

In the preceding example, the output of the append operator is as follows.

Item

Description

Append

Operator name.

Seq Scan on t1

Name of an operator that scans the t1 table in sequence.

Seq Scan on t2

Name of an operator that scans the t2 table in sequence.

Example 2: SQL statement with UNION ALL.

gaussdb=# EXPLAIN SELECT * FROM t1 UNION ALL SELECT * FROM t2; 
                           QUERY PLAN                             
----------------------------------------------------------------- 
 Result  (cost=0.00..4.00 rows=200 width=15) 
   ->  Append  (cost=0.00..4.00 rows=200 width=15) 
         ->  Seq Scan on t1  (cost=0.00..2.00 rows=100 width=15) 
         ->  Seq Scan on t2  (cost=0.00..2.00 rows=100 width=15) 
(4 rows)

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