Updated on 2025-05-29 GMT+08:00

Result

Description

Result is used to process the condition expression (2 > 1) that needs to be calculated only once or the INSERT statement that contains only one VALUES clause. In this case, the process can be returned in advance and no subsequent operation is required.

Typical Scenarios

  • The Result node is used to optimize the query of constant condition expressions. The condition expression does not depend on the scanned data, for example, select * from t1 where 1 > 2.
  • If the SELECT statement does not contain the FROM clause or the INSERT statement contains only one VALUES clause, the executor directly calculates the projection attribute of SELECT or uses the VALUES clause to construct a tuple.

Examples

Example 1: The Result node is used to optimize the query of constant condition expressions.

-- Prepare data.
gaussdb=#DROP TABLE IF EXISTS t1;
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

-- Execution result.
gaussdb=#EXPLAIN SELECT * FROM t1 WHERE 1 > 2; 
                QUERY PLAN
------------------------------------------
 Result  (cost=0.00..0.01 rows=1 width=0)
   One-Time Filter: false
(2 rows)

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

Item

Description

Result

Operator name.

One-Time Filter

The constant expression is always false during filtering. Therefore, the expression needs to be executed only once.

Example 2: SELECT does not contain the FROM clause.

gaussdb=#EXPLAIN SELECT dbe_raw.bit_and('1','2'); 
                QUERY PLAN
------------------------------------------
 Result  (cost=0.00..0.01 rows=1 width=0)
(1 row)

Example 3: The INSERT statement contains only one VALUES clause.

gaussdb=#EXPLAIN INSERT INTO t1 VALUES(1, 2, 3); 
                   QUERY PLAN
------------------------------------------------
 Insert on t1  (cost=0.00..0.01 rows=1 width=0)
   Node/s: All datanodes
   Node expr: c1
   ->  Result  (cost=0.00..0.01 rows=1 width=0)
(4 rows)

-- Drop.
gaussdb=#DROP TABLE IF EXISTS t1;