更新时间:2025-03-13 GMT+08:00
WindowAgg
算子说明
WindowAgg算子用于处理元组窗口聚合,WindowAgg算子与Agg算子在功能上类似,实现的模式也相似。主要的区别在于,WindowAgg算子处理的元组限定于同一个窗口内,而Agg算子处理的元组是“整个表”(GROUP BY划分)。
典型场景
查询语句中包含窗口函数,如:row_number() OVER (PARTITION BY xxx)、avg(xxx) OVER (PARTITION BY xxx)。
示例
--数据准备。 gaussdb=# DROP TABLE IF EXISTS t; gaussdb=# CREATE TABLE t(a int, b int, c int); CREATE TABLE gaussdb=# INSERT INTO t VALUES(generate_series(1, 10), generate_series(601, 610), generate_series(901, 910)); INSERT 0 10 --执行结果。 gaussdb=# EXPLAIN SELECT a, avg(b) OVER(partition by a) FROM t; QUERY PLAN --------------------------------------------------------------------- Streaming (type: GATHER) (cost=14.18..14.82 rows=21 width=8) Node/s: All datanodes -> WindowAgg (cost=13.37..13.60 rows=21 width=8) -> Sort (cost=13.37..13.40 rows=21 width=8) Sort Key: a -> Seq Scan on t (cost=0.00..13.13 rows=20 width=8) (6 rows) --删除。 gaussdb=# DROP TABLE IF EXISTS t;
父主题: 运算符