[TOC] # SELECT INTO ELECT INTO 算子用于将查询结果赋值给变量列表,查询仅返回一行数据。 如下示例查询中,`SELECT`输出列为`COUNT(*)`和`MAX(c1)`,其查询结果分别赋值给变量 @a 和 @b。 ~~~ obclient>CREATE TABLE t1(c1 INT, c2 INT); Query OK, 0 rows affected (0.12 sec) obclient>INSERT INTO t1 VALUES(1,1); Query OK, 1 rows affected (0.12 sec) obclient>INSERT INTO t1 VALUES(2,2); Query OK, 1 rows affected (0.12 sec) obclient>EXPLAIN SELECT COUNT(*), MAX(c1) INTO @a, @b FROM t1\G; *************************** 1. row *************************** 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) ~~~ 上述示例中,执行计划展示中的 outputs & filters 详细列出了 SELECT INTO 算子的输出信息如下: <table data-tag="table" id="table-tv5-ot1-6ce" class="table"><colgroup span="1" width="139" data-tag="col" id="col-ij8-d3m-rjw" colwidth="1*" colnum="1" colname="col1" style="width:50%" class="col"></colgroup><colgroup span="1" width="609" data-tag="col" id="col-c3k-ijk-6jx" colwidth="1*" colnum="2" colname="col2" style="width:50%" class="col"></colgroup><thead id="thead-sw2-y9p-7qr" class="thead"><tr id="tr-obu-hf0-69k"><th id="td-est-jht-40j"><p id="p-6zk-wzn-wg8"><b>信息名称</b></p></th><th id="td-xlq-cwo-3eo"><p id="p-2q6-k8a-ity"><b>含义</b></p></th></tr></thead><tbody data-tag="tbody" id="tbody-22j-6nf-6mr" class="tbody"><tr data-tag="tr" id="tr-2f1-6wb-xbt" class="tr"><td data-tag="td" id="td-twb-05y-j5s" class="td"><p id="p-dqv-arz-q8w">output</p></td><td data-tag="td" id="td-oig-5ts-9zp" class="td"><p id="p-u42-fqd-yip">该算子赋值给变量列表的表达式。</p></td></tr><tr data-tag="tr" id="tr-o7q-v9u-rub" class="tr"><td data-tag="td" id="td-j84-b5i-lti" class="td"><p id="p-04a-fgo-6k0">filter</p></td><td data-tag="td" id="td-ei6-b7z-mkx" class="td"><p id="p-71n-19j-6be">该算子上的过滤条件。</p><p id="p-kv3-i48-90r">由于示例中 SELECT INTO 算子没有设置 filter,所以为 nil。</p></td></tr></tbody></table>