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

Execution Plans

The following SQL statement is used as an example:

1
2
3
4
5
gaussdb=# DROP TABLE IF EXISTS t1;
gaussdb=# DROP TABLE IF EXISTS t2;
gaussdb=# CREATE TABLE t1 (c1 int, c2 int);
gaussdb=# CREATE TABLE t2 (c1 int, c2 int);
gaussdb=# SET explain_perf_mode = pretty;
Run the EXPLAIN command and the output is as follows:
gaussdb=# EXPLAIN SELECT * FROM t1,t2 WHERE t1.c1 = t2.c2;
                            QUERY PLAN                             
-------------------------------------------------------------------
 Hash Join  (cost=23.73..341.30 rows=16217 width=180)
   Hash Cond: (t1.c1 = t2.c2)
   ->  Seq Scan on t1  (cost=0.00..122.17 rows=5317 width=76)
   ->  Hash  (cost=16.10..16.10 rows=610 width=104)
         ->  Seq Scan on t2  (cost=0.00..16.10 rows=610 width=104)
(5 rows)

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

Interpretation of the execution plan layers (vertical):

  • Layer 1: Seq Scan on t2

    The table scan operator scans the table t2 using Seq Scan. At this layer, data in the table t2 is read from a buffer or disk, and then transferred to the upper-layer node for calculation.

  • Layer 2: Hash

    Hash operator. It is used to calculate the hash value of the operator transferred from the lower layer for subsequent hash join operations.

  • Layer 3: Seq Scan on t1

    The table scan operator scans the table t1 using Seq Scan. At this layer, data in the table t1 is read from a buffer or disk, and then transferred to the upper-layer node for hash join calculation.

  • Layer 4: Hash Join

    Join operator. It is used to join data in the t1 and t2 tables using the hash join method and output the result data.