The SELECT INTO operator is used to assign the query result to a list of variables. The query returns only one row of data.
In the following example query, the output columns of SELECT are COUNT(*) and MAX(c1). Their query results are assigned to variables @a and @b respectively.
obclient> CREATE TABLE t1(c1 INT, c2 INT);
Query OK, 0 rows affected
obclient> INSERT INTO t1 VALUES(1,1);
Query OK, 1 rows affected
obclient> INSERT INTO t1 VALUES(2,2);
Query OK, 1 rows affected
obclient> EXPLAIN SELECT COUNT(*), MAX(c1) INTO @a, @b FROM t1;
Query Plan:
=========================================
|ID|OPERATOR |NAME|EST. ROWS|COST|
-----------------------------------------
|0 |SELECT INTO | |0 |37 |
|1 | SCALAR GROUP BY| |1 |37 |
|2 | TABLE SCAN |t1 |2 |37 |
=========================================
Outputs & filters:
-------------------------------------
0 - output([T_FUN_COUNT(*)], [T_FUN_MAX(t1.c1)]), filter(nil)
1 - output([T_FUN_COUNT(*)], [T_FUN_MAX(t1.c1)]), filter(nil),
group(nil), agg_func([T_FUN_COUNT(*)], [T_FUN_MAX(t1.c1)])
2 - output([t1.c1]), filter(nil),
access([t1.c1]), partitions(p0)
In the preceding example, the outputs & filters section of the execution plan shows the output information of the SELECT INTO operator as follows:
Information name |
Description |
|---|---|
| output | The expressions assigned to a list of variables by this operator. |
| filter | The filter predicate of this operator. In the example, no filter is set for the SELECT INTO operator, so the value is nil. |