官术网_书友最值得收藏!

  • Mastering PostgreSQL 10
  • Hans Jürgen Sch?nig
  • 150字
  • 2021-06-30 19:04:01

Investigating performance

Grouping sets is a powerful feature; they help to reduce the number of expensive queries. Internally, PostgreSQL will basically turn to traditional GroupAggregates to make things work. A GroupAggregate node requires sorted data, so be prepared that PostgreSQL might do a lot of temporary sorting:

test=# explain SELECT region, country, avg(production) 
FROM t_oil
WHERE country IN ('USA', 'Canada', 'Iran', 'Oman')
GROUP BY GROUPING SETS ( (), region, country);
QUERY PLAN
---------------------------------------------------------------
GroupAggregate (cost=22.58..32.69 rows=34 width=52)
Group Key: region
Group Key: ()
Sort Key: country
Group Key: country
-> Sort (cost=22.58..23.04 rows=184 width=24)
Sort Key: region
-> Seq Scan on t_oil
(cost=0.00..15.66 rows=184 width=24)
              Filter: (country = ANY 
('{USA,Canada,Iran,Oman}'::text[]))
(9 rows)

In PostgreSQL, hash aggregates are only supported for normal GROUP BY clauses involving no grouping sets. In PostgreSQL 10.0, the planner already has more options than in PostgreSQL 9.6. Expect grouping sets to be faster in the new version.

主站蜘蛛池模板: 宣威市| 绿春县| 沂南县| 建平县| 六盘水市| 靖江市| 婺源县| 新安县| 长泰县| 彭泽县| 双辽市| 灵石县| 古蔺县| 竹山县| 大姚县| 逊克县| 磴口县| 乡城县| 丰台区| 南岸区| 铜山县| 神池县| 德清县| 辉县市| 徐州市| 新宾| 乌海市| 昭平县| 沙洋县| 伊金霍洛旗| 湾仔区| 巴马| 巫溪县| 淮北市| 都匀市| 白朗县| 永吉县| 林州市| 宁乡县| 汤阴县| 黔江区|