TopPercent

名称

TopPercent算子

介绍

通过TopPercent算子可获取结果集中前n%的数据。

举例

--清理环境
DROP TABLE t1 CASCADE;

--创建环境
CREATE TABLE t1(a int);
INSERT INTO t1 SELECT generate_series(1,100);
ANALYZE t1;

EXPLAIN ANALYZE SELECT TOP 10 PERCENT * FROM t1 ORDER BY a DESC;
                                                QUERY PLAN
----------------------------------------------------------------------------------------------------------
 TopPercent  (cost=11.32..11.35 rows=10 width=4) (actual time=0.11..0.11 rows=10 loops=1)
   ->  Sort  (cost=11.32..11.57 rows=100 width=4) (actual time=0.05..0.05 rows=6 loops=2)
         Sort Key: A
         ->  Seq Scan on T1  (cost=0.00..8.00 rows=100 width=4) (actual time=0.01..0.04 rows=100 loops=1)
 Planning Time: 0.10 msec
 Execution Time: 0.20 msec
(6 rows)