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

  • Mastering PostgreSQL 12
  • Hans Jürgen Sch?nig
  • 263字
  • 2021-08-20 10:00:26

Using bitmap scans effectively

The question naturally arising now is, when is a bitmap scan most beneficial and when is it chosen by the optimizer? From my point of view, there are really only two use cases:

  • To avoid fetching the same block over and over again
  • To combine relatively bad conditions

The first case is quite common. Suppose you are looking for everybody who speaks a certain language. For the sake of this example, we can assume that 10% of all people speak the required language. Scanning the index would mean that a block in the table has to be scanned all over again, since many skilled speakers might be stored in the same block. By applying a bitmap scan, it is ensured that a specific block is only used once, which of course leads to better performance.

The second common use case is to use relatively weak criteria together. Let's suppose we are looking for everybody between 20 and 30 years of age owning a yellow shirt. Now, maybe 15% of all people are between 20 and 30 and maybe 15% of all people actually own a yellow shirt. Scanning a table sequentially is expensive, and so PostgreSQL might decide to choose two indexes because the final result might consist of just 1% of the data. Scanning both indexes might be cheaper than reading all of the data.

In PostgreSQL 10.0, parallel bitmap heap scans are supported. Usually, bitmap scans are used by comparatively expensive queries. Added parallelism in this area is, therefore, a huge step forward and definitely beneficial.

主站蜘蛛池模板: 格尔木市| 肇庆市| 霍城县| 克拉玛依市| 京山县| 南平市| 周宁县| 九江市| 交口县| 报价| 呼伦贝尔市| 商丘市| 安国市| 青田县| 黑河市| 禄丰县| 宝应县| 平昌县| 双辽市| 揭东县| 万盛区| 博客| 五莲县| 麦盖提县| 平舆县| 扶风县| 天全县| 班玛县| 屏东县| 抚顺县| 重庆市| 安泽县| 抚州市| 开江县| 延边| 西乌珠穆沁旗| 五指山市| 祁东县| 湖南省| 大新县| 梧州市|