The SEQUENCE operator calculates the value of the pseudo-column SEQUENCE.
The pseudo-column SEQUENCE is a sequence created by CREATE SEQUENCE. The calculation is performed each time a row is output by the underlying operator.
Example: Calculate the current and next values of the pseudo-column SEQUENCE
obclient> CREATE TABLE t1(c1 INT, c2 INT);
Query OK, 0 rows affected
obclient> CREATE TABLE t2(c1 INT, c2 INT);
Query OK, 0 rows affected
obclient> CREATE SEQUENCE seq INCREMENT BY 1 START WITH 1;
Query OK, 0 rows affected
obclient> EXPLAIN SELECT seq.NEXTVAL, seq.CURRVAL FROM t1;
Query Plan:
=====================================
|ID|OPERATOR |NAME|EST. ROWS|COST |
-------------------------------------
|0 |SEQUENCE | |100000 |77868|
|1 | TABLE SCAN|T1 |100000 |64066|
=====================================
Outputs & filters:
-------------------------------------
0 - output([SEQ.NEXTVAL], [SEQ.CURRVAL]), filter(nil)
1 - output([T1.__pk_increment]), filter(nil),
access([T1.__pk_increment]), partitions(p0)
In the preceding example, operator 0 SEQUENCE in the execution plan is used to calculate the sequence values. output([SEQ.NEXTVAL], [SEQ.CURRVAL]) specifies that SEQUENCE needs to calculate the current and next values of the sequence. Each time table t1 outputs a row of data, SEQUENCE calculates the sequence value once. The outputs & filters section of the execution plan shows the output information of the SEQUENCE operator as follows:
Information name |
Description |
|---|---|
| output | The output columns of this operator. The SEQUENCE operator parameters are as follows:
|
| filter | The filter condition of this operator. In the example, no filter is set for the SEQUENCE operator, so the value is nil. |